glimmer-dsl-swt 4.20.11.0 → 4.20.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22a275c90700a95d9bb50a11500062bc752ae0993177af88f8c84afb150615e2
4
- data.tar.gz: fa1470d45be2485bd2304eccfb8f93a0f45b841c81bc7891de65144fb6e7b8ac
3
+ metadata.gz: 94916ca37afe49d1a86e6cdc4dbc26ea0c427aeb367933bff3545cff184af89c
4
+ data.tar.gz: 9f661b2400af578023b997e2fd157a2ed83f9472be8e87a06a8e05f03b8c4510
5
5
  SHA512:
6
- metadata.gz: 72447b790c797f63c78ce456cfe638a74140294e3f710432465a773e63c97c5198ecec9c5d4a6cc6de36a8bfbb5ec743300c3ffdd2db2c638ab031bbf125d44d
7
- data.tar.gz: 577412f2a8a2313f3fc61568ac4d435e6d7158725ff2199eaef5e935c165745a872971f4fb8d48d8d8d0ae3d1a3b19078d956f65e54da7b9c0dcd582c7d73a5a
6
+ metadata.gz: ae954846060d6f0128a1a0451cfabedd7b5911585c14276223660a8ed1783951e2c21207c03375b79c7c1fd56155f1611259c755964b4929cdbdd2c1c8751280
7
+ data.tar.gz: fffe1578254cc9f8fa633f519d4948a3f8f94712d5e5e16167ecbb3faf7d1cc7d37da40bd73a4bbb755aa75091682f50df450589e1c1b8a8bc8a582e67be7c4f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.12.2
4
+
5
+ - Make Shape listeners check inclusion against all sub-shapes
6
+ - Refactor Hello, Canvas Drag & Drop! sample to use composite shapes (e.g. ball containing a ball border)
7
+
8
+ ### 4.20.12.1
9
+
10
+ - Hello, Canvas Drag & Drop! sample
11
+
12
+ ### 4.20.12.0
13
+
14
+ - Canvas Shape Listeners: on_mouse_up, on_mouse_down, on_mouse_move, on_drag_detected
15
+ - Make scaffolding not generate an empty () after shell
16
+ - Hello, Canvas Shape Listeners! Sample
17
+
18
+ ### 4.20.11.1
19
+
20
+ - Make scaffolded app project use bundler optionally only and still load glimmer-dsl-swt otherwise, like in gem-packaged mode (`glimmer package:gem`) to avoid erroring out about bundler.
21
+
3
22
  ### 4.20.11.0
4
23
 
5
24
  - Shape `#center_x`/`#center_y` methods to identify a shape's center point
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.11.0
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.12.2
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -15,7 +15,7 @@
15
15
  [<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
16
16
  Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
17
17
 
18
- [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.11.0 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.12.2 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
19
19
 
20
20
  **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still a beta, so default back to `bind` whenever needed).
21
21
 
@@ -45,12 +45,6 @@ shell {
45
45
  }.open
46
46
  ```
47
47
 
48
- Run via `glimmer samples` or directly:
49
-
50
- ```
51
- glimmer samples/hello/hello_world.rb
52
- ```
53
-
54
48
  Glimmer app:
55
49
 
56
50
  ![Hello World](images/glimmer-hello-world.png)
@@ -62,25 +56,25 @@ Learn more about [Hello, World!](docs/reference/GLIMMER_SAMPLES#hello-world).
62
56
  Glimmer GUI DSL code (from [samples/hello/hello_table.rb](samples/hello/hello_table.rb)):
63
57
 
64
58
  ```ruby
65
- # ... model code precedes
66
59
  shell {
67
60
  grid_layout
68
61
 
69
62
  text 'Hello, Table!'
70
63
  background_image File.expand_path('hello_table/baseball_park.png', __dir__)
64
+ image File.expand_path('hello_table/baseball_park.png', __dir__)
71
65
 
72
66
  label {
73
67
  layout_data :center, :center, true, false
74
68
 
75
69
  text 'BASEBALL PLAYOFF SCHEDULE'
76
- background :transparent
70
+ background :transparent if OS.windows?
77
71
  foreground rgb(94, 107, 103)
78
72
  font name: 'Optima', height: 38, style: :bold
79
73
  }
80
74
 
81
75
  combo(:read_only) {
82
76
  layout_data :center, :center, true, false
83
- selection bind(BaseballGame, :playoff_type)
77
+ selection <=> [BaseballGame, :playoff_type]
84
78
  font height: 14
85
79
  }
86
80
 
@@ -121,10 +115,10 @@ shell {
121
115
  }
122
116
 
123
117
  # Data-bind table items (rows) to a model collection property, specifying column properties ordering per nested model
124
- items bind(BaseballGame, :schedule), column_properties(:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion)
118
+ items <=> [BaseballGame, :schedule, column_properties: [:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion]]
125
119
 
126
120
  # Data-bind table selection
127
- selection bind(BaseballGame, :selected_game)
121
+ selection <=> [BaseballGame, :selected_game]
128
122
 
129
123
  # Default initial sort property
130
124
  sort_property :date
@@ -147,20 +141,13 @@ shell {
147
141
  text 'Book Selected Game'
148
142
  layout_data :center, :center, true, false
149
143
  font height: 14
150
- enabled bind(BaseballGame, :selected_game)
144
+ enabled <= [BaseballGame, :selected_game]
151
145
 
152
146
  on_widget_selected {
153
147
  book_selected_game
154
148
  }
155
149
  }
156
- }.open
157
- # ...
158
- ```
159
-
160
- Run via `glimmer samples` or directly:
161
-
162
- ```
163
- glimmer samples/hello/hello_table.rb
150
+ }
164
151
  ```
165
152
 
166
153
  Glimmer App:
@@ -174,7 +161,6 @@ Learn more about [Hello, Table!](docs/reference/GLIMMER_SAMPLES#hello-table).
174
161
  Glimmer GUI DSL code (from [samples/elaborate/tetris.rb](samples/elaborate/tetris.rb)):
175
162
 
176
163
  ```ruby
