glimmer-dsl-swt 4.24.0.1 → 4.24.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2295,35 +2295,86 @@ Example of canvas shape parameter data-binding (you may copy/paste in [`girb`](G
2295
2295
  require 'glimmer-dsl-swt'
2296
2296
 
2297
2297
  class HelloCanvasDataBinding
2298
- include Glimmer::GUI::CustomWindow # alias for Glimmer::UI::CustomShell
2299
-
2300
- CANVAS_WIDTH = 300
2301
- CANVAS_HEIGHT = 300
2298
+ class PathShape
2299
+ attr_accessor :foreground_red, :foreground_green, :foreground_blue, :line_width_value, :line_style_value
2300
+
2301
+ def foreground_value
2302
+ [foreground_red, foreground_green, foreground_blue]
2303
+ end
2304
+
2305
+ def line_style_value_options
2306
+ [:solid, :dash, :dot, :dashdot, :dashdotdot]
2307
+ end
2308
+ end
2302
2309
 
2303
- attr_accessor :x1_value, :y1_value, :x2_value, :y2_value, :foreground_red, :foreground_green, :foreground_blue, :line_width_value, :line_style_value
2310
+ class LinePathShape < PathShape
2311
+ attr_accessor :x1_value, :y1_value, :x2_value, :y2_value
2312
+ end
2304
2313
 
2305
- def foreground_value
2306
- rgb(foreground_red, foreground_green, foreground_blue)
2314
+ class QuadPathShape < PathShape
2315
+ attr_accessor :x1_value, :y1_value, :cx_value, :cy_value, :x2_value, :y2_value
2316
+
2317
+ def point_array
2318
+ [x1_value, y1_value, cx_value, cy_value, x2_value, y2_value]
2319
+ end
2307
2320
  end
2308
2321
 
2309
- def line_style_value_options
2310
- [:solid, :dash, :dot, :dashdot, :dashdotdot]
2322
+ class CubicPathShape < PathShape
2323
+ attr_accessor :x1_value, :y1_value, :cx1_value, :cy1_value, :cx2_value, :cy2_value, :x2_value, :y2_value
2324
+
2325
+ def point_array
2326
+ [x1_value, y1_value, cx1_value, cy1_value, cx2_value, cy2_value, x2_value, y2_value]
2327
+ end
2311
2328
  end
2312
2329
 
2330
+ include Glimmer::GUI::Application # alias for Glimmer::UI::CustomShell / Glimmer::UI::CustomWindow
2331
+
2332
+ CANVAS_WIDTH = 300
2333
+ CANVAS_HEIGHT = 300
2334
+
2313
2335
  before_body do
2314
- self.x1_value = 0
2315
- self.y1_value = 0
2316
- self.x2_value = CANVAS_WIDTH
2317
- self.y2_value = CANVAS_HEIGHT
2318
- self.foreground_red = 28
2319
- self.foreground_green = 128
2320
- self.foreground_blue = 228
2321
- self.line_width_value = 3
2322
- self.line_style_value = :dot
2336
+ @line = LinePathShape.new
2337
+ @line.x1_value = 5
2338
+ @line.y1_value = 5
2339
+ @line.x2_value = CANVAS_WIDTH - 5
2340
+ @line.y2_value = CANVAS_HEIGHT - 5
2341
+ @line.foreground_red = 28
2342
+ @line.foreground_green = 128
2343
+ @line.foreground_blue = 228
2344
+ @line.line_width_value = 3
2345
+ @line.line_style_value = :dash
2346
+
2347
+ @quad = QuadPathShape.new
2348
+ @quad.x1_value = 5
2349
+ @quad.y1_value = CANVAS_HEIGHT - 5
2350
+ @quad.cx_value = (CANVAS_WIDTH - 10)/2.0
2351
+ @quad.cy_value = 5
2352
+ @quad.x2_value = CANVAS_WIDTH - 5
2353
+ @quad.y2_value = CANVAS_HEIGHT - 5
2354
+ @quad.foreground_red = 28
2355
+ @quad.foreground_green = 128
2356
+ @quad.foreground_blue = 228
2357
+ @quad.line_width_value = 3
2358
+ @quad.line_style_value = :dot
2359
+
2360
+ @cubic = CubicPathShape.new
2361
+ @cubic.x1_value = 5
2362
+ @cubic.y1_value = (CANVAS_WIDTH - 10)/2.0
2363
+ @cubic.cx1_value = (CANVAS_WIDTH - 10)*0.25
2364
+ @cubic.cy1_value = (CANVAS_WIDTH - 10)*0.25
2365
+ @cubic.cx2_value = (CANVAS_WIDTH - 10)*0.75
2366
+ @cubic.cy2_value = (CANVAS_WIDTH - 10)*0.75
2367
+ @cubic.x2_value = CANVAS_WIDTH - 5
2368
+ @cubic.y2_value = (CANVAS_WIDTH - 10)/2.0
2369
+ @cubic.foreground_red = 28
2370
+ @cubic.foreground_green = 128
2371
+ @cubic.foreground_blue = 228
2372
+ @cubic.line_width_value = 3
2373
+ @cubic.line_style_value = :dashdot
2323
2374
  end
2324
2375
 
2325
2376
  body {
2326
- shell {
2377
+ shell(:no_resize) {
2327
2378
  text 'Hello, Canvas Data-Binding!'
2328
2379
 
2329
2380
  tab_folder {
@@ -2334,7 +2385,7 @@ class HelloCanvasDataBinding
2334
2385
  horizontal_spacing 0
2335
2386
  vertical_spacing 0
2336
2387
  }
2337
- text 'line'
2388
+ text 'Line'
2338
2389
 
2339
2390
  label {
2340
2391
  layout_data(:fill, :center, false, false) {
@@ -2348,13 +2399,14 @@ class HelloCanvasDataBinding
2348
2399
  }
2349
2400
  text 'y1'
2350
2401
  }
2402
+
2351
2403
  spinner {
2352
2404
  layout_data(:fill, :center, false, false) {
2353
2405
  horizontal_span 3
2354
2406
  }
2355
2407
  maximum CANVAS_WIDTH
2356
2408
  increment 3
2357
- selection <=> [self, :x1_value]
2409
+ selection <=> [@line, :x1_value]
2358
2410
  }
2359
2411
  spinner {
2360
2412
  layout_data(:fill, :center, false, false) {
@@ -2362,8 +2414,9 @@ class HelloCanvasDataBinding
2362
2414
  }
2363
2415
  maximum CANVAS_HEIGHT
2364
2416
  increment 3
2365
- selection <=> [self, :y1_value]
2417
+ selection <=> [@line, :y1_value]
2366
2418
  }
2419
+
2367
2420
  label {
2368
2421
  layout_data(:fill, :center, false, false) {
2369
2422
  horizontal_span 3
@@ -2376,13 +2429,14 @@ class HelloCanvasDataBinding
2376
2429
  }
2377
2430
  text 'y2'
2378
2431
  }
2432
+
2379
2433
  spinner {
2380
2434
  layout_data(:fill, :center, false, false) {
2381
2435
  horizontal_span 3
2382
2436
  }
2383
2437
  maximum CANVAS_WIDTH
2384
2438
  increment 3
2385
- selection <=> [self, :x2_value]
2439
+ selection <=> [@line, :x2_value]
2386
2440
  }
2387
2441
  spinner {
2388
2442
  layout_data(:fill, :center, false, false) {
@@ -2390,8 +2444,9 @@ class HelloCanvasDataBinding
2390
2444
  }
2391
2445
  maximum CANVAS_HEIGHT
2392
2446
  increment 3
2393
- selection <=> [self, :y2_value]
2447
+ selection <=> [@line, :y2_value]
2394
2448
  }
2449
+
2395
2450
  label {
2396
2451
  layout_data(:fill, :center, false, false) {
2397
2452
  horizontal_span 2
@@ -2410,13 +2465,14 @@ class HelloCanvasDataBinding
2410
2465
  }
2411
2466
  text 'foreground blue'
2412
2467
  }
2468
+
2413
2469
  spinner {
2414
2470
  layout_data(:fill, :center, false, false) {
2415
2471
  horizontal_span 2
2416
2472
  }
2417
2473
  maximum 255
2418
2474
  increment 10
2419
- selection <=> [self, :foreground_red]
2475
+ selection <=> [@line, :foreground_red]
2420
2476
  }
2421
2477
  spinner {
2422
2478
  layout_data(:fill, :center, false, false) {
@@ -2424,7 +2480,7 @@ class HelloCanvasDataBinding
2424
2480
  }
2425
2481
  maximum 255
2426
2482
  increment 10
2427
- selection <=> [self, :foreground_green]
2483
+ selection <=> [@line, :foreground_green]
2428
2484
  }
2429
2485
  spinner {
2430
2486
  layout_data(:fill, :center, false, false) {
@@ -2432,8 +2488,9 @@ class HelloCanvasDataBinding
2432
2488
  }
2433
2489
  maximum 255
2434
2490
  increment 10
2435
- selection <=> [self, :foreground_blue]
2491
+ selection <=> [@line, :foreground_blue]
2436
2492
  }
2493
+
2437
2494
  label {
2438
2495
  layout_data(:fill, :center, false, false) {
2439
2496
  horizontal_span 3
@@ -2446,48 +2503,648 @@ class HelloCanvasDataBinding
2446
2503
  }
2447
2504
  text 'line style'
2448
2505
  }
2506
+
2449
2507
  spinner {
2450
2508
  layout_data(:fill, :center, false, false) {
2451
2509
  horizontal_span 3
2452
2510
  }
2453
2511
  maximum 255
2454
- selection <=> [self, :line_width_value]
2512
+ selection <=> [@line, :line_width_value]
2455
2513
  }
2456
2514
  combo(:read_only) {
2457
2515
  layout_data(:fill, :center, false, false) {
2458
2516
  horizontal_span 3
2459
2517
  }
2460
- selection <=> [self, :line_style_value]
2518
+ selection <=> [@line, :line_style_value]
2461
2519
  }
2462
- canvas {
2520
+
2521
+ @line_canvas = canvas {
2463
2522
  layout_data(:center, :center, false, false) {
2464
2523
  horizontal_span 6
2465
2524
  width_hint CANVAS_WIDTH
2466
2525
  height_hint CANVAS_WIDTH
2467
2526
  }
2527
+
2468
2528
  background :white
2469
2529
 
2470
2530
  line {
2471
- x1 <= [self, :x1_value]
2472
- y1 <= [self, :y1_value]
2473
- x2 <= [self, :x2_value]
2474
- y2 <= [self, :y2_value]
2475
- foreground <= [self, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
2476
- line_width <= [self, :line_width_value]
2477
- line_style <= [self, :line_style_value]
2531
+ x1 <= [@line, :x1_value]
2532
+ y1 <= [@line, :y1_value]
2533
+ x2 <= [@line, :x2_value]
2534
+ y2 <= [@line, :y2_value]
2535
+ foreground <= [@line, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
2536
+ line_width <= [@line, :line_width_value]
2537
+ line_style <= [@line, :line_style_value]
2538
+ }
2539
+
2540
+ @line_oval1 = oval {
2541
+ x <= [@line, :x1_value, on_read: ->(val) {val - 5}]
2542
+ y <= [@line, :y1_value, on_read: ->(val) {val - 5}]
2543
+ width 10
2544
+ height 10
2545
+ background :black
2478
2546
  }
2547
+
2548
+ @line_oval2 = oval {
2549
+ x <= [@line, :x2_value, on_read: ->(val) {val - 5}]
2550
+ y <= [@line, :y2_value, on_read: ->(val) {val - 5}]
2551
+ width 10
2552
+ height 10
2553
+ background :black
2554
+ }
2555
+
2556
+ on_mouse_down do |mouse_event|
2557
+ @selected_shape = @line_canvas.shape_at_location(mouse_event.x, mouse_event.y)
2558
+ @selected_shape = nil unless @selected_shape.is_a?(Glimmer::SWT::Custom::Shape::Oval)
2559
+ @line_canvas.cursor = :hand if @selected_shape
2560
+ end
2561
+
2562
+ on_drag_detected do |drag_detect_event|
2563
+ @drag_detected = true
2564
+ @drag_current_x = drag_detect_event.x
2565
+ @drag_current_y = drag_detect_event.y
2566
+ end
2567
+
2568
+ on_mouse_move do |mouse_event|
2569
+ if @drag_detected && @selected_shape
2570
+ delta_x = mouse_event.x - @drag_current_x
2571
+ delta_y = mouse_event.y - @drag_current_y
2572
+ case @selected_shape
2573
+ when @line_oval1
2574
+ @line.x1_value += delta_x
2575
+ @line.y1_value += delta_y
2576
+ when @line_oval2
2577
+ @line.x2_value += delta_x
2578
+ @line.y2_value += delta_y
2579
+ end
2580
+ @drag_current_x = mouse_event.x
2581
+ @drag_current_y = mouse_event.y
2582
+ end
2583
+ end
2584
+
2585
+ on_mouse_up do |mouse_event|
2586
+ @line_canvas.cursor = :arrow
2587
+ @drag_detected = false
2588
+ @selected_shape = nil
2589
+ end
2590
+ }
2591
+ }
2592
+
2593
+ tab_item {
2594
+ grid_layout(6, true) {
2595
+ margin_width 0
2596
+ margin_height 0
2597
+ horizontal_spacing 0
2598
+ vertical_spacing 0
2599
+ }
2600
+ text 'Quad'
2601
+
2602
+ label {
2603
+ layout_data(:fill, :center, false, false) {
2604
+ horizontal_span 3
2605
+ }
2606
+ text 'x1'
2607
+ }
2608
+ label {
2609
+ layout_data(:fill, :center, false, false) {
2610
+ horizontal_span 3
2611
+ }
2612
+ text 'y1'
2613
+ }
2614
+
2615
+ spinner {
2616
+ layout_data(:fill, :center, false, false) {
2617
+ horizontal_span 3
2618
+ }
2619
+ maximum CANVAS_WIDTH
2620
+ increment 3
2621
+ selection <=> [@quad, :x1_value]
2622
+ }
2623
+ spinner {
2624
+ layout_data(:fill, :center, false, false) {
2625
+ horizontal_span 3
2626
+ }
2627
+ maximum CANVAS_HEIGHT
2628
+ increment 3
2629
+ selection <=> [@quad, :y1_value]
2630
+ }
2631
+
2632
+ label {
2633
+ layout_data(:fill, :center, false, false) {
2634
+ horizontal_span 3
2635
+ }
2636
+ text 'control x'
2637
+ }
2638
+ label {
2639
+ layout_data(:fill, :center, false, false) {
2640
+ horizontal_span 3
2641
+ }
2642
+ text 'control y'
2643
+ }
2644
+
2645
+ spinner {
2646
+ layout_data(:fill, :center, false, false) {
2647
+ horizontal_span 3
2648
+ }
2649
+ maximum CANVAS_WIDTH
2650
+ increment 3
2651
+ selection <=> [@quad, :cx_value]
2652
+ }
2653
+ spinner {
2654
+ layout_data(:fill, :center, false, false) {
2655
+ horizontal_span 3
2656
+ }
2657
+ maximum CANVAS_HEIGHT
2658
+ increment 3
2659
+ selection <=> [@quad, :cy_value]
2660
+ }
2661
+
2662
+ label {
2663
+ layout_data(:fill, :center, false, false) {
2664
+ horizontal_span 3
2665
+ }
2666
+ text 'x2'
2667
+ }
2668
+ label {
2669
+ layout_data(:fill, :center, false, false) {
2670
+ horizontal_span 3
2671
+ }
2672
+ text 'y2'
2673
+ }
2674
+
2675
+ spinner {
2676
+ layout_data(:fill, :center, false, false) {
2677
+ horizontal_span 3
2678
+ }
2679
+ maximum CANVAS_WIDTH
2680
+ increment 3
2681
+ selection <=> [@quad, :x2_value]
2682
+ }
2683
+ spinner {
2684
+ layout_data(:fill, :center, false, false) {
2685
+ horizontal_span 3
2686
+ }
2687
+ maximum CANVAS_HEIGHT
2688
+ increment 3
2689
+ selection <=> [@quad, :y2_value]
2690
+ }
2691
+
2692
+ label {
2693
+ layout_data(:fill, :center, false, false) {
2694
+ horizontal_span 2
2695
+ }
2696
+ text 'foreground red'
2697
+ }
2698
+ label {
2699
+ layout_data(:fill, :center, false, false) {
2700
+ horizontal_span 2
2701
+ }
2702
+ text 'foreground green'
2703
+ }
2704
+ label {
2705
+ layout_data(:fill, :center, false, false) {
2706
+ horizontal_span 2
2707
+ }
2708
+ text 'foreground blue'
2709
+ }
2710
+
2711
+ spinner {
2712
+ layout_data(:fill, :center, false, false) {
2713
+ horizontal_span 2
2714
+ }
2715
+ maximum 255
2716
+ increment 10
2717
+ selection <=> [@quad, :foreground_red]
2718
+ }
2719
+ spinner {
2720
+ layout_data(:fill, :center, false, false) {
2721
+ horizontal_span 2
2722
+ }
2723
+ maximum 255
2724
+ increment 10
2725
+ selection <=> [@quad, :foreground_green]
2726
+ }
2727
+ spinner {
2728
+ layout_data(:fill, :center, false, false) {
2729
+ horizontal_span 2
2730
+ }
2731
+ maximum 255
2732
+ increment 10
2733
+ selection <=> [@quad, :foreground_blue]
2734
+ }
2735
+
2736
+ label {
2737
+ layout_data(:fill, :center, false, false) {
2738
+ horizontal_span 3
2739
+ }
2740
+ text 'line width'
2741
+ }
2742
+ label {
2743
+ layout_data(:fill, :center, false, false) {
2744
+ horizontal_span 3
2745
+ }
2746
+ text 'line style'
2747
+ }
2748
+
2749
+ spinner {
2750
+ layout_data(:fill, :center, false, false) {
2751
+ horizontal_span 3
2752
+ }
2753
+ maximum 255
2754
+ selection <=> [@quad, :line_width_value]
2755
+ }
2756
+ combo(:read_only) {
2757
+ layout_data(:fill, :center, false, false) {
2758
+ horizontal_span 3
2759
+ }
2760
+ selection <=> [@quad, :line_style_value]
2761
+ }
2762
+
2763
+ @quad_canvas = canvas {
2764
+ layout_data(:center, :center, false, false) {
2765
+ horizontal_span 6
2766
+ width_hint CANVAS_WIDTH
2767
+ height_hint CANVAS_WIDTH
2768
+ }
2769
+
2770
+ background :white
2771
+
2772
+ path {
2773
+ foreground <= [@quad, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
2774
+ line_width <= [@quad, :line_width_value]
2775
+ line_style <= [@quad, :line_style_value]
2776
+
2777
+ quad {
2778
+ point_array <= [@quad, :point_array, computed_by: [:x1_value, :y1_value, :cx_value, :cy_value, :x2_value, :y2_value]]
2779
+ }
2780
+ }
2781
+
2782
+ @quad_oval1 = oval {
2783
+ x <= [@quad, :x1_value, on_read: ->(val) {val - 5}]
2784
+ y <= [@quad, :y1_value, on_read: ->(val) {val - 5}]
2785
+ width 10
2786
+ height 10
2787
+ background :black
2788
+ }
2789
+
2790
+ @quad_oval2 = oval {
2791
+ x <= [@quad, :cx_value, on_read: ->(val) {val - 5}]
2792
+ y <= [@quad, :cy_value, on_read: ->(val) {val - 5}]
2793
+ width 10
2794
+ height 10
2795
+ background :dark_gray
2796
+ }
2797
+
2798
+ @quad_oval3 = oval {
2799
+ x <= [@quad, :x2_value, on_read: ->(val) {val - 5}]
2800
+ y <= [@quad, :y2_value, on_read: ->(val) {val - 5}]
2801
+ width 10
2802
+ height 10
2803
+ background :black
2804
+ }
2805
+
2806
+ on_mouse_down do |mouse_event|
2807
+ @selected_shape = @quad_canvas.shape_at_location(mouse_event.x, mouse_event.y)
2808
+ @selected_shape = nil unless @selected_shape.is_a?(Glimmer::SWT::Custom::Shape::Oval)
2809
+ @quad_canvas.cursor = :hand if @selected_shape
2810
+ end
2811
+
2812
+ on_drag_detected do |drag_detect_event|
2813
+ @drag_detected = true
2814
+ @drag_current_x = drag_detect_event.x
2815
+ @drag_current_y = drag_detect_event.y
2816
+ end
2817
+
2818
+ on_mouse_move do |mouse_event|
2819
+ if @drag_detected && @selected_shape
2820
+ delta_x = mouse_event.x - @drag_current_x
2821
+ delta_y = mouse_event.y - @drag_current_y
2822
+ case @selected_shape
2823
+ when @quad_oval1
2824
+ @quad.x1_value += delta_x
2825
+ @quad.y1_value += delta_y
2826
+ when @quad_oval2
2827
+ @quad.cx_value += delta_x
2828
+ @quad.cy_value += delta_y
2829
+ when @quad_oval3
2830
+ @quad.x2_value += delta_x
2831
+ @quad.y2_value += delta_y
2832
+ end
2833
+ @drag_current_x = mouse_event.x
2834
+ @drag_current_y = mouse_event.y
2835
+ end
2836
+ end
2837
+
2838
+ on_mouse_up do |mouse_event|
2839
+ @quad_canvas.cursor = :arrow
2840
+ @drag_detected = false
2841
+ @selected_shape = nil
2842
+ end
2843
+ }
2844
+ }
2845
+
2846
+ tab_item {
2847
+ grid_layout(6, true) {
2848
+ margin_width 0
2849
+ margin_height 0
2850
+ horizontal_spacing 0
2851
+ vertical_spacing 0
2852
+ }
2853
+ text 'Cubic'
2854
+
2855
+ label {
2856
+ layout_data(:fill, :center, false, false) {
2857
+ horizontal_span 3
2858
+ }
2859
+ text 'x1'
2860
+ }
2861
+ label {
2862
+ layout_data(:fill, :center, false, false) {
2863
+ horizontal_span 3
2864
+ }
2865
+ text 'y1'
2866
+ }
2867
+
2868
+ spinner {
2869
+ layout_data(:fill, :center, false, false) {
2870
+ horizontal_span 3
2871
+ }
2872
+ maximum CANVAS_WIDTH
2873
+ increment 3
2874
+ selection <=> [@cubic, :x1_value]
2875
+ }
2876
+ spinner {
2877
+ layout_data(:fill, :center, false, false) {
2878
+ horizontal_span 3
2879
+ }
2880
+ maximum CANVAS_HEIGHT
2881
+ increment 3
2882
+ selection <=> [@cubic, :y1_value]
2883
+ }
2884
+
2885
+ label {
2886
+ layout_data(:fill, :center, false, false) {
2887
+ horizontal_span 3
2888
+ }
2889
+ text 'control 1 x'
2890
+ }
2891
+ label {
2892
+ layout_data(:fill, :center, false, false) {
2893
+ horizontal_span 3
2894
+ }
2895
+ text 'control 1 y'
2896
+ }
2897
+
2898
+ spinner {
2899
+ layout_data(:fill, :center, false, false) {
2900
+ horizontal_span 3
2901
+ }
2902
+ maximum CANVAS_WIDTH
2903
+ increment 3
2904
+ selection <=> [@cubic, :cx1_value]
2905
+ }
2906
+ spinner {
2907
+ layout_data(:fill, :center, false, false) {
2908
+ horizontal_span 3
2909
+ }
2910
+ maximum CANVAS_HEIGHT
2911
+ increment 3
2912
+ selection <=> [@cubic, :cy1_value]
2913
+ }
2914
+
2915
+ label {
2916
+ layout_data(:fill, :center, false, false) {
2917
+ horizontal_span 3
2918
+ }
2919
+ text 'control 2 x'
2920
+ }
2921
+ label {
2922
+ layout_data(:fill, :center, false, false) {
2923
+ horizontal_span 3
2924
+ }
2925
+ text 'control 2 y'
2926
+ }
2927
+
2928
+ spinner {
2929
+ layout_data(:fill, :center, false, false) {
2930
+ horizontal_span 3
2931
+ }
2932
+ maximum CANVAS_WIDTH
2933
+ increment 3
2934
+ selection <=> [@cubic, :cx2_value]
2935
+ }
2936
+ spinner {
2937
+ layout_data(:fill, :center, false, false) {
2938
+ horizontal_span 3
2939
+ }
2940
+ maximum CANVAS_HEIGHT
2941
+ increment 3
2942
+ selection <=> [@cubic, :cy2_value]
2943
+ }
2944
+
2945
+ label {
2946
+ layout_data(:fill, :center, false, false) {
2947
+ horizontal_span 3
2948
+ }
2949
+ text 'x2'
2950
+ }
2951
+ label {
2952
+ layout_data(:fill, :center, false, false) {
2953
+ horizontal_span 3
2954
+ }
2955
+ text 'y2'
2956
+ }
2957
+
2958
+ spinner {
2959
+ layout_data(:fill, :center, false, false) {
2960
+ horizontal_span 3
2961
+ }
2962
+ maximum CANVAS_WIDTH
2963
+ increment 3
2964
+ selection <=> [@cubic, :x2_value]
2965
+ }
2966
+ spinner {
2967
+ layout_data(:fill, :center, false, false) {
2968
+ horizontal_span 3
2969
+ }
2970
+ maximum CANVAS_HEIGHT
2971
+ increment 3
2972
+ selection <=> [@cubic, :y2_value]
2973
+ }
2974
+
2975
+ label {
2976
+ layout_data(:fill, :center, false, false) {
2977
+ horizontal_span 2
2978
+ }
2979
+ text 'foreground red'
2980
+ }
2981
+ label {
2982
+ layout_data(:fill, :center, false, false) {
2983
+ horizontal_span 2
2984
+ }
2985
+ text 'foreground green'
2986
+ }
2987
+ label {
2988
+ layout_data(:fill, :center, false, false) {
2989
+ horizontal_span 2
2990
+ }
2991
+ text 'foreground blue'
2992
+ }
2993
+
2994
+ spinner {
2995
+ layout_data(:fill, :center, false, false) {
2996
+ horizontal_span 2
2997
+ }
2998
+ maximum 255
2999
+ increment 10
3000
+ selection <=> [@cubic, :foreground_red]
3001
+ }
3002
+ spinner {
3003
+ layout_data(:fill, :center, false, false) {
3004
+ horizontal_span 2
3005
+ }
3006
+ maximum 255
3007
+ increment 10
3008
+ selection <=> [@cubic, :foreground_green]
3009
+ }
3010
+ spinner {
3011
+ layout_data(:fill, :center, false, false) {
3012
+ horizontal_span 2
3013
+ }
3014
+ maximum 255
3015
+ increment 10
3016
+ selection <=> [@cubic, :foreground_blue]
3017
+ }
3018
+
3019
+ label {
3020
+ layout_data(:fill, :center, false, false) {
3021
+ horizontal_span 3
3022
+ }
3023
+ text 'line width'
3024
+ }
3025
+ label {
3026
+ layout_data(:fill, :center, false, false) {
3027
+ horizontal_span 3
3028
+ }
3029
+ text 'line style'
3030
+ }
3031
+
3032
+ spinner {
3033
+ layout_data(:fill, :center, false, false) {
3034
+ horizontal_span 3
3035
+ }
3036
+ maximum 255
3037
+ selection <=> [@cubic, :line_width_value]
3038
+ }
3039
+ combo(:read_only) {
3040
+ layout_data(:fill, :center, false, false) {
3041
+ horizontal_span 3
3042
+ }
3043
+ selection <=> [@cubic, :line_style_value]
3044
+ }
3045
+
3046
+ @cubic_canvas = canvas {
3047
+ layout_data(:center, :center, false, false) {
3048
+ horizontal_span 6
3049
+ width_hint CANVAS_WIDTH
3050
+ height_hint CANVAS_WIDTH
3051
+ }
3052
+
3053
+ background :white
3054
+
3055
+ path {
3056
+ foreground <= [@cubic, :foreground_value, computed_by: [:foreground_red, :foreground_green, :foreground_blue]]
3057
+ line_width <= [@cubic, :line_width_value]
3058
+ line_style <= [@cubic, :line_style_value]
3059
+
3060
+ cubic {
3061
+ point_array <= [@cubic, :point_array, computed_by: [:x1_value, :y1_value, :cx1_value, :cy1_value, :cx2_value, :cy2_value, :x2_value, :y2_value]]
3062
+ }
3063
+ }
3064
+
3065
+ @cubic_oval1 = oval {
3066
+ x <= [@cubic, :x1_value, on_read: ->(val) {val - 5}]
3067
+ y <= [@cubic, :y1_value, on_read: ->(val) {val - 5}]
3068
+ width 10
3069
+ height 10
3070
+ background :black
3071
+ }
3072
+
3073
+ @cubic_oval2 = oval {
3074
+ x <= [@cubic, :cx1_value, on_read: ->(val) {val - 5}]
3075
+ y <= [@cubic, :cy1_value, on_read: ->(val) {val - 5}]
3076
+ width 10
3077
+ height 10
3078
+ background :dark_gray
3079
+ }
3080
+
3081
+ @cubic_oval3 = oval {
3082
+ x <= [@cubic, :cx2_value, on_read: ->(val) {val - 5}]
3083
+ y <= [@cubic, :cy2_value, on_read: ->(val) {val - 5}]
3084
+ width 10
3085
+ height 10
3086
+ background :dark_gray
3087
+ }
3088
+
3089
+ @cubic_oval4 = oval {
3090
+ x <= [@cubic, :x2_value, on_read: ->(val) {val - 5}]
3091
+ y <= [@cubic, :y2_value, on_read: ->(val) {val - 5}]
3092
+ width 10
3093
+ height 10
3094
+ background :black
3095
+ }
3096
+
3097
+ on_mouse_down do |mouse_event|
3098
+ @selected_shape = @cubic_canvas.shape_at_location(mouse_event.x, mouse_event.y)
3099
+ @selected_shape = nil unless @selected_shape.is_a?(Glimmer::SWT::Custom::Shape::Oval)
3100
+ @cubic_canvas.cursor = :hand if @selected_shape
3101
+ end
3102
+
3103
+ on_drag_detected do |drag_detect_event|
3104
+ @drag_detected = true
3105
+ @drag_current_x = drag_detect_event.x
3106
+ @drag_current_y = drag_detect_event.y
3107
+ end
3108
+
3109
+ on_mouse_move do |mouse_event|
3110
+ if @drag_detected && @selected_shape
3111
+ delta_x = mouse_event.x - @drag_current_x
3112
+ delta_y = mouse_event.y - @drag_current_y
3113
+ case @selected_shape
3114
+ when @cubic_oval1
3115
+ @cubic.x1_value += delta_x
3116
+ @cubic.y1_value += delta_y
3117
+ when @cubic_oval2
3118
+ @cubic.cx1_value += delta_x
3119
+ @cubic.cy1_value += delta_y
3120
+ when @cubic_oval3
3121
+ @cubic.cx2_value += delta_x
3122
+ @cubic.cy2_value += delta_y
3123
+ when @cubic_oval4
3124
+ @cubic.x2_value += delta_x
3125
+ @cubic.y2_value += delta_y
3126
+ end
3127
+ @drag_current_x = mouse_event.x
3128
+ @drag_current_y = mouse_event.y
3129
+ end
3130
+ end
3131
+
3132
+ on_mouse_up do |mouse_event|
3133
+ @cubic_canvas.cursor = :arrow
3134
+ @drag_detected = false
3135
+ @selected_shape = nil
3136
+ end
2479
3137
  }
2480
3138
  }
2481
3139
  }
2482
3140
  }
2483
3141
  }
2484
-
2485
3142
  end
2486
3143
 
2487
3144
  HelloCanvasDataBinding.launch
2488
3145
  ```
2489
3146
 
2490
- ![Glimmer Example Canvas Data-Binding Line Changed](/images/glimmer-hello-canvas-data-binding-line-changed.png)
3147
+ ![Glimmer Example Canvas Data-Binding](/images/glimmer-hello-canvas-data-binding.gif)
2491
3148
 
2492
3149
  If you ever have special needs for optimization, you could always default to direct SWT painting via [org.eclipse.swt.graphics.GC](https://help.eclipse.org/2020-12/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/graphics/GC.html) instead. Learn more at the [SWT Graphics Guide](https://www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html) and [SWT Image Guide](https://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Saving%20Images).
2493
3150
 
@@ -3579,7 +4236,7 @@ Example:
3579
4236
  shell {
3580
4237
  @tree = tree {
3581
4238
  items <= [company, :owner, tree_properties: {children: :coworkers, text: :name}]
3582
- selection <=> [company, :selected_coworker]
4239
+ selection <=> [company, :selected_coworker]
3583
4240
  }
3584
4241
  }
3585
4242
  ```