glimmer-dsl-swt 4.18.4.3 → 4.18.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -0
  3. data/README.md +81 -5089
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_COMMAND.md +591 -0
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +183 -0
  7. data/docs/reference/GLIMMER_GIRB.md +30 -0
  8. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +3366 -0
  9. data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +202 -0
  10. data/docs/reference/GLIMMER_SAMPLES.md +676 -0
  11. data/docs/reference/GLIMMER_STYLE_GUIDE.md +14 -0
  12. data/glimmer-dsl-swt.gemspec +16 -8
  13. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +3 -3
  14. data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
  15. data/lib/glimmer/dsl/swt/image_expression.rb +3 -0
  16. data/lib/glimmer/dsl/swt/observe_expression.rb +8 -5
  17. data/lib/glimmer/dsl/swt/pixel_expression.rb +38 -0
  18. data/lib/glimmer/dsl/swt/timer_exec_expression.rb +35 -0
  19. data/lib/glimmer/dsl/swt/widget_expression.rb +1 -0
  20. data/lib/glimmer/swt/color_proxy.rb +4 -3
  21. data/lib/glimmer/swt/custom/animation.rb +10 -8
  22. data/lib/glimmer/swt/custom/code_text.rb +24 -20
  23. data/lib/glimmer/swt/custom/drawable.rb +54 -6
  24. data/lib/glimmer/swt/custom/shape.rb +91 -60
  25. data/lib/glimmer/swt/display_proxy.rb +11 -10
  26. data/lib/glimmer/swt/image_proxy.rb +17 -6
  27. data/lib/glimmer/swt/properties.rb +35 -10
  28. data/lib/glimmer/swt/widget_proxy.rb +17 -3
  29. data/lib/glimmer/ui/custom_widget.rb +17 -0
  30. data/samples/elaborate/mandelbrot_fractal.rb +103 -0
  31. data/samples/elaborate/meta_sample.rb +1 -1
  32. data/samples/elaborate/tetris.rb +5 -18
  33. data/samples/elaborate/tetris/view/block.rb +1 -1
  34. data/samples/elaborate/tetris/view/playfield.rb +1 -1
  35. data/samples/hello/hello_canvas_animation.rb +1 -1
  36. data/samples/hello/hello_canvas_transform.rb +1 -1
  37. data/samples/hello/hello_table.rb +1 -1
  38. data/samples/hello/hello_table/baseball_park.png +0 -0
  39. metadata +14 -6
  40. data/samples/elaborate/meta_sample/meta_sample_logo.png +0 -0
  41. data/samples/hello/hello_canvas_transform/hello_canvas_transform_image.png +0 -0
@@ -50,6 +50,7 @@ module Glimmer
50
50
  DEFAULT_STYLES = {
51
51
  'arrow' => [:arrow],
52
52
  'button' => [:push],
53
+ 'canvas' => [:double_buffered],
53
54
  'checkbox' => [:check],
54
55
  'check' => [:check],
55
56
  'drag_source' => [:drop_copy],
@@ -136,7 +137,8 @@ module Glimmer
136
137
  end
137
138
  end
138
139
 
139
- attr_reader :parent_proxy, :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
140
+ attr_reader :parent_proxy, :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer, :finished_add_content
141
+ alias finished_add_content? finished_add_content
140
142
 
141
143
  # Initializes a new SWT Widget
142
144
  #
@@ -147,6 +149,7 @@ module Glimmer
147
149
  #
148
150
  # Styles is a comma separate list of symbols representing SWT styles in lower case
149
151
  def initialize(*init_args, swt_widget: nil)
152
+ @image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered))
150
153
  if swt_widget.nil?
151
154
  underscored_widget_name, parent, args = init_args
152
155
  @parent_proxy = parent
@@ -169,6 +172,7 @@ module Glimmer
169
172
  if respond_to?(:on_widget_disposed)
170
173
  on_widget_disposed {
171
174
  clear_shapes
175
+ deregister_shape_painting
172
176
  }
173
177
  end
174
178
  end
