glimmer-dsl-swt 4.22.0.0 → 4.22.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +191 -169
  3. data/README.md +5 -5
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_COMMAND.md +2 -2
  6. data/docs/reference/GLIMMER_CONFIGURATION.md +14 -3
  7. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +98 -20
  8. data/docs/reference/GLIMMER_SAMPLES.md +13 -0
  9. data/glimmer-dsl-swt.gemspec +0 -0
  10. data/lib/ext/glimmer/config.rb +41 -24
  11. data/lib/glimmer/data_binding/observable_widget.rb +6 -6
  12. data/lib/glimmer/data_binding/widget_binding.rb +2 -1
  13. data/lib/glimmer/dsl/swt/observe_expression.rb +2 -1
  14. data/lib/glimmer/dsl/swt/transform_expression.rb +1 -1
  15. data/lib/glimmer/launcher.rb +15 -14
  16. data/lib/glimmer/rake_task/scaffold.rb +2 -14
  17. data/lib/glimmer/swt/color_proxy.rb +5 -5
  18. data/lib/glimmer/swt/custom/drawable.rb +4 -0
  19. data/lib/glimmer/swt/custom/shape/line.rb +0 -1
  20. data/lib/glimmer/swt/custom/shape/path.rb +2 -2
  21. data/lib/glimmer/swt/custom/shape/path_segment.rb +2 -2
  22. data/lib/glimmer/swt/custom/shape/point.rb +8 -1
  23. data/lib/glimmer/swt/custom/shape.rb +170 -69
  24. data/lib/glimmer/swt/display_proxy.rb +15 -10
  25. data/lib/glimmer/swt/image_proxy.rb +5 -5
  26. data/lib/glimmer/swt/message_box_proxy.rb +5 -5
  27. data/lib/glimmer/swt/shape_listener_proxy.rb +55 -0
  28. data/lib/glimmer/swt/transform_proxy.rb +3 -3
  29. data/lib/glimmer/swt/tray_proxy.rb +4 -4
  30. data/lib/glimmer/swt/widget_proxy.rb +5 -7
  31. data/lib/glimmer/ui/custom_shape.rb +34 -10
  32. data/lib/glimmer/ui/custom_widget.rb +3 -8
  33. data/lib/glimmer-dsl-swt.rb +6 -2
  34. data/samples/elaborate/klondike_solitaire/model/column_pile.rb +0 -1
  35. data/samples/elaborate/klondike_solitaire/view/column_pile.rb +3 -16
  36. data/samples/elaborate/klondike_solitaire/view/dealing_pile.rb +1 -1
  37. data/samples/elaborate/klondike_solitaire/view/dealt_pile.rb +12 -5
  38. data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +2 -1
  39. data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +2 -2
  40. data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +2 -2
  41. data/samples/elaborate/klondike_solitaire/view/klondike_solitaire_menu_bar.rb +60 -0
  42. data/samples/elaborate/klondike_solitaire/view/playing_card.rb +3 -2
  43. data/samples/elaborate/klondike_solitaire.rb +13 -55
  44. data/samples/elaborate/mandelbrot_fractal.rb +3 -1
  45. data/samples/elaborate/quarto/model/game.rb +124 -0
  46. data/samples/elaborate/quarto/model/piece/cube.rb +31 -0
  47. data/samples/elaborate/quarto/model/piece/cylinder.rb +31 -0
  48. data/samples/elaborate/quarto/model/piece.rb +70 -0
  49. data/samples/elaborate/quarto/view/available_pieces_area.rb +72 -0
  50. data/samples/elaborate/quarto/view/board.rb +65 -0
  51. data/samples/elaborate/quarto/view/cell.rb +85 -0
  52. data/samples/elaborate/quarto/view/cube.rb +73 -0
  53. data/samples/elaborate/quarto/view/cylinder.rb +72 -0
  54. data/samples/elaborate/quarto/view/message_box_panel.rb +114 -0
  55. data/samples/elaborate/quarto/view/piece.rb +56 -0
  56. data/samples/elaborate/quarto/view/selected_piece_area.rb +69 -0
  57. data/samples/elaborate/quarto.rb +190 -0
  58. data/samples/hello/hello_custom_widget.rb +23 -5
  59. metadata +17 -23
  60. data/bin/glimmer_runner.rb +0 -4
