glimmer-dsl-swt 4.24.0.1 → 4.24.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,35 +22,86 @@
22
22
  require 'glimmer-dsl-swt'
23
23
 
24
24
  class HelloCanvasDataBinding
25
- include Glimmer::GUI::CustomWindow # alias for Glimmer::UI::CustomShell
26
-
27
- CANVAS_WIDTH = 300
28
- CANVAS_HEIGHT = 300
25
+ class PathShape
26
+ attr_accessor :foreground_red, :foreground_green, :foreground_blue, :line_width_value, :line_style_value
27
+
28
+ def foreground_value
29
+ [foreground_red, foreground_green, foreground_blue]
30
+ end
31
+
32
+ def line_style_value_options
33
+ [:solid, :dash, :dot, :dashdot, :dashdotdot]
34
+ end
35
+ end
29
36
 
30
- attr_accessor :x1_value, :y1_value, :x2_value, :y2_value, :foreground_red, :foreground_green, :foreground_blue, :line_width_value, :line_style_value
37
+ class LinePathShape < PathShape
38
+ attr_accessor :x1_value, :y1_value, :x2_value, :y2_value
39
+ end
31
40
 
32
- def foreground_value
33
- rgb(foreground_red, foreground_green, foreground_blue)
41
+ class QuadPathShape < PathShape
42
+ attr_accessor :x1_value, :y1_value, :cx_value, :cy_value, :x2_value, :y2_value
43
+
44
+ def point_array
45
+ [x1_value, y1_value, cx_value, cy_value, x2_value, y2_value]
46
+ end
34
47
  end
35
48
 
36
- def line_style_value_options
37
- [:solid, :dash, :dot, :dashdot, :dashdotdot]
49
+ class CubicPathShape < PathShape
50
+ attr_accessor :x1_value, :y1_value, :cx1_value, :cy1_value, :cx2_value, :cy2_value, :x2_value, :y2_value
51
+
52
+ def point_array
53
+ [x1_value, y1_value, cx1_value, cy1_value, cx2_value, cy2_value, x2_value, y2_value]
54
+ end
38
55
  end
39
56
 
57
+ include Glimmer::GUI::Application # alias for Glimmer::UI::CustomShell / Glimmer::UI::CustomWindow
58
+
59
+ CANVAS_WIDTH = 300
60
+ CANVAS_HEIGHT = 300
61
+
40
62
  before_body do
41
- self.x1_value = 0
42
- self.y1_value = 0
43
- self.x2_value = CANVAS_WIDTH
44
- self.y2_value = CANVAS_HEIGHT
45
- self.foreground_red = 28
46
- self.foreground_green = 128
47
- self.foreground_blue = 228
48
- self.line_width_value = 3
49
- self.line_style_value = :dot
63
+ @line = LinePathShape.new
64
+ @line.x1_value = 5
65
+ @line.y1_value = 5
66
+ @line.x2_value = CANVAS_WIDTH - 5
67
+ @line.y2_value = CANVAS_HEIGHT - 5
68
+ @line.foreground_red = 28
69
+ @line.foreground_green = 128
70
+ @line.foreground_blue = 228
71
+ @line.line_width_value = 3
72
+ @line.line_style_value = :dash
73
+
74
+ @quad = QuadPathShape.new
75
+ @quad.x1_value = 5
76
+ @quad.y1_value = CANVAS_HEIGHT - 5
77
+ @quad.cx_value = (CANVAS_WIDTH - 10)/2.0
78
+ @quad.cy_value = 5
79
+ @quad.x2_value = CANVAS_WIDTH - 5
80
+ @quad.y2_value = CANVAS_HEIGHT - 5
81
+ @quad.foreground_red = 28
82
+ @quad.foreground_green = 128
83
+ @quad.foreground_blue = 228
84
+ @quad.line_width_value = 3
85
+ @quad.line_style_value = :dot
86
+
87
+ @cubic = CubicPathShape.new
88
+ @cubic.x1_value = 5
89
+ @cubic.y1_value = (CANVAS_WIDTH - 10)/2.0
90
+ @cubic.cx1_value = (CANVAS_WIDTH - 10)*0.25
91
+ @cubic.cy1_value = (CANVAS_WIDTH - 10)*0.25
92
+ @cubic.cx2_value = (CANVAS_WIDTH - 10)*0.75
93
+ @cubic.cy2_value = (CANVAS_WIDTH - 10)*0.75
94
+ @cubic.x2_value = CANVAS_WIDTH - 5
95
+ @cubic.y2_value = (CANVAS_WIDTH - 10)/2.0
96
+ @cubic.foreground_red = 28
97
+ @cubic.foreground_green = 128
98
+ @cubic.foreground_blue = 228
99
+ @cubic.line_width_value = 3
100
+ @cubic.line_style_value = :dashdot
50
101
  end