177
- # ... more code resides in other files (navigate sample files to learn more)
178
164
  shell(:no_resize) {
179
165
  grid_layout {
180
166
  num_columns 2
@@ -196,13 +182,6 @@ shell(:no_resize) {
196
182
  layout_data(:fill, :fill, true, true)
197
183
  }
198
184
  }
199
- # ...
200
- ```
201
-
202
- Run via `glimmer samples` or directly:
203
-
204
- ```
205
- glimmer samples/elaborate/tetris.rb
206
185
  ```
207
186
 
208
187
  Glimmer app:
@@ -347,7 +326,7 @@ jgem install glimmer-dsl-swt
347
326
 
348
327
  Or this command if you want a specific version:
349
328
  ```
350
- jgem install glimmer-dsl-swt -v 4.20.11.0
329
+ jgem install glimmer-dsl-swt -v 4.20.12.2
351
330
  ```
352
331
 
353
332
  `jgem` is JRuby's version of `gem` command.
@@ -375,7 +354,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
375
354
 
376
355
  Add the following to `Gemfile`:
377
356
  ```
378
- gem 'glimmer-dsl-swt', '~> 4.20.11.0'
357
+ gem 'glimmer-dsl-swt', '~> 4.20.12.2'
379
358
  ```
380
359
 
381
360
  And, then run:
@@ -396,7 +375,7 @@ glimmer
396
375
  ```
397
376
 
398
377
  ```
399
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.11.0
378
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.12.2
400
379
 
401
380
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
402
381
 
@@ -443,7 +422,9 @@ Select a Glimmer task to run: (Press ↑/↓ arrow to move, Enter to select and
443
422
  glimmer scaffold:gem:customwidget[name,namespace] # Scaffold Glimmer::UI::CustomWidget subclass (part of a view) under its own Ruby gem project (namespace is required) [alt: scaffold:gem:cw]
444
423
  ```
445
424
 
446
- Learn more at: [docs/reference/GLIMMER_COMMAND.md](docs/reference/GLIMMER_COMMAND.md)
425
+ Learn more at:
426
+
427
+ [docs/reference/GLIMMER_COMMAND.md](docs/reference/GLIMMER_COMMAND.md)
447
428
 
448
429
  ## Girb (Glimmer irb) Command
449
430
 
@@ -455,7 +436,9 @@ girb
455
436
 
456
437
  ![GIRB](/images/glimmer-girb.png)
457
438
 
458
- Learn more at: [docs/reference/GLIMMER_GIRB.md](docs/reference/GLIMMER_GIRB.md)
439
+ Learn more at:
440
+
441
+ [docs/reference/GLIMMER_GIRB.md](docs/reference/GLIMMER_GIRB.md)
459
442
 
460
443
  ## Glimmer GUI DSL Syntax
461
444
 
@@ -495,13 +478,17 @@ table(:multi) {
495
478
 
496
479
  If you need more widgets, you can check out the [Nebula Project](https://github.com/AndyObtiva/glimmer-cw-nebula) (50+ enterprise-grade custom widgets)
497
480
 
498
- Learn more at: [docs/reference/GLIMMER_GUI_DSL_SYNTAX.md](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md)
481
+ Learn more at:
482
+
483
+ [docs/reference/GLIMMER_GUI_DSL_SYNTAX.md](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md)
499
484
 
500
485
  ## Glimmer Configuration
501
486
 
502
487
  Glimmer configuration may be done via the `Glimmer::Config` module.
503
488
 
504
- Learn more at: [docs/reference/GLIMMER_CONFIGURATION.md](docs/reference/GLIMMER_CONFIGURATION.md)
489
+ Learn more at:
490
+
491
+ [docs/reference/GLIMMER_CONFIGURATION.md](docs/reference/GLIMMER_CONFIGURATION.md)
505
492
 
506
493
  ## Glimmer Style Guide
507
494
 
@@ -509,6 +496,10 @@ Learn more at: [docs/reference/GLIMMER_CONFIGURATION.md](docs/reference/GLIMMER_
509
496
 
510
497
  ## Samples
511
498
 
499
+ See a listing of samples including screenshots and explanations at:
500
+
501
+ [docs/reference/GLIMMER_SAMPLES.md](/docs/reference/GLIMMER_SAMPLES.md)
502
+
512
503
  Check the [samples](/docs/reference/GLIMMER_SAMPLES.md) directory in [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt) for examples on how to write Glimmer applications. To run a sample, make sure to install the `glimmer-dsl-swt` gem first and then run:
513
504
  ```
514
505
  glimmer samples
@@ -518,8 +509,6 @@ glimmer samples
518
509
 
519
510
  ![Glimmer Meta-Sample](/images/glimmer-meta-sample.png)
520
511
 
521
- See a listing of samples including screenshots and explanations at: [docs/reference/GLIMMER_SAMPLES.md](/docs/reference/GLIMMER_SAMPLES.md)
522
-
523
512
  ## In Production
524
513
 
525
514
  The following production apps have been built with Glimmer.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.11.0
1
+ 4.20.12.2
@@ -44,6 +44,8 @@
44
44
  - [Hello, Canvas Transform!](#hello-canvas-transform)
45
45
  - [Hello, Canvas Path!](#hello-canvas-path)
46
46
  - [Hello, Canvas Data Binding!](#hello-canvas-data-binding)
47
+ - [Hello, Canvas Shape Listeners!](#hello-canvas-shape-listeners)
48
+ - [Hello, Canvas Drag and Drop!](#hello-canvas-drag-and-drop)
47
49
  - [Hello, Cursor!](#hello-cursor)
48
50
  - [Hello, Progress Bar!](#hello-progress-bar)
49
51
  - [Hello, Tree!](#hello-tree)
@@ -816,6 +818,32 @@ Hello, Canvas Data Binding!
816
818
 
817
819
  ![Hello Canvas Data Binding Line Changed](/images/glimmer-hello-canvas-data-binding-line-changed.png)
818
820
 
821
+ #### Hello, Canvas Shape Listeners!
822
+
823
+ This sample demonstrates Canvas Shape DSL listeners, which are constrained within the bounds of their owning shape.
824
+
825
+ Code:
826
+
827
+ [samples/hello/hello_canvas_shape_listeners.rb](/samples/hello/hello_canvas_shape_listeners.rb)
828
+
829
+ Hello, Canvas Shape Listeners!
830
+
831
+ ![Hello Canvas Shape Listeners](/images/glimmer-hello-canvas-shape-listeners.png)
832
+
833
+ Hello, Canvas Shape Listeners! - Dragged Circle
834
+
835
+ ![Hello Canvas Shape Listeners Dragged](/images/glimmer-hello-canvas-shape-listeners-dragged.png)
836
+
837
+ #### Hello, Canvas Drag and Drop!
838
+
839
+ This sample demonstrates Canvas Shape DSL drag and drop (different from standard widget drag and drop).
840
+
841
+ Code:
842
+
843
+ [samples/hello/hello_canvas_drag_and_drop.rb](/samples/hello/hello_canvas_drag_and_drop.rb)
844
+
845
+ ![Hello Canvas Drag and Drop](/images/glimmer-hello-canvas-drag-and-drop.gif)
846
+
819
847
  #### Hello, Cursor!
820
848
 
821
849
  This sample demonstrates the use of the `cursor` property keyword to change the mouse cursor.
Binary file
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'glimmer/dsl/expression'
23
23
  require 'glimmer/swt/display_proxy'
24
+ require 'glimmer/swt/custom/shape'
24
25
 
25
26
  module Glimmer
26
27
  module DSL
@@ -31,9 +32,9 @@ module Glimmer
31
32
  def can_interpret?(parent, keyword, *args, &block)
32
33
  Glimmer::Config.logger.debug {"keyword starts with on_: #{keyword.start_with?('on_')}"}
33
34
  return false unless keyword.start_with?('on_')
34
- widget_or_display_parentage = parent.respond_to?(:swt_widget) || parent.is_a?(Glimmer::SWT::DisplayProxy)
35
- Glimmer::Config.logger.debug {"parent #{parent} is a widget or display: #{widget_or_display_parentage}"}
36
- return false unless widget_or_display_parentage
35
+ proper_parent = parent.respond_to?(:swt_widget) || parent.is_a?(Glimmer::SWT::DisplayProxy) || parent.is_a?(Glimmer::SWT::Custom::Shape)
36
+ Glimmer::Config.logger.debug {"parent #{parent} is a widget, shape, or display: #{proper_parent}"}
37
+ return false unless proper_parent
37
38
  Glimmer::Config.logger.debug {"block exists?: #{!block.nil?}"}
38
39
  raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
39
40
  Glimmer::Config.logger.debug {"args are empty?: #{args.empty?}"}
@@ -445,9 +445,15 @@ module Glimmer
445
445
  def app_main_file(app_name)
446
446
  <<~MULTI_LINE_STRING
447
447
  $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
448
-
449
- require 'bundler/setup'
450
- Bundler.require(:default)
448
+
449
+ begin
450
+ require 'bundler/setup'
451
+ Bundler.require(:default)
452
+ rescue
453
+ # this runs when packaged as a gem (no bundler)
454
+ require 'glimmer-dsl-swt'
455
+ # add more gems if needed
456
+ end
451
457
  require '#{file_name(app_name)}/view/app_view'
452
458
 
453
459
  class #{class_name(app_name)}
@@ -634,7 +640,7 @@ module Glimmer
634
640
  ## Top-most widget must be a shell or another custom shell
635
641
  #
636
642
  body {
637
- shell(#{':fill_screen' if shell_type == :desktopify}) {
643
+ shell#{'(:fill_screen)' if shell_type == :desktopify} {
638
644
  # Replace example content below with custom shell content
639
645
  minimum_size #{shell_type == :desktopify ? '768, 432' : '420, 240'}
640
646
  image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
@@ -239,6 +239,7 @@ module Glimmer
239
239
  end
240
240
  end
241
241
  end
242
+ alias translate move_by
242
243
 
243
244
  # rotates shape for an angle around its center
244
245
  # this operation is not cumulative (it resets angle every time)
@@ -563,6 +564,19 @@ module Glimmer
563
564
  end
564
565
  end
565
566
 
567
+ def can_handle_observation_request?(observation_request)
568
+ drawable.can_handle_observation_request?(observation_request)
569
+ end
570
+
571
+ def handle_observation_request(observation_request, &block)
572
+ shape_block = lambda do |event|
573
+ included = include?(event.x, event.y)
574
+ included ||= shapes.to_a.detect { |shape| shape.include?(event.x, event.y) }
575
+ block.call(event) if included
576
+ end
577
+ drawable.handle_observation_request(observation_request, &shape_block)
578
+ end
579
+
566
580
  # Sets data just like SWT widgets
567
581
  def set_data(key=nil, value)
568
582
  @data ||= {}
@@ -180,7 +180,7 @@ module Glimmer
180
180
  raise Glimmer::Error, 'Invalid custom shape for having no body! Please define body block!' if body_block.nil?
181
181
  @body_root = instance_exec(&body_block)
182
182
  raise Glimmer::Error, 'Invalid custom shape for having an empty body! Please fill body block!' if @body_root.nil?
183
- auto_exec do
183
+ auto_exec do # TODO is this necessary given shape is a lightweight construct (not SWT widget) ?
184
184
  @body_root.set_data('custom_shape', self)
185
185
  end
186
186
  execute_hook('after_body')
@@ -0,0 +1,101 @@
1
+ require 'glimmer-dsl-swt'
2
+
3
+ class HelloCanvasDragAndDrop
4
+ include Glimmer::UI::CustomShell
5
+
6
+ body {
7
+ shell {
8
+ row_layout(:vertical) {
9
+ margin_width 0
10
+ margin_height 0
11
+ fill true
12
+ center true
13
+ }
14
+ text 'Hello, Canvas Drag & Drop!'
15
+
16
+ label(:center) {
17
+ text 'Drag orange balls and drop in the square.'
18
+ font height: 16
19
+ }
20
+
21
+ canvas {
22
+ layout_data {
23
+ width 350
24
+ height 350
25
+ }
26
+
27
+ background :white
28
+
29
+ @drop_square = rectangle(150, 260, 50, 50) {
30
+ background :white
31
+
32
+ # unspecified width and height become max width and max height by default
33
+ @drop_square_border = rectangle(0, 0) {
34
+ foreground :black
35
+ line_width 3
36
+ line_style :dash
37
+ }
38
+
39
+ @number_shape = text {
40
+ x :default
41
+ y :default
42
+ string '0'
43
+ }
44
+
45
+ on_mouse_move do
46
+ if @dragging
47
+ @drop_square_border.foreground = :red
48
+ end
49
+ end
50
+
51
+ on_mouse_up do
52
+ if @dragging
53
+ ball_count = @number_shape.string.to_i
54
+ @number_shape.dispose
55
+ @drop_square.content {
56
+ @number_shape = text {
57
+ x :default
58
+ y :default
59
+ string (ball_count + 1).to_s
60
+ }
61
+ }
62
+ @dragging.dispose
63
+ end
64
+ end
65
+ }
66
+
67
+ 10.times do |n|
68
+ an_oval = oval((rand*300).to_i, (rand*200).to_i, 50, 50) {
69
+ background rgb(255, 165, 0)
70
+
71
+ # unspecified width and height become max width and max height by default
72
+ oval(0, 0) {
73
+ foreground :black
74
+ }
75
+
76
+ on_drag_detected do |event|
77
+ @dragging = an_oval
78
+ @last_x = event.x
79
+ @last_y = event.y
80
+ end
81
+ }
82
+ end
83
+
84
+ on_mouse_up do
85
+ @drop_square_border.foreground = :black
86
+ @dragging = nil
87
+ end
88
+
89
+ on_mouse_move do |event|
90
+ if @dragging
91
+ @dragging.move_by((event.x - @last_x), (event.y - @last_y))
92
+ @last_x = event.x
93
+ @last_y = event.y
94
+ end
95
+ end
96
+ }
97
+ }
98
+ }
99
+ end
100
+
101
+ HelloCanvasDragAndDrop.launch
@@ -0,0 +1,171 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer-dsl-swt'
23
+
24
+ class HelloCanvasShapeListeners
25
+ include Glimmer::UI::CustomShell
26
+
27
+ attr_accessor :shape_name, :listener_event, :dragged_shape
28
+
29
+ body {
30
+ shell {
31
+ row_layout(:vertical) {
32
+ fill true
33
+ center true
34
+ margin_width 0
35
+ margin_height 0
36
+ }
37
+
38
+ text 'Hello, Canvas Shape Listeners!'
39
+
40
+ label(:center) {
41
+ text 'Current Shape:'
42
+ font style: :bold
43
+ }
44
+ label(:center) {
45
+ text <= [self, :shape_name]
46
+ }
47
+
48
+ label(:center) {
49
+ text 'Current Event:'
50
+ font style: :bold
51
+ }
52
+ label(:center) {
53
+ text <= [self, :listener_event]
54
+ }
55
+
56
+ canvas { |canvas_proxy|
57
+ layout_data {
58
+ width 350
59
+ height 200
60
+ }
61
+
62
+ background :white
63
+
64
+ @rectangle = rectangle(25, 25, 50, 50) {
65
+ background :red
66
+
67
+ # these listener events are limited to the rectangle bounds
68
+
69
+ on_mouse_down do |event|
70
+ self.shape_name = 'Square'
71
+ self.listener_event = 'Mouse Down'
72
+ end
73
+
74
+ on_drag_detected do |event|
75
+ self.shape_name = 'Square'
76
+ self.listener_event += ' / Drag Detected'
77
+ self.dragged_shape = @rectangle
78
+ end
79
+
80
+ on_mouse_move do |event|
81
+ if listener_event.to_s.empty? || shape_name != 'Square'
82
+ self.listener_event = "Mouse Move"
83
+ elsif !listener_event.to_s.include?('Mouse Move')
84
+ self.listener_event += " / Mouse Move"
85
+ end
86
+ self.shape_name = 'Square'
87
+ end
88
+
89
+ on_mouse_up do |event|
90
+ self.shape_name = 'Square'
91
+ self.listener_event += ' / Mouse Up'
92
+ self.dragged_shape = nil
93
+ end
94
+ }
95
+
96
+ @oval = oval(150, 120, 50, 50) {
97
+ background :green
98
+
99
+ # these listener events are limited to the oval bounds
100
+
101
+ on_mouse_down do |event|
102
+ self.shape_name = 'Circle'
103
+ self.listener_event = 'Mouse Down'
104
+ end
105
+
106
+ on_drag_detected do |event|
107
+ self.shape_name = 'Circle'
108
+ self.listener_event += ' / Drag Detected'
109
+ self.dragged_shape = @oval
110
+ end
111
+
112
+ on_mouse_move do |event|
113
+ if listener_event.to_s.empty? || shape_name != 'Circle'
114
+ self.listener_event = "Mouse Move"
115
+ elsif !listener_event.to_s.include?('Mouse Move')
116
+ self.listener_event += " / Mouse Move"
117
+ end
118
+ self.shape_name = 'Circle'
119
+ end
120
+
121
+ on_mouse_up do |event|
122
+ self.shape_name = 'Circle'
123
+ self.listener_event += ' / Mouse Up'
124
+ self.dragged_shape = nil
125
+ end
126
+ }
127
+
128
+ @polygon = polygon(260, 25, 300, 25, 260, 65) {
129
+ background :blue
130
+
131
+ # these listener events are limited to the polygon bounds
132
+
133
+ on_mouse_down do |event|
134
+ self.shape_name = 'Triangle'
135
+ self.listener_event = 'Mouse Down'
136
+ end
137
+
138
+ on_drag_detected do |event|
139
+ self.shape_name = 'Triangle'
140
+ self.listener_event += ' / Drag Detected'
141
+ self.dragged_shape = @polygon
142
+ end
143
+
144
+ on_mouse_move do |event|
145
+ if listener_event.to_s.empty? || shape_name != 'Triangle'
146
+ self.listener_event = "Mouse Move"
147
+ elsif !listener_event.to_s.include?('Mouse Move')
148
+ self.listener_event += " / Mouse Move"
149
+ end
150
+ self.shape_name = 'Triangle'
151
+ end
152
+
153
+ on_mouse_up do |event|
154
+ self.shape_name = 'Triangle'
155
+ self.listener_event += ' / Mouse Up'
156
+ self.dragged_shape = nil
157
+ end
158
+ }
159
+
160
+ # This is a general canvas listener event, which is used to move shape even if mouse goes out of its bounds
161
+ on_mouse_move do |event|
162
+ dragged_shape.move_by(event.x - @last_x.to_f, event.y - @last_y.to_f) if dragged_shape
163
+ @last_x = event.x
164
+ @last_y = event.y
165
+ end
166
+ }
167
+ }
168
+ }
169
+ end
170
+
171
+ HelloCanvasShapeListeners.launch
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.20.11.0
4
+ version: 4.20.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-22 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -576,7 +576,9 @@ files:
576
576
  - samples/hello/hello_canvas_animation.rb
577
577
  - samples/hello/hello_canvas_animation_multi.rb
578
578
  - samples/hello/hello_canvas_data_binding.rb
579
+ - samples/hello/hello_canvas_drag_and_drop.rb
579
580
  - samples/hello/hello_canvas_path.rb
581
+ - samples/hello/hello_canvas_shape_listeners.rb
580
582
  - samples/hello/hello_canvas_transform.rb
581
583
  - samples/hello/hello_checkbox.rb
582
584
  - samples/hello/hello_checkbox_group.rb