@@ -0,0 +1,69 @@
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 'piece'
23
+
24
+ class Quarto
25
+ module View
26
+ class SelectedPieceArea
27
+ include Glimmer::UI::CustomShape
28
+
29
+ options :game
30
+ option :location_x, default: 0
31
+ option :location_y, default: 0
32
+
33
+ attr_reader :selected_piece
34
+
35
+ body {
36
+ rectangle(location_x, location_y, PIECES_AREA_WIDTH, SELECTED_PIECE_AREA_HEIGHT) {
37
+ background COLOR_WOOD
38
+
39
+ rectangle(0, 0, :max, :max, round: true) { # border
40
+ foreground :black
41
+ line_width 2
42
+ }
43
+
44
+ text('Selected Piece', 15, 10) {
45
+ font height: 18, style: :bold
46
+ }
47
+
48
+ on_drop do |drop_event|
49
+ dragged_piece = drop_event.dragged_shape
50
+ if dragged_piece.parent.get_data('custom_shape').is_a?(AvailablePiecesArea)
51
+ model = dragged_piece.get_data('custom_shape').model
52
+ dragged_piece.dispose
53
+ body_root.content {
54
+ @selected_piece = piece(game: game, model: model, location_x: 15, location_y: 15 + 25)
55
+ }
56
+ game.select_piece(model)
57
+ else
58
+ drop_event.doit = false
59
+ end
60
+ end
61
+ }
62
+ }
63
+
64
+ def reset_selected_piece
65
+ @selected_piece&.dispose
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,190 @@
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 'yaml'
24
+
25
+ require_relative 'quarto/model/game'
26
+ require_relative 'quarto/view/board'
27
+ require_relative 'quarto/view/available_pieces_area'
28
+ require_relative 'quarto/view/selected_piece_area'
29
+ require_relative 'quarto/view/message_box_panel'
30
+
31
+ class Quarto
32
+ include Glimmer::UI::CustomShell
33
+
34
+ BOARD_DIAMETER = 430
35
+ PIECES_AREA_WIDTH = 252
36
+ AVAILABLE_PIECES_AREA_HEIGHT = 295
37
+ SELECTED_PIECE_AREA_HEIGHT = 124
38
+ CELL_DIAMETER = 68
39
+ CELL_LINE_WIDTH = 5
40
+ CELL_MARGIN = 7
41
+ SHELL_MARGIN = 15
42
+ AREA_MARGIN = 10
43
+ ROW_COUNT = 4
44
+ COLUMN_COUNT = 4
45
+ COLOR_WOOD = rgb(239, 196, 156)
46
+ COLOR_AREA = rgb(206, 188, 170)
47
+ COLOR_LIGHT_WOOD = rgb(254, 187, 120)
48
+ COLOR_DARK_WOOD = rgb(204, 108, 58)
49
+ MESSAGE_BOX_PANEL_WIDTH = 300
50
+ MESSAGE_BOX_PANEL_HEIGHT = 100
51
+ FILE_QUARTO_CONFIG = File.join(Dir.home, '.quarto')
52
+
53
+ before_body do
54
+ load_quarto_config
55
+ @game = Model::Game.new
56
+
57
+ observe(@game, :current_move) do |new_move|
58
+ perform_current_move
59
+ end
60
+
61
+ observe(@game, :over) do |game_over_status|
62
+ if game_over_status
63
+ game_over_message = "Game Over! "
64
+ game_over_message += @game.winner_player_number.nil? ? "Draw!" : "Player #{@game.winner_player_number} wins!"
65
+ body_root.content {
66
+ @open_message_box_panel&.close
67
+ @open_message_box_panel = message_box_panel(
68
+ message: game_over_message,
69
+ background_color: COLOR_LIGHT_WOOD,
70
+ text_font: {height: 16}
71
+ ) {
72
+ on_closed do
73
+ restart_game
74
+ end
75
+ }
76
+ }
77
+ end
78
+ end
79
+ end
80
+
81
+ after_body do
82
+ perform_current_move
83
+ end
84
+
85
+ body {
86
+ shell(:shell_trim, (:double_buffered unless OS.mac?)) {
87
+ text 'Glimmer Quarto'
88
+ minimum_size BOARD_DIAMETER + AREA_MARGIN + PIECES_AREA_WIDTH + SHELL_MARGIN*2 + (OS.linux? ? 52 : (OS.windows? ? 16 : 0)), BOARD_DIAMETER + 24 + SHELL_MARGIN*2 + (OS.linux? ? 96 : (OS.windows? ? 32 : 0))
89
+ maximum_size BOARD_DIAMETER + AREA_MARGIN + PIECES_AREA_WIDTH + SHELL_MARGIN*2 + (OS.linux? ? 52 : (OS.windows? ? 16 : 0)), BOARD_DIAMETER + 24 + SHELL_MARGIN*2 + (OS.linux? ? 96 : (OS.windows? ? 32 : 0))
90
+ background COLOR_WOOD
91
+
92
+ quarto_menu_bar
93
+
94
+ @board = board(game: @game, location_x: SHELL_MARGIN, location_y: SHELL_MARGIN)
95
+
96
+ @available_pieces_area = available_pieces_area(game: @game, location_x: SHELL_MARGIN + BOARD_DIAMETER + AREA_MARGIN, location_y: SHELL_MARGIN)
97
+ @selected_piece_area = selected_piece_area(game: @game, location_x: SHELL_MARGIN + BOARD_DIAMETER + AREA_MARGIN, location_y: SHELL_MARGIN + AVAILABLE_PIECES_AREA_HEIGHT + AREA_MARGIN)
98
+ }
99
+ }
100
+
101
+ def quarto_menu_bar
102
+ menu_bar {
103
+ menu {
104
+ text 'Game'
105
+
106
+ menu_item {
107
+ text 'Restart'
108
+
109
+ on_widget_selected do
110
+ restart_game
111
+ end
112
+ }
113
+
114
+ menu_item {
115
+ text 'Exit'
116
+
117
+ on_widget_selected do
118
+ exit(0)
119
+ end
120
+ }
121
+ }
122
+ menu {
123
+ text 'Help'
124
+
125
+ menu_item(:check) {
126
+ text 'Help Pop-Ups Enabled'
127
+ selection <=> [self, :help_pop_ups_enabled]
128
+ }
129
+ }
130
+ }
131
+ end
132
+
133
+ def help_pop_ups_enabled
134
+ @quarto_config[:help_pop_ups_enabled]
135
+ end
136
+ alias help_pop_ups_enabled? help_pop_ups_enabled
137
+
138
+ def help_pop_ups_enabled=(new_value)
139
+ @quarto_config[:help_pop_ups_enabled] = new_value
140
+ save_quarto_config
141
+ end
142
+
143
+ def load_quarto_config
144
+ @quarto_config = YAML.load(File.read(FILE_QUARTO_CONFIG)) rescue {}
145
+ @quarto_config[:help_pop_ups_enabled] = true if @quarto_config[:help_pop_ups_enabled].nil?
146
+ @quarto_config
147
+ end
148
+
149
+ def save_quarto_config
150
+ File.write(FILE_QUARTO_CONFIG, YAML.dump(@quarto_config))
151
+ rescue => e
152
+ puts "Unable to save quarto config file to: #{@quarto_config}"
153
+ end
154
+
155
+ def perform_current_move
156
+ verbiage = nil
157
+ case @game.current_move
158
+ when :select_piece
159
+ @available_pieces_area.pieces.each {|piece| piece.drag_source = true}
160
+ verbiage = "Player #{@game.current_player_number} must drag a piece to the Selected Piece\narea for the other player to place on the board!"
161
+ when :place_piece
162
+ @available_pieces_area.pieces.each {|piece| piece.drag_source = false}
163
+ @selected_piece_area.selected_piece.drag_source = true
164
+ verbiage = "Player #{@game.current_player_number} must drag the selected piece to the board\nin order to place it!"
165
+ end
166
+ body_root.text = "Glimmer Quarto | Player #{@game.current_player_number} #{@game.current_move.to_s.split('_').map(&:capitalize).join(' ')}"
167
+ if help_pop_ups_enabled?
168
+ async_exec do
169
+ body_root.content {
170
+ @open_message_box_panel&.close
171
+ @open_message_box_panel = message_box_panel(
172
+ message: verbiage,
173
+ background_color: COLOR_LIGHT_WOOD,
174
+ text_font: {height: 16}
175
+ )
176
+ }
177
+ body_root.redraw if OS.windows?
178
+ end
179
+ end
180
+ end
181
+
182
+ def restart_game
183
+ @available_pieces_area.reset_pieces
184
+ @selected_piece_area.reset_selected_piece
185
+ @board.reset_cells
186
+ @game.restart
187
+ end
188
+ end
189
+
190
+ Quarto.launch
@@ -32,11 +32,24 @@ class GreetingLabel
32
32
  option :greeting, default: 'Hello'
