glimmer-dsl-swt 4.20.13.9 → 4.20.13.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +5 -5
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_SAMPLES.md +37 -3
  6. data/docs/reference/GLIMMER_STYLE_GUIDE.md +2 -1
  7. data/glimmer-dsl-swt.gemspec +0 -0
  8. data/lib/glimmer-dsl-swt.rb +1 -0
  9. data/lib/glimmer/rake_task/scaffold.rb +14 -14
  10. data/lib/glimmer/swt/custom/code_text.rb +4 -4
  11. data/lib/glimmer/swt/custom/drawable.rb +1 -0
  12. data/lib/glimmer/swt/custom/shape.rb +20 -1
  13. data/lib/glimmer/swt/custom/shape/arc.rb +2 -0
  14. data/lib/glimmer/swt/custom/shape/cubic.rb +1 -0
  15. data/lib/glimmer/swt/custom/shape/line.rb +1 -0
  16. data/lib/glimmer/swt/custom/shape/oval.rb +2 -0
  17. data/lib/glimmer/swt/custom/shape/path.rb +1 -5
  18. data/lib/glimmer/swt/custom/shape/point.rb +1 -0
  19. data/lib/glimmer/swt/custom/shape/polygon.rb +2 -0
  20. data/lib/glimmer/swt/custom/shape/polyline.rb +1 -0
  21. data/lib/glimmer/swt/custom/shape/rectangle.rb +1 -0
  22. data/samples/elaborate/calculator.rb +2 -2
  23. data/samples/elaborate/contact_manager.rb +2 -2
  24. data/samples/elaborate/game_of_life.rb +111 -0
  25. data/samples/elaborate/game_of_life/model/cell.rb +72 -0
  26. data/samples/elaborate/game_of_life/model/grid.rb +97 -0
  27. data/samples/elaborate/klondike_solitaire.rb +3 -22
  28. data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +8 -3
  29. data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +4 -4
  30. data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +8 -1
  31. data/samples/elaborate/klondike_solitaire/view/playing_card.rb +2 -2
  32. data/samples/elaborate/login.rb +2 -2
  33. data/samples/elaborate/mandelbrot_fractal.rb +12 -12
  34. data/samples/elaborate/meta_sample.rb +2 -2
  35. data/samples/elaborate/metronome.rb +2 -2
  36. data/samples/elaborate/parking.rb +146 -0
  37. data/samples/elaborate/parking/model/parking_floor.rb +41 -0
  38. data/samples/elaborate/parking/model/parking_presenter.rb +42 -0
  39. data/samples/elaborate/parking/model/parking_spot.rb +46 -0
  40. data/samples/elaborate/stock_ticker.rb +8 -8
  41. data/samples/elaborate/tetris.rb +4 -4
  42. data/samples/elaborate/tetris/view/bevel.rb +2 -2
  43. data/samples/elaborate/tetris/view/score_lane.rb +2 -2
  44. data/samples/elaborate/tic_tac_toe.rb +6 -6
  45. data/samples/elaborate/timer.rb +4 -4
  46. data/samples/elaborate/weather.rb +4 -4
  47. data/samples/hello/hello_button.rb +2 -2
  48. data/samples/hello/hello_c_combo.rb +2 -2
  49. data/samples/hello/hello_canvas.rb +4 -4
  50. data/samples/hello/hello_canvas_animation.rb +2 -2
  51. data/samples/hello/hello_canvas_data_binding.rb +2 -2
  52. data/samples/hello/hello_checkbox.rb +2 -2
  53. data/samples/hello/hello_checkbox_group.rb +2 -2
  54. data/samples/hello/hello_code_text.rb +2 -2
  55. data/samples/hello/hello_color_dialog.rb +2 -2
  56. data/samples/hello/hello_combo.rb +2 -2
  57. data/samples/hello/hello_computed.rb +14 -22
  58. data/samples/hello/hello_cool_bar.rb +2 -2
  59. data/samples/hello/hello_cursor.rb +2 -2
  60. data/samples/hello/hello_custom_shape.rb +2 -2
  61. data/samples/hello/hello_custom_shell.rb +2 -2
  62. data/samples/hello/hello_custom_widget.rb +4 -4
  63. data/samples/hello/hello_date_time.rb +2 -2
  64. data/samples/hello/hello_directory_dialog.rb +2 -2
  65. data/samples/hello/hello_file_dialog.rb +2 -2
  66. data/samples/hello/hello_font_dialog.rb +2 -2
  67. data/samples/hello/hello_group.rb +2 -2
  68. data/samples/hello/hello_list_multi_selection.rb +2 -2
  69. data/samples/hello/hello_list_single_selection.rb +2 -2
  70. data/samples/hello/hello_progress_bar.rb +2 -2
  71. data/samples/hello/hello_radio.rb +2 -2
  72. data/samples/hello/hello_radio_group.rb +2 -2
  73. data/samples/hello/hello_scale.rb +2 -2
  74. data/samples/hello/hello_spinner.rb +2 -2
  75. data/samples/hello/hello_table.rb +2 -2
  76. data/samples/hello/hello_text.rb +2 -2
  77. data/samples/hello/hello_tool_bar.rb +2 -2
  78. data/samples/hello/hello_tray_item.rb +2 -2
  79. data/samples/hello/hello_tree.rb +4 -4
  80. metadata +9 -2
