glimmer-dsl-swt 4.21.2.4 → 4.22.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +208 -167
- data/README.md +18 -11
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_COMMAND.md +2 -2
- data/docs/reference/GLIMMER_CONFIGURATION.md +14 -3
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +277 -112
- data/docs/reference/GLIMMER_SAMPLES.md +26 -0
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/ext/glimmer/config.rb +41 -24
- data/lib/glimmer/data_binding/observable_widget.rb +6 -6
- data/lib/glimmer/data_binding/widget_binding.rb +4 -3
- data/lib/glimmer/dsl/swt/observe_expression.rb +2 -1
- data/lib/glimmer/dsl/swt/sync_call_expression.rb +38 -0
- data/lib/glimmer/dsl/swt/transform_expression.rb +1 -1
- data/lib/glimmer/launcher.rb +15 -14
- data/lib/glimmer/rake_task/package.rb +5 -3
- data/lib/glimmer/rake_task/scaffold.rb +2 -14
- data/lib/glimmer/swt/color_proxy.rb +5 -5
- data/lib/glimmer/swt/custom/drawable.rb +8 -2
- data/lib/glimmer/swt/custom/shape/line.rb +0 -1
- data/lib/glimmer/swt/custom/shape/path.rb +2 -2
- data/lib/glimmer/swt/custom/shape/path_segment.rb +2 -2
- data/lib/glimmer/swt/custom/shape/point.rb +8 -1
- data/lib/glimmer/swt/custom/shape.rb +170 -69
- data/lib/glimmer/swt/display_proxy.rb +15 -10
- data/lib/glimmer/swt/image_proxy.rb +5 -5
- data/lib/glimmer/swt/message_box_proxy.rb +5 -5
- data/lib/glimmer/swt/shape_listener_proxy.rb +55 -0
- data/lib/glimmer/swt/shell_proxy.rb +1 -1
- data/lib/glimmer/swt/transform_proxy.rb +3 -3
- data/lib/glimmer/swt/tray_proxy.rb +4 -4
- data/lib/glimmer/swt/widget_proxy.rb +14 -10
- data/lib/glimmer/ui/custom_shape.rb +34 -10
- data/lib/glimmer/ui/custom_widget.rb +7 -10
- data/lib/glimmer-dsl-swt.rb +6 -2
- data/samples/elaborate/battleship/view/cell.rb +10 -2
- data/samples/elaborate/klondike_solitaire/model/column_pile.rb +0 -1
- data/samples/elaborate/klondike_solitaire/view/column_pile.rb +3 -16
- data/samples/elaborate/klondike_solitaire/view/dealing_pile.rb +1 -1
- data/samples/elaborate/klondike_solitaire/view/dealt_pile.rb +12 -5
- data/samples/elaborate/klondike_solitaire/view/empty_playing_card.rb +2 -1
- data/samples/elaborate/klondike_solitaire/view/foundation_pile.rb +2 -2
- data/samples/elaborate/klondike_solitaire/view/hidden_playing_card.rb +2 -2
- data/samples/elaborate/klondike_solitaire/view/klondike_solitaire_menu_bar.rb +60 -0
- data/samples/elaborate/klondike_solitaire/view/playing_card.rb +3 -2
- data/samples/elaborate/klondike_solitaire.rb +13 -55
- data/samples/elaborate/mandelbrot_fractal.rb +3 -1
- data/samples/elaborate/quarto/model/game.rb +124 -0
- data/samples/elaborate/quarto/model/piece/cube.rb +31 -0
- data/samples/elaborate/quarto/model/piece/cylinder.rb +31 -0
- data/samples/elaborate/quarto/model/piece.rb +70 -0
- data/samples/elaborate/quarto/view/available_pieces_area.rb +72 -0
- data/samples/elaborate/quarto/view/board.rb +65 -0
- data/samples/elaborate/quarto/view/cell.rb +85 -0
- data/samples/elaborate/quarto/view/cube.rb +73 -0
- data/samples/elaborate/quarto/view/cylinder.rb +72 -0
- data/samples/elaborate/quarto/view/message_box_panel.rb +114 -0
- data/samples/elaborate/quarto/view/piece.rb +56 -0
- data/samples/elaborate/quarto/view/selected_piece_area.rb +69 -0
- data/samples/elaborate/quarto.rb +190 -0
- data/samples/hello/hello_custom_widget.rb +23 -5
- data/samples/hello/hello_scrolled_composite.rb +95 -0
- data/samples/hello/hello_world.rb +1 -0
- data/vendor/swt/linux/swt.jar +0 -0
- data/vendor/swt/linux_aarch64/swt.jar +0 -0
- data/vendor/swt/mac/swt.jar +0 -0
- data/vendor/swt/mac_aarch64/swt.jar +0 -0
- data/vendor/swt/windows/swt.jar +0 -0
- metadata +21 -25
- data/bin/glimmer_runner.rb +0 -4
@@ -0,0 +1,114 @@
|
|
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 Quarto
|
23
|
+
module View
|
24
|
+
class MessageBoxPanel
|
25
|
+
include Glimmer::UI::CustomShape
|
26
|
+
|
27
|
+
FONT_HEIGHT_DEFAULT = 12
|
28
|
+
BUTTON_TEXT_DEFAULT = 'OK'
|
29
|
+
|
30
|
+
option :message
|
31
|
+
option :location_x, default: :default
|
32
|
+
option :location_y, default: :default
|
33
|
+
option :size_width
|
34
|
+
option :size_height
|
35
|
+
option :background_color, default: :white
|
36
|
+
option :foreground_color, default: :black
|
37
|
+
option :border_line_width, default: 1
|
38
|
+
option :text_font, default: {height: FONT_HEIGHT_DEFAULT}
|
39
|
+
option :text_color, default: :black
|
40
|
+
|
41
|
+
attr_reader :closed
|
42
|
+
alias closed? closed
|
43
|
+
|
44
|
+
def can_handle_observation_request?(observation_request)
|
45
|
+
observation_request == 'on_closed' || super
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle_observation_request(observation_request, &block)
|
49
|
+
if observation_request == 'on_closed'
|
50
|
+
@on_closed_handlers ||= []
|
51
|
+
@on_closed_handlers << block
|
52
|
+
else
|
53
|
+
super
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
before_body do
|
58
|
+
@font_height = text_font[:height] || FONT_HEIGHT_DEFAULT
|
59
|
+
self.size_width ||= [:default, @font_height*4.0]
|
60
|
+
self.size_height ||= [:default, @font_height*4.0]
|
61
|
+
@text_offset = -1.2*@font_height
|
62
|
+
|
63
|
+
display {
|
64
|
+
on_swt_keyup do |key_event|
|
65
|
+
close if key_event.keyCode == swt(:cr)
|
66
|
+
end
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
body {
|
71
|
+
rectangle(location_x, location_y, size_width, size_height, round: true) {
|
72
|
+
background background_color
|
73
|
+
|
74
|
+
text(message, :default, [:default, @text_offset]) {
|
75
|
+
foreground :black
|
76
|
+
font text_font
|
77
|
+
}
|
78
|
+
|
79
|
+
rectangle(0, 0, :max, :max, round: true) { # border drawn around max dimensions of parent
|
80
|
+
foreground foreground_color
|
81
|
+
line_width border_line_width
|
82
|
+
}
|
83
|
+
|
84
|
+
rectangle(:default, [:default, @font_height + (@font_height/2.0)], @font_height*5.5, @font_height*2.0, @font_height, @font_height, round: true) {
|
85
|
+
background background_color
|
86
|
+
|
87
|
+
text(BUTTON_TEXT_DEFAULT) {
|
88
|
+
foreground text_color
|
89
|
+
font text_font
|
90
|
+
}
|
91
|
+
|
92
|
+
on_mouse_up do
|
93
|
+
close
|
94
|
+
end
|
95
|
+
}
|
96
|
+
|
97
|
+
rectangle(:default, [:default, @font_height + (@font_height/2.0)], @font_height*5.5, @font_height*2.0, @font_height, @font_height, round: true) { # border
|
98
|
+
foreground foreground_color
|
99
|
+
line_width border_line_width
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
def close
|
105
|
+
unless @closed
|
106
|
+
@closed = true
|
107
|
+
@on_closed_handlers&.each {|handler| handler.call}
|
108
|
+
@on_closed_handlers&.clear
|
109
|
+
body_root.dispose
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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 'cylinder'
|
23
|
+
require_relative 'cube'
|
24
|
+
|
25
|
+
class Quarto
|
26
|
+
module View
|
27
|
+
class Piece
|
28
|
+
include Glimmer::UI::CustomShape
|
29
|
+
|
30
|
+
SIZE_SHORT = 28
|
31
|
+
SIZE_TALL = 48
|
32
|
+
BASIC_SHAPE_WIDTH = 48
|
33
|
+
BASIC_SHAPE_HEIGHT = 28
|
34
|
+
LINE_THICKNESS = 2
|
35
|
+
|
36
|
+
options :game, :model, :location_x, :location_y
|
37
|
+
|
38
|
+
before_body do
|
39
|
+
@background_color = model.light? ? COLOR_LIGHT_WOOD : COLOR_DARK_WOOD
|
40
|
+
@size = model.short? ? SIZE_SHORT : SIZE_TALL
|
41
|
+
@shape_location_x = 0
|
42
|
+
@shape_location_y = model.short? ? 20 : 0
|
43
|
+
end
|
44
|
+
|
45
|
+
body {
|
46
|
+
shape(location_x, location_y) {
|
47
|
+
if model.is_a?(Model::Piece::Cylinder)
|
48
|
+
cylinder(location_x: @shape_location_x, location_y: @shape_location_y, cylinder_height: @size, oval_width: BASIC_SHAPE_WIDTH, oval_height: BASIC_SHAPE_HEIGHT, pitted: model.pitted?, background_color: @background_color, line_thickness: LINE_THICKNESS)
|
49
|
+
else
|
50
|
+
cube(location_x: @shape_location_x, location_y: @shape_location_y, cube_height: @size, rectangle_width: BASIC_SHAPE_WIDTH, rectangle_height: BASIC_SHAPE_HEIGHT, pitted: model.pitted?, background_color: @background_color, line_thickness: LINE_THICKNESS)
|
51
|
+
end
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -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
|
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 :
|
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
|
-
@
|
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.
|
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, :
|
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
|
@@ -0,0 +1,95 @@
|
|
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
|
+
grid_layout {
|
28
|
+
margin_width 0
|
29
|
+
margin_height 0
|
30
|
+
}
|
31
|
+
|
32
|
+
text 'Hello, Scrolled Composite!'
|
33
|
+
maximum_size 400, 400
|
34
|
+
|
35
|
+
composite {
|
36
|
+
layout_data {
|
37
|
+
horizontal_alignment :center
|
38
|
+
}
|
39
|
+
|
40
|
+
row_layout
|
41
|
+
|
42
|
+
button {
|
43
|
+
text '<<'
|
44
|
+
|
45
|
+
on_widget_selected do
|
46
|
+
@scrolled_composite.set_origin(0, @scrolled_composite.origin.y)
|
47
|
+
end
|
48
|
+
}
|
49
|
+
|
50
|
+
button {
|
51
|
+
text '>>'
|
52
|
+
|
53
|
+
on_widget_selected do
|
54
|
+
@scrolled_composite.set_origin(@inner_composite.size.x, @scrolled_composite.origin.y)
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
button {
|
59
|
+
text '^^'
|
60
|
+
|
61
|
+
on_widget_selected do
|
62
|
+
@scrolled_composite.set_origin(@scrolled_composite.origin.x, 0)
|
63
|
+
end
|
64
|
+
}
|
65
|
+
|
66
|
+
button {
|
67
|
+
text 'vv'
|
68
|
+
|
69
|
+
on_widget_selected do
|
70
|
+
@scrolled_composite.set_origin(@scrolled_composite.origin.x, @inner_composite.size.y)
|
71
|
+
end
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
@scrolled_composite = scrolled_composite {
|
76
|
+
layout_data :fill, :fill, true, true
|
77
|
+
|
78
|
+
@inner_composite = composite {
|
79
|
+
row_layout(:vertical)
|
80
|
+
|
81
|
+
background :white
|
82
|
+
|
83
|
+
50.times do |n|
|
84
|
+
label {
|
85
|
+
layout_data {
|
86
|
+
height 20
|
87
|
+
}
|
88
|
+
|
89
|
+
text "Line #{n+1} has a lot of gibberish in it. In fact, it has so much gibberish that it does not fit the window horizontally, so scrollbars must be used to see all the text."
|
90
|
+
background :white
|
91
|
+
}
|
92
|
+
end
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}.open
|
data/vendor/swt/linux/swt.jar
CHANGED
Binary file
|
Binary file
|
data/vendor/swt/mac/swt.jar
CHANGED
Binary file
|
Binary file
|
data/vendor/swt/windows/swt.jar
CHANGED
Binary file
|