Class: AGTkObjPlace

Inherits:
Object
  • Object
show all
Defined in:
lib/a-tkcommons.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_obj = nil, _side = 'both', _cursor = nil, _bind = true) ⇒ AGTkObjPlace

Returns a new instance of AGTkObjPlace.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# 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

Instance Attribute Details

#h0Object (readonly)

Returns the value of attribute h0.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def h0
  @h0
end

#heightObject

Returns the value of attribute height.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def height
  @height
end

#motionObject

Returns the value of attribute motion.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def motion
  @motion
end

#objObject (readonly)

Returns the value of attribute obj.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def obj
  @obj
end

#rObject

Returns the value of attribute r.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def r
  @r
end

#relheightObject

Returns the value of attribute relheight.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def relheight
  @relheight
end

#relwidthObject

Returns the value of attribute relwidth.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def relwidth
  @relwidth
end

#start_xObject

Returns the value of attribute start_x.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def start_x
  @start_x
end

#start_yObject

Returns the value of attribute start_y.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def start_y
  @start_y
end

#w0Object (readonly)

Returns the value of attribute w0.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def w0
  @w0
end

#widthObject

Returns the value of attribute width.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def width
  @width
end

#x0Object (readonly)

Returns the value of attribute x0.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def x0
  @x0
end

#y0Object (readonly)

Returns the value of attribute y0.



158
159
160
# File 'lib/a-tkcommons.rb', line 158

def y0
  @y0
end

Instance Method Details

#amove(_x, _y) ⇒ Object



247
248
249
# File 'lib/a-tkcommons.rb', line 247

def amove(_x,_y)
  move(_x - @x0 , _y - @y0)
end

#do_enter(x, y) ⇒ Object



213
214
215
216
# File 'lib/a-tkcommons.rb', line 213

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

#do_leaveObject



218
219
220
# File 'lib/a-tkcommons.rb', line 218

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

#do_motion(_x, _y) ⇒ Object



227
228
229
230
# 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) ⇒ Object



222
223
224
225
# File 'lib/a-tkcommons.rb', line 222

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

#go(_w, _h) ⇒ Object



251
252
253
254
255
256
257
258
259
260
# 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

#hObject



205
206
207
208
209
210
211
# 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) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
# 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

#wObject



197
198
199
200
201
202
203
# File 'lib/a-tkcommons.rb', line 197

def w
  if TkWinfo.mapped?(@obj)
    @w0= TkWinfo.width(@obj)
  else
    @w0= TkWinfo.reqwidth(@obj)
  end
end