@@ -178,11 +182,17 @@ module Glimmer
178
182
  # No Op by default
179
183
  end
180
184
 
181
- # Subclasses may override to perform post add_content work
185
+ # Subclasses may override to perform post add_content work.
186
+ # Make sure its logic detects if it ran before since it could run multiple times
187
+ # when adding content multiple times post creation.
182
188
  def post_add_content
183
189
  # No Op by default
184
190
  end
185
-
191
+
192
+ def finish_add_content!
193
+ @finished_add_content = true
194
+ end
195
+
186
196
  def extract_args(underscored_widget_name, args)
187
197
  @arg_extractor_mapping ||= {
188
198
  'menu_item' => lambda do |args|
@@ -544,6 +554,10 @@ module Glimmer
544
554
  DisplayProxy.instance.sync_exec(&block)
545
555
  end
546
556
 
557
+ def timer_exec(delay_in_millis, &block)
558
+ DisplayProxy.instance.timer_exec(delay_in_millis, &block)
559
+ end
560
+
547
561
  def has_style?(style)
548
562
  comparison = interpret_style(style)
549
563
  (@swt_widget.style & comparison) == comparison
@@ -158,11 +158,17 @@ module Glimmer
158
158
  def after_body(&block)
159
159
  @after_body_block = block
160
160
  end
161
+
162
+ # Current custom widgets being rendered. Useful to yoke all observers evaluated during rendering of their custom widgets for automatical disposal on_widget_disposed
163
+ def current_custom_widgets
164
+ @current_custom_widgets ||= []
165
+ end
161
166
  end
162
167
 
163
168
  attr_reader :body_root, :swt_widget, :parent, :parent_proxy, :swt_style, :options
164
169
 
165
170
  def initialize(parent, *swt_constants, options, &content)
171
+ Glimmer::UI::CustomWidget.current_custom_widgets << self
166
172
  @parent_proxy = @parent = parent
167
173
  @parent_proxy = @parent&.get_data('proxy') if @parent.respond_to?(:get_data) && @parent.get_data('proxy')
168
174
  @swt_style = SWT::SWTProxy[*swt_constants]
@@ -177,6 +183,9 @@ module Glimmer
177
183
  @swt_widget = @body_root.swt_widget
178
184
  @swt_widget.set_data('custom_widget', self)
179
185
  execute_hook('after_body')
186
+ @dispose_listener_registration = @body_root.on_widget_disposed do
187
+ observer_registrations.each(&:deregister)
188
+ end
180
189
  end
181
190
 
182
191
  # Subclasses may override to perform post initialization work on an added child
@@ -184,6 +193,10 @@ module Glimmer
184
193
  # No Op by default
185
194
  end
186
195
 
196
+ def observer_registrations
197
+ @observer_registrations ||= []
198
+ end
199
+
187
200
  def can_handle_observation_request?(observation_request)
188
201
  observation_request = observation_request.to_s
189
202
  result = false
@@ -273,6 +286,10 @@ module Glimmer
273
286
  SWT::DisplayProxy.instance.sync_exec(&block)
274
287
  end
275
288
 
289
+ def timer_exec(delay_in_millis, &block)
290
+ SWT::DisplayProxy.instance.timer_exec(delay_in_millis, &block)
291
+ end
292
+
276
293
  # Returns content block if used as an attribute reader (no args)
277
294
  # Otherwise, if a block is passed, it adds it as content to this custom widget
278
295
  def content(&block)
@@ -0,0 +1,103 @@
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 'complex'
23
+ require 'bigdecimal'
24
+ require 'concurrent-ruby'
25
+
26
+ # Mandelbrot implementation
27
+ # Courtesy of open-source code at:
28
+ # https://github.com/gotbadger/ruby-mandelbrot
29
+ class Mandelbrot
30
+
31
+ attr_accessor :max_iterations
32
+
33
+ def initialize(max_iterations)
34
+ @max_iterations = max_iterations
35
+ end
36
+
37
+ def calculate_all(x_array, y_array)
38
+ thread_pool = Concurrent::FixedThreadPool.new(Concurrent.processor_count)
39
+ width = x_array.size
40
+ height = y_array.size
41
+ pixel_rows_array = Concurrent::Array.new(height)
42
+ height.times do |y|
43
+ pixel_rows_array[y] ||= Concurrent::Array.new(width)
44
+ width.times do |x|
45
+ thread_pool.post do
46
+ pixel_rows_array[y][x] = calculate(x_array[x], y_array[y]).last
47
+ end
48
+ end
49
+ end
50
+ thread_pool.shutdown
51
+ thread_pool.wait_for_termination
52
+ pixel_rows_array
53
+ end
54
+
55
+ def calculate(x,y)
56
+ base_case = [Complex(x,y), 0]
57
+ Array.new(max_iterations, base_case).inject(base_case) do |prev ,base|
58
+ z, itr = prev
59
+ c, _ = base
60
+ val = z*z + c
61
+ itr += 1 unless val.abs < 2
62
+ [val, itr]
63
+ end
64
+ end
65
+ end
66
+
67
+ class MandelbrotFractal
68
+ include Glimmer::UI::CustomShell
69
+
70
+ before_body {
71
+ @colors = [[0, 0, 0]] + 40.times.map { |i| [255 - i*5, 255 - i*5, 55 + i*5] }
72
+ @colors = @colors.map {|color_data| rgb(*color_data).swt_color}
73
+ mandelbrot = Mandelbrot.new(@colors.size - 1)
74
+ @y_array = (1.0).step(-1,-0.0030).to_a
75
+ @x_array = (-2.0).step(0.5,0.0030).to_a
76
+ @height = @y_array.size
77
+ @width = @x_array.size
78
+ @pixel_rows_array = mandelbrot.calculate_all(@x_array, @y_array)
79
+ @image = Image.new(display.swt_display, @width, @height)
80
+ image_gc = org.eclipse.swt.graphics.GC.new(@image)
81
+ @height.times { |y|
82
+ @width.times { |x|
83
+ new_foreground = @colors[@pixel_rows_array[y][x]]
84
+ image_gc.foreground = @current_foreground = new_foreground unless new_foreground == @current_foreground
85
+ image_gc.draw_point x, y
86
+ }
87
+ }
88
+ }
89
+
90
+ body {
91
+ shell {
92
+ text 'Mandelbrot Fractal'
93
+ minimum_size @width, @height + 12
94
+ image @image
95
+
96
+ canvas {
97
+ image @image
98
+ }
99
+ }
100
+ }
101
+ end
102
+
103
+ MandelbrotFractal.launch
@@ -203,7 +203,7 @@ class MetaSampleApplication
203
203
  shell(:fill_screen) {
204
204
  minimum_size 1280, 768
205
205
  text 'Glimmer Meta-Sample (The Sample of Samples)'
206
- image File.expand_path('meta_sample/meta_sample_logo.png', __dir__)
206
+ image File.expand_path('../../icons/scaffold_app.png', __dir__)
207
207
 
208
208
  sash_form {
209
209
  composite {
@@ -139,10 +139,6 @@ class Tetris
139
139
  score_lane(game: game, block_size: BLOCK_SIZE) {
140
140
  layout_data(:fill, :fill, true, true)
141
141
  }
142
-
143
- on_widget_disposed {
144
- deregister_observers
145
- }
146
142
  }
147
143
  }
148
144
 
@@ -159,19 +155,19 @@ class Tetris
159
155
  color = colored ? color(([:white] + Model::Tetromino::LETTER_COLORS.values).sample) : color(:white)
160
156
  x = column * icon_block_size
161
157
  y = row * icon_block_size
162
- rectangle(x, y, icon_block_size, icon_block_size, fill: true) {
158
+ rectangle(x, y, icon_block_size, icon_block_size) {
163
159
  background color
164
160
  }
165
- polygon(x, y, x + icon_block_size, y, x + icon_block_size - icon_bevel_pixel_size, y + icon_bevel_pixel_size, x + icon_bevel_pixel_size, y + icon_bevel_pixel_size, fill: true) {
161
+ polygon(x, y, x + icon_block_size, y, x + icon_block_size - icon_bevel_pixel_size, y + icon_bevel_pixel_size, x + icon_bevel_pixel_size, y + icon_bevel_pixel_size) {
166
162
  background rgb(color.red + 4*BEVEL_CONSTANT, color.green + 4*BEVEL_CONSTANT, color.blue + 4*BEVEL_CONSTANT)
167
163
  }
168
- polygon(x + icon_block_size, y, x + icon_block_size - icon_bevel_pixel_size, y + icon_bevel_pixel_size, x + icon_block_size - icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, x + icon_block_size, y + icon_block_size, fill: true) {
164
+ polygon(x + icon_block_size, y, x + icon_block_size - icon_bevel_pixel_size, y + icon_bevel_pixel_size, x + icon_block_size - icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, x + icon_block_size, y + icon_block_size) {
169
165
  background rgb(color.red - BEVEL_CONSTANT, color.green - BEVEL_CONSTANT, color.blue - BEVEL_CONSTANT)
170
166
  }
171
- polygon(x + icon_block_size, y + icon_block_size, x, y + icon_block_size, x + icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, x + icon_block_size - icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, fill: true) {
167
+ polygon(x + icon_block_size, y + icon_block_size, x, y + icon_block_size, x + icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, x + icon_block_size - icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size) {
172
168
  background rgb(color.red - 2*BEVEL_CONSTANT, color.green - 2*BEVEL_CONSTANT, color.blue - 2*BEVEL_CONSTANT)
173
169
  }
174
- polygon(x, y, x, y + icon_block_size, x + icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, x + icon_bevel_pixel_size, y + icon_bevel_pixel_size, fill: true) {
170
+ polygon(x, y, x, y + icon_block_size, x + icon_bevel_pixel_size, y + icon_block_size - icon_bevel_pixel_size, x + icon_bevel_pixel_size, y + icon_bevel_pixel_size) {
175
171
  background rgb(color.red - BEVEL_CONSTANT, color.green - BEVEL_CONSTANT, color.blue - BEVEL_CONSTANT)
176
172
  }
177
173
  }
@@ -206,15 +202,6 @@ class Tetris
206
202
  message "Glimmer Tetris\n\nGlimmer DSL for SWT Sample\n\nCopyright (c) 2007-2021 Andy Maleh"
207
203
  }.open
208
204
  end
209
-
210
- def deregister_observers
211
- @show_high_scores_observer&.deregister
212
- @game_over_observer&.deregister
213
- @keyboard_down_listener&.deregister
214
- @keyboard_up_listener&.deregister
215
- @about_observer&.deregister
216
- @quit_observer&.deregister
217
- end
218
205
  end
219
206
 
220
207
  Tetris.launch
@@ -27,7 +27,7 @@ class Tetris
27
27
  options :game_playfield, :block_size, :row, :column
28
28
 
29
29
  body {
30
- canvas(:double_buffered) {
30
+ canvas {
31
31
  background bind(game_playfield[row][column], :color)
32
32
  polygon(0, 0, block_size, 0, block_size - 4, 4, 4, 4) {
33
33
  background bind(game_playfield[row][column], :color) { |color_value|
@@ -29,7 +29,7 @@ class Tetris
29
29
  options :game_playfield, :playfield_width, :playfield_height, :block_size
30
30
 
31
31
  body {
32
- composite(:double_buffered) {
32
+ composite((:double_buffered unless OS.mac?)) {
33
33
  grid_layout {
34
34
  num_columns playfield_width
35
35
  make_columns_equal_width true
@@ -25,7 +25,7 @@ shell {
25
25
  text 'Hello, Canvas Animation!'
26
26
  minimum_size 800, 420
27
27
 
28
- canvas(:double_buffered) {
28
+ canvas {
29
29
  animation {
30
30
  every 0.01 # in seconds (one hundredth)
31
31
 
@@ -1,6 +1,6 @@
1
1
  include Glimmer
2
2
 
3
- glimmer_logo = File.expand_path('./hello_canvas_transform/hello_canvas_transform_image.png', __dir__)
3
+ glimmer_logo = File.expand_path('../../icons/scaffold_app.png', __dir__)
4
4
 
5
5
  shell {
6
6
  text 'Hello, Canvas Transform!'
@@ -192,7 +192,7 @@ class HelloTable
192
192
  layout_data :center, :center, true, false
193
193
 
194
194
  text 'BASEBALL PLAYOFF SCHEDULE'
195
- background :transparent
195
+ background :transparent if OS.windows?
196
196
  foreground rgb(94, 107, 103)
197
197
  font name: 'Optima', height: 38, style: :bold
198
198
  }
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.4.3
4
+ version: 4.18.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-07 00:00:00.000000000 Z
11
+ date: 2021-02-11 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.11
18
+ version: 1.1.1
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.11
26
+ version: 1.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
@@ -361,6 +361,13 @@ files:
361
361
  - bin/girb
362
362
  - bin/girb_runner.rb
363
363
  - bin/glimmer
364
+ - docs/reference/GLIMMER_COMMAND.md
365
+ - docs/reference/GLIMMER_CONFIGURATION.md
366
+ - docs/reference/GLIMMER_GIRB.md
367
+ - docs/reference/GLIMMER_GUI_DSL_SYNTAX.md
368
+ - docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md
369
+ - docs/reference/GLIMMER_SAMPLES.md
370
+ - docs/reference/GLIMMER_STYLE_GUIDE.md
364
371
  - glimmer-dsl-swt.gemspec
365
372
  - icons/scaffold_app.icns
366
373
  - icons/scaffold_app.ico
@@ -405,6 +412,7 @@ files:
405
412
  - lib/glimmer/dsl/swt/message_box_expression.rb
406
413
  - lib/glimmer/dsl/swt/multiply_expression.rb
407
414
  - lib/glimmer/dsl/swt/observe_expression.rb
415
+ - lib/glimmer/dsl/swt/pixel_expression.rb
408
416
  - lib/glimmer/dsl/swt/property_expression.rb
409
417
  - lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb
410
418
  - lib/glimmer/dsl/swt/rgb_expression.rb
@@ -415,6 +423,7 @@ files:
415
423
  - lib/glimmer/dsl/swt/sync_exec_expression.rb
416
424
  - lib/glimmer/dsl/swt/tab_item_expression.rb
417
425
  - lib/glimmer/dsl/swt/table_items_data_binding_expression.rb
426
+ - lib/glimmer/dsl/swt/timer_exec_expression.rb
418
427
  - lib/glimmer/dsl/swt/transform_expression.rb
419
428
  - lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb
420
429
  - lib/glimmer/dsl/swt/tree_properties_expression.rb
@@ -468,8 +477,8 @@ files:
468
477
  - samples/elaborate/contact_manager/contact_manager_presenter.rb
469
478
  - samples/elaborate/contact_manager/contact_repository.rb
470
479
  - samples/elaborate/login.rb
480
+ - samples/elaborate/mandelbrot_fractal.rb
471
481
  - samples/elaborate/meta_sample.rb
472
- - samples/elaborate/meta_sample/meta_sample_logo.png
473
482
  - samples/elaborate/tetris.rb
474
483
  - samples/elaborate/tetris/model/block.rb
475
484
  - samples/elaborate/tetris/model/game.rb
@@ -489,7 +498,6 @@ files:
489
498
  - samples/hello/hello_canvas.rb
490
499
  - samples/hello/hello_canvas_animation.rb
491
500
  - samples/hello/hello_canvas_transform.rb
492
- - samples/hello/hello_canvas_transform/hello_canvas_transform_image.png
493
501
  - samples/hello/hello_checkbox.rb
494
502
  - samples/hello/hello_checkbox_group.rb
495
503
  - samples/hello/hello_code_text.rb