glimmer-dsl-swt 4.20.5.2 → 4.20.9.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: 96f6467362290fdacff3b7ba74020595c6987cbfcf96f3aa74772eae62b97eee
4
- data.tar.gz: 11ca90c762d11542fc349579e683400b97e86b3e48517b42b07156338c0b1ba6
3
+ metadata.gz: 67146280061b1d25faa20a00e53ee4afed1f45c28ab2e7fd8054b528db26076c
4
+ data.tar.gz: 8c5a14a627a19f5247bf49ed7b73aeed59b057b6eabeab6d6a554c7828a4885b
5
5
  SHA512:
6
- metadata.gz: 9d42cc550e00628928bf483b7f27fec1c3fb57a027d5fcbcfe0bc2168e1552c32e554490eb6c05f39c63548288187435f2d484516bed77af1023c3ebd93327ec
7
- data.tar.gz: 41397cae14bceb062ffd7cc822305a0b5407d4ab0db8ec763c5dd8d850a809e2a6d9b6693a1319f982c9231b107b4ef5357e8f7bc61d7da83e314d742dcf1a40
6
+ metadata.gz: aa70e97297e9d502fad7fa4456e161302aa32ba9c44bf6ee7a7d4aabca2fcdb1ade0946c912f3c705987238738fdb5be4a9c0c9615638dabf891f58ed128a656
7
+ data.tar.gz: a72892383f756b6b990ce37ed319fa6f36de7a4d8832ea380921cd4a6bcda827f43f94dfa4419843ab146804081a9b6393c29f21a55056ffd94b870811c42a3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.9.0
4
+
5
+ - Canvas animation fps/frame_rate property to set frames-per-second rate of rendering (alternative to every)
6
+
7
+ ### 4.20.8.0
8
+
9
+ - Support data-binding Animation `duration_limit` property
10
+ - Improve support of Animation `duration_limit` property in recognizing when an animation is finished
11
+ - Added duration limit to Hello, Canvas Animation! sample
12
+
13
+ ### 4.20.7.0
14
+
15
+ - Add Canvas Animation DSL #finished, #finished?, #finished= properties
16
+ - Update Hello, Canvas Animation! (formerly had Data Binding suffix)
17
+ - Update Hello, Canvas Animation Multi! (formerly did not have Multi suffix)
18
+
19
+ ### 4.20.6.0
20
+
21
+ - Canvas Animation DSL: support parallel animations per canvas (running along canvas static shapes too)
22
+
3
23
  ### 4.20.5.2
4
24
 
5
25
  - Identify trimmed Canvas Shape DSL attribute `fill_rule` styles without `fill_` prefix
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.5.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.20.9.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.5.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).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.9.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
 
@@ -347,7 +347,7 @@ jgem install glimmer-dsl-swt
347
347
 
348
348
  Or this command if you want a specific version:
349
349
  ```
350
- jgem install glimmer-dsl-swt -v 4.20.5.2
350
+ jgem install glimmer-dsl-swt -v 4.20.9.0
351
351
  ```
352
352
 
353
353
  `jgem` is JRuby's version of `gem` command.
@@ -375,7 +375,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
375
375
 
376
376
  Add the following to `Gemfile`:
377
377
  ```
378
- gem 'glimmer-dsl-swt', '~> 4.20.5.2'
378
+ gem 'glimmer-dsl-swt', '~> 4.20.9.0'
379
379
  ```
380
380
 
381
381
  And, then run:
@@ -396,7 +396,7 @@ glimmer
396
396
  ```
397
397
 
398
398
  ```
399
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.5.2
399
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.9.0
400
400
 
