glimmer-dsl-swt 4.20.6.0 → 4.20.9.1

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: 4d7ca988f6d990ae7520a2b6319c538a793f7499a23713e97ce02f32e3db2bec
4
- data.tar.gz: a50dfa303380c6415d6a286f351a55931a4b1e09d73d7cc3e4602b52a00c179d
3
+ metadata.gz: e37d0806e8aaa9348e085cee3068003ab71eba9b55dcf9dc0a6dc19df8f9a351
4
+ data.tar.gz: ffc3acfdc525c51c694d1461f28955b77b3f33869abfb6a9fc7b2c40624085c4
5
5
  SHA512:
6
- metadata.gz: a8739fded7624fc8a007850dfa84fabeba144ffd3830fb83284e6abd733be75d8500da1be339d4827f30e14d702a4472f271198d90101d30573696f6a6dfdb14
7
- data.tar.gz: c95d53ca9b574ec413b1630c2b415deb2fa3e65a091bc3d5d40b391b3c6083db5e74158c3f9d3572523682c4a02e75afee465ffef2e83f96cbc3bbc7e671698a
6
+ metadata.gz: 85e233e9aca10e9674ef33ec09ab00ecbe04d122f9bc9e6bbbba24d48b187bf9f89eaa55bf8b4001eec37b4825995e2e8427f39ede64f76d51767ee1e60421a5
7
+ data.tar.gz: d168d8a89386a65ee536e372eeb0f4b958e536db7d8ec0f6b280dc8249b268108997e037b107aa59c3fe1f59bb8003c9a7b5c557749a31c962eb2cbb97d90d42
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.9.1
4
+
5
+ - Fix issue with not being able to use :default x/y location with composite/custom shapes containing lines
6
+
7
+ ### 4.20.9.0
8
+
9
+ - Canvas animation fps/frame_rate property to set frames-per-second rate of rendering (alternative to every)
10
+
11
+ ### 4.20.8.0
12
+
13
+ - Support data-binding Animation `duration_limit` property
14
+ - Improve support of Animation `duration_limit` property in recognizing when an animation is finished
15
+ - Added duration limit to Hello, Canvas Animation! sample
16
+
17
+ ### 4.20.7.0
18
+
19
+ - Add Canvas Animation DSL #finished, #finished?, #finished= properties
20
+ - Update Hello, Canvas Animation! (formerly had Data Binding suffix)
21
+ - Update Hello, Canvas Animation Multi! (formerly did not have Multi suffix)
22
+
3
23
  ### 4.20.6.0
4
24
 
5
25
  - Canvas Animation DSL: support parallel animations per canvas (running along canvas static shapes too)
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.6.0
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 4.20.9.1
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.6.0 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.9.1 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.6.0
350
+ jgem install glimmer-dsl-swt -v 4.20.9.1
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.6.0'
378
+ gem 'glimmer-dsl-swt', '~> 4.20.9.1'
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.6.0
399
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.9.1
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.6.0
1
+ 4.20.9.1
@@ -2239,7 +2239,7 @@ 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
 
@@ -2247,7 +2247,7 @@ Glimmer provides built-in support for animations via a declarative Animation DSL
2247
2247
 
2248
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 per `canvas` (or widget) parent (they do not compete or starve each other).
2250
+ Multiple simultaneous animations are supported per `canvas` (or widget) parent.
2251
2251
 
2252
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
 
@@ -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
@@ -21,6 +21,7 @@
21
21
 
22
22
  require 'glimmer/swt/properties'
23
23
  require 'glimmer/swt/custom/shape'
24
+ require 'bigdecimal'
24
25
 
25
26
  module Glimmer
26
27
  module SWT
@@ -28,6 +29,7 @@ module Glimmer
28
29
  # Represents an animation declaratively
29
30
  class Animation
30
31
  include Properties
32
+ include Glimmer::DataBinding::ObservableModel
31
33
 
32
34
  class << self
33
35
  def schedule_frame_animation(animation, &frame_animation_block)
@@ -77,18 +79,21 @@ module Glimmer
77
79
  end
78
80
  end
79
81
 
80
- 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
81
84
  alias current_frame_index frame_index
82
- attr_accessor :frame_block, :every, :cycle_count, :frame_count, :started, :duration_limit
83
85
  alias started? started
86
+ alias finished? finished
87
+ alias frame_rate fps
88
+ alias frame_rate= fps=
84
89
  # TODO consider supporting an async: false option
85
90
 
86
91
  def initialize(parent)
87
92
  @parent = parent
88
93
  @parent.requires_shape_disposal = true
89
- @started = true
90
- @frame_index = 0
91
- @cycle_count_index = 0
94
+ self.started = true
95
+ self.frame_index = 0
96
+ self.cycle_count_index = 0
92
97
  @start_number = 0 # denotes the number of starts (increments on every start)
93
98
  self.class.swt_display # ensures initializing variable to set from GUI thread
94
99
  end
@@ -111,9 +116,11 @@ module Glimmer
111
116
  def start
112
117
  return if @start_number > 0 && started?
113
118
  @start_number += 1
114
- @started = true
115
119
  @start_time = Time.now
120
+ @duration = 0
116
121
  @original_start_time = @start_time if @duration.nil?
122
+ self.finished = false if finished?
123
+ self.started = true
117
124
  # TODO track when finished in a variable for finite animations (whether by frame count, cycle count, or duration limit)
118
125
  Thread.new do
119
126
  start_number = @start_number
@@ -132,16 +139,16 @@ module Glimmer
132
139
 
133
140
  def stop
134
141
  return if stopped?
135
- @started = false
136
- @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?
137
144
  end
138
145
 