@@ -149,33 +149,33 @@ class MandelbrotFractal
149
149
 
150
150
  option :zoom, default: 1.0
151
151
 
152
- before_body {
152
+ before_body do
153
153
  Display.app_name = 'Mandelbrot Fractal'
154
154
  # pre-calculate mandelbrot image
155
155
  @mandelbrot_image = build_mandelbrot_image
156
- }
156
+ end
157
157
 
158
- after_body {
159
- observe(Mandelbrot, :work_in_progress) {
158
+ after_body do
159
+ observe(Mandelbrot, :work_in_progress) do
160
160
  update_mandelbrot_shell_title!
161
- }
162
- observe(Mandelbrot, :zoom) {
161
+ end
162
+ observe(Mandelbrot, :zoom) do
163
163
  update_mandelbrot_shell_title!
164
- }
164
+ end
165
165
  # pre-calculate zoomed mandelbrot images even before the user zooms in
166
166
  puts 'Starting background calculation thread...'
167
- @thread = Thread.new {
167
+ @thread = Thread.new do
168
168
  future_zoom = 1.5
169
- loop {
169
+ loop do
170
170
  puts "Creating mandelbrot for background calculation at zoom: #{future_zoom}"
171
171
  the_mandelbrot = Mandelbrot.for(max_iterations: color_palette.size - 1, zoom: future_zoom, background: true)
172
172
  pixels = the_mandelbrot.calculate_points
173
173
  build_mandelbrot_image(mandelbrot_zoom: future_zoom)
174
174
  @canvas.cursor = :cross unless @canvas.disposed?
175
175
  future_zoom += 0.5
176
- }
177
- }
178
- }
176
+ end
177
+ end
178
+ end
179
179
 