401
401
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
402
402
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.5.2
1
+ 4.20.9.0
@@ -2239,17 +2239,17 @@ Learn more at the [Hello, Canvas Transform! Sample](GLIMMER_SAMPLES.md#hello-can
2239
2239
 
2240
2240
  ### Canvas Animation DSL
2241
2241
 
2242
- **(ALPHA FEATURE)**
2242
+ **(EXPERIMENTAL EARLY ALPHA FEATURE)**
2243
2243
 
2244
2244
  (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.)
2245
2245
 
2246
- Glimmer additionally provides built-in support for animations via a declarative Animation DSL, another sub-DSL of the Glimmer GUI DSL.
2246
+ Glimmer provides built-in support for animations via a declarative Animation DSL, another sub-DSL of the Glimmer GUI DSL.
2247
2247
 
2248
- Animations take advantage of multi-threading, automatically running each animation in its own independent thread of execution while updating the GUI asynchronously.
2248
+ Animations take advantage of multi-threading, with Glimmer DSL for SWT automatically running each animation in its own independent thread of execution while updating the GUI asynchronously.
2249
2249
 
2250
- Multiple simultaneous animations are supported by declaring an animation per `canvas` (or widget) parent.
2250
+ Multiple simultaneous animations are supported per `canvas` (or widget) parent.
2251
2251
 
2252
- `canvas` has the `:double_buffered` SWT style by default to ensure flicker-free rendering. If you need to disable it for whatever reason, just pass the `:none` SWT style instead (e.g. `canvas(:none)`)
2252
+ `canvas` has the `:double_buffered` SWT style by default on platforms other than the Mac to ensure flicker-free rendering (Mac does not need it). If you need to disable it for whatever reason, just pass the `:none` SWT style instead (e.g. `canvas(:none)`)
2253
2253
 
2254
2254
  This example says it all (it moves a tiny red square across a blue background) (you may copy/paste in [`girb`](GLIMMER_GIRB.md)):
2255
2255
 
@@ -2281,12 +2281,15 @@ Screenshot:
2281
2281
 
2282
2282
  Keywords:
2283
2283
  - `animation` declares an animation under a canvas, which renders frames using a frame block indefinitely or finitely depending on (cycle_count/frame_count) properties
2284
- - `every` specifies delay in seconds between every two frame renders
2285
- - `frame` a block that can contain Shape DSL syntax that is rendered dynamically with variables calculated on the fly
2286
- - `cycle` a property that takes an array to cycle into a second variable for the `frame` block
2287
- - `cycle_count` an optional cycle count limit after which the animation stops
2288
- - `frame_count` an optional frame count limit after which the animation stops
2289
- - `started` a boolean indicating if the animation is started right away or stopped waiting for manual startup via `#start` method
2284
+ - `every` specifies delay in seconds between every two frame renders (an alternative to `fps`, cannot use together)
2285
+ - `fps` (alias: `frame_rate`) specifies frame rate as frames per second (an alternative to `every`, cannot use together)
2286
+ - `frame {|index, cycle_var| }` a block that can contain Shape DSL syntax that is rendered dynamically with variables calculated on the fly
2287
+ - `cycle` an optional property that takes an array to cycle into a second variable for the `frame` block
2288
+ - `cycle_count` an optional cycle count limit after which the animation stops (finishes)
2289
+ - `frame_count` an optional frame count limit after which the animation stops (finishes)
2290
+ - `duration_limit` an optional duration limit in seconds after which the animation stops (finishes)
2291
+ - `started`/`started?` a boolean indicating if the animation is started right away or stopped waiting for manual startup via `#start` method
2292
+ - `finished`/`finished?` a boolean indicating if the animation finished (for finite animations only)
2290
2293
 
2291
2294
  API of Animation Object (returned from `animation` keyword):
2292
2295
  - `#start` starts an animation that is indefinite or has never been started before (i.e. having `started: false` option). Otherwise, resumes a stopped animation that has not been completed.
@@ -39,7 +39,7 @@
39
39
  - [Hello, Code Text!](#hello-code-text)
40
40
  - [Hello, Canvas!](#hello-canvas)
41
41
  - [Hello, Canvas Animation!](#hello-canvas-animation)
42
- - [Hello, Canvas Animation Data Binding!](#hello-canvas-animation-data-binding)
42
+ - [Hello, Canvas Animation Multi!](#hello-canvas-animation-multi)
43
43
  - [Hello, Canvas Transform!](#hello-canvas-transform)
44
44
  - [Hello, Canvas Path!](#hello-canvas-path)
45
45
  - [Hello, Canvas Data Binding!](#hello-canvas-data-binding)
@@ -743,31 +743,27 @@ Hello, Canvas! Data-Binding (changing a `text` shape `string` via data-binding c
743
743
 
744
744
  #### Hello, Canvas Animation!
745
745
 
746
- This sample demonstrates the use of the `canvas` widget and [Animation DSL](#canvas-animation-dsl) in Glimmer.
746
+ This sample demonstrates the use of the [Canvas Animation DSL](#canvas-animation-dsl) with data-binding.
747
747
 
748
748
  Code:
749
749
 
750
- [samples/hello/hello_canvas_animation.rb](/samples/hello/hello_canvas_animation.rb)
750
+ [samples/hello/hello_canvas_animation_data_binding.rb](/samples/hello/hello_canvas_animation_data_binding.rb)
751
751
 
752
752
  Hello, Canvas Animation!
753
753
 
754
- ![Hello Canvas Animation](/images/glimmer-hello-canvas-animation.png)
755
-
756
- Hello, Canvas Animation Another Frame!
754
+ ![Hello Canvas Animation Data Binding](/images/glimmer-hello-canvas-animation.gif)
757
755
 
758
- ![Hello Canvas Animation Frame 2](/images/glimmer-hello-canvas-animation-frame2.png)
756
+ #### Hello, Canvas Animation Multi!
759
757
 
760
- #### Hello, Canvas Animation Data Binding!
761
-
762
- This sample demonstrates the use of the [Canvas Animation DSL](#canvas-animation-dsl) with data-binding.
758
+ This sample demonstrates parallel animations in the [Canvas Animation DSL](/docs/reference/GLIMMER_GUI_DSL_SYNTAX#canvas-animation-dsl).
763
759
 
764
760
  Code:
765
761
 
766
- [samples/hello/hello_canvas_animation_data_binding.rb](/samples/hello/hello_canvas_animation_data_binding.rb)
762
+ [samples/hello/hello_canvas_animation_multi.rb](/samples/hello/hello_canvas_animation_multi.rb)
767
763
 
768
- Hello, Canvas Animation Data Binding!
764
+ Hello, Canvas Animation Multi!
769
765
 
770
- ![Hello Canvas Animation Data Binding](/images/glimmer-hello-canvas-animation-data-binding.gif)
766
+ ![Hello Canvas Animation Multi](/images/glimmer-hello-canvas-animation-multi.gif)
771
767
 
772
768
  #### Hello, Canvas Transform!
773
769
 
Binary file
@@ -20,6 +20,8 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer/swt/properties'
23
+ require 'glimmer/swt/custom/shape'
24
+ require 'bigdecimal'
23
25
 
24
26
  module Glimmer
25
27
  module SWT
@@ -27,6 +29,7 @@ module Glimmer
27
29
  # Represents an animation declaratively
28
30
  class Animation
29
31
  include Properties
32
+ include Glimmer::DataBinding::ObservableModel
30
33
 
31
34
  class << self
32
35
  def schedule_frame_animation(animation, &frame_animation_block)
@@ -76,18 +79,21 @@ module Glimmer
76
79
  end
77
80
  end
78
81
 
79
- attr_reader :parent, :options, :frame_index, :cycle
82
+ attr_reader :parent, :options
83
+ attr_accessor :frame_index, :cycle, :frame_block, :every, :fps, :cycle_count, :frame_count, :started, :duration_limit, :duration, :finished, :cycle_count_index
80
84
  alias current_frame_index frame_index
81
- attr_accessor :frame_block, :every, :cycle_count, :frame_count, :started, :duration_limit
82
85
  alias started? started
86
+ alias finished? finished
87
+ alias frame_rate fps
88
+ alias frame_rate= fps=
83
89
  # TODO consider supporting an async: false option
84
90
 
85
91
  def initialize(parent)
86
92
  @parent = parent
87
93
  @parent.requires_shape_disposal = true
88
- @started = true
89
- @frame_index = 0
90
- @cycle_count_index = 0
94
+ self.started = true
95
+ self.frame_index = 0
96
+ self.cycle_count_index = 0
91
97
  @start_number = 0 # denotes the number of starts (increments on every start)
92
98
  self.class.swt_display # ensures initializing variable to set from GUI thread
93
99
  end
@@ -110,9 +116,11 @@ module Glimmer
110
116
  def start
111
117
  return if @start_number > 0 && started?
112
118
  @start_number += 1
113
- @started = true
114
119
  @start_time = Time.now
120
+ @duration = 0
115
121
  @original_start_time = @start_time if @duration.nil?
122
+ self.finished = false if finished?
123
+ self.started = true
116
124
  # TODO track when finished in a variable for finite animations (whether by frame count, cycle count, or duration limit)
117
125
  Thread.new do
118
126
  start_number = @start_number
@@ -131,16 +139,16 @@ module Glimmer
131
139
 
132
140
  def stop
133
141
  return if stopped?
134
- @started = false
135
- @duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
142
+ self.started = false
143
+ self.duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
136
144
  end
137
145
 
138
146
  # Restarts an animation (whether indefinite or not and whether stopped or not)
139
147
  def restart
140
- @original_start_time = @start_time = nil
141
- @duration = nil
142
- @frame_index = 0
143
- @cycle_count_index = 0
148
+ @original_start_time = @start_time = Time.now
149
+ self.duration = 0
150
+ self.frame_index = 0
151
+ self.cycle_count_index = 0
144
152
  stop
145
153
  start
146
154
  end
@@ -182,6 +190,24 @@ module Glimmer
182
190
  end
183
191
  end
184
192
 
193
+ def cycle_count_index=(value)
194
+ @cycle_count_index = value
195
+ self.finished = true if cycle_limited? && @cycle_count_index == @cycle_count
196
+ @cycle_count_index
197
+ end
198
+
199
+ def frame_index=(value)
200
+ @frame_index = value
201
+ self.finished = true if frame_count_limited? && @frame_index == @frame_count
202
+ @frame_index
203
+ end
204
+
205
+ def duration=(value)
206
+ @duration = value
207
+ self.finished = true if surpassed_duration_limit?
208
+ @duration
209
+ end
210
+
185
211
  def cycle_enabled?
186
212
  @cycle.is_a?(Array)
187
213
  end
@@ -191,15 +217,15 @@ module Glimmer
191
217
  end
192
218
 
193
219
  def duration_limited?
194
- @duration_limit.is_a?(Integer)
220
+ @duration_limit.is_a?(Numeric) && @duration_limit > 0
195
221
  end
196
222
 
197
223
  def frame_count_limited?
198
- @frame_count.is_a?(Integer)
224
+ @frame_count.is_a?(Integer) && @frame_count > 0
199
225
  end
200
226
 
201
227
  def surpassed_duration_limit?
202
- duration_limited? && ((Time.now - @start_time) > (@duration_limit - @duration.to_f))
228
+ duration_limited? && ((Time.now - @start_time) > @duration_limit)
203
229
  end
204
230
 
205
231
  def within_duration_limit?
@@ -210,32 +236,45 @@ module Glimmer
210
236
 
211
237
  # Returns true on success of painting a frame and false otherwise
212
238
  def draw_frame(start_number)
213
- return false if stopped? ||
214
- start_number != @start_number ||
215
- (frame_count_limited? && @frame_index == @frame_count) ||
216
- (cycle_limited? && @cycle_count_index == @cycle_count) ||
217
- surpassed_duration_limit?
239
+ if stopped? or
240
+ (start_number != @start_number) or
241
+ (frame_count_limited? && @frame_index == @frame_count) or
242
+ (cycle_limited? && @cycle_count_index == @cycle_count) or
243
+ surpassed_duration_limit?
244
+ self.duration = Time.now - @start_time
245
+ return false
246
+ end
218
247
  block_args = [@frame_index]
219
248
  block_args << @cycle[@frame_index % @cycle.length] if cycle_enabled?
220
249
  current_frame_index = @frame_index
221
250
  current_cycle_count_index = @cycle_count_index
222
251
  self.class.schedule_frame_animation(self) do
252
+ self.duration = Time.now - @start_time # TODO should this be set here, after the if statement, in the else too, or outside both?
223
253
  if started? && start_number == @start_number && within_duration_limit?
224
254
  unless @parent.isDisposed
225
- @parent.clear_shapes # TODO adjust this to clear only the shapes of this animation (not all shapes) to allow simultaneous animations to occur on the same parent
226
- @parent.content { frame_block.call(*block_args) }
255
+ @shapes.to_a.each(&:dispose)
256
+ parent_shapes_before = @parent.shapes.clone
257
+ @parent.content {
258
+ frame_block.call(*block_args)
259
+ }
260
+ @shapes = @parent.shapes - parent_shapes_before
261
+ self.duration = Time.now - @start_time # TODO consider if this is needed
227
262
  end
228
263
  else
229
264
  if stopped? && @frame_index > current_frame_index
230
- @started = false
231
- @frame_index = current_frame_index
232
- @cycle_count_index = current_cycle_count_index
265
+ self.frame_index = current_frame_index
266
+ self.cycle_count_index = current_cycle_count_index
233
267
  end
234
268
  end
235
269
  end
236
- @frame_index += 1
237
- @cycle_count_index += 1 if cycle_limited? && (@frame_index % @cycle&.length&.to_i) == 0
238
- sleep(every) if every.is_a?(Numeric)
270
+ self.frame_index += 1
271
+ self.cycle_count_index += 1 if cycle_limited? && (@frame_index % @cycle&.length&.to_i) == 0
272
+ # TODO consider using timer_exec as a perhaps more reliable alternative
273
+ if every.is_a?(Numeric) && every > 0
274
+ sleep(every)
275
+ elsif fps.is_a?(Numeric) && fps > 0
276
+ sleep((BigDecimal(1.0.to_s) / BigDecimal(fps.to_f.to_s)).to_f)
277
+ end
239
278
  true
240
279
  rescue => e
241
280
  Glimmer::Config.logger.error {e}
@@ -207,6 +207,8 @@ class MetaSampleApplication
207
207
  image File.expand_path('../../icons/scaffold_app.png', __dir__)
208
208
 
209
209
  sash_form {
210
+ weights 4, 14
211
+
210
212
  composite {
211
213
  grid_layout(1, false) {
212
214
  margin_width 0
@@ -282,8 +284,6 @@ class MetaSampleApplication
282
284
  left_margin 7
283
285
  right_margin 7
284
286
  }
285
-
286
- weights 4, 11
287
287
  }
288
288
  }
289
289
  }
@@ -20,49 +20,129 @@
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  require 'glimmer-dsl-swt'
23
+ require 'bigdecimal'
23
24
 
24
- include Glimmer
25
-
26
- shell {
27
- text 'Hello, Canvas Animation!'
28
- minimum_size 800, 420
29
-
30
- canvas {
31
- animation {
32
- every 0.01 # in seconds (one hundredth)
33
-
34
- frame { |index| # frame block loops indefinitely (unless frame_count is set to an integer)
35
- background rgb(index%255, 100, 200) # sets canvas background color
25
+ class HelloCanvasAnimation
26
+ include Glimmer::UI::CustomShell
27
+
28
+ attr_accessor :animation_every, :animation_fps, :animation_frame_count, :animation_duration_limit, :animation_started, :animation_finished
29
+
30
+ before_body {
31
+ @animation_every = 0.050 # seconds
32
+ @animation_fps = 0
33
+ @animation_frame_count = 100
34
+ @animation_duration_limit = 0 # seconds
35
+ @animation_started = true
36
+ @animation_finished = false
37
+ }
38
+
39
+ body {
40
+ shell {
41
+ grid_layout(2, true)
42
+ text 'Hello, Canvas Animation!'
43
+
44
+ # row 1
45
+ button {
46
+ layout_data(:fill, :center, true, false)
47
+ text <= [self, :animation_started, on_read: ->(value) { value ? 'Stop' : 'Resume' }]
48
+ enabled <= [self, :animation_finished, on_read: :!]
36
49
 
37
- oval(0, 0, 400, 400) { # x, y, width, height
38
- foreground :black # sets oval background color
39
- }
40
- arc(0, 0, 400, 400, -1.4*index%360, 10) { # x, y, width, height, start angle, arc angle
41
- background rgb(200, 200, 50) # sets arc background color
42
- }
50
+ on_widget_selected do
51
+ if @animation.started?
52
+ @animation.stop
53
+ else
54
+ @animation.start
55
+ end
56
+ end
57
+ }
58
+ button {
59
+ layout_data(:fill, :center, true, false)
60
+ text 'Restart'
61
+
62
+ on_widget_selected do
63
+ @animation.restart
64
+ end
43
65
  }
44
- }
45
- }
46
-
47
- canvas {
48
- colors = [:yellow, :red]
49
- animation {
50
- every 0.25 # in seconds (one quarter)
51
- cycle colors # cycles array of colors into the second variable of the frame block below
52
-
53
- frame { |index, color| # frame block loops indefinitely (unless frame_count or cycle_count is set to an integer)
54
- outside_color = colors[index % 2]
55
- inside_color = colors[(index + 1) % 2]
56
-
57
- background outside_color # sets canvas background color
58
66
 
59
- rectangle(0, 0, 200, 200) {
60
- background inside_color # sets rectangle background color
67
+ # row 2
68
+ label {
69
+ text 'every'
70
+ }
71
+ label {
72
+ text 'frames per second'
73
+ }
74
+
75
+ # row 3
76
+ spinner {
77
+ layout_data(:fill, :center, true, false)
78
+ digits 3
79
+ minimum 0
80
+ maximum 100
81
+ selection <=> [self, :animation_every, on_read: ->(v) {(BigDecimal(v.to_s)*1000).to_f}, on_write: ->(v) {(BigDecimal(v.to_s)/1000).to_f}]
82
+ }
83
+ spinner {
84
+ layout_data(:fill, :center, true, false)
85
+ minimum 0
86
+ maximum 100
87
+ selection <=> [self, :animation_fps]
88
+ }
89
+
90
+ # row 4
91
+ label {
92
+ text 'frame count (0=unlimited)'
93
+ }
94
+ label {
95
+ text 'duration limit (0=unlimited)'
96
+ }
97
+
98
+ # row 5
99
+ spinner {
100
+ layout_data(:fill, :center, true, false)
101
+ minimum 0
102
+ maximum 100
103
+ selection <=> [self, :animation_frame_count]
104
+ }
105
+ spinner {
106
+ layout_data(:fill, :center, true, false)
107
+ minimum 0
108
+ maximum 10
109
+ selection <=> [self, :animation_duration_limit]
110
+ }
111
+
112
+ canvas {
113
+ layout_data(:fill, :fill, true, true) {
114
+ horizontal_span 2
115
+ width_hint 320
116
+ height_hint 320
61
117
  }
62
- rectangle(200, 200, 200, 200) {
63
- background inside_color # sets rectangle background color
118
+ @animation = animation {
119
+ every <= [self, :animation_every]
120
+ fps <= [self, :animation_fps]
121
+ frame_count <= [self, :animation_frame_count]
122
+ duration_limit <= [self, :animation_duration_limit]
123
+ started <=> [self, :animation_started]
124
+ finished <=> [self, :animation_finished]
125
+
126
+ frame { |index|
127
+ background rgb(index%100, index%100 + 100, index%55 + 200)
128
+ oval(index*3%300, index*3%300, 20, 20) {
129
+ background :yellow
130
+ }
131
+ }
64
132
  }
65
133
  }
66
134
  }
67
135
  }
68
- }.open
136
+
137
+ def animation_every=(value)
138
+ @animation_every = value
139
+ self.animation_fps = 0 if @animation_every.to_f > 0
140
+ end
141
+
142
+ def animation_fps=(value)
143
+ @animation_fps = value
144
+ self.animation_every = 0 if @animation_fps.to_f > 0
145
+ end
146
+ end
147
+
148
+ HelloCanvasAnimation.launch
@@ -0,0 +1,109 @@
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
+ include Glimmer
25
+
26
+ shell {
27
+ text 'Hello, Canvas Animation Multi!'
28
+ minimum_size 1200, 420
29
+
30
+ canvas {
31
+ background :white
32
+
33
+ animation {
34
+ every 0.01 # in seconds (one hundredth)
35
+
36
+ frame { |index| # frame block loops indefinitely (unless frame_count is set to an integer)
37
+ oval(0, 0, 400, 400) { # x, y, width, height
38
+ foreground :black # sets oval background color
39
+ }
40
+ arc(0, 0, 400, 400, -1.4*index%360, 10) { # x, y, width, height, start angle, arc angle
41
+ background rgb(50, 200, 50) # sets arc background color
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ canvas {
48
+ background :white
49
+
50
+ colors = [:yellow, :red]
51
+
52
+ animation {
53
+ every 0.25 # in seconds (one quarter)
54
+ cycle colors # cycles array of colors into the second variable of the frame block below
55
+
56
+ frame { |index, color| # frame block loops indefinitely (unless frame_count or cycle_count is set to an integer)
57
+ outside_color = colors[index % 2]
58
+ inside_color = colors[(index + 1) % 2]
59
+
60
+ background outside_color # sets canvas background color
61
+
62
+ rectangle(0, 0, 200, 200) {
63
+ background inside_color # sets rectangle background color
64
+ }
65
+ rectangle(200, 200, 200, 200) {
66
+ background inside_color # sets rectangle background color
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ canvas {
73
+ background :white
74
+
75
+ colors = [:yellow, :red]
76
+
77
+ animation {
78
+ every 0.25 # in seconds (one quarter)
79
+ cycle colors # cycles array of colors into the second variable of the frame block below
80
+
81
+ frame { |index, color| # frame block loops indefinitely (unless frame_count or cycle_count is set to an integer)
82
+ outside_color = colors[index % 2]
83
+ inside_color = colors[(index + 1) % 2]
84
+
85
+ background outside_color # sets canvas background color
86
+
87
+ rectangle(0, 0, 200, 200) {
88
+ background inside_color # sets rectangle background color
89
+ }
90
+ rectangle(200, 200, 200, 200) {
91
+ background inside_color # sets rectangle background color
92
+ }
93
+ }
94
+ }
95
+
96
+ animation {
97
+ every 0.01 # in seconds (one hundredth)
98
+
99
+ frame { |index| # frame block loops indefinitely (unless frame_count is set to an integer)
100
+ oval(0, 0, 400, 400) { # x, y, width, height
101
+ foreground :black # sets oval background color
102
+ }
103
+ arc(0, 0, 400, 400, -1.4*index%360, 10) { # x, y, width, height, start angle, arc angle
104
+ background rgb(50, 200, 50) # sets arc background color
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }.open
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.5.2
4
+ version: 4.20.9.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-17 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -574,7 +574,7 @@ files:
574
574
  - samples/hello/hello_c_tab.rb
575
575
  - samples/hello/hello_canvas.rb
576
576
  - samples/hello/hello_canvas_animation.rb
577
- - samples/hello/hello_canvas_animation_data_binding.rb
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
580
  - samples/hello/hello_canvas_transform.rb
@@ -1,66 +0,0 @@
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
- require 'bigdecimal'
24
-
25
- class HelloAnimationDataBinding
26
- include Glimmer::UI::CustomShell
27
-
28
- attr_accessor :delay_time
29
-
30
- before_body {
31
- @delay_time = 0.050
32
- }
33
-
34
- body {
35
- shell {
36
- text 'Hello, Canvas Animation Data Binding!'
37
- minimum_size 320, 320
38
-
39
- canvas {
40
- grid_layout
41
-
42
- spinner {
43
- layout_data(:center, :center, true, true) {
44
- minimum_width 75
45
- }
46
- digits 3
47
- minimum 1
48
- maximum 100
49
- selection <=> [self, :delay_time, on_read: ->(v) {(BigDecimal(v.to_s)*1000).to_f}, on_write: ->(v) {(BigDecimal(v.to_s)/1000).to_f}]
50
- }
51
- animation {
52
- every <= [self, :delay_time]
53
-
54
- frame { |index|
55
- background rgb(index%100, index%100 + 100, index%55 + 200)
56
- oval(index*3%300, index*3%300, 20, 20) {
57
- background :yellow
58
- }
59
- }
60
- }
61
- }
62
- }
63
- }
64
- end
65
-
66
- HelloAnimationDataBinding.launch