class AGTkObjPlace

Attributes

h0[R]
height[RW]
motion[RW]
obj[R]
r[RW]
relheight[RW]
relwidth[RW]
start_x[RW]
start_y[RW]
w0[R]
width[RW]
x0[R]
y0[R]

Public Class Methods

new(_obj=nil , _side='both' , _cursor=nil, _bind = true ) click to toggle source
# File lib/a-tkcommons.rb, line 161
def initialize(_obj=nil , _side='both' , _cursor=nil, _bind = true )
  if !_obj
    return
  end
  @obj = _obj
  if !_cursor
    case _side
    when 'x'
      _cursor = 'sb_h_double_arrow'
    when 'y'
      _cursor = 'sb_v_double_arrow'
    when 'both'
      _cursor = 'draft_small'
    end
  end
  @motion = false
  @side = _side
  @x0 = TkPlace.info(@obj)['x']
  @y0 = TkPlace.info(@obj)['y']
  if TkWinfo.mapped?(@obj)
    @w0=TkWinfo.width(@obj)
    @h0=TkWinfo.height(@obj)
  else
    @w0=TkWinfo.reqwidth(@obj)
    @h0=TkWinfo.reqheight(@obj)
  end
  @start_x = @x0
  @start_y = @y0
  @cursor = _cursor
  if _bind
    @obj.bind_append("Enter", proc{|x, y| do_enter(x, y)}, "%x %y")
    @obj.bind_append("ButtonPress-1", proc{|x, y| do_press(x,y)}, "%x %y")
    @obj.bind_append("B1-Motion", proc{|x, y| do_motion(x,y)},"%x %y")
  end
end

Public Instance Methods

amove(_x,_y) click to toggle source
# File lib/a-tkcommons.rb, line 247
def amove(_x,_y)
  move(_x - @x0 , _y - @y0)
end
do_enter(x, y) click to toggle source
# File lib/a-tkcommons.rb, line 213
def do_enter(x, y)
  @oldcursor = @obj.cget('cursor')
  @obj.configure('cursor'=> @cursor)
end
do_leave() click to toggle source
# File lib/a-tkcommons.rb, line 218
def do_leave
  @obj.configure('cursor'=>@oldcursor)
end
do_motion( _x, _y) click to toggle source
# File lib/a-tkcommons.rb, line 227
def do_motion( _x, _y)
  @motion = true
  move(_x - @start_x, _y - @start_y)
end
do_press(x, y) click to toggle source
# File lib/a-tkcommons.rb, line 222
def do_press(x, y)
  @start_x = x
  @start_y = y
end
go(_w, _h) click to toggle source
# File lib/a-tkcommons.rb, line 251
def go(_w, _h)
  case @side
  when 'x'
    @w0 = _w
    @obj.place('width' => @w0, 'height'=>@height, 'relwidth'=>@relwidth, 'relheight'=>@relheight)
  when 'y'
    @h0 = _h
    @obj.place('height' => @h0, 'width' => @width, 'relwidth'=>@relwidth, 'relheight'=>@relheight)
  end
end
h() click to toggle source
# File lib/a-tkcommons.rb, line 205
def h
  if TkWinfo.mapped?(@obj)
    @h0= TkWinfo.height(@obj)
  else
    @h0= TkWinfo.reqheight(@obj)
  end
end
move(_x,_y) click to toggle source
# File lib/a-tkcommons.rb, line 232
def move(_x,_y)
  case @side
  when 'both'
    @x0 = @x0 + _x  if (@x0 + _x) >= 0
    @y0 = @y0 + _y
    @obj.place('x' => @x0, 'y' => @y0, 'width' => @width, 'height'=>@height, 'relwidth'=>@relwidth, 'relheight'=>@relheight)
  when 'x'
    @x0 = @x0 + _x  if (@x0 + _x) >= 0
    @obj.place('x' => @x0, 'width' => @width, 'height'=>@height, 'relwidth'=>@relwidth, 'relheight'=>@relheight)
  when 'y'
    @y0 = @y0 + _y
    @obj.place('y' => @y0, 'width' => @width, 'height'=>@height, 'relwidth'=>@relwidth, 'relheight'=>@relheight)
  end
end
w() click to toggle source
# File lib/a-tkcommons.rb, line 197
def w
  if TkWinfo.mapped?(@obj)
    @w0= TkWinfo.width(@obj)
  else
    @w0= TkWinfo.reqwidth(@obj)
  end
end