Class: AGTkPlaceManager

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

Instance Method Summary collapse

Constructor Details

#initialize(_agobj, _active = false) ⇒ AGTkPlaceManager

Returns a new instance of AGTkPlaceManager.



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 108

def initialize(_agobj, _active=false)
  #Tk.messageBox('message'=>_active.to_s)
  unless defined? _agobj.ag_parent
    return
  end
  @agobj = _agobj
  if !defined? @@place_managers
    @@place_managers = Array.new
  end
  if @agobj.ag_parent != nil
    @top = @agobj.ag_parent
    while @top.l_manager.simple_manager == nil
      @top = @top.ag_parent
    end
  end
  initx0x3
  flash
  obj_bind
  activate if _active
  object_inspector_select if _active
  @active = _active
  @last_layout = @agobj.props['layout_man']['manager']['get'].call
  @@place_managers << self
  @cursor = 'fleur'
end

Instance Method Details

#activate(free = true) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 273

def activate(free=true)
  if free
    @@place_managers.each do |value|
      value.deactivate
    end
  else
    self.free_rect
  end
  _layout = @agobj.props['layout_man']['manager']['get'].call
  _bind = _layout == 'place'
  if	_bind && @last_layout != 'place'
    @agobj.obj.place('x'=> @ox0,'y'=> @oy0)
  end
  create_rect(_bind)
  @last_layout = _layout
  @active = true
end

#active?Boolean

Returns:

  • (Boolean)


291
292
293
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 291

def active?
  return @active
end

#borderObject



425
426
427
428
429
430
431
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 425

def border
  @l1.delete if defined? @l1
  @l1 = TkcLine.new(@agobj.ag_parent.canvas, @ox0, @oy0, @ox3,@oy0, @ox3,@oy3, @ox0 , @oy3, @ox0, @oy0){
    fill 'red'
    width 0.2
  }
end

#create_rect(_bind = true) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 295

def create_rect(_bind = true)
  _L = 6
  _mx = 0
  _my = 0

  # r1         r14       r4
  # r12                  r34
  # r2         r23       r3

  _x0_RectLeft = @x0 - _L - _mx
  _x3_RectLeft = @x3  + _mx
  _x14_RectLeft = (@x3 + @x0)/2 - _L/2
  _y0_RectLeft = @y0 - _L - _my
  _y3_RectLeft = @y3  + _my
  _y12_RectLeft = (@y3 + @y0 - _L)/2

  @r1 = AGTkObjRect.new(@agobj.ag_parent.obj, _x0_RectLeft,  _y0_RectLeft, _L,  _L,'both',
  'top_left_corner',_bind)
  @r12 = AGTkObjRect.new(@agobj.ag_parent.obj, _x0_RectLeft,  _y12_RectLeft, _L,  _L,
  'x', 'sb_h_double_arrow',_bind)
  @r2 = AGTkObjRect.new(@agobj.ag_parent.obj, _x0_RectLeft, _y3_RectLeft, _L,  _L,'both', 'bottom_left_corner',_bind)
  @r3 = AGTkObjRect.new(@agobj.ag_parent.obj,_x3_RectLeft,  _y3_RectLeft, _L,  _L,'both','bottom_right_corner',_bind)
  @r34 = AGTkObjRect.new(@agobj.ag_parent.obj, _x3_RectLeft,  _y12_RectLeft, _L,   _L, 'x', 'sb_h_double_arrow',_bind)
  @r4 = AGTkObjRect.new(@agobj.ag_parent.obj,_x3_RectLeft, _y0_RectLeft, _L,  _L,'both', 'top_right_corner',_bind)
  @r14 = AGTkObjRect.new(@agobj.ag_parent.obj, _x14_RectLeft, _y0_RectLeft, _L, _L,'y', 'sb_v_double_arrow',_bind)
  @r23 = AGTkObjRect.new(@agobj.ag_parent.obj, _x14_RectLeft, _y3_RectLeft, _L,  _L,'y', 'sb_v_double_arrow',_bind)
  if _bind
    @r1.r.bind("ButtonRelease-1", proc{do_Release(@r1)})
    @r1.r.bind_append("B1-Motion",proc{geomvar(@r1)})
    @r12.r.bind("ButtonRelease-1", proc{do_Release(@r12)})
    @r12.r.bind_append("B1-Motion",proc{geomvar(@r12)})
    @r2.r.bind("ButtonRelease-1", proc{do_Release(@r2)})
    @r2.r.bind_append("B1-Motion",proc{geomvar(@r2)})
    @r3.r.bind("ButtonRelease-1", proc{do_Release(@r3)})
    @r3.r.bind_append("B1-Motion",proc{geomvar(@r3)})
    @r34.r.bind("ButtonRelease-1", proc{do_Release(@r34)})
    @r34.r.bind_append("B1-Motion",proc{geomvar(@r34)})
    @r4.r.bind("ButtonRelease-1", proc{do_Release(@r4)})
    @r4.r.bind_append("B1-Motion",proc{geomvar(@r4)})
    @r14.r.bind("ButtonRelease-1", proc{do_Release(@r14)})
    @r14.r.bind_append("B1-Motion",proc{geomvar(@r14)})
    @r23.r.bind("ButtonRelease-1", proc{do_Release(@r23)})
    @r23.r.bind_append("B1-Motion",proc{geomvar(@r23)})

    @r1.r.bind_append("ButtonPress-1", proc{@r1.r.callback_break})
    @r12.r.bind_append("ButtonPress-1", proc{@r12.r.callback_break})
    @r2.r.bind_append("ButtonPress-1", proc{@r2.r..callback_break})
    @r3.r.bind_append("ButtonPress-1", proc{@r3.r.callback_break})
    @r34.r.bind_append("ButtonPress-1", proc{@r34.r.callback_break})
    @r4.r.bind_append("ButtonPress-1", proc{@r4.r.callback_break})
    @r14.r.bind_append("ButtonPress-1", proc{@r14.r.callback_break})
    @r23.r.bind_append("ButtonPress-1", proc{@r23.r.callback_break})
  end
  flash
