glimmer-dsl-swt 4.18.0.2 → 4.18.1.0

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: 7aaf0dca4f250ba15d538f31b0d127fa1f49187208dde61e11fb7d59ce54b33b
4
- data.tar.gz: 2fc8e9ea4778467e9f29c90c1e5eaa908eb73fa2df0fea2680141f2c89492174
3
+ metadata.gz: 174d5b75d96fe6595809e3f212aa30b4fd17caec61fe98018ce8fcf72880c036
4
+ data.tar.gz: 42f16bb6b36d68dea3ed1886d1993f65b539cc47e22799a4c7bd02fad2208389
5
5
  SHA512:
6
- metadata.gz: 5babde26d2b5440917f5b30ba2409701f11fa7210e190922ab3d4873d2db03113b5a3b68adfe1a97767cff2ed931259728dc4735cee596aec09c0f21cc9ed3d6
7
- data.tar.gz: 198238910b291593d4249716b29e7ce52fce909d3f1b4e8606d1451c9c22b19a74cc0f19fdda2f6f7a3f4182cc0fc595770bc5359ca82890db5b4892204e54bb
6
+ metadata.gz: 220d7fbbba99b5b9f65c334cd0aec9a3ddb4120227d3ea2876e7ab9327027d70e651b849a4891dd58e5e61f85dce01382919a212c2c39d9d79af83106596bfa3
7
+ data.tar.gz: ca8a7864a504618abd517aaf97832a185b84e86b7fb21ef4a27ffd70edc068822d1d5aae0ebdd192c9cd5ab106411fd78512354f676e49e1ac2b0dd8a1072154
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.18.1.0
4
+
5
+ - Canvas Shape DSL
6
+ - Hello, Canvas! Sample
7
+ - Animation DSL
8
+ - Hello, Canvas Animation! Sample
9
+ - Fixed issue with async_exec not working in ShellProxy when delegate widget is nil
10
+
3
11
  ### 4.18.0.2
4
12
 
5
13
  - Minor update on Hello, Dialog! 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.18.0.2
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.18.1.0
2
2
 
3
3
 
4
4
  ## JRuby Desktop Development GUI Framework
