glimmer-dsl-swt 4.18.3.0 → 4.18.3.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 +19 -0
- data/README.md +48 -5
- data/VERSION +1 -1
- data/glimmer-dsl-swt.gemspec +7 -6
- data/lib/ext/glimmer/config.rb +24 -7
- data/lib/glimmer/data_binding/widget_binding.rb +14 -4
- data/lib/glimmer/swt/custom/shape.rb +3 -2
- data/lib/glimmer/swt/directory_dialog_proxy.rb +3 -3
- data/lib/glimmer/swt/display_proxy.rb +25 -4
- data/lib/glimmer/swt/file_dialog_proxy.rb +3 -3
- data/lib/glimmer/swt/shell_proxy.rb +13 -2
- data/lib/glimmer/swt/widget_listener_proxy.rb +14 -5
- data/lib/glimmer/swt/widget_proxy.rb +1 -1
- data/lib/glimmer/ui/custom_shell.rb +10 -9
- data/lib/glimmer/ui/custom_widget.rb +22 -14
- data/samples/elaborate/meta_sample.rb +81 -24
- data/samples/elaborate/tetris.rb +63 -32
- data/samples/elaborate/tetris/model/game.rb +180 -139
- data/samples/elaborate/tetris/model/tetromino.rb +28 -25
- data/samples/elaborate/tetris/view/game_over_dialog.rb +13 -17
- data/samples/elaborate/tetris/view/score_lane.rb +5 -5
- data/samples/elaborate/tetris/view/tetris_menu_bar.rb +72 -0
- data/samples/elaborate/tic_tac_toe.rb +4 -4
- data/samples/hello/hello_canvas_transform.rb +1 -1
- data/samples/hello/hello_link.rb +1 -1
- metadata +5 -4
@@ -38,31 +38,32 @@ class Tetris
|
|
38
38
|
Z: :red,
|
39
39
|
}
|
40
40
|
|
41
|
-
attr_reader :letter, :preview
|
41
|
+
attr_reader :game, :letter, :preview
|
42
42
|
alias preview? preview
|
43
43
|
attr_accessor :orientation, :blocks, :row, :column
|
44
44
|
|
45
|
-
def initialize
|
45
|
+
def initialize(game)
|
46
|
+
@game = game
|
46
47
|
@letter = LETTER_COLORS.keys.sample
|
47
48
|
@orientation = :north
|
48
49
|
@blocks = default_blocks
|
49
50
|
@preview = true
|
50
51
|
new_row = 0
|
51
|
-
new_column = (PREVIEW_PLAYFIELD_WIDTH - width)/2
|
52
|
+
new_column = (Model::Game::PREVIEW_PLAYFIELD_WIDTH - width)/2
|
52
53
|
update_playfield(new_row, new_column)
|
53
54
|
end
|
54
55
|
|
55
56
|
def playfield
|
56
|
-
@preview ?
|
57
|
+
@preview ? game.preview_playfield : game.playfield
|
57
58
|
end
|
58
59
|
|
59
60
|
def launch!
|
60
61
|
remove_from_playfield
|
61
62
|
@preview = false
|
62
63
|
new_row = 1 - height
|
63
|
-
new_column = (
|
64
|
+
new_column = (game.playfield_width - width)/2
|
64
65
|
update_playfield(new_row, new_column)
|
65
|
-
|
66
|
+
game.tetrominoes << self
|
66
67
|
end
|
67
68
|
|
68
69
|
def update_playfield(new_row = nil, new_column = nil)
|
@@ -89,16 +90,16 @@ class Tetris
|
|
89
90
|
|
90
91
|
def stopped?
|
91
92
|
return true if @stopped || @preview
|
92
|
-
playfield_remaining_heights =
|
93
|
+
playfield_remaining_heights = game.playfield_remaining_heights(self)
|
93
94
|
result = bottom_most_blocks.any? do |bottom_most_block|
|
94
95
|
playfield_column = @column + bottom_most_block[:column_index]
|
95
96
|
playfield_remaining_heights[playfield_column] &&
|
96
97
|
@row + bottom_most_block[:row] >= playfield_remaining_heights[playfield_column] - 1
|
97
98
|
end
|
98
|
-
if result && !
|
99
|
+
if result && !game.hypothetical?
|
99
100
|
@stopped = result
|
100
|
-
|
101
|
-
|
101
|
+
game.consider_eliminating_lines
|
102
|
+
@game.consider_adding_tetromino
|
102
103
|
end
|
103
104
|
result
|
104
105
|
end
|
@@ -124,9 +125,10 @@ class Tetris
|
|
124
125
|
end
|
125
126
|
|
126
127
|
def right_blocked?
|
127
|
-
(@column ==
|
128
|
+
(@column == game.playfield_width - width) ||
|
128
129
|
right_most_blocks.any? { |right_most_block|
|
129
|
-
|
130
|
+
(@row + right_most_block[:row_index]) >= 0 &&
|
131
|
+
playfield[@row + right_most_block[:row_index]][@column + right_most_block[:column_index] + 1].occupied?
|
130
132
|
}
|
131
133
|
end
|
132
134
|
|
@@ -150,7 +152,8 @@ class Tetris
|
|
150
152
|
def left_blocked?
|
151
153
|
(@column == 0) ||
|
152
154
|
left_most_blocks.any? { |left_most_block|
|
153
|
-
|
155
|
+
(@row + left_most_block[:row_index]) >= 0 &&
|
156
|
+
playfield[@row + left_most_block[:row_index]][@column + left_most_block[:column_index] - 1].occupied?
|
154
157
|
}
|
155
158
|
end
|
156
159
|
|
@@ -179,7 +182,7 @@ class Tetris
|
|
179
182
|
@blocks.size
|
180
183
|
end
|
181
184
|
|
182
|
-
def down
|
185
|
+
def down!
|
183
186
|
launch! if preview?
|
184
187
|
unless stopped?
|
185
188
|
new_row = @row + 1
|
@@ -187,14 +190,14 @@ class Tetris
|
|
187
190
|
end
|
188
191
|
end
|
189
192
|
|
190
|
-
def left
|
193
|
+
def left!
|
191
194
|
unless left_blocked?
|
192
195
|
new_column = @column - 1
|
193
196
|
update_playfield(@row, new_column)
|
194
197
|
end
|
195
198
|
end
|
196
199
|
|
197
|
-
def right
|
200
|
+
def right!
|
198
201
|
unless right_blocked?
|
199
202
|
new_column = @column + 1
|
200
203
|
update_playfield(@row, new_column)
|
@@ -202,11 +205,11 @@ class Tetris
|
|
202
205
|
end
|
203
206
|
|
204
207
|
# Rotate in specified direcation, which can be :right (clockwise) or :left (counterclockwise)
|
205
|
-
def rotate(direction)
|
208
|
+
def rotate!(direction)
|
206
209
|
return if stopped?
|
207
210
|
can_rotate = nil
|
208
211
|
new_blocks = nil
|
209
|
-
|
212
|
+
game.hypothetical do
|
210
213
|
hypothetical_rotated_tetromino = hypothetical_tetromino
|
211
214
|
new_blocks = hypothetical_rotated_tetromino.rotate_blocks(direction)
|
212
215
|
can_rotate = !hypothetical_rotated_tetromino.stopped? && !hypothetical_rotated_tetromino.right_blocked? && !hypothetical_rotated_tetromino.left_blocked?
|
@@ -222,13 +225,13 @@ class Tetris
|
|
222
225
|
end
|
223
226
|
|
224
227
|
def rotate_blocks(direction)
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
228
|
+
new_blocks = Matrix[*@blocks].transpose.to_a
|
229
|
+
if direction == :right
|
230
|
+
new_blocks = new_blocks.map(&:reverse)
|
231
|
+
else
|
232
|
+
new_blocks = new_blocks.reverse
|
233
|
+
end
|
234
|
+
Matrix[*new_blocks].to_a
|
232
235
|
end
|
233
236
|
|
234
237
|
def hypothetical_tetromino
|
@@ -19,12 +19,20 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
+
require_relative 'tetris_menu_bar'
|
23
|
+
|
22
24
|
class Tetris
|
23
25
|
module View
|
24
26
|
class GameOverDialog
|
25
27
|
include Glimmer::UI::CustomShell
|
26
28
|
|
27
|
-
options :parent_shell
|
29
|
+
options :parent_shell, :game
|
30
|
+
|
31
|
+
after_body {
|
32
|
+
observe(game, :game_over) do |game_over|
|
33
|
+
hide if !game_over
|
34
|
+
end
|
35
|
+
}
|
28
36
|
|
29
37
|
body {
|
30
38
|
dialog(parent_shell) {
|
@@ -34,6 +42,8 @@ class Tetris
|
|
34
42
|
}
|
35
43
|
text 'Tetris'
|
36
44
|
|
45
|
+
tetris_menu_bar(game: game)
|
46
|
+
|
37
47
|
label(:center) {
|
38
48
|
text 'Game Over!'
|
39
49
|
font name: 'Menlo', height: 30, style: :bold
|
@@ -43,30 +53,16 @@ class Tetris
|
|
43
53
|
text 'Play Again?'
|
44
54
|
|
45
55
|
on_widget_selected {
|
46
|
-
|
47
|
-
|
48
|
-
body_root.close
|
56
|
+
hide
|
57
|
+
game.restart!
|
49
58
|
}
|
50
59
|
}
|
51
60
|
|
52
61
|
on_shell_activated {
|
53
|
-
Model::Game.game_over = true
|
54
62
|
display.beep
|
55
63
|
}
|
56
|
-
|
57
|
-
on_shell_closed {
|
58
|
-
exit_game
|
59
|
-
}
|
60
|
-
|
61
|
-
on_key_pressed { |event|
|
62
|
-
exit_game if event.keyCode == swt(:cr)
|
63
|
-
}
|
64
64
|
}
|
65
65
|
}
|
66
|
-
|
67
|
-
def exit_game
|
68
|
-
display.dispose if Model::Game.game_over?
|
69
|
-
end
|
70
66
|
end
|
71
67
|
end
|
72
68
|
end
|
@@ -27,7 +27,7 @@ class Tetris
|
|
27
27
|
class ScoreLane
|
28
28
|
include Glimmer::UI::CustomWidget
|
29
29
|
|
30
|
-
options :block_size
|
30
|
+
options :block_size, :game
|
31
31
|
|
32
32
|
before_body {
|
33
33
|
@font_name = 'Menlo'
|
@@ -48,14 +48,14 @@ class Tetris
|
|
48
48
|
text 'Next'
|
49
49
|
font name: @font_name, height: @font_height, style: :bold
|
50
50
|
}
|
51
|
-
playfield(game_playfield:
|
51
|
+
playfield(game_playfield: game.preview_playfield, playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
|
52
52
|
|
53
53
|
label(:center) {
|
54
54
|
text 'Score'
|
55
55
|
font name: @font_name, height: @font_height, style: :bold
|
56
56
|
}
|
57
57
|
label(:center) {
|
58
|
-
text bind(
|
58
|
+
text bind(game, :score)
|
59
59
|
font height: @font_height
|
60
60
|
}
|
61
61
|
|
@@ -66,7 +66,7 @@ class Tetris
|
|
66
66
|
font name: @font_name, height: @font_height, style: :bold
|
67
67
|
}
|
68
68
|
label(:center) {
|
69
|
-
text bind(
|
69
|
+
text bind(game, :lines)
|
70
70
|
font height: @font_height
|
71
71
|
}
|
72
72
|
|
@@ -77,7 +77,7 @@ class Tetris
|
|
77
77
|
font name: @font_name, height: @font_height, style: :bold
|
78
78
|
}
|
79
79
|
label(:center) {
|
80
|
-
text bind(
|
80
|
+
text bind(game, :level)
|
81
81
|
font height: @font_height
|
82
82
|
}
|
83
83
|
}
|
@@ -0,0 +1,72 @@
|
|
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 Tetris
|
23
|
+
module View
|
24
|
+
class TetrisMenuBar
|
25
|
+
include Glimmer::UI::CustomWidget
|
26
|
+
|
27
|
+
options :game
|
28
|
+
|
29
|
+
body {
|
30
|
+
menu_bar {
|
31
|
+
menu {
|
32
|
+
text '&Game'
|
33
|
+
|
34
|
+
menu_item {
|
35
|
+
text '&Start'
|
36
|
+
enabled bind(game, :game_over)
|
37
|
+
accelerator :command, :s
|
38
|
+
|
39
|
+
on_widget_selected {
|
40
|
+
game.start!
|
41
|
+
}
|
42
|
+
}
|
43
|
+
menu_item(:check) {
|
44
|
+
text '&Pause'
|
45
|
+
accelerator :command, :p
|
46
|
+
enabled bind(game, :game_over, on_read: :!)
|
47
|
+
selection bind(game, :paused)
|
48
|
+
}
|
49
|
+
menu_item {
|
50
|
+
text '&Restart'
|
51
|
+
accelerator :command, :r
|
52
|
+
enabled bind(game, :game_over, on_read: :!)
|
53
|
+
|
54
|
+
on_widget_selected {
|
55
|
+
game.restart!
|
56
|
+
}
|
57
|
+
}
|
58
|
+
menu_item(:separator)
|
59
|
+
menu_item {
|
60
|
+
text '&Exit'
|
61
|
+
accelerator :command, :x
|
62
|
+
|
63
|
+
on_widget_selected {
|
64
|
+
parent_proxy.close
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2007-2021 Andy Maleh
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
# a copy of this software and associated documentation files (the
|
5
5
|
# "Software"), to deal in the Software without restriction, including
|
@@ -7,10 +7,10 @@
|
|
7
7
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
8
|
# permit persons to whom the Software is furnished to do so, subject to
|
9
9
|
# the following conditions:
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# The above copyright notice and this permission notice shall be
|
12
12
|
# included in all copies or substantial portions of the Software.
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
15
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
16
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
@@ -28,7 +28,7 @@ class TicTacToe
|
|
28
28
|
@tic_tac_toe_board = Board.new
|
29
29
|
@shell = shell {
|
30
30
|
text "Tic-Tac-Toe"
|
31
|
-
minimum_size
|
31
|
+
minimum_size 176, 200
|
32
32
|
composite {
|
33
33
|
grid_layout 3, true
|
34
34
|
(1..3).each { |row|
|
data/samples/hello/hello_link.rb
CHANGED
@@ -49,7 +49,7 @@ shell { |main_shell|
|
|
49
49
|
}
|
50
50
|
on_mouse_up { |mouse_event|
|
51
51
|
unless @selected_link.nil?
|
52
|
-
@help_shell.close unless @help_shell.nil? || @help_shell.
|
52
|
+
@help_shell.close unless @help_shell.nil? || @help_shell.disposed?
|
53
53
|
@help_shell = shell(:no_trim) {
|
54
54
|
grid_layout {
|
55
55
|
margin_width 10
|
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.3.
|
4
|
+
version: 4.18.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-27 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.
|
18
|
+
version: 1.0.11
|
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.
|
26
|
+
version: 1.0.11
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
@@ -476,6 +476,7 @@ files:
|
|
476
476
|
- samples/elaborate/tetris/view/game_over_dialog.rb
|
477
477
|
- samples/elaborate/tetris/view/playfield.rb
|
478
478
|
- samples/elaborate/tetris/view/score_lane.rb
|
479
|
+
- samples/elaborate/tetris/view/tetris_menu_bar.rb
|
479
480
|
- samples/elaborate/tic_tac_toe.rb
|
480
481
|
- samples/elaborate/tic_tac_toe/board.rb
|
481
482
|
- samples/elaborate/tic_tac_toe/cell.rb
|