33
33
 
34
34
  # internal attribute (not a custom widget option)
35
- attr_accessor :color
35
+ attr_accessor :label_color
36
+
37
+ def can_handle_observation_request?(event, &block)
38
+ event.to_s == 'on_color_changed' || super
39
+ end
40
+
41
+ def handle_observation_request(event, &block)
42
+ if event.to_s == 'on_color_changed'
43
+ @color_changed_handlers ||= []
44
+ @color_changed_handlers << block
45
+ else
46
+ super
47
+ end
48
+ end
36
49
 
37
50
  before_body do
38
51
  @font = {height: 24, style: :bold}
39
- @color = :black
52
+ @label_color = :black
40
53
  end
41
54
 
42
55
  after_body do
@@ -44,7 +57,8 @@ class GreetingLabel
44
57
 
45
58
  Thread.new {
46
59
  colors.cycle { |color|
47
- self.color = color
60
+ self.label_color = color
61
+ @color_changed_handlers&.each {|handler| handler.call(color)}
48
62
  sleep(1)
49
63
  }
50
64
  }
@@ -55,7 +69,7 @@ class GreetingLabel
55
69
  label(swt_style) {
56
70
  text "#{greeting}, #{name}!"
57
71
  font @font
58
- foreground <=> [self, :color]
72
+ foreground <=> [self, :label_color]
59
73
  }