@@ -286,6 +286,8 @@ Glimmer App:
286
286
  - [Cursor](#cursor)
287
287
  - [Layouts](#layouts)
288
288
  - [Layout Data](#layout-data)
289
+ - [Canvas Shape DSL](#canvas-shape-dsl)
290
+ - [Canvas Animation DSL](#canvas-animation-dsl)
289
291
  - [Data-Binding](#data-binding)
290
292
  - [General Examples](#general-examples)
291
293
  - [Combo](#combo)
@@ -359,6 +361,8 @@ Glimmer App:
359
361
  - [Hello, Button!](#hello-button)
360
362
  - [Hello, Link!](#hello-link)
361
363
  - [Hello, Dialog!](#hello-dialog)
364
+ - [Hello, Canvas!](#hello-canvas)
365
+ - [Hello, Canvas Animation!](#hello-canvas-animation)
362
366
  - [Elaborate Samples](#elaborate-samples)
363
367
  - [User Profile](#user-profile)
364
368
  - [Login](#login)
@@ -452,7 +456,7 @@ jgem install glimmer-dsl-swt
452
456
 
453
457
  Or this command if you want a specific version:
454
458
  ```
455
- jgem install glimmer-dsl-swt -v 4.18.0.2
459
+ jgem install glimmer-dsl-swt -v 4.18.1.0
456
460
 
457
461
 
458
462
  ```
@@ -472,7 +476,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
472
476
 
473
477
  Add the following to `Gemfile`:
474
478
  ```
475
- gem 'glimmer-dsl-swt', '~> 4.18.0.2
479
+ gem 'glimmer-dsl-swt', '~> 4.18.1.0
476
480
  '
477
481
  ```
478
482
 
@@ -531,7 +535,7 @@ bin/glimmer samples
531
535
  Below are the full usage instructions that come up when running `glimmer` without args.
532
536
 
533
537
  ```
534
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.18.0.2
538
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.18.1.0
535
539
 
536
540
 
537
541
 
@@ -1010,7 +1014,7 @@ Output:
1010
1014
 
1011
1015
  Css glimmer-dsl-css 1.1.0 AndyMaleh Glimmer DSL for CSS
1012
1016
  Opal glimmer-dsl-opal 0.8.0 AndyMaleh Glimmer DSL for Opal
1013
- Swt glimmer-dsl-swt 4.18.0.2
1017
+ Swt glimmer-dsl-swt 4.18.1.0
1014
1018
 
1015
1019
  AndyMaleh Glimmer DSL for SWT
1016
1020
  Tk glimmer-dsl-tk 0.0.6 AndyMaleh Glimmer DSL for Tk
@@ -2285,6 +2289,113 @@ Also, for a reference, check the SWT API:
2285
2289
 
2286
2290
  https://help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/index.html
2287
2291
 
2292
+
2293
+ ### Canvas Shape DSL
2294
+
2295
+ (note: this is a very new feature of Glimmer. It may change a bit while getting battle tested. As always, you could default to basic SWT usage if needed.)
2296
+
2297
+ Glimmer supports drawing graphics directly on a `canvas` widget via SWT (or any widget for that matter though `canvas` is recommended for drawing).
2298
+
2299
+ This is accomplished via the Shape DSL a sub-DSL of the Glimmer GUI DSL, which makes it possible to draw graphics declaratively with very understandable and maintainable syntax.
2300
+
2301
+ Shape keywords are listed below (they basically match method names and arguments on [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) minus the `draw` or `fill` prefix in downcase):
2302
+ - `arc​(int x, int y, int width, int height, int startAngle, int arcAngle)`
2303
+ - `focus​(int x, int y, int width, int height)`
2304
+ - `image(Image image, int x, int y)`
2305
+ - `line(int x1, int y1, int x2, int y2)`
2306
+ - `oval(int x, int y, int width, int height)`
2307
+ - `point​(int x, int y)`
2308
+ - `polygon(int[] pointArray)`
2309
+ - `polyline(int[] pointArray)`
2310
+ - `rectangle(int x, int y, int width, int height)`
2311
+ - `round_rectangle(int x, int y, int width, int height, int arcWidth, int arcHeight)`
2312
+ - `gradiant_rectangle​(int x, int y, int width, int height, boolean vertical)`
2313
+ - `text(String string, int x, int y)`
2314
+
2315
+ Shape keywords that can be filled with color can take an additional keyword argument `fill: true`
2316
+
2317
+ Optionally, a shape keyword takes a block that can set any attributes from [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) (methods starting with `set`), which enable setting the `background` for filling and `foreground` for drawing.
2318
+
2319
+ Example (you may copy/paste in [`girb`](#girb-glimmer-irb-command)):
2320
+
2321
+ ```ruby
2322
+ include Glimmer
2323
+
2324
+ shell {
2325
+ text 'Canvas Example!'
2326
+ minimum_size 320, 400
2327
+
2328
+ canvas {
2329
+ background :yellow
2330
+ rectangle(0, 0, 220, 400, fill: true) {
2331
+ background :red
2332
+ }
2333
+ round_rectangle(50, 20, 300, 150, 30, 50, fill: true) {
2334
+ background :magenta
2335
+ }
2336
+ gradient_rectangle(150, 200, 100, 70, true, fill: true) {
2337
+ background :dark_magenta
2338
+ foreground :yellow
2339
+ }
2340
+ rectangle(200, 80, 108, 36) {
2341
+ foreground color(:dark_blue)
2342
+ }
2343
+ }
2344
+ }.open
2345
+ ```
2346
+
2347
+ Learn more at the [Hello, Canvas! Sample](#hello-canvas).
2348
+
2349
+ ### Canvas Animation DSL
2350
+
2351
+ (note: this is a very new feature of Glimmer. It may change a bit while getting battle tested. As always, you could default to basic SWT usage if needed.)
2352
+
2353
+ Glimmer additionally provides built-in support for animations via a declarative Animation DSL, another sub-DSL of the Glimmer GUI DSL.
2354
+
2355
+ Animations take advantage of multi-threading, each animation runs in its own independent thread of execution while updating the GUI asynchronously.
2356
+
2357
+ This example says it all (it moves a tiny red square across a blue background):
2358
+
2359
+ ```ruby
2360
+ include Glimmer
2361
+
2362
+ shell {
2363
+ text 'Canvas Animation Example!'
2364
+ minimum_size 400, 400
2365
+
2366
+ canvas {
2367
+ animation {
2368
+ every 0.1
2369
+
2370
+ frame { |index|
2371
+ background rgb(index%100, index%100 + 100, index%55 + 200)
2372
+ rectangle(index, index, 20, 20, fill: true) {
2373
+ background :red
2374
+ }
2375
+ }
2376
+ }
2377
+ }
2378
+ }.open
2379
+ ```
2380
+
2381
+ Keywords involved:
2382
+ - `animation` declares an animation under a canvas, which renders frames indefinitely or finitely depending on properties
2383
+ - `every` specifies delay in seconds between every two frame renders
2384
+ - `frame` a block that can contain Shape DSL syntax that is rendered dynamically with variables calculated on the fly
2385
+ - `cycle` a property that takes an array to cycle into a second variable for the `frame` block
2386
+ - `cycle_count` an optional cycle count limit after which the animation stops
2387
+ - `frame_count` an optional frame count limit after which the animation stops
2388
+ - `started` a boolean indicating if the animation is started right away or stopped waiting for manual startup via `#start` method
2389
+
2390
+ API:
2391
+ - `#start` starts animation as a method on the animation object (returned from `animation` keyword)
2392
+ - `#stop` stops animation gracefully as a method on the animation object (returned from `animation` keyword)
2393
+
2394
+ Caveat:
2395
+ In order for animation to occur, the frame block must include changes that happen directly on the canvas (like setting initial background updating every frame) not just changes to shapes. This should be fixed in the future.
2396
+
2397
+ Learn more at the [Hello, Canvas Animation! Sample](#hello-canvas-animation).
2398
+
2288
2399
  ### Data-Binding
2289
2400
 
2290
2401
  Data-binding is done with `bind` command following widget property to bind and taking model and bindable attribute as arguments.
@@ -4357,6 +4468,34 @@ Hello, Dialog! Open Dialog
4357
4468
 
4358
4469
  ![Hello Dialog Open Dialog](images/glimmer-hello-dialog-open-dialog.png)
4359
4470
 
4471
+ #### Hello, Canvas!
4472
+
4473
+ This sample demonstrates the use of the `canvas` widget and [Shape DSL](#canvas-shape-dsl) in Glimmer.
4474
+
4475
+ Code:
4476
+
4477
+ [samples/hello/hello_canvas.rb](samples/hello/hello_canvas.rb)
4478
+
4479
+ Hello, Canvas!
4480
+
4481
+ ![Hello Canvas](images/glimmer-hello-canvas.png)
4482
+
4483
+ #### Hello, Canvas Animation!
4484
+
4485
+ This sample demonstrates the use of the `canvas` widget and [Animation DSL](#canvas-animation-dsl) in Glimmer.
4486
+
4487
+ Code:
4488
+
4489
+ [samples/hello/hello_canvas_animation.rb](samples/hello/hello_canvas_animation.rb)
4490
+
4491
+ Hello, Canvas Animation!
4492
+
4493
+ ![Hello Canvas Animation](images/glimmer-hello-canvas-animation.png)
4494
+
4495
+ Hello, Canvas Animation Another Frame!
4496
+
4497
+ ![Hello Canvas Animation Frame 2](images/glimmer-hello-canvas-animation-frame2.png)
4498
+
4360
4499
  ### Elaborate Samples
4361
4500
 
4362
4501
  For more elaborate samples, check the following:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.18.0.2
1
+ 4.18.1.0
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: glimmer-dsl-swt 4.18.0.2 ruby lib
5
+ # stub: glimmer-dsl-swt 4.18.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-swt".freeze
9
- s.version = "4.18.0.2"
9
+ s.version = "4.18.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["AndyMaleh".freeze]
14
- s.date = "2021-01-13"
14
+ s.date = "2021-01-19"
15
15
  s.description = "Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) is a native-GUI cross-platform desktop development library written in JRuby, an OS-threaded faster version of Ruby. Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring of desktop application user-interfaces while relying on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in data-binding support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models (test-first) afterwards. To get started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets. Glimmer also includes native-executable packaging support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in Ruby as truly native DMG/PKG/APP files on the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged Shell Scripts on Linux.".freeze
16
16
  s.email = "andy.am@gmail.com".freeze
17
17
  s.executables = ["glimmer".freeze, "girb".freeze]
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
  "lib/glimmer/data_binding/table_items_binding.rb",
43
43
  "lib/glimmer/data_binding/tree_items_binding.rb",
44
44
  "lib/glimmer/data_binding/widget_binding.rb",
45
+ "lib/glimmer/dsl/swt/animation_expression.rb",
45
46
  "lib/glimmer/dsl/swt/async_exec_expression.rb",
46
47
  "lib/glimmer/dsl/swt/bind_expression.rb",
47
48
  "lib/glimmer/dsl/swt/block_property_expression.rb",
@@ -73,6 +74,7 @@ Gem::Specification.new do |s|
73
74
  "lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb",
74
75
  "lib/glimmer/dsl/swt/rgb_expression.rb",
75
76
  "lib/glimmer/dsl/swt/rgba_expression.rb",
77
+ "lib/glimmer/dsl/swt/shape_expression.rb",
76
78
  "lib/glimmer/dsl/swt/shell_expression.rb",
77
79
  "lib/glimmer/dsl/swt/swt_expression.rb",
78
80
  "lib/glimmer/dsl/swt/sync_exec_expression.rb",
@@ -89,9 +91,12 @@ Gem::Specification.new do |s|
89
91
  "lib/glimmer/rake_task/scaffold.rb",
90
92
  "lib/glimmer/swt/color_proxy.rb",
91
93
  "lib/glimmer/swt/cursor_proxy.rb",
94
+ "lib/glimmer/swt/custom/animation.rb",
92
95
  "lib/glimmer/swt/custom/checkbox_group.rb",
93
96
  "lib/glimmer/swt/custom/code_text.rb",
97
+ "lib/glimmer/swt/custom/drawable.rb",
94
98
  "lib/glimmer/swt/custom/radio_group.rb",
99
+ "lib/glimmer/swt/custom/shape.rb",
95
100
  "lib/glimmer/swt/date_time_proxy.rb",
96
101
  "lib/glimmer/swt/directory_dialog_proxy.rb",
97
102
  "lib/glimmer/swt/display_proxy.rb",
@@ -105,6 +110,7 @@ Gem::Specification.new do |s|
105
110
  "lib/glimmer/swt/menu_proxy.rb",
106
111
  "lib/glimmer/swt/message_box_proxy.rb",
107
112
  "lib/glimmer/swt/packages.rb",
113
+ "lib/glimmer/swt/properties.rb",
108
114
  "lib/glimmer/swt/sash_form_proxy.rb",
109
115
  "lib/glimmer/swt/scrolled_composite_proxy.rb",
110
116
  "lib/glimmer/swt/shell_proxy.rb",
@@ -132,6 +138,8 @@ Gem::Specification.new do |s|
132
138
  "samples/elaborate/user_profile.rb",
133
139
  "samples/hello/hello_browser.rb",
134
140
  "samples/hello/hello_button.rb",
141
+ "samples/hello/hello_canvas.rb",
142
+ "samples/hello/hello_canvas_animation.rb",
135
143
  "samples/hello/hello_checkbox.rb",
136
144
  "samples/hello/hello_checkbox_group.rb",
137
145
  "samples/hello/hello_combo.rb",
@@ -174,7 +182,7 @@ Gem::Specification.new do |s|
174
182
  s.specification_version = 4
175
183
 
176
184
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
177
- s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 1.0.7"])
185
+ s.add_runtime_dependency(%q<glimmer>.freeze, ["~> 1.0.8"])
178
186
  s.add_runtime_dependency(%q<super_module>.freeze, [">= 1.4.1", "< 2.0.0"])
179
187
  s.add_runtime_dependency(%q<nested_inherited_jruby_include_package>.freeze, [">= 0.3.0", "< 2.0.0"])
180
188
  s.add_runtime_dependency(%q<puts_debuggerer>.freeze, [">= 0.11.0", "< 2.0.0"])
@@ -193,7 +201,7 @@ Gem::Specification.new do |s|
193
201
  s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.16.1"])
194
202
  s.add_development_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
195
203
  else
196
- s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.7"])
204
+ s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.8"])
197
205
  s.add_dependency(%q<super_module>.freeze, [">= 1.4.1", "< 2.0.0"])
198
206
  s.add_dependency(%q<nested_inherited_jruby_include_package>.freeze, [">= 0.3.0", "< 2.0.0"])
199
207
  s.add_dependency(%q<puts_debuggerer>.freeze, [">= 0.11.0", "< 2.0.0"])
@@ -213,7 +221,7 @@ Gem::Specification.new do |s|
213
221
  s.add_dependency(%q<simplecov-lcov>.freeze, ["~> 0.7.0"])
214
222
  end
215
223
  else
216
- s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.7"])
224
+ s.add_dependency(%q<glimmer>.freeze, ["~> 1.0.8"])
217
225
  s.add_dependency(%q<super_module>.freeze, [">= 1.4.1", "< 2.0.0"])
218
226
  s.add_dependency(%q<nested_inherited_jruby_include_package>.freeze, [">= 0.3.0", "< 2.0.0"])
219
227
  s.add_dependency(%q<puts_debuggerer>.freeze, [">= 0.11.0", "< 2.0.0"])
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -30,7 +30,7 @@ module Glimmer
30
30
  'org.eclipse.swt.graphics',
31
31
  'org.eclipse.swt.browser',
32
32
  'org.eclipse.swt.custom',
33
- 'org.eclipse.swt.dnd',
33
+ 'org.eclipse.swt.dnd',
34
34
  ]
35
35
 
36
36
  class << self
@@ -99,9 +99,9 @@ module Glimmer
99
99
  end
100
100
 
101
101
  def reset_logger!
102
- @first_time = !defined?(@@logger)
102
+ @first_time = !defined?(@@logger)
103
103
  old_level = logger.level unless @first_time
104
- self.logger = Logging.logger['glimmer'].tap do |logger|
104
+ self.logger = Logging.logger['glimmer'].tap do |logger|
105
105
  logger.level = old_level || :error
106
106
  appenders = []
107
107
  appenders << Logging.appenders.stdout(logging_appender_options) if logging_devices.include?(:stdout)
@@ -37,6 +37,7 @@ require 'super_module'
37
37
  require 'rouge'
38
38
  require 'date'
39
39
  require 'facets/string/capitalized'
40
+ require 'facets/hash/symbolize_keys'
40
41
 
41
42
  # Internal requires
42
43
  require 'ext/glimmer/config'
@@ -0,0 +1,43 @@
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/static_expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/swt/custom/animation'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module SWT
29
+ class AnimationExpression < StaticExpression
30
+ include ParentExpression
31
+
32
+ def interpret(parent, keyword, *args, &block)
33
+ Glimmer::SWT::Custom::Animation.new(parent)
34
+ end
35
+
36
+ def add_content(parent, &block)
37
+ super
38
+ parent.post_add_content
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -54,6 +54,7 @@ module Glimmer
54
54
  block_property
55
55
  widget
56
56
  custom_widget
57
+ shape
57
58
  ]
58
59
  )
59
60
  end
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -22,6 +22,7 @@
22
22
  require 'glimmer/dsl/expression'
23
23
  require 'glimmer/dsl/top_level_expression'
24
24
  require 'glimmer/swt/font_proxy'
25
+ require 'glimmer/swt/custom/shape'
25
26
 
26
27
  module Glimmer
27
28
  module DSL
@@ -32,9 +33,10 @@ module Glimmer
32
33
  include TopLevelExpression
33
34
 
34
35
  def can_interpret?(parent, keyword, *args, &block)
35
- keyword.to_s == 'font' and
36
+ keyword.to_s == 'font' and
36
37
  (parent.nil? || !parent.respond_to?('font')) and
37
- args.size == 1 and
38
+ !parent.is_a?(Glimmer::SWT::Custom::Shape) and
39
+ args.size == 1 and
38
40
  args.first.is_a?(Hash)
39
41
  end
40
42
 
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -0,0 +1,56 @@
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/expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/swt/swt_proxy'
25
+ require 'glimmer/swt/custom/shape'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module SWT
30
+ class ShapeExpression < Expression
31
+ include ParentExpression
32
+
33
+ def can_interpret?(parent, keyword, *args, &block)
34
+ (
35
+ (parent.respond_to?(:swt_widget) and parent.swt_widget.is_a?(org.eclipse.swt.graphics.Drawable)) or
36
+ (parent.respond_to?(:swt_display) and parent.swt_display.is_a?(org.eclipse.swt.graphics.Drawable))
37
+ ) and
38
+ Glimmer::SWT::Custom::Shape.valid?(parent, keyword, *args, &block)
39
+ end
40
+
41
+ def interpret(parent, keyword, *args, &block)
42
+ Glimmer::SWT::Custom::Shape.new(parent, keyword, *args)
43
+ end
44
+
45
+ def add_content(parent, &block)
46
+ super
47
+ parent.post_add_content
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -32,9 +32,10 @@ module Glimmer
32
32
  EXCLUDED_KEYWORDS = %w[shell display tab_item]
33
33
 
34
34
  def can_interpret?(parent, keyword, *args, &block)
35
- !EXCLUDED_KEYWORDS.include?(keyword) and
36
- parent.respond_to?(:swt_widget) and #TODO change to composite?(parent)
35
+ result = !EXCLUDED_KEYWORDS.include?(keyword) &&
36
+ parent.respond_to?(:swt_widget) && #TODO change to composite?(parent)
37
37
  Glimmer::SWT::WidgetProxy.widget_exists?(keyword)
38
+ (keyword.to_s == 'text' && args.first.is_a?(String)) ? false : result
38
39
  end
39
40
 
40
41
  def interpret(parent, keyword, *args, &block)
@@ -47,8 +48,11 @@ module Glimmer
47
48
  end
48
49
 
49
50
  end
51
+
50
52
  end
53
+
51
54
  end
55
+
52
56
  end
53
57
 
54
58
  require 'glimmer/swt/widget_proxy'
@@ -0,0 +1,116 @@
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/swt/properties'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ module Custom
27
+ # Represents an animation declaratively
28
+ class Animation
29
+ include Properties # TODO rename to Properties
30
+
31
+ attr_reader :parent, :options, :frame_index
32
+ alias current_frame_index frame_index
33
+ attr_accessor :frame_block, :every, :cycle, :cycle_count, :frame_count, :started
34
+ # TODO consider supporting an async: false option
35
+
36
+ def initialize(parent)
37
+ @parent = parent
38
+ @started = true
39
+ @frame_index = 0
40
+ end
41
+
42
+ def post_add_content
43
+ @parent.on_widget_disposed { stop }
44
+ start if @started
45
+ end
46
+
47
+ def start
48
+ swt_display = Glimmer::SWT::DisplayProxy.instance.swt_display
49
+ return if swt_display.is_disposed?
50
+ Thread.new do
51
+ frame_rendering_block = lambda do
52
+ block_args = [@frame_index]
53
+ block_args << @cycle[@frame_index % @cycle.length] if @cycle.is_a?(Array)
54
+ swt_display.async_exec do
55
+ @parent.clear_shapes
56
+ @parent.content {
57
+ frame_block.call(*block_args)
58
+ }
59
+ end
60
+ @frame_index += 1
61
+ sleep(every) if every.is_a?(Numeric)
62
+ end
63
+
64
+ if cycle_count.is_a?(Integer) && cycle.is_a?(Array)
65
+ (cycle_count * cycle.length).times do
66
+ break if break_condition?
67
+ begin
68
+ frame_rendering_block.call
69
+ rescue => e
70
+ Glimmer::Config.logger.error {e}
71
+ break
72
+ end
73
+ end
74
+ else
75
+ loop do
76
+ break if break_condition?
77
+ begin
78
+ frame_rendering_block.call
79
+ rescue => e
80
+ Glimmer::Config.logger.error {e}
81
+ break
82
+ end
83
+ end
84
+ end
85
+ @started = false
86
+ end
87
+ end
88
+
89
+ def stop
90
+ @started = false
91
+ end
92
+
93
+ def has_attribute?(attribute_name, *args)
94
+ respond_to?(ruby_attribute_setter(attribute_name)) && respond_to?(ruby_attribute_getter(attribute_name))
95
+ end
96
+
97
+ def set_attribute(attribute_name, *args)
98
+ send(ruby_attribute_setter(attribute_name), *args)
99
+ end
100
+
101
+ def get_attribute(attribute_name)
102
+ send(ruby_attribute_getter(attribute_name))
103
+ end
104
+
105
+ private
106
+
107
+ def break_condition?
108
+ !@started || (@frame_count.is_a?(Integer) && @frame_index == @frame_count)
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,43 @@
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
+ module Glimmer
23
+ module SWT
24
+ module Custom
25
+ # Represents SWT drawable controls (widgets like canvas) and display
26
+ module Drawable
27
+ def shapes
28
+ @shapes ||= []
29
+ end
30
+
31
+ def clear_shapes
32
+ shapes.dup.each do |shape|
33
+ shape.paint_listener_proxy&.unregister
34
+ shapes.delete(shape)
35
+ end
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,135 @@
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/swt/properties'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ module Custom
27
+ # Represents a shape (graphics) to be drawn on a control/widget/canvas/display
28
+ # swt_widget returns the parent (e.g. a `canvas` WidgetProxy), equivalent to `parent.swt_widget`
29
+ # That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
30
+ class Shape
31
+ include Properties
32
+ # TODO support textExtent as an option
33
+ # TODO support a Pattern DSL for methods that take Pattern arguments
34
+
35
+ class << self
36
+ def valid?(parent, keyword, *args, &block)
37
+ gc_instance_methods.include?(method_name(keyword, args))
38
+ end
39
+
40
+ def gc_instance_methods
41
+ org.eclipse.swt.graphics.GC.instance_methods.map(&:to_s)
42
+ end
43
+
44
+ def arg_options(args, extract: false)
45
+ arg_options_method = extract ? :pop : :last
46
+ options = args.send(arg_options_method) if args.last.is_a?(Hash)
47
+ options.nil? ? {} : options.symbolize_keys
48
+ end
49
+
50
+ def method_name(keyword, args)
51
+ gc_instance_method_name_prefix = arg_options(args)[:fill] ? 'fill_' : 'draw_'
52
+ "#{gc_instance_method_name_prefix}#{keyword}"
53
+ end
54
+ end
55
+
56
+ attr_reader :parent, :name, :args, :options, :swt_widget, :paint_listener_proxy
57
+
58
+ def initialize(parent, keyword, *args)
59
+ @parent = parent
60
+ @name = keyword
61
+ @method_name = self.class.method_name(keyword, args)
62
+ @options = self.class.arg_options(args, extract: true)
63
+ @args = args
64
+ @swt_widget = parent.respond_to?(:swt_display) ? parent.swt_display : parent.swt_widget
65
+ @properties = {}
66
+ @parent.shapes << self
67
+ end
68
+
69
+ def fill?
70
+ !draw?
71
+ end
72
+
73
+ def draw?
74
+ !@options[:fill]
75
+ end
76
+
77
+ def post_add_content
78
+ event_handler = lambda do |event|
79
+ @properties.each do |property, args|
80
+ method_name = attribute_setter(property)
81
+ handle_conversions(method_name, args)
82
+ event.gc.send(method_name, *args)
83
+ end
84
+ event.gc.send(@method_name, *@args)
85
+ end
86
+ if parent.respond_to?(:swt_display)
87
+ @paint_listener_proxy = @parent.on_swt_paint(&event_handler)
88
+ else
89
+ @paint_listener_proxy = @parent.on_paint_control(&event_handler)
90
+ end
91
+ end
92
+
93
+ def handle_conversions(method_name, args)
94
+ the_java_method = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.detect {|m| m.name == method_name}
95
+ if args.first.is_a?(Symbol) || args.first.is_a?(String)
96
+ if the_java_method.parameter_types.first == Color.java_class
97
+ args[0] = ColorProxy.new(args[0])
98
+ end
99
+ end
100
+ if args.first.is_a?(ColorProxy)
101
+ args[0] = args[0].swt_color
102
+ end
103
+ if args.first.is_a?(Hash)
104
+ if the_java_method.parameter_types.first == Font.java_class
105
+ args[0] = FontProxy.new(args[0])
106
+ end
107
+ end
108
+ if args.first.is_a?(FontProxy)
109
+ args[0] = args[0].swt_font
110
+ end
111
+
112
+ # TODO convert SWT style symbol to integer if method takes integer
113
+ end
114
+
115
+ def has_attribute?(attribute_name, *args)
116
+ # TODO test that attribute getter responds too
117
+ self.class.gc_instance_methods.include?(attribute_setter(attribute_name))
118
+ end
119
+
120
+ def set_attribute(attribute_name, *args)
121
+ # TODO special treatment for color symbols
122
+ @properties[attribute_name] = args
123
+ end
124
+
125
+ def get_attribute(attribute_name)
126
+ @properties.symbolize_keys[attribute_name.to_s.to_sym]
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -20,6 +20,7 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/swt/widget_listener_proxy'
23
+ require 'glimmer/swt/custom/drawable'
23
24
 
24
25
  module Glimmer
25
26
  module SWT
@@ -36,6 +37,8 @@ module Glimmer
36
37
  # Follows the Proxy Design Pattern
37
38
  class DisplayProxy
38
39
  include_package 'org.eclipse.swt.widgets'
40
+
41
+ include Custom::Drawable
39
42
 
40
43
  OBSERVED_MENU_ITEMS = ['about', 'preferences']
41
44
 
@@ -60,6 +63,18 @@ module Glimmer
60
63
  def content(&block)
61
64
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::DisplayExpression.new, &block)
62
65
  end
66
+
67
+ def async_exec(&block)
68
+ @swt_display.async_exec(&block)
69
+ end
70
+
71
+ def sync_exec(&block)
72
+ @swt_display.sync_exec(&block)
73
+ end
74
+
75
+ def timer_exec(&block)
76
+ @swt_display.timer_exec(&block)
77
+ end
63
78
 
64
79
  def method_missing(method, *args, &block)
65
80
  if can_handle_observation_request?(method)
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -0,0 +1,49 @@
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
+ module Glimmer
23
+ module SWT
24
+ module Properties
25
+ def ruby_attribute_setter(attribute_name)
26
+ "#{normalized_attribute(attribute_name)}="
27
+ end
28
+
29
+ def attribute_setter(attribute_name)
30
+ "set#{normalized_attribute(attribute_name).camelcase(:upper)}"
31
+ end
32
+
33
+ def attribute_getter(attribute_name)
34
+ "get#{normalized_attribute(attribute_name).camelcase(:upper)}"
35
+ end
36
+
37
+ def normalized_attribute(attribute_name)
38
+ attribute_name = attribute_name.to_s if attribute_name.is_a?(Symbol)
39
+ attribute_name = attribute_name.underscore unless attribute_name.downcase?
40
+ attribute_name = attribute_name.sub(/^get_/, '') if attribute_name.start_with?('get_')
41
+ attribute_name = attribute_name.sub(/^set_/, '') if attribute_name.start_with?('set_')
42
+ attribute_name = attribute_name.sub(/=$/, '') if attribute_name.end_with?('=')
43
+ attribute_name
44
+ end
45
+ alias ruby_attribute_getter normalized_attribute
46
+
47
+ end
48
+ end
49
+ end
@@ -64,10 +64,11 @@ module Glimmer
64
64
  @swt_widget.setLayout(FillLayout.new)
65
65
  @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN)
66
66
  # TODO make this an option not the default
67
+ shell_swt_display = Glimmer::SWT::DisplayProxy.instance.swt_display
67
68
  on_swt_show do
68
69
  Thread.new do
69
70
  sleep(0.25)
70
- async_exec do
71
+ shell_swt_display.async_exec do
71
72
  @swt_widget.setActive unless @swt_widget.isDisposed
72
73
  end
73
74
  end
@@ -26,6 +26,8 @@ require 'glimmer/swt/swt_proxy'
26
26
  require 'glimmer/swt/display_proxy'
27
27
  require 'glimmer/swt/dnd_proxy'
28
28
  require 'glimmer/swt/image_proxy'
29
+ require 'glimmer/swt/properties'
30
+ require 'glimmer/swt/custom/drawable'
29
31
 
30
32
  # TODO refactor to make file smaller and extract sub-widget-proxies out of this
31
33
 
@@ -42,6 +44,8 @@ module Glimmer
42
44
  # Follows the Proxy Design Pattern
43
45
  class WidgetProxy
44
46
  include Packages
47
+ include Properties
48
+ include Custom::Drawable
45
49
 
46
50
  DEFAULT_STYLES = {
47
51
  'arrow' => [:arrow],
@@ -667,28 +671,6 @@ module Glimmer
667
671
  DEFAULT_STYLES[underscored_widget_name] || [:none]
668
672
  end
669
673
 
670
- def ruby_attribute_setter(attribute_name)
671
- "#{normalized_attribute(attribute_name)}="
672
- end
673
-
674
- def attribute_setter(attribute_name)
675
- "set#{normalized_attribute(attribute_name).camelcase(:upper)}"
676
- end
677
-
678
- def attribute_getter(attribute_name)
679
- "get#{normalized_attribute(attribute_name).camelcase(:upper)}"
680
- end
681
-
682
- def normalized_attribute(attribute_name)
683
- attribute_name = attribute_name.to_s if attribute_name.is_a?(Symbol)
684
- attribute_name = attribute_name.underscore unless attribute_name.downcase?
685
- attribute_name = attribute_name.sub(/^get_/, '') if attribute_name.start_with?('get_')
686
- attribute_name = attribute_name.sub(/^set_/, '') if attribute_name.start_with?('set_')
687
- attribute_name = attribute_name.sub(/=$/, '') if attribute_name.end_with?('=')
688
- attribute_name
689
- end
690
- alias ruby_attribute_getter normalized_attribute
691
-
692
674
  # TODO refactor following methods to eliminate duplication
693
675
  # perhaps consider relying on raising an exception to avoid checking first
694
676
  # unless that gives obscure SWT errors
@@ -0,0 +1,62 @@
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
+ include Glimmer
23
+
24
+ shell {
25
+ text 'Hello, Canvas!'
26
+ minimum_size 320, 400
27
+
28
+ canvas {
29
+ background :yellow
30
+ rectangle(0, 0, 220, 400, fill: true) {
31
+ background :red
32
+ }
33
+ round_rectangle(50, 20, 300, 150, 30, 50, fill: true) {
34
+ background :magenta
35
+ }
36
+ gradient_rectangle(150, 200, 100, 70, true, fill: true) {
37
+ background :dark_magenta
38
+ foreground :yellow
39
+ }
40
+ gradient_rectangle(50, 200, 30, 70, false, fill: true) {
41
+ background :magenta
42
+ foreground :dark_blue
43
+ }
44
+ rectangle(200, 80, 108, 36) {
45
+ foreground color(:dark_blue)
46
+ }
47
+ text('Picasso', 60, 80) {
48
+ background :yellow
49
+ foreground :dark_magenta
50
+ font name: 'Courier', height: 30
51
+ }
52
+ oval(110, 310, 100, 100, fill: true) {
53
+ background rgb(128, 138, 248)
54
+ }
55
+ arc(210, 210, 100, 100, 30, -77, fill: true) {
56
+ background :red
57
+ }
58
+ polygon([250, 210, 260, 170, 270, 210, 290, 230, 250, 210]) {
59
+ background :dark_yellow
60
+ }
61
+ }
62
+ }.open
@@ -0,0 +1,66 @@
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
+ include Glimmer
23
+
24
+ shell {
25
+ text 'Hello, Canvas Animation!'
26
+ minimum_size 800, 420
27
+
28
+ canvas {
29
+ animation {
30
+ every 0.01 # in seconds (one hundredth)
31
+
32
+ frame { |index| # frame block loops indefinitely (unless frame_count is set to an integer)
33
+ background rgb(index%255, 100, 200) # sets canvas background color
34
+
35
+ oval(0, 0, 400, 400) { # x, y, width, height
36
+ foreground :black # sets oval background color
37
+ }
38
+ arc(0, 0, 400, 400, -1*index%360, 10, fill: true) { # x, y, width, height, start angle, arc angle
39
+ background rgb(200, 200, 50) # sets arc background color
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ canvas {
46
+ colors = [:yellow, :red]
47
+ animation {
48
+ every 0.25 # in seconds (one quarter)
49
+ cycle colors # cycles array of colors into the second variable of the frame block below
50
+
51
+ frame { |index, color| # frame block loops indefinitely (unless frame_count or cycle_count is set to an integer)
52
+ outside_color = colors[index % 2]
53
+ inside_color = colors[(index + 1) % 2]
54
+
55
+ background outside_color # sets canvas background color
56
+
57
+ rectangle(0, 0, 200, 200, fill: true) {
58
+ background inside_color # sets rectangle background color
59
+ }
60
+ rectangle(200, 200, 200, 200, fill: true) {
61
+ background inside_color # sets rectangle background color
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }.open
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.18.0.2
4
+ version: 4.18.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2021-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 1.0.7
18
+ version: 1.0.8
19
19
  name: glimmer
20
20
  type: :runtime
21
21
  prerelease: false
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.7
26
+ version: 1.0.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
@@ -373,6 +373,7 @@ files:
373
373
  - lib/glimmer/data_binding/table_items_binding.rb
374
374
  - lib/glimmer/data_binding/tree_items_binding.rb
375
375
  - lib/glimmer/data_binding/widget_binding.rb
376
+ - lib/glimmer/dsl/swt/animation_expression.rb
376
377
  - lib/glimmer/dsl/swt/async_exec_expression.rb
377
378
  - lib/glimmer/dsl/swt/bind_expression.rb
378
379
  - lib/glimmer/dsl/swt/block_property_expression.rb
@@ -404,6 +405,7 @@ files:
404
405
  - lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb
405
406
  - lib/glimmer/dsl/swt/rgb_expression.rb
406
407
  - lib/glimmer/dsl/swt/rgba_expression.rb
408
+ - lib/glimmer/dsl/swt/shape_expression.rb
407
409
  - lib/glimmer/dsl/swt/shell_expression.rb
408
410
  - lib/glimmer/dsl/swt/swt_expression.rb
409
411
  - lib/glimmer/dsl/swt/sync_exec_expression.rb
@@ -420,9 +422,12 @@ files:
420
422
  - lib/glimmer/rake_task/scaffold.rb
421
423
  - lib/glimmer/swt/color_proxy.rb
422
424
  - lib/glimmer/swt/cursor_proxy.rb
425
+ - lib/glimmer/swt/custom/animation.rb
423
426
  - lib/glimmer/swt/custom/checkbox_group.rb
424
427
  - lib/glimmer/swt/custom/code_text.rb
428
+ - lib/glimmer/swt/custom/drawable.rb
425
429
  - lib/glimmer/swt/custom/radio_group.rb
430
+ - lib/glimmer/swt/custom/shape.rb
426
431
  - lib/glimmer/swt/date_time_proxy.rb
427
432
  - lib/glimmer/swt/directory_dialog_proxy.rb
428
433
  - lib/glimmer/swt/display_proxy.rb
@@ -436,6 +441,7 @@ files:
436
441
  - lib/glimmer/swt/menu_proxy.rb
437
442
  - lib/glimmer/swt/message_box_proxy.rb
438
443
  - lib/glimmer/swt/packages.rb
444
+ - lib/glimmer/swt/properties.rb
439
445
  - lib/glimmer/swt/sash_form_proxy.rb
440
446
  - lib/glimmer/swt/scrolled_composite_proxy.rb
441
447
  - lib/glimmer/swt/shell_proxy.rb
@@ -463,6 +469,8 @@ files:
463
469
  - samples/elaborate/user_profile.rb
464
470
  - samples/hello/hello_browser.rb
465
471
  - samples/hello/hello_button.rb
472
+ - samples/hello/hello_canvas.rb
473
+ - samples/hello/hello_canvas_animation.rb
466
474
  - samples/hello/hello_checkbox.rb
467
475
  - samples/hello/hello_checkbox_group.rb
468
476
  - samples/hello/hello_combo.rb