end

#deactivateObject



253
254
255
256
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 253

def deactivate
  self.free_rect
  @active = false
end

#do_enter_obj(x, y) ⇒ Object



160
161
162
163
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 160

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

#do_leave_objObject



165
166
167
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 165

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

#do_mov_obj(x, y) ⇒ Object



169
170
171
172
173
174
175
176
177
178
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 169

def do_mov_obj(x,y)
  x00 = @x0
  y00 = @y0
  @x0 = @x0 + x - @start_x
  @y0 = @y0 + y - @start_y
  @agobj.obj.place('x'=>@x0, 'y'=>@y0)
  @x3 = @x3 + @x0 - x00
  @y3 = @y3 + @y0 - y00
  move_other_obj(@x0 - x00,@y0 - y00)
end

#do_mov_obj_delta(_delta_x = 1, _delta_y = 1) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 180

def do_mov_obj_delta(_delta_x=1, _delta_y=1)
  x00 = @x0
  y00 = @y0
  @x0 = @x0 + _delta_x
  #@agobj.update_property('place', 'x', @x0)
  @y0 = @y0 + _delta_y
  #@agobj.update_property('place', 'y', @y0)
  @agobj.obj.place('x'=>@x0, 'y'=>@y0)
  @x3 = @x3 + @x0 - x00
  @y3 = @y3 + @y0 - y00
end

#do_mov_obj_delta_dim(_delta_width = 1, _delta_height = 1) ⇒ Object



192
193
194
195
196
197
198
199
200
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 192

def do_mov_obj_delta_dim(_delta_width=1, _delta_height=1)
  _width = @x3 - @x0 + _delta_width
  _height = @y3 - @y0 + _delta_height
  #@agobj.update_property('place', 'width', _width)
  #@agobj.update_property('place', 'height', _height)
  @agobj.obj.place('width'=>_width, 'height'=>_height)
  @x3 = @x0 + _width
  @y3 = @y0 + _height
end

#do_press_obj(x, y) ⇒ Object



207
208
209
210
211
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 207

def do_press_obj(x, y)
  @start_x = x
  @start_y = y
  object_inspector_select
end

#do_Release(_r) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 474

