glimmer-dsl-swt 4.20.10.1 → 4.20.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +28 -39
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +6 -0
- data/docs/reference/GLIMMER_SAMPLES.md +17 -0
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +4 -3
- data/lib/glimmer/rake_task/scaffold.rb +10 -4
- data/lib/glimmer/swt/custom/animation.rb +1 -0
- data/lib/glimmer/swt/custom/code_text.rb +21 -0
- data/lib/glimmer/swt/custom/shape.rb +52 -1
- data/lib/glimmer/swt/custom/shape/image.rb +7 -2
- data/samples/hello/hello_canvas_shape_listeners.rb +171 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6def93b1e2b7c5b5275126e53dbb42e23021721f41a23f98528d1f69f01f1b
|
4
|
+
data.tar.gz: 4d5b8fc17d10df490b1614e573d8a678c418f10cc2e5d43d0352905cf5245b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae5f9df309f2e0aada6c7557abb786faffc4cfdac5f82945183389bff644376106f0b41d1bc2b9b0d0cd2aaa14a07f2ad506545290cc7870354c377cad98c06
|
7
|
+
data.tar.gz: 85fabb309339aed175bb2bc662af3b9ba9f8b365114bbdaf3f4a642b94187bf2f07406c32c716b3ab71bcfa739a64ff53e7b846a9228e18ed0fe6d84f9890e3a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 4.20.12.0
|
4
|
+
|
5
|
+
- Canvas Shape Listeners: on_mouse_up, on_mouse_down, on_mouse_move, on_drag_detected
|
6
|
+
- Make scaffolding not generate an empty () after shell
|
7
|
+
|
8
|
+
### 4.20.11.1
|
9
|
+
|
10
|
+
- 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.
|
11
|
+
|
12
|
+
### 4.20.11.0
|
13
|
+
|
14
|
+
- Shape `#center_x`/`#center_y` methods to identify a shape's center point
|
15
|
+
- Shape `#rotate` method to rotate around center point
|
16
|
+
|
17
|
+
### 4.20.10.2
|
18
|
+
|
19
|
+
- Fix issue "Resolve 'NameError: uninitialized constant Glimmer::DataBinding' on Windows" https://github.com/AndyObtiva/glimmer-dsl-swt/issues/9 (originally in https://github.com/AMaleh/glimmer-dsl-swt/pull/1)
|
20
|
+
|
3
21
|
### 4.20.10.1
|
4
22
|
|
5
23
|
- Hello, Scale! sample.
|
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.
|
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.0
|
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.
|
18
|
+
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.12.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).
|
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
|
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
|
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
|
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
|
144
|
+
enabled <= [BaseballGame, :selected_game]
|
151
145
|
|
152
146
|
on_widget_selected {
|
153
147
|
book_selected_game
|
154
148
|
}
|
155
149
|
}
|
156
|
-
}
|
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.
|
329
|
+
jgem install glimmer-dsl-swt -v 4.20.12.0
|
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.
|
357
|
+
gem 'glimmer-dsl-swt', '~> 4.20.12.0'
|
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.
|
378
|
+
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.12.0
|
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:
|
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:
|
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:
|
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:
|
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.
|
1
|
+
4.20.12.0
|
@@ -1901,6 +1901,8 @@ They are implemented with the help of the highly robust Java built-in shape geom
|
|
1901
1901
|
- `Shape#contain?(x, y)` : indicates if shape contains x, y point
|
1902
1902
|
- `Shape#include?(x, y)` : indicates if shape includes x, y point on the edge if drawn or inside if filled (include uses contain for filled shapes)
|
1903
1903
|
- `Shape#move_by(x_delta, y_delta)` : moves shape object at x, y location
|
1904
|
+
- `Shape#rotate(angle)` : rotates around center by an angle (not cumulative, reseting angle on every call)
|
1905
|
+
- `Shape#rotatation_angle` : current rotation angle (according to use of rotate method)
|
1904
1906
|
- `Shape#dispose` : disposes of shape, removing it form its parent canvas, widget, or shape
|
1905
1907
|
- `Shape#content {}` : reopens a shape to add more content inside it using the Glimmer GUI DSL (e.g. Canvas Shape DSL) just like `WidgetProxy#content {}`.
|
1906
1908
|
- `Shape#size` : calculated size for shape bounding box (e.g. a polygon with an irregular shape will have its bounding box width and height calculated)
|
@@ -1921,6 +1923,10 @@ They are implemented with the help of the highly robust Java built-in shape geom
|
|
1921
1923
|
- `Shape#default_y?` : calculated top-left corner y position
|
1922
1924
|
- `Shape#calculated_x` : calculated top-left corner x position when default/delta is set (i.e. centered within parent)
|
1923
1925
|
- `Shape#calculated_y` : calculated top-left corner y position when default/delta is set (i.e. centered within parent)
|
1926
|
+
- `Shape#center_x` : center x
|
1927
|
+
- `Shape#center_y` : center y
|
1928
|
+
- `Shape#x_end` : right-most included x coordinate
|
1929
|
+
- `Shape#y_end` : bottom-most included y coordinate
|
1924
1930
|
|
1925
1931
|
Check [Hello, Canvas!](GLIMMER_SAMPLES.md#hello-canvas) for an example.
|
1926
1932
|
|
@@ -44,6 +44,7 @@
|
|
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)
|
47
48
|
- [Hello, Cursor!](#hello-cursor)
|
48
49
|
- [Hello, Progress Bar!](#hello-progress-bar)
|
49
50
|
- [Hello, Tree!](#hello-tree)
|
@@ -816,6 +817,22 @@ Hello, Canvas Data Binding!
|
|
816
817
|
|
817
818
|
![Hello Canvas Data Binding Line Changed](/images/glimmer-hello-canvas-data-binding-line-changed.png)
|
818
819
|
|
820
|
+
#### Hello, Canvas Shape Listeners!
|
821
|
+
|
822
|
+
This sample demonstrates Canvas Shape DSL listeners, which are constrained within the bounds of their owning shape.
|
823
|
+
|
824
|
+
Code:
|
825
|
+
|
826
|
+
[samples/hello/hello_canvas_shape_listeners.rb](/samples/hello/hello_canvas_shape_listeners.rb)
|
827
|
+
|
828
|
+
Hello, Canvas Shape Listeners!
|
829
|
+
|
830
|
+
![Hello Canvas Shape Listeners](/images/glimmer-hello-canvas-shape-listeners.png)
|
831
|
+
|
832
|
+
Hello, Canvas Shape Listeners! - Dragged Circle
|
833
|
+
|
834
|
+
![Hello Canvas Shape Listeners Dragged](/images/glimmer-hello-canvas-shape-listeners-dragged.png)
|
835
|
+
|
819
836
|
#### Hello, Cursor!
|
820
837
|
|
821
838
|
This sample demonstrates the use of the `cursor` property keyword to change the mouse cursor.
|
data/glimmer-dsl-swt.gemspec
CHANGED
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
|
-
|
35
|
-
Glimmer::Config.logger.debug {"parent #{parent} is a widget or display: #{
|
36
|
-
return false unless
|
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
|
-
|
450
|
-
|
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
|
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?
|
@@ -19,6 +19,7 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
+
require 'glimmer/data_binding/observable_model'
|
22
23
|
require 'glimmer/swt/properties'
|
23
24
|
require 'glimmer/swt/custom/shape'
|
24
25
|
require 'bigdecimal'
|
@@ -1,3 +1,24 @@
|
|
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
|
+
|
1
22
|
require 'glimmer/ui/custom_widget'
|
2
23
|
|
3
24
|
module Glimmer
|
@@ -239,6 +239,46 @@ module Glimmer
|
|
239
239
|
end
|
240
240
|
end
|
241
241
|
end
|
242
|
+
alias translate move_by
|
243
|
+
|
244
|
+
# rotates shape for an angle around its center
|
245
|
+
# this operation is not cumulative (it resets angle every time)
|
246
|
+
# consumers may inspect corresponding rotation_angle attribute to know which angle the shape is currently at for convenience
|
247
|
+
# this overrides any pre-existing transforms that are applied to shape
|
248
|
+
def rotate(angle)
|
249
|
+
half_width = calculated_width/2.0
|
250
|
+
half_height = calculated_height/2.0
|
251
|
+
self.transform = Glimmer::SWT::TransformProxy.new(self).translate(half_width, half_height).rotate(angle).translate(-1.0*half_width, -1.0*half_height)
|
252
|
+
@rotation_angle = angle
|
253
|
+
end
|
254
|
+
|
255
|
+
# returns rotation angle
|
256
|
+
# consumers may inspect rotation_angle attribute to know which angle the shape is rotated at via rotate method
|
257
|
+
# it is not guaranteed to give the right result if a transform is applied outside of rotate method.
|
258
|
+
# starts at 0
|
259
|
+
def rotation_angle
|
260
|
+
@rotation_angle.to_f
|
261
|
+
end
|
262
|
+
|
263
|
+
def center_x
|
264
|
+
center_x_dependencies = [x_end, calculated_width]
|
265
|
+
if center_x_dependencies != @center_x_dependencies
|
266
|
+
@center_x_dependencies = center_x_dependencies
|
267
|
+
the_x_end, the_calculated_width = center_x_dependencies
|
268
|
+
@center_x = the_x_end - the_calculated_width/2.0
|
269
|
+
end
|
270
|
+
@center_x
|
271
|
+
end
|
272
|
+
|
273
|
+
def center_y
|
274
|
+
center_y_dependencies = [y_end, calculated_height]
|
275
|
+
if center_y_dependencies != @center_y_dependencies
|
276
|
+
@center_y_dependencies = center_y_dependencies
|
277
|
+
the_y_end, the_calculated_height = center_y_dependencies
|
278
|
+
@center_y = the_y_end - the_calculated_height/2.0
|
279
|
+
end
|
280
|
+
@center_y
|
281
|
+
end
|
242
282
|
|
243
283
|
def content(&block)
|
244
284
|
Glimmer::SWT::DisplayProxy.instance.auto_exec do
|
@@ -524,6 +564,17 @@ module Glimmer
|
|
524
564
|
end
|
525
565
|
end
|
526
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
|
+
block.call(event) if include?(event.x, event.y)
|
574
|
+
end
|
575
|
+
drawable.handle_observation_request(observation_request, &shape_block)
|
576
|
+
end
|
577
|
+
|
527
578
|
# Sets data just like SWT widgets
|
528
579
|
def set_data(key=nil, value)
|
529
580
|
@data ||= {}
|
@@ -936,7 +987,7 @@ module Glimmer
|
|
936
987
|
@x_end
|
937
988
|
end
|
938
989
|
|
939
|
-
#
|
990
|
+
# bottom-most y coordinate in this shape (adding up its height and location)
|
940
991
|
def y_end
|
941
992
|
y_end_dependencies = [calculated_height, default_y?, !default_y? && y]
|
942
993
|
if y_end_dependencies != @y_end_dependencies
|
@@ -25,6 +25,7 @@ require 'glimmer/swt/display_proxy'
|
|
25
25
|
require 'glimmer/swt/color_proxy'
|
26
26
|
require 'glimmer/swt/font_proxy'
|
27
27
|
require 'glimmer/swt/transform_proxy'
|
28
|
+
require 'glimmer/swt/image_proxy'
|
28
29
|
|
29
30
|
module Glimmer
|
30
31
|
module SWT
|
@@ -69,11 +70,15 @@ module Glimmer
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def width
|
72
|
-
dest_width ||
|
73
|
+
dest_width || image_proxy.bounds.width
|
73
74
|
end
|
74
75
|
|
75
76
|
def height
|
76
|
-
dest_height ||
|
77
|
+
dest_height || image_proxy.bounds.height
|
78
|
+
end
|
79
|
+
|
80
|
+
def image_proxy
|
81
|
+
ImageProxy.create(image)
|
77
82
|
end
|
78
83
|
|
79
84
|
def default_x?
|
@@ -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.
|
4
|
+
version: 4.20.12.0
|
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-
|
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
|
@@ -577,6 +577,7 @@ files:
|
|
577
577
|
- samples/hello/hello_canvas_animation_multi.rb
|
578
578
|
- samples/hello/hello_canvas_data_binding.rb
|
579
579
|
- samples/hello/hello_canvas_path.rb
|
580
|
+
- samples/hello/hello_canvas_shape_listeners.rb
|
580
581
|
- samples/hello/hello_canvas_transform.rb
|
581
582
|
- samples/hello/hello_checkbox.rb
|
582
583
|
- samples/hello/hello_checkbox_group.rb
|