Class: AGTkObjRect

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-rad/lib/tk/al-tk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_parent, _x0, _y0, _w0, _h0, _side, _cursor, _bind = true) ⇒ AGTkObjRect

Returns a new instance of AGTkObjRect.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 16

def initialize(_parent, _x0, _y0, _w0 , _h0, _side , _cursor, _bind = true )
  if _bind
    _bc = 'white'
  else
    _bc = 'red'
  end
  @r = TkLabel.new(_parent){
    background _bc
    highlightbackground 'black'
    relief 'groove'
    place('x' => _x0 , 'y' => _y0, 'width' => _w0, 'height' => _h0)
  }
  @motion = false
  @side = _side
  @x0 = _x0
  @y0 = _y0
  @w0 = _w0
  @h0 = _h0
  @start_x = _x0
  @start_y = _y0
  @cursor = _cursor
  if _bind
    @r.bind("Enter", proc{|x, y| do_enter(x, y)}, "%x %y")
    @r.bind("ButtonPress-1", proc{|e| do_press(e.x, e.y)})
    @r.bind("B1-Motion", proc{|x, y| do_motion(x,y)},"%x %y")
  end
end

Instance Attribute Details

#h0Object (readonly)

Returns the value of attribute h0.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def h0
  @h0
end

#motionObject

Returns the value of attribute motion.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def motion
  @motion
end

#rObject

Returns the value of attribute r.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def r
  @r
end

#start_xObject

Returns the value of attribute start_x.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def start_x
  @start_x
end

#start_yObject

Returns the value of attribute start_y.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def start_y
  @start_y
end

#w0Object (readonly)

Returns the value of attribute w0.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def w0
  @w0
end

#x0Object (readonly)

Returns the value of attribute x0.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def x0
  @x0
end

#y0Object (readonly)

Returns the value of attribute y0.



14
15
16
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 14

def y0
  @y0
end

Instance Method Details

#do_enter(x, y) ⇒ Object



44
45
46
47
48
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 44

def do_enter(x, y)
  @oldcursor = @r.cget('cursor')
  @r.configure('cursor'=> @cursor)
  
end

#do_leaveObject



50
51
52
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 50

def do_leave
  @r.configure('cursor'=>@oldcursor)
end

#do_motion(x, y) ⇒ Object



59
60
61
62
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 59

def do_motion( x, y)
  @motion = true
  move(x - @start_x, y - @start_y)
end

#do_press(x, y) ⇒ Object



54
55
56
57
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 54

def do_press(x, y)
  @start_x = x
  @start_y = y
end

#move(_x, _y) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 64

def move(_x,_y)
  case @side
  when 'both'
    @x0 = @x0 + _x
    @y0 = @y0 + _y
    @r.place('x' => @x0, 'y' => @y0)
  when 'x'
    @x0 = @x0 + _x
    @r.place('x' => @x0)
  when 'y'
    @y0 = @y0 + _y
    @r.place('y' => @y0)
  end
end