def do_Release(_r)
  # r1         r14       r4
  # r12                  r34
  # r2         r23       r3
  if _r.motion
    case _r
    when @r1
      w = @ox3 - @ox0
      h = @oy3 - @oy0
      @agobj.update_property(@agobj, 'place', 'x', @ox0) if @ox0 != @x0
      @agobj.update_property(@agobj, 'place', 'y', @oy0) if @oy0 != @y0
      @agobj.update_property(@agobj, 'place', 'width', w) if w != @x3 - @x0
      @agobj.update_property(@agobj, 'place', 'height', h) if h != @y3 - @y0
    when @r12
      w = @ox3 - @ox0
      @agobj.update_property(@agobj, 'place', 'x', @ox0) if @ox0 != @x0
      @agobj.update_property(@agobj, 'place', 'width', w) if w != @x3 - @x0
    when @r2
      w = @ox3 - @ox0
      h = @oy3 - @oy0
      @agobj.update_property(@agobj, 'place', 'x', @ox0) if @ox0 != @x0
      @agobj.update_property(@agobj, 'place', 'width', w) if w != @x3 - @x0
      @agobj.update_property(@agobj, 'place', 'height', h) if h != @y3 - @y0
    when @r23
      h = @oy3 - @oy0
      @agobj.update_property(@agobj, 'place', 'height', h) if h != @y3 - @y0
    when @r3
      w = @ox3 - @ox0
      h = @oy3 - @oy0
      @agobj.update_property(@agobj, 'place', 'width', w) if w != @x3 - @x0
      @agobj.update_property(@agobj, 'place', 'height', h) if h != @y3 - @y0
    when @r34
      w = @ox3 - @ox0
      @agobj.update_property(@agobj, 'place', 'width', w) if w != @x3 - @x0
    when @r4
      w = @ox3 - @ox0
      h = @oy3 - @oy0

      @agobj.update_property(@agobj, 'place', 'y', @oy0) if @oy0 != @y0
      @agobj.update_property(@agobj, 'place', 'width', w) if w != @x3 - @x0
      @agobj.update_property(@agobj, 'place', 'height', h) if h != @y3 - @y0
    when @r14
      h = @oy3 - @oy0
      @agobj.update_property(@agobj, 'place', 'y', @oy0) if @oy0 != @y0
      @agobj.update_property(@agobj, 'place', 'height', h) if h != @y3 - @y0

    end
    @x0 = @ox0
    @y0 = @oy0
    @x3 = @ox3
    @y3 = @oy3
    @l1.delete if defined? @l1
    _r.motion = false
  end
end

#do_release_obj(x, y) ⇒ Object



155
156
157
158
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 155

def do_release_obj(x,y)
   @agobj.update_property(@agobj, 'place', 'x', @x0)
   @agobj.update_property(@agobj, 'place', 'y', @y0)
end

#do_start(_r) ⇒ Object



385
386
387
388
389
390
391
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 385

def do_start(_r)
  case _r
  when @r3
    @r4.start_x = _r.start_x
    @r2.start_y = _r.start_y
  end
end

#flashObject



351
352
353
354
355
356
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 351

def flash
  @ox0 = @x0
  @ox3 = @x3
  @oy0 = @y0
  @oy3 = @y3
end

#free_rectObject



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 358

def free_rect
  if defined? @r1
    @r1.r.destroy
  end
  if defined? @r2
    @r2.r.destroy
  end
  if defined? @r3
    @r3.r.destroy
  end
  if defined? @r4
    @r4.r.destroy
  end
  if defined? @r14
    @r14.r.destroy
  end
  if defined? @r23
    @r23.r.destroy
  end
  if defined? @r12
    @r12.r.destroy
  end
  if defined? @r34
    @r34.r.destroy
  end
end

#geomvar(_r) ⇒ Object



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 433

def geomvar(_r)
  # r1         r14       r4
  # r12                  r34
  # r2         r23       r3
  case _r
  when @r1
    w = @ox3 - @r1.x0 - @r1.w0
    h = @oy3 - @r1.y0 - @r1.h0
    @ox0 = @ox3 - w
    @oy0 = @oy3 - h
  when @r12
    w = @ox3 - @r12.x0 - @r12.w0
    @ox0 = @ox3 - w
  when @r2
    w = @ox3 - @r2.x0 - @r2.w0
    h = @r2.y0 - @oy0
    @ox0 = @ox3 - w
    @oy3 = @oy0 + h
  when @r23
    h = @r23.y0 - @oy0
    @oy3 = @oy0 + h
  when @r3
    w = @r3.x0  - @ox0
    h = @r3.y0  - @oy0
    @ox3 = @ox0 + w
    @oy3 = @oy0 + h
  when @r34
    w = @r34.x0  - @ox0
    @ox3 = @ox0 + w
  when @r4
    w = @r4.x0  - @ox0
    h = @oy3 - @r4.y0 - @r4.h0
    @oy0 = @oy3 - h
    @ox3 = @ox0 + w
  when @r14
    h = @oy3 - @r14.y0 - @r14.h0
    @oy0 = @oy3 - h
  end
  resize_rect(@ox0, @oy0 , @ox3, @oy3, _r)
end

#getx0x3Object



213
214
215
216
217
218
219
220
221
222
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 213

def getx0x3
  @agobj.props['place']['x']['value'] = @agobj.props['place']['x']['get'].call.to_i
  @agobj.props['place']['y']['value'] = @agobj.props['place']['y']['get'].call.to_i
  @agobj.props['place']['width']['value'] = @agobj.props['place']['width']['get'].call.to_i
  @agobj.props['place']['height']['value'] = @agobj.props['place']['height']['get'].call.to_i
  @x0 = @agobj.props['place']['x']['value']
  @y0 = @agobj.props['place']['y']['value']
  @x3 = @x0 + @agobj.props['place']['width']['value']
  @y3 = @y0 + @agobj.props['place']['height']['value']