139
146
  # Restarts an animation (whether indefinite or not and whether stopped or not)
140
147
  def restart
141
- @original_start_time = @start_time = nil
142
- @duration = nil
143
- @frame_index = 0
144
- @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
145
152
  stop
146
153
  start
147
154
  end
@@ -183,6 +190,24 @@ module Glimmer
183
190
  end
184
191
  end
185
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
+
186
211
  def cycle_enabled?
187
212
  @cycle.is_a?(Array)
188
213
  end
@@ -192,15 +217,15 @@ module Glimmer
192
217
  end
193
218
 
194
219
  def duration_limited?
195
- @duration_limit.is_a?(Integer)
220
+ @duration_limit.is_a?(Numeric) && @duration_limit > 0
196
221
  end
197
222
 
198
223
  def frame_count_limited?
199
- @frame_count.is_a?(Integer)
224
+ @frame_count.is_a?(Integer) && @frame_count > 0
200
225
  end
201
226
 
202
227
  def surpassed_duration_limit?
203
- duration_limited? && ((Time.now - @start_time) > (@duration_limit - @duration.to_f))
228
+ duration_limited? && ((Time.now - @start_time) > @duration_limit)
204
229
  end
205
230
 
206
231
  def within_duration_limit?
@@ -211,16 +236,20 @@ module Glimmer
211
236
 
212
237
  # Returns true on success of painting a frame and false otherwise
213
238
  def draw_frame(start_number)
214
- return false if stopped? ||
215
- start_number != @start_number ||
216
- (frame_count_limited? && @frame_index == @frame_count) ||
217
- (cycle_limited? && @cycle_count_index == @cycle_count) ||
218
- 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
219
247
  block_args = [@frame_index]
220
248
  block_args << @cycle[@frame_index % @cycle.length] if cycle_enabled?
221
249
  current_frame_index = @frame_index
222
250
  current_cycle_count_index = @cycle_count_index
223
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?
224
253
  if started? && start_number == @start_number && within_duration_limit?
225
254
  unless @parent.isDisposed
226
255
  @shapes.to_a.each(&:dispose)
@@ -229,18 +258,23 @@ module Glimmer
229
258
  frame_block.call(*block_args)
230
259
  }
231
260
  @shapes = @parent.shapes - parent_shapes_before
261
+ self.duration = Time.now - @start_time # TODO consider if this is needed
232
262
  end
233
263
  else
234
264
  if stopped? && @frame_index > current_frame_index
235
- @started = false
236
- @frame_index = current_frame_index
237
- @cycle_count_index = current_cycle_count_index
265
+ self.frame_index = current_frame_index
266
+ self.cycle_count_index = current_cycle_count_index
238
267
  end
239
268
  end
240
269
  end
241
- @frame_index += 1
242
- @cycle_count_index += 1 if cycle_limited? && (@frame_index % @cycle&.length&.to_i) == 0
243
- 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
244
278
  true
245
279
  rescue => e
246
280
  Glimmer::Config.logger.error {e}
@@ -71,14 +71,14 @@ module Glimmer
71
71
  # Logical x coordinate relative to parent
72
72
  def x
73
73
  x_value = bounds.x
74
- x_value -= parent.absolute_x if parent.is_a?(Shape)
74
+ x_value -= parent.absolute_x if parent.is_a?(Shape) && parent.class != Shape
75
75
  x_value
76
76
  end
77
77
 
78
78
  # Logical y coordinate relative to parent
79
79
  def y
80
80
  y_value = bounds.y
81
- y_value -= parent.absolute_y if parent.is_a?(Shape)
81
+ y_value -= parent.absolute_y if parent.is_a?(Shape) && parent.class != Shape
82
82
  y_value
83
83
  end
84
84
 
@@ -91,7 +91,7 @@ module Glimmer
91
91
  end
92
92
 
93
93
  def absolute_x1
94
- if parent.is_a?(Shape)
94
+ if parent.is_a?(Shape) && parent.class != Shape
95
95
  parent.absolute_x + x1
96
96
  else
97
97
  x1
@@ -99,7 +99,7 @@ module Glimmer
99
99
  end
100
100
 
101
101
  def absolute_y1
102
- if parent.is_a?(Shape)
102
+ if parent.is_a?(Shape) && parent.class != Shape
103
103
  parent.absolute_y + y1
104
104
  else
105
105
  y1
@@ -107,7 +107,7 @@ module Glimmer
107
107
  end
108
108
 
109
109
  def absolute_x2
110
- if parent.is_a?(Shape)
110
+ if parent.is_a?(Shape) && parent.class != Shape
111
111
  parent.absolute_x + x2.to_f
112
112
  else
113
113
  x2
@@ -115,7 +115,7 @@ module Glimmer
115
115
  end
116
116
 
117
117
  def absolute_y2
118
- if parent.is_a?(Shape)
118
+ if parent.is_a?(Shape) && parent.class != Shape
119
119
  parent.absolute_y + y2.to_f
120
120
  else
121
121
  y2
@@ -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,90 +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 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
- }
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
45
37
  }
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
- }
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: :!]
49
+
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
68
65
  }
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
66
 
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
- }
67
+ # row 2
68
+ label {
69
+ text 'every'
93
70
  }
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
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
102
117
  }
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
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
+ }
105
132
  }
106
133
  }
107
134
  }
108
135
  }
109
- }.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.6.0
4
+ version: 4.20.9.1
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-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ dependencies:
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 0.12.0
72
+ version: 0.13.0
73
73
  - - "<"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.0.0
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 0.12.0
83
+ version: 0.13.0
84
84
  - - "<"
85
85
  - !ruby/object:Gem::Version
86
86
  version: 2.0.0
@@ -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