51
102
 
52
103
  body {
53
- shell {
104
+ shell(:no_resize) {
54
105
  text 'Hello, Canvas Data-Binding!'
55
106
 
56
107
  tab_folder {
@@ -61,7 +112,7 @@ class HelloCanvasDataBinding
61
112
  horizontal_spacing 0
62
113
  vertical_spacing 0
63
114
  }
64
- text 'line'
115
+ text 'Line'
65
116
 
66
117
  label {
67
118
  layout_data(:fill, :center, false, false) {
@@ -75,13 +126,14 @@ class HelloCanvasDataBinding
75
126
  }
76
127
  text 'y1'
77
128
  }
129
+
78
130
  spinner {
79
131
  layout_data(:fill, :center, false, false) {
80
132
  horizontal_span 3
81
133
  }
82
134
  maximum CANVAS_WIDTH
83
135
  increment 3
84
- selection <=> [self, :x1_value]
136
+ selection <=> [@line, :x1_value]
85
137
  }
86
138
  spinner {
87
139
  layout_data(:fill, :center, false, false) {
@@ -89,8 +141,9 @@ class HelloCanvasDataBinding
89
141
  }
90
142
  maximum CANVAS_HEIGHT
91
143
  increment 3
92
- selection <=> [self, :y1_value]
144
+ selection <=> [@line, :y1_value]
93
145
  }
146
+
94
147
  label {
95
148
  layout_data(:fill, :center, false, false) {
96
149
  horizontal_span 3
@@ -103,13 +156,14 @@ class HelloCanvasDataBinding
103
156
  }
104
157
  text 'y2'
105
158
  }
159
+
106
160
  spinner {
107
161
  layout_data(:fill, :center, false, false) {
108
162
  horizontal_span 3
109
163
  }
110
164
  maximum CANVAS_WIDTH
111
165
  increment 3
112
- selection <=> [self, :x2_value]
166
+ selection <=> [@line, :x2_value]
113
167
  }
114
168
  spinner {
115
169
  layout_data(:fill, :center, false, false) {
@@ -117,8 +171,9 @@ class HelloCanvasDataBinding
117
171
  }
118
172
  maximum CANVAS_HEIGHT
119
173
  increment 3
120
- selection <=> [self, :y2_value]
174
+ selection <=> [@line, :y2_value]
121
175
  }
176
+
122
177
  label {
123
178
  layout_data(:fill, :center, false, false) {
124
179
  horizontal_span 2
@@ -137,13 +192,14 @@ class HelloCanvasDataBinding
137
192
  }
138
193
  text 'foreground blue'
139
194
  }
195
+
140
196
  spinner {
141
197
  layout_data(:fill, :center, false, false) {
142
198
  horizontal_span 2
143
199
  }
144
200
  maximum 255
145
201
  increment 10
146
- selection <=> [self, :foreground_red]
202
+ selection <=> [@line, :foreground_red]
147
203
  }
148
204
  spinner {
149
205
  layout_data(:fill, :center, false, false) {
@@ -151,7 +207,7 @@ class HelloCanvasDataBinding
151
207
  }
152
208
  maximum 255
153
209
  increment 10
154
- selection <=> [self, :foreground_green]
210
+ selection <=> [@line, :foreground_green]
155
211
  }
156
212
  spinner {
157
213
  layout_data(:fill, :center, false, false) {
@@ -159,8 +215,9 @@ class HelloCanvasDataBinding
159
215
  }
160
216
  maximum 255
161
217
  increment 10
162
- selection <=> [self, :foreground_blue]
218
+ selection <=> [@line, :foreground_blue]
163
219
  }
220
+
164
221
  label {
165
222
  layout_data(:fill, :center, false, false) {
166
223
  horizontal_span 3
@@ -173,42 +230,642 @@ class HelloCanvasDataBinding
173
230
  }
174
231
  text 'line style'
175
232
  }
233
+
176
234
  spinner {
177
235
  layout_data(:fill, :center, false, false) {
178
236
  horizontal_span 3
179
237
  }
180
238
  maximum 255
181
- selection <=> [self, :line_width_value]
239
+ selection <=> [@line, :line_width_value]
182
240
  }
183
241
  combo(:read_only) {
184
242
  layout_data(:fill, :center, false, false) {
185
243
  horizontal_span 3
186
244
  }
187
- selection <=> [self, :line_style_value]
245
+ selection <=> [@line, :line_style_value]
188
246
  }
189
- canvas {
247
+
248
+ @line_canvas = canvas {
190
249
  layout_data(:center, :center, false, false) {
191
250
  horizontal_span 6
192
251
  width_hint CANVAS_WIDTH
193
252
  height_hint CANVAS_WIDTH
194
253
  }
254
+
195
255
  background :white
196
256
 
197
257
  line {
198
- x1 <= [self, :x1_value]
199
- y1 <= [self, :y1_value]
200
- x2 <= [self, :x2_value]
201
- y2 <= [self, :y2_value]
202
- foreground <= [self, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
203
- line_width <= [self, :line_width_value]
204
- line_style <= [self, :line_style_value]
258
+ x1 <= [@line, :x1_value]
259
+ y1 <= [@line, :y1_value]
260
+ x2 <= [@line, :x2_value]
261
+ y2 <= [@line, :y2_value]
262
+ foreground <= [@line, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
263
+ line_width <= [@line, :line_width_value]
264
+ line_style <= [@line, :line_style_value]
265
+ }
266
+
267
+ @line_oval1 = oval {
268
+ x <= [@line, :x1_value, on_read: ->(val) {val - 5}]
269
+ y <= [@line, :y1_value, on_read: ->(val) {val - 5}]
270
+ width 10
271
+ height 10
272
+ background :black
205
273
  }
274
+
275
+ @line_oval2 = oval {
276
+ x <= [@line, :x2_value, on_read: ->(val) {val - 5}]
277
+ y <= [@line, :y2_value, on_read: ->(val) {val - 5}]
278
+ width 10
279
+ height 10
280
+ background :black
281
+ }
282
+
283
+ on_mouse_down do |mouse_event|
284
+ @selected_shape = @line_canvas.shape_at_location(mouse_event.x, mouse_event.y)
285
+ @selected_shape = nil unless @selected_shape.is_a?(Glimmer::SWT::Custom::Shape::Oval)
286
+ @line_canvas.cursor = :hand if @selected_shape
287
+ end
288
+
289
+ on_drag_detected do |drag_detect_event|
290
+ @drag_detected = true
291
+ @drag_current_x = drag_detect_event.x
292
+ @drag_current_y = drag_detect_event.y
293
+ end
294
+
295
+ on_mouse_move do |mouse_event|
296
+ if @drag_detected && @selected_shape
297
+ delta_x = mouse_event.x - @drag_current_x
298
+ delta_y = mouse_event.y - @drag_current_y
299
+ case @selected_shape
300
+ when @line_oval1
301
+ @line.x1_value += delta_x
302
+ @line.y1_value += delta_y
303
+ when @line_oval2
304
+ @line.x2_value += delta_x
305
+ @line.y2_value += delta_y
306
+ end
307
+ @drag_current_x = mouse_event.x
308
+ @drag_current_y = mouse_event.y
309
+ end
310
+ end
311
+
312
+ on_mouse_up do |mouse_event|
313
+ @line_canvas.cursor = :arrow
314
+ @drag_detected = false
315
+ @selected_shape = nil
316
+ end
317
+ }
318
+ }
319
+
320
+ tab_item {
321
+ grid_layout(6, true) {
322
+ margin_width 0
323
+ margin_height 0
324
+ horizontal_spacing 0
325
+ vertical_spacing 0
326
+ }
327
+ text 'Quad'
328
+
329
+ label {
330
+ layout_data(:fill, :center, false, false) {
331
+ horizontal_span 3
332
+ }
333
+ text 'x1'
334
+ }
335
+ label {
336
+ layout_data(:fill, :center, false, false) {
337
+ horizontal_span 3
338
+ }
339
+ text 'y1'
340
+ }
341
+
342
+ spinner {
343
+ layout_data(:fill, :center, false, false) {
344
+ horizontal_span 3
345
+ }
346
+ maximum CANVAS_WIDTH
347
+ increment 3
348
+ selection <=> [@quad, :x1_value]
349
+ }
350
+ spinner {
351
+ layout_data(:fill, :center, false, false) {
352
+ horizontal_span 3
353
+ }
354
+ maximum CANVAS_HEIGHT
355
+ increment 3
356
+ selection <=> [@quad, :y1_value]
357
+ }
358
+
359
+ label {
360
+ layout_data(:fill, :center, false, false) {
361
+ horizontal_span 3
362
+ }
363
+ text 'control x'
364
+ }
365
+ label {
366
+ layout_data(:fill, :center, false, false) {
367
+ horizontal_span 3
368
+ }
369
+ text 'control y'
370
+ }
371
+
372
+ spinner {
373
+ layout_data(:fill, :center, false, false) {
374
+ horizontal_span 3
375
+ }
376
+ maximum CANVAS_WIDTH
377
+ increment 3
378
+ selection <=> [@quad, :cx_value]
379
+ }
380
+ spinner {
381
+ layout_data(:fill, :center, false, false) {
382
+ horizontal_span 3
383
+ }
384
+ maximum CANVAS_HEIGHT
385
+ increment 3
386
+ selection <=> [@quad, :cy_value]
387
+ }
388
+
389
+ label {
390
+ layout_data(:fill, :center, false, false) {
391
+ horizontal_span 3
392
+ }
393
+ text 'x2'
394
+ }
395
+ label {
396
+ layout_data(:fill, :center, false, false) {
397
+ horizontal_span 3
398
+ }
399
+ text 'y2'
400
+ }
401
+
402
+ spinner {
403
+ layout_data(:fill, :center, false, false) {
404
+ horizontal_span 3
405
+ }
406
+ maximum CANVAS_WIDTH
407
+ increment 3
408
+ selection <=> [@quad, :x2_value]
409
+ }
410
+ spinner {
411
+ layout_data(:fill, :center, false, false) {
412
+ horizontal_span 3
413
+ }
414
+ maximum CANVAS_HEIGHT
415
+ increment 3
416
+ selection <=> [@quad, :y2_value]
417
+ }
418
+
419
+ label {
420
+ layout_data(:fill, :center, false, false) {
421
+ horizontal_span 2
422
+ }
423
+ text 'foreground red'
424
+ }
425
+ label {
426
+ layout_data(:fill, :center, false, false) {
427
+ horizontal_span 2
428
+ }
429
+ text 'foreground green'
430
+ }
431
+ label {
432
+ layout_data(:fill, :center, false, false) {
433
+ horizontal_span 2
434
+ }
435
+ text 'foreground blue'
436
+ }
437
+
438
+ spinner {
439
+ layout_data(:fill, :center, false, false) {
440
+ horizontal_span 2
441
+ }
442
+ maximum 255
443
+ increment 10
444
+ selection <=> [@quad, :foreground_red]
445
+ }
446
+ spinner {
447
+ layout_data(:fill, :center, false, false) {
448
+ horizontal_span 2
449
+ }
450
+ maximum 255
451
+ increment 10
452
+ selection <=> [@quad, :foreground_green]
453
+ }
454
+ spinner {
455
+ layout_data(:fill, :center, false, false) {
456
+ horizontal_span 2
457
+ }
458
+ maximum 255
459
+ increment 10
460
+ selection <=> [@quad, :foreground_blue]
461
+ }
462
+
463
+ label {
464
+ layout_data(:fill, :center, false, false) {
465
+ horizontal_span 3
466
+ }
467
+ text 'line width'
468
+ }
469
+ label {
470
+ layout_data(:fill, :center, false, false) {
471
+ horizontal_span 3
472
+ }
473
+ text 'line style'
474
+ }
475
+
476
+ spinner {
477
+ layout_data(:fill, :center, false, false) {
478
+ horizontal_span 3
479
+ }
480
+ maximum 255
481
+ selection <=> [@quad, :line_width_value]
482
+ }
483
+ combo(:read_only) {
484
+ layout_data(:fill, :center, false, false) {
485
+ horizontal_span 3
486
+ }
487
+ selection <=> [@quad, :line_style_value]
488
+ }
489
+
490
+ @quad_canvas = canvas {
491
+ layout_data(:center, :center, false, false) {
492
+ horizontal_span 6
493
+ width_hint CANVAS_WIDTH
494
+ height_hint CANVAS_WIDTH
495
+ }
496
+
497
+ background :white
498
+
499
+ path {
500
+ foreground <= [@quad, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
501
+ line_width <= [@quad, :line_width_value]
502
+ line_style <= [@quad, :line_style_value]
503
+
504
+ quad {
505
+ point_array <= [@quad, :point_array, computed_by: [:x1_value, :y1_value, :cx_value, :cy_value, :x2_value, :y2_value]]
506
+ }
507
+ }
508
+
509
+ @quad_oval1 = oval {
510
+ x <= [@quad, :x1_value, on_read: ->(val) {val - 5}]
511
+ y <= [@quad, :y1_value, on_read: ->(val) {val - 5}]
512
+ width 10
513
+ height 10
514
+ background :black
515
+ }
516
+
517
+ @quad_oval2 = oval {
518
+ x <= [@quad, :cx_value, on_read: ->(val) {val - 5}]
519
+ y <= [@quad, :cy_value, on_read: ->(val) {val - 5}]
520
+ width 10
521
+ height 10
522
+ background :dark_gray
523
+ }
524
+
525
+ @quad_oval3 = oval {
526
+ x <= [@quad, :x2_value, on_read: ->(val) {val - 5}]
527
+ y <= [@quad, :y2_value, on_read: ->(val) {val - 5}]
528
+ width 10
529
+ height 10
530
+ background :black
531
+ }
532
+
533
+ on_mouse_down do |mouse_event|
534
+ @selected_shape = @quad_canvas.shape_at_location(mouse_event.x, mouse_event.y)
535
+ @selected_shape = nil unless @selected_shape.is_a?(Glimmer::SWT::Custom::Shape::Oval)
536
+ @quad_canvas.cursor = :hand if @selected_shape
537
+ end
538
+
539
+ on_drag_detected do |drag_detect_event|
540
+ @drag_detected = true
541
+ @drag_current_x = drag_detect_event.x
542
+ @drag_current_y = drag_detect_event.y
543
+ end
544
+
545
+ on_mouse_move do |mouse_event|
546
+ if @drag_detected && @selected_shape
547
+ delta_x = mouse_event.x - @drag_current_x
548
+ delta_y = mouse_event.y - @drag_current_y
549
+ case @selected_shape
550
+ when @quad_oval1
551
+ @quad.x1_value += delta_x
552
+ @quad.y1_value += delta_y
553
+ when @quad_oval2
554
+ @quad.cx_value += delta_x
555
+ @quad.cy_value += delta_y
556
+ when @quad_oval3
557
+ @quad.x2_value += delta_x
558
+ @quad.y2_value += delta_y
559
+ end
560
+ @drag_current_x = mouse_event.x
561
+ @drag_current_y = mouse_event.y
562
+ end
563
+ end
564
+
565
+ on_mouse_up do |mouse_event|
566
+ @quad_canvas.cursor = :arrow
567
+ @drag_detected = false
568
+ @selected_shape = nil
569
+ end
570
+ }
571
+ }
572
+
573
+ tab_item {
574
+ grid_layout(6, true) {
575
+ margin_width 0
576
+ margin_height 0
577
+ horizontal_spacing 0
578
+ vertical_spacing 0
579
+ }
580
+ text 'Cubic'
581
+
582
+ label {
583
+ layout_data(:fill, :center, false, false) {
584
+ horizontal_span 3
585
+ }
586
+ text 'x1'
587
+ }
588
+ label {
589
+ layout_data(:fill, :center, false, false) {
590
+ horizontal_span 3
591
+ }
592
+ text 'y1'
593
+ }
594
+
595
+ spinner {
596
+ layout_data(:fill, :center, false, false) {
597
+ horizontal_span 3
598
+ }
599
+ maximum CANVAS_WIDTH
600
+ increment 3
601
+ selection <=> [@cubic, :x1_value]
602
+ }
603
+ spinner {
604
+ layout_data(:fill, :center, false, false) {
605
+ horizontal_span 3
606
+ }
607
+ maximum CANVAS_HEIGHT
608
+ increment 3
609
+ selection <=> [@cubic, :y1_value]
610
+ }
611
+
612
+ label {
613
+ layout_data(:fill, :center, false, false) {
614
+ horizontal_span 3
615
+ }
616
+ text 'control 1 x'
617
+ }
618
+ label {
619
+ layout_data(:fill, :center, false, false) {
620
+ horizontal_span 3
621
+ }
622
+ text 'control 1 y'
623
+ }
624
+
625
+ spinner {
626
+ layout_data(:fill, :center, false, false) {
627
+ horizontal_span 3
628
+ }
629
+ maximum CANVAS_WIDTH
630
+ increment 3
631
+ selection <=> [@cubic, :cx1_value]
632
+ }
633
+ spinner {
634
+ layout_data(:fill, :center, false, false) {
635
+ horizontal_span 3
636
+ }
637
+ maximum CANVAS_HEIGHT
638
+ increment 3
639
+ selection <=> [@cubic, :cy1_value]
640
+ }
641
+
642
+ label {
643
+ layout_data(:fill, :center, false, false) {
644
+ horizontal_span 3
645
+ }
646
+ text 'control 2 x'
647
+ }
648
+ label {
649
+ layout_data(:fill, :center, false, false) {
650
+ horizontal_span 3
651
+ }
652
+ text 'control 2 y'
653
+ }
654
+
655
+ spinner {
656
+ layout_data(:fill, :center, false, false) {
657
+ horizontal_span 3
658
+ }
659
+ maximum CANVAS_WIDTH
660
+ increment 3
661
+ selection <=> [@cubic, :cx2_value]
662
+ }
663
+ spinner {
664
+ layout_data(:fill, :center, false, false) {
665
+ horizontal_span 3
666
+ }
667
+ maximum CANVAS_HEIGHT
668
+ increment 3
669
+ selection <=> [@cubic, :cy2_value]
670
+ }
671
+
672
+ label {
673
+ layout_data(:fill, :center, false, false) {
674
+ horizontal_span 3
675
+ }
676
+ text 'x2'
677
+ }
678
+ label {
679
+ layout_data(:fill, :center, false, false) {
680
+ horizontal_span 3
681
+ }
682
+ text 'y2'
683
+ }
684
+
685
+ spinner {
686
+ layout_data(:fill, :center, false, false) {
687
+ horizontal_span 3
688
+ }
689
+ maximum CANVAS_WIDTH
690
+ increment 3
691
+ selection <=> [@cubic, :x2_value]
692
+ }
693
+ spinner {
694
+ layout_data(:fill, :center, false, false) {
695
+ horizontal_span 3
696
+ }
697
+ maximum CANVAS_HEIGHT
698
+ increment 3
699
+ selection <=> [@cubic, :y2_value]
700
+ }
701
+
702
+ label {
703
+ layout_data(:fill, :center, false, false) {
704
+ horizontal_span 2
705
+ }
706
+ text 'foreground red'
707
+ }
708
+ label {
709
+ layout_data(:fill, :center, false, false) {
710
+ horizontal_span 2
711
+ }
712
+ text 'foreground green'
713
+ }
714
+ label {
715
+ layout_data(:fill, :center, false, false) {
716
+ horizontal_span 2
717
+ }
718
+ text 'foreground blue'
719
+ }
720
+
721
+ spinner {
722
+ layout_data(:fill, :center, false, false) {
723
+ horizontal_span 2
724
+ }
725
+ maximum 255
726
+ increment 10
727
+ selection <=> [@cubic, :foreground_red]
728
+ }
729
+ spinner {
730
+ layout_data(:fill, :center, false, false) {
731
+ horizontal_span 2
732
+ }
733
+ maximum 255
734
+ increment 10
735
+ selection <=> [@cubic, :foreground_green]
736
+ }
737
+ spinner {
738
+ layout_data(:fill, :center, false, false) {
739
+ horizontal_span 2
740
+ }
741
+ maximum 255
742
+ increment 10
743
+ selection <=> [@cubic, :foreground_blue]
744
+ }
745
+
746
+ label {
747
+ layout_data(:fill, :center, false, false) {
748
+ horizontal_span 3
749
+ }
750
+ text 'line width'
751
+ }
752
+ label {
753
+ layout_data(:fill, :center, false, false) {
754
+ horizontal_span 3
755
+ }
756
+ text 'line style'
757
+ }
758
+
759
+ spinner {
760
+ layout_data(:fill, :center, false, false) {
761
+ horizontal_span 3
762
+ }
763
+ maximum 255
764
+ selection <=> [@cubic, :line_width_value]
765
+ }
766
+ combo(:read_only) {
767
+ layout_data(:fill, :center, false, false) {
768
+ horizontal_span 3
769
+ }
770
+ selection <=> [@cubic, :line_style_value]
771
+ }
772
+
773
+ @cubic_canvas = canvas {
774
+ layout_data(:center, :center, false, false) {
775
+ horizontal_span 6
776
+ width_hint CANVAS_WIDTH
777
+ height_hint CANVAS_WIDTH
778
+ }
779
+
780
+ background :white
781
+
782
+ path {
783
+ foreground <= [@cubic, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
784
+ line_width <= [@cubic, :line_width_value]
785
+ line_style <= [@cubic, :line_style_value]
786
+
787
+ cubic {
788
+ point_array <= [@cubic, :point_array, computed_by: [:x1_value, :y1_value, :cx1_value, :cy1_value, :cx2_value, :cy2_value, :x2_value, :y2_value]]
789
+ }
790
+ }
791
+
792
+ @cubic_oval1 = oval {
793
+ x <= [@cubic, :x1_value, on_read: ->(val) {val - 5}]
794
+ y <= [@cubic, :y1_value, on_read: ->(val) {val - 5}]
795
+ width 10
796
+ height 10
797
+ background :black
798
+ }
799
+
800
+ @cubic_oval2 = oval {
801
+ x <= [@cubic, :cx1_value, on_read: ->(val) {val - 5}]
802
+ y <= [@cubic, :cy1_value, on_read: ->(val) {val - 5}]
803
+ width 10
804
+ height 10
805
+ background :dark_gray
806
+ }
807
+
808
+ @cubic_oval3 = oval {
809
+ x <= [@cubic, :cx2_value, on_read: ->(val) {val - 5}]
810
+ y <= [@cubic, :cy2_value, on_read: ->(val) {val - 5}]
811
+ width 10
812
+ height 10
813
+ background :dark_gray
814
+ }
815
+
816
+ @cubic_oval4 = oval {
817
+ x <= [@cubic, :x2_value, on_read: ->(val) {val - 5}]
818
+ y <= [@cubic, :y2_value, on_read: ->(val) {val - 5}]
819
+ width 10
820
+ height 10
821
+ background :black
822
+ }
823
+
824
+ on_mouse_down do |mouse_event|
825
+ @selected_shape = @cubic_canvas.shape_at_location(mouse_event.x, mouse_event.y)
826
+ @selected_shape = nil unless @selected_shape.is_a?(Glimmer::SWT::Custom::Shape::Oval)
827
+ @cubic_canvas.cursor = :hand if @selected_shape
828
+ end
829
+
830
+ on_drag_detected do |drag_detect_event|
831
+ @drag_detected = true
832
+ @drag_current_x = drag_detect_event.x
833
+ @drag_current_y = drag_detect_event.y
834
+ end
835
+
836
+ on_mouse_move do |mouse_event|
837
+ if @drag_detected && @selected_shape
838
+ delta_x = mouse_event.x - @drag_current_x
839
+ delta_y = mouse_event.y - @drag_current_y
840
+ case @selected_shape
841
+ when @cubic_oval1
842
+ @cubic.x1_value += delta_x
843
+ @cubic.y1_value += delta_y
844
+ when @cubic_oval2
845
+ @cubic.cx1_value += delta_x
846
+ @cubic.cy1_value += delta_y
847
+ when @cubic_oval3
848
+ @cubic.cx2_value += delta_x
849
+ @cubic.cy2_value += delta_y
850
+ when @cubic_oval4
851
+ @cubic.x2_value += delta_x
852
+ @cubic.y2_value += delta_y
853
+ end
854
+ @drag_current_x = mouse_event.x
855
+ @drag_current_y = mouse_event.y
856
+ end
857
+ end
858
+
859
+ on_mouse_up do |mouse_event|
860
+ @cubic_canvas.cursor = :arrow
861
+ @drag_detected = false
862
+ @selected_shape = nil
863
+ end
206
864
  }
207
865
  }
208
866
  }
209
867
  }
210
868
  }
211
-
212
869
  end
213
870
 
214
871
  HelloCanvasDataBinding.launch