end

#initx0x3(_prop = nil, _value = nil) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 224

def initx0x3(_prop = nil, _value = nil)
  case _prop
  when 'x'
    _x = @x0
    @x0 = _value.to_i
    @x3 = @x3 + @x0 - _x
  when 'y'
    _y = @y0
    @y0 = _value.to_i
    @y3 = @y3 + @y0 - _y
  when 'width'
    @x3 = @x0 + _value.to_i
  when 'height'
    @y3 = @y0 + _value.to_i
  when nil, 'text'
    getx0x3
  end
  @start_x = @x0 if defined? @x0
  @start_y = @y0 if defined? @y0
end

#move_other_obj(x, y) ⇒ Object



245
246
247
248
249
250
251
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 245

def move_other_obj(x,y)
  @@place_managers.each do |value|
    if (value != self)&&(value.active?)
      value.do_mov_obj_delta(x,y)
    end
  end
end

#move_rect(x, y) ⇒ Object



530
531
532
533
534
535
536
537
538
539
540
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 530

def move_rect(x,y)
  @r1.move(x,y) if defined? @r1
  @r2.move(x,y) if defined? @r2
  @r3.move(x,y) if defined? @r3
  @r4.move(x,y) if defined? @r4
  @r14.move(x,y) if defined? @r14
  @ox0 = @agobj.x0
  @ox3 = @agobj.x3
  @oy0 = @agobj.y0
  @oy3 = @agobj.y3
end

#obj_bindObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 134

def obj_bind
  if (@agobj.ag_parent != nil)
    @agobj.obj.bind_append("ButtonPress-1", proc{|e| do_press_obj(e.x, e.y);@agobj.obj.callback_break})
    @agobj.obj.bind_append("ButtonRelease-1", proc{|e| do_release_obj(e.x, e.y)})
    @agobj.obj.bind("B1-Motion", proc{|x, y| do_mov_obj(x,y)},"%x %y")
    @agobj.obj.bind("Control-ButtonPress-1", proc{
      if active?
        deactivate
      else
        activate(false)
      end
      #do_bypass_parent_bind
    })
    @agobj.obj.bind("Control-ButtonRelease-1", proc{})
    if @agobj.obj.configure('cursor') != nil
      @agobj.obj.bind_append("Enter", proc{|x, y| do_enter_obj(x, y)}, "%x %y" )
      @agobj.obj.bind_append("Leave", proc{do_leave_obj})
    end
  end
end

#object_inspector_selectObject



202
203
204
205
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 202

def object_inspector_select
  @agobj.select
  #@agobj.object_inspector.select(@agobj, false) if !defined? @agobj.object_inspector.active_object or @agobj.object_inspector.active_object != @agobj
end

#refreshObject



266
267
268
269
270
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 266

def refresh
  Tk.update
  getx0x3
   activate(false)
end

#refresh_activeObject



258
259
260
261
262
263
264
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 258

def refresh_active
  @@place_managers.each do |value|
    if  value.active?
      value.refresh
    end
  end
end

#resize_rect(_x0, _y0, _x3, _y3, _r) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 393

def resize_rect(_x0,_y0, _x3,_y3, _r)
  # r1         r14       r4
  # r12                  r34
  # r2         r23       r3
  if defined? _r
    if _r != @r1
      @r1.r.place('x' =>_x0 - @r1.w0 , 'y' => _y0 - @r1.h0)
    end
    if _r != @r2
      @r2.r.place('x' =>_x0 - @r2.w0, 'y' => _y3)
    end
    if _r != @r3
      @r3.r.place('x' =>_x3, 'y' => _y3)
    end
    if _r != @r4
      @r4.r.place('x' =>_x3, 'y' => _y0  - @r4.h0)
    end
    if _r != @r14
      @r14.r.place('x' => (_x3 +_x0 - @r14.w0)/2, 'y' => _y0  - @r14.h0)
    end
    if _r != @r23
      @r23.r.place('x' => (_x3 +_x0 - @r23.w0)/2, 'y' => _y3)
    end
    if _r != @r12
      @r12.r.place('x' => _x0 - @r12.w0, 'y' => (_y3  + _y0 - @r12.w0)/2)
    end
    if _r != @r34
      @r34.r.place('x' => _x3 , 'y' => (_y3  + _y0 - @r34.w0)/2)
    end
  end
end