180
180
  body {
181
181
  shell(:no_resize) {
@@ -192,13 +192,13 @@ end
192
192
  class MetaSampleApplication
193
193
  include Glimmer::UI::CustomShell
194
194
 
195
- before_body {
195
+ before_body do
196
196
  Sample.ensure_user_glimmer_directory
197
197
  selected_sample_directory = SampleDirectory.sample_directories.first
198
198
  selected_sample = selected_sample_directory.samples.first
199
199
  selected_sample_directory.selected_sample_name = selected_sample.name
200
200
  Display.app_name = 'Glimmer Meta-Sample'
201
- }
201
+ end
202
202
 
203
203
  body {
204
204
  shell(:fill_screen) {
@@ -64,9 +64,9 @@ class Metronome
64
64
 
65
65
  attr_accessor :rhythm
66
66
 
67
- before_body {
67
+ before_body do
68
68
  @rhythm = Rhythm.new(4)
69
- }
69
+ end
70
70
 
71
71
  body {
72
72
  shell(:no_resize) {
@@ -0,0 +1,146 @@
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
+ require_relative 'parking/model/parking_presenter'
25
+
26
+ class Parking
27
+ include Glimmer::UI::CustomShell
28
+
29
+ FLOOR_COUNT = 4
30
+
31
+ before_body do
32
+ @parking_spots = Model::ParkingSpot::LETTERS.clone
33
+ @parking_presenter = Model::ParkingPresenter.new(FLOOR_COUNT)
34
+ end
35
+
36
+ body {
37
+ shell(:no_resize) {
38
+ row_layout(:vertical) {
39
+ center true
40
+ }
41
+
42
+ text 'Parking'
43
+
44
+ label {
45
+ text 'Select an available spot to park'
46
+ font height: 30
47
+ }
48
+ label {
49
+ text 'Floor:'
50
+ font height: 20
51
+ }
52
+ spinner {
53
+ minimum 1
54
+ maximum FLOOR_COUNT
55
+ font height: 20
56
+ selection <=> [@parking_presenter, :selected_floor]
57
+
58
+ on_widget_selected do
59
+ @parking_spots = Model::ParkingSpot::LETTERS.clone
60
+ @canvas.dispose_shapes
61
+ @canvas.content {
62
+ parking_floor
63
+ }
64
+ end
65
+ }
66
+ @canvas = canvas {
67
+ layout_data {
68
+ width 600
69
+ height 600
70
+ }
71
+
72
+ background :dark_gray
73
+
74
+ parking_floor
75
+ }
76
+ }
77
+ }
78
+
79
+ def parking_floor
80
+ parking_quad(67.5, 0, 125)
81
+ parking_quad(67.5, 0, 125) { |shp|
82
+ shp.rotate(90)
83
+ }
84
+ parking_quad(67.5, 0, 125) { |shp|
85
+ shp.rotate(180)
86
+ }
87
+ parking_quad(67.5, 0, 125) { |shp|
88
+ shp.rotate(270)
89
+ }
90
+ end
91
+
92
+ def parking_quad(location_x, location_y, length, &block)
93
+ distance = (1.0/3)*length
94
+ parking_spot(location_x, location_y, length, &block)
95
+ parking_spot(location_x + distance, location_y, length, &block)
96
+ parking_spot(location_x + 2*distance, location_y, length, &block)
97
+ parking_spot(location_x + 3*distance, location_y, length, &block)
98
+ end
99
+
100
+ def parking_spot(location_x, location_y, length, &block)
101
+ parking_spot_letter = @parking_spots.shift
102
+ height = length
103
+ width = (2.0/3)*length
104
+ shape(location_x, location_y) { |the_shape|
105
+ line_width (1.0/15)*length
106
+ foreground :white
107
+
108
+ block&.call(the_shape)
109
+
110
+ rectangle(location_x, location_y, width, height) {
111
+ background <= [
112
+ @parking_presenter.floors[@parking_presenter.selected_floor - 1].parking_spots[parking_spot_letter],
113
+ :booked,
114
+ on_read: ->(b) {b ? :red : :dark_gray}
115
+ ]
116
+
117
+ text {
118
+ x :default
119
+ y :default
120
+ string parking_spot_letter
121
+ font height: 20
122
+ }
123
+
124
+ on_mouse_up do
125
+ begin
126
+ @parking_presenter.floors[@parking_presenter.selected_floor - 1].book!(parking_spot_letter)
127
+ message_box {
128
+ text 'Parking Booked!'
129
+ message "Floor #{@parking_presenter.selected_floor} Parking Spot #{parking_spot_letter} Is Booked!"
130
+ }.open
131
+ rescue => e
132
+ # No Op if already booked
133
+ end
134
+ end
135
+ }
136
+
137
+ line(location_x, location_y, location_x, location_y + height)
138
+ line(location_x, location_y, location_x + width, location_y)
139
+ line(location_x + width, location_y, location_x + width, location_y + height)
140
+
141
+ }
142
+ end
143
+ end
144
+
145
+ Parking.launch
146
+
@@ -0,0 +1,41 @@
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_relative 'parking_spot'
23
+
24
+ class Parking
25
+ module Model
26
+ class ParkingFloor
27
+ attr_reader :number, :parking_spots
28
+
29
+ def initialize(floor_number)
30
+ @number = floor_number
31
+ @parking_spots = ParkingSpot::LETTERS.reduce({}) do |hash, letter|
32
+ hash.merge(letter => ParkingSpot.new(self, letter))
33
+ end
34
+ end
35
+
36
+ def book!(parking_spot_letter)
37
+ parking_spots[parking_spot_letter].book!
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
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_relative 'parking_floor'
23
+
24
+ class Parking
25
+ module Model
26
+ class ParkingPresenter
27
+ attr_reader :floor_count
28
+ attr_accessor :floors, :selected_floor
29
+
30
+ def initialize(floor_count)
31
+ self.floors = 1.upto(floor_count).map do |floor_number|
32
+ ParkingFloor.new(floor_number)
33
+ end
34
+ self.selected_floor = 1
35
+ end
36
+
37
+ def book(parking_spot_letter)
38
+ self.floors[selected_floor - 1].book(parking_spot_letter)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
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
+ class Parking
23
+ module Model
24
+ class ParkingSpot
25
+ LETTERS = %W[A B C D E F G H I J K L M N O P]
26
+
27
+ attr_reader :parking_floor, :letter
28
+ attr_accessor :booked
29
+ alias booked? booked
30
+
31
+ def initialize(parking_floor, letter)
32
+ @parking_floor = parking_floor
33
+ @letter = letter
34
+ end
35
+
36
+ def book!
37
+ raise "Floor #{parking_floor.number} Parking Spot #{letter} Is Already Booked!" if booked?
38
+ self.booked = true
39
+ end
40
+
41
+ def free!
42
+ self.booked = false
43
+ end
44
+ end
45
+ end
46
+ end
@@ -65,7 +65,7 @@ class StockTicker
65
65
 
66
66
  include Glimmer::UI::CustomShell
67
67
 
68
- before_body {
68
+ before_body do
69
69
  @stocks = [
70
70
  Stock.new('DELL', 81),
71
71
  Stock.new('AAPL', 121),
@@ -126,16 +126,16 @@ class StockTicker
126
126
  end
127
127
  end
128
128
  end
129
- }
129
+ end
130
130
 
131
- after_body {
132
- @thread = Thread.new {
133
- loop {
131
+ after_body do
132
+ @thread = Thread.new do
133
+ loop do
134
134
  @stocks.each(&:tick!)
135
135
  sleep(0.01)
136
- }
137
- }
138
- }
136
+ end
137
+ end
138
+ end
139
139
 
140
140
  body {
141
141
  shell {
@@ -43,7 +43,7 @@ class Tetris
43
43
 
44
44
  attr_reader :game
45
45
 
46
- before_body {
46
+ before_body do
47
47
  @mutex = Mutex.new
48
48
  @game = Model::Game.new(playfield_width, playfield_height)
49
49
 
@@ -99,9 +99,9 @@ class Tetris
99
99
  exit(0)
100
100
  }
101
101
  }
102
- }
102
+ end
103
103
 
104
- after_body {
104
+ after_body do
105
105
  observe(@game, :game_over) do |game_over|
106
106
  if game_over
107
107
  show_high_score_dialog
@@ -117,7 +117,7 @@ class Tetris
117
117
  end
118
118
  end
119
119
  @game.start!
120
- }
120
+ end
121
121
 
122
122
  body {
123
123
  shell(:no_resize) {
@@ -29,9 +29,9 @@ class Tetris
29
29
  option :x, default: 0
30
30
  option :y, default: 0
31
31
 
32
- before_body {
32
+ before_body do
33
33
  self.bevel_pixel_size = 0.16*size.to_f if bevel_pixel_size.nil?
34
- }
34
+ end
35
35
 
36
36
  body {
37
37
  rectangle(x, y, size, size) {
@@ -29,10 +29,10 @@ class Tetris
29
29
 
30
30
  options :block_size, :game
31
31
 
32
- before_body {
32
+ before_body do
33
33
  @font_name = FONT_NAME
34
34
  @font_height = FONT_TITLE_HEIGHT
35
- }
35
+ end
36
36
 
37
37
  body {
38
38
  composite {