60
74
  }
61
75
 
@@ -82,5 +96,9 @@ shell {
82
96
  }
83
97
 
84
98
  # the colors option cycles between colors for the label foreground every second
85
- greeting_label(:center, name: 'Mary', greeting: 'Aloha', colors: [:red, :dark_green, :blue])
99
+ greeting_label(:center, name: 'Mary', greeting: 'Aloha', colors: [:red, :dark_green, :blue]) {
100
+ on_color_changed do |color|
101
+ puts "Label color changed: #{color}"
102
+ end
103
+ }
86
104
  }.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.22.0.0
4
+ version: 4.22.1.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-12-11 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -144,26 +144,6 @@ dependencies:
144
144
  - - "<"
145
145
  - !ruby/object:Gem::Version
146
146
  version: 2.0.0
147
- - !ruby/object:Gem::Dependency
148
- requirement: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: 2.3.0
153
- - - "<"
154
- - !ruby/object:Gem::Version
155
- version: 3.0.0
156
- name: logging
157
- prerelease: false
158
- type: :runtime
159
- version_requirements: !ruby/object:Gem::Requirement
160
- requirements:
161
- - - ">="
162
- - !ruby/object:Gem::Version
163
- version: 2.3.0
164
- - - "<"
165
- - !ruby/object:Gem::Version
166
- version: 3.0.0
167
147
  - !ruby/object:Gem::Dependency
168
148
  requirement: !ruby/object:Gem::Requirement
169
149
  requirements:
@@ -404,7 +384,6 @@ files:
404
384
  - bin/girb_runner.rb
405
385
  - bin/glimmer
406
386
  - bin/glimmer-setup
407
- - bin/glimmer_runner.rb
408
387
  - docs/reference/GLIMMER_COMMAND.md
409
388
  - docs/reference/GLIMMER_CONFIGURATION.md
410
389
  - docs/reference/GLIMMER_GIRB.md
@@ -522,6 +501,7 @@ files:
522
501
  - lib/glimmer/swt/proxy_properties.rb
523
502
  - lib/glimmer/swt/sash_form_proxy.rb
524
503
  - lib/glimmer/swt/scrolled_composite_proxy.rb
504
+ - lib/glimmer/swt/shape_listener_proxy.rb
525
505
  - lib/glimmer/swt/shell_proxy.rb
526
506
  - lib/glimmer/swt/style_constantizable.rb
527
507
  - lib/glimmer/swt/styled_text_proxy.rb
@@ -591,6 +571,7 @@ files:
591
571
  - samples/elaborate/klondike_solitaire/view/empty_playing_card.rb
592
572
  - samples/elaborate/klondike_solitaire/view/foundation_pile.rb
593
573
  - samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb
574
+ - samples/elaborate/klondike_solitaire/view/klondike_solitaire_menu_bar.rb
594
575
  - samples/elaborate/klondike_solitaire/view/playing_card.rb
595
576
  - samples/elaborate/klondike_solitaire/view/tableau.rb
596
577
  - samples/elaborate/login.rb
@@ -601,6 +582,19 @@ files:
601
582
  - samples/elaborate/parking/model/parking_floor.rb
602
583
  - samples/elaborate/parking/model/parking_presenter.rb
603
584
  - samples/elaborate/parking/model/parking_spot.rb
585
+ - samples/elaborate/quarto.rb
586
+ - samples/elaborate/quarto/model/game.rb
587
+ - samples/elaborate/quarto/model/piece.rb
588
+ - samples/elaborate/quarto/model/piece/cube.rb
589
+ - samples/elaborate/quarto/model/piece/cylinder.rb
590
+ - samples/elaborate/quarto/view/available_pieces_area.rb
591
+ - samples/elaborate/quarto/view/board.rb
592
+ - samples/elaborate/quarto/view/cell.rb
593
+ - samples/elaborate/quarto/view/cube.rb
594
+ - samples/elaborate/quarto/view/cylinder.rb
595
+ - samples/elaborate/quarto/view/message_box_panel.rb
596
+ - samples/elaborate/quarto/view/piece.rb
597
+ - samples/elaborate/quarto/view/selected_piece_area.rb
604
598
  - samples/elaborate/stock_ticker.rb
605
599
  - samples/elaborate/tetris.rb
606
600
  - samples/elaborate/tetris/model/block.rb
@@ -1,4 +0,0 @@
1
- require_relative '../lib/glimmer-dsl-swt'
2
- require_relative '../lib/glimmer/launcher'
3
-
4
- Glimmer::Launcher.new(ARGV).launch