glimmer-dsl-opal 0.25.2 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +46 -9
- data/VERSION +1 -1
- data/lib/glimmer/dsl/opal/combo_selection_data_binding_expression.rb +3 -3
- data/lib/glimmer/dsl/opal/menu_expression.rb +0 -3
- data/lib/glimmer/swt/c_combo_proxy.rb +30 -1
- data/lib/glimmer/swt/combo_proxy.rb +10 -2
- data/lib/glimmer/swt/control_editor.rb +2 -2
- data/lib/glimmer/swt/dialog_proxy.rb +11 -4
- data/lib/glimmer/swt/display_proxy.rb +18 -3
- data/lib/glimmer/swt/shell_proxy.rb +28 -1
- data/lib/glimmer/swt/table_item_proxy.rb +0 -20
- data/lib/glimmer/swt/table_proxy.rb +4 -0
- data/lib/glimmer/swt/widget_proxy.rb +48 -7
- data/lib/glimmer/ui/custom_shell.rb +2 -0
- data/lib/glimmer/ui/custom_widget.rb +2 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/login.rb +3 -5
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/block.rb +48 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/game.rb +275 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/past_game.rb +39 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/model/tetromino.rb +329 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/block.rb +36 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/high_score_dialog.rb +122 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/playfield.rb +56 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/score_lane.rb +83 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris/view/tetris_menu_bar.rb +136 -0
- data/lib/glimmer-dsl-opal/samples/elaborate/tetris.rb +150 -0
- data/lib/glimmer-dsl-opal/samples/hello/hello_custom_widget.rb +1 -1
- data/lib/glimmer-dsl-opal.rb +1 -0
- metadata +14 -4
@@ -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 'block'
|
23
|
+
|
24
|
+
class Tetris
|
25
|
+
module View
|
26
|
+
class Playfield
|
27
|
+
include Glimmer::UI::CustomWidget
|
28
|
+
|
29
|
+
options :game_playfield, :playfield_width, :playfield_height, :block_size
|
30
|
+
|
31
|
+
body {
|
32
|
+
composite {
|
33
|
+
grid_layout {
|
34
|
+
num_columns playfield_width
|
35
|
+
make_columns_equal_width true
|
36
|
+
margin_width block_size
|
37
|
+
margin_height block_size
|
38
|
+
horizontal_spacing 0
|
39
|
+
vertical_spacing 0
|
40
|
+
}
|
41
|
+
|
42
|
+
playfield_height.times { |row|
|
43
|
+
playfield_width.times { |column|
|
44
|
+
block(game_playfield: game_playfield, block_size: block_size, row: row, column: column) {
|
45
|
+
layout_data {
|
46
|
+
width_hint block_size
|
47
|
+
height_hint block_size
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,83 @@
|
|
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 'block'
|
23
|
+
require_relative 'playfield'
|
24
|
+
|
25
|
+
class Tetris
|
26
|
+
module View
|
27
|
+
class ScoreLane
|
28
|
+
include Glimmer::UI::CustomWidget
|
29
|
+
|
30
|
+
options :block_size, :game
|
31
|
+
|
32
|
+
before_body do
|
33
|
+
@font_name = FONT_NAME
|
34
|
+
@font_height = FONT_TITLE_HEIGHT
|
35
|
+
end
|
36
|
+
|
37
|
+
body {
|
38
|
+
composite {
|
39
|
+
row_layout {
|
40
|
+
type :vertical
|
41
|
+
center true
|
42
|
+
}
|
43
|
+
label(:center) {
|
44
|
+
text 'Next'
|
45
|
+
font name: @font_name, height: @font_height, style: FONT_TITLE_STYLE
|
46
|
+
}
|
47
|
+
playfield(game_playfield: game.preview_playfield, playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: block_size)
|
48
|
+
|
49
|
+
label(:center) {
|
50
|
+
text 'Score'
|
51
|
+
font name: @font_name, height: @font_height, style: FONT_TITLE_STYLE
|
52
|
+
}
|
53
|
+
label(:center) {
|
54
|
+
text <= [game, :score]
|
55
|
+
font height: @font_height
|
56
|
+
}
|
57
|
+
|
58
|
+
label # spacer
|
59
|
+
|
60
|
+
label(:center) {
|
61
|
+
text 'Lines'
|
62
|
+
font name: @font_name, height: @font_height, style: FONT_TITLE_STYLE
|
63
|
+
}
|
64
|
+
label(:center) {
|
65
|
+
text <= [game, :lines]
|
66
|
+
font height: @font_height
|
67
|
+
}
|
68
|
+
|
69
|
+
label # spacer
|
70
|
+
|
71
|
+
label(:center) {
|
72
|
+
text 'Level'
|
73
|
+
font name: @font_name, height: @font_height, style: FONT_TITLE_STYLE
|
74
|
+
}
|
75
|
+
label(:center) {
|
76
|
+
text <= [game, :level]
|
77
|
+
font height: @font_height
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,136 @@
|
|
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
|
+
COMMAND_KEY = OS.mac? ? :command : :ctrl
|
28
|
+
|
29
|
+
options :game
|
30
|
+
|
31
|
+
body {
|
32
|
+
menu_bar {
|
33
|
+
menu {
|
34
|
+
text '&Game'
|
35
|
+
|
36
|
+
menu_item {
|
37
|
+
text '&Start'
|
38
|
+
enabled <= [game, :game_over]
|
39
|
+
accelerator COMMAND_KEY, :s
|
40
|
+
|
41
|
+
on_widget_selected {
|
42
|
+
game.start!
|
43
|
+
}
|
44
|
+
}
|
45
|
+
menu_item(:check) {
|
46
|
+
text '&Pause'
|
47
|
+
accelerator COMMAND_KEY, :p
|
48
|
+
enabled <= [game, :game_over, on_read: ->(value) { !value && !game.show_high_scores }]
|
49
|
+
enabled <= [game, :show_high_scores, on_read: ->(value) { !value && !game.game_over }]
|
50
|
+
selection <=> [game, :paused]
|
51
|
+
}
|
52
|
+
menu_item {
|
53
|
+
text '&Restart'
|
54
|
+
accelerator COMMAND_KEY, :r
|
55
|
+
|
56
|
+
on_widget_selected {
|
57
|
+
game.restart!
|
58
|
+
}
|
59
|
+
}
|
60
|
+
menu_item(:separator)
|
61
|
+
menu_item {
|
62
|
+
text '&Exit'
|
63
|
+
accelerator COMMAND_KEY, :x
|
64
|
+
|
65
|
+
on_widget_selected {
|
66
|
+
parent_proxy.close
|
67
|
+
}
|
68
|
+
}
|
69
|
+
} # end of menu
|
70
|
+
|
71
|
+
menu {
|
72
|
+
text '&View'
|
73
|
+
|
74
|
+
menu {
|
75
|
+
text '&High Scores'
|
76
|
+
menu_item(:check) {
|
77
|
+
text '&Show'
|
78
|
+
accelerator COMMAND_KEY, :shift, :h
|
79
|
+
selection <=> [game, :show_high_scores]
|
80
|
+
}
|
81
|
+
menu_item {
|
82
|
+
text '&Clear'
|
83
|
+
accelerator COMMAND_KEY, :shift, :c
|
84
|
+
|
85
|
+
on_widget_selected {
|
86
|
+
game.clear_high_scores!
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
} # end of menu
|
91
|
+
|
92
|
+
menu {
|
93
|
+
text '&Options'
|
94
|
+
menu {
|
95
|
+
text 'Up Action'
|
96
|
+
menu_item(:radio) {
|
97
|
+
text '&Instant Down'
|
98
|
+
accelerator COMMAND_KEY, :shift, :i
|
99
|
+
selection <=> [game, :instant_down_on_up, computed_by: :up_arrow_action]
|
100
|
+
}
|
101
|
+
menu_item(:radio) {
|
102
|
+
text 'Rotate &Right'
|
103
|
+
accelerator COMMAND_KEY, :shift, :r
|
104
|
+
selection <=> [game, :rotate_right_on_up, computed_by: :up_arrow_action]
|
105
|
+
}
|
106
|
+
menu_item(:radio) {
|
107
|
+
text 'Rotate &Left'
|
108
|
+
accelerator COMMAND_KEY, :shift, :l
|
109
|
+
selection <=> [game, :rotate_left_on_up, computed_by: :up_arrow_action]
|
110
|
+
}
|
111
|
+
}
|
112
|
+
} # end of menu
|
113
|
+
|
114
|
+
menu {
|
115
|
+
text '&Help'
|
116
|
+
|
117
|
+
menu_item {
|
118
|
+
text '&About'
|
119
|
+
accelerator COMMAND_KEY, :shift, :a
|
120
|
+
|
121
|
+
on_widget_selected {
|
122
|
+
parent_custom_shell&.show_about_dialog
|
123
|
+
}
|
124
|
+
}
|
125
|
+
} # end of menu
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
def parent_custom_shell
|
130
|
+
# grab custom shell widget wrapping parent widget proxy (i.e. Tetris) and invoke method on it
|
131
|
+
the_parent_custom_shell = parent_proxy&.get_data('custom_shell')
|
132
|
+
the_parent_custom_shell if the_parent_custom_shell&.visible?
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,150 @@
|
|
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 'tetris/model/game'
|
23
|
+
|
24
|
+
require_relative 'tetris/view/playfield'
|
25
|
+
require_relative 'tetris/view/score_lane'
|
26
|
+
require_relative 'tetris/view/high_score_dialog'
|
27
|
+
require_relative 'tetris/view/tetris_menu_bar'
|
28
|
+
class Event
|
29
|
+
def location
|
30
|
+
`#@native.location`
|
31
|
+
end
|
32
|
+
end
|
33
|
+
class Tetris
|
34
|
+
include Glimmer::UI::CustomShell
|
35
|
+
|
36
|
+
BLOCK_SIZE = 7
|
37
|
+
FONT_NAME = 'Menlo'
|
38
|
+
FONT_TITLE_HEIGHT = 32
|
39
|
+
FONT_TITLE_STYLE = :bold
|
40
|
+
BEVEL_CONSTANT = 20
|
41
|
+
|
42
|
+
option :playfield_width, default: Model::Game::PLAYFIELD_WIDTH
|
43
|
+
option :playfield_height, default: Model::Game::PLAYFIELD_HEIGHT
|
44
|
+
|
45
|
+
attr_reader :game
|
46
|
+
|
47
|
+
before_body do
|
48
|
+
@game = Model::Game.new(playfield_width, playfield_height)
|
49
|
+
|
50
|
+
Display.app_name = 'Glimmer Tetris'
|
51
|
+
|
52
|
+
display {
|
53
|
+
on_swt_keydown do |key_event|
|
54
|
+
case key_event.keyCode
|
55
|
+
when swt(:arrow_up), 'w'.bytes.first
|
56
|
+
case game.up_arrow_action
|
57
|
+
when :instant_down
|
58
|
+
game.down!(instant: true)
|
59
|
+
when :rotate_right
|
60
|
+
game.rotate!(:right)
|
61
|
+
when :rotate_left
|
62
|
+
game.rotate!(:left)
|
63
|
+
end
|
64
|
+
when swt(:arrow_down), 's'.bytes.first
|
65
|
+
game.down!
|
66
|
+
when swt(:arrow_left), 'a'.bytes.first
|
67
|
+
game.left!
|
68
|
+
when swt(:arrow_right), 'd'.bytes.first
|
69
|
+
game.right!
|
70
|
+
when 'q'.bytes.first
|
71
|
+
game.rotate!(:left)
|
72
|
+
when 'e'.bytes.first
|
73
|
+
game.rotate!(:right)
|
74
|
+
when swt(:shift), swt(:alt)
|
75
|
+
game.rotate!(:right)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
after_body do
|
82
|
+
observe(@game, :game_over) do |game_over|
|
83
|
+
if game_over
|
84
|
+
show_high_score_dialog
|
85
|
+
else
|
86
|
+
start_moving_tetrominos_down
|
87
|
+
end
|
88
|
+
end
|
89
|
+
observe(@game, :show_high_scores) do |show_high_scores|
|
90
|
+
if show_high_scores
|
91
|
+
show_high_score_dialog
|
92
|
+
else
|
93
|
+
@high_score_dialog.close unless @high_score_dialog.nil? || @high_score_dialog.disposed? || !@high_score_dialog.visible?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
@game.start!
|
97
|
+
end
|
98
|
+
|
99
|
+
body {
|
100
|
+
shell(:no_resize) {
|
101
|
+
grid_layout {
|
102
|
+
num_columns 2
|
103
|
+
make_columns_equal_width false
|
104
|
+
margin_width 0
|
105
|
+
margin_height 0
|
106
|
+
horizontal_spacing 0
|
107
|
+
}
|
108
|
+
|
109
|
+
text 'Glimmer Tetris'
|
110
|
+
background rgb(236, 236, 236)
|
111
|
+
|
112
|
+
tetris_menu_bar(game: game)
|
113
|
+
|
114
|
+
playfield(game_playfield: game.playfield, playfield_width: playfield_width, playfield_height: playfield_height, block_size: BLOCK_SIZE) {
|
115
|
+
layout_data {
|
116
|
+
width_hint 370
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
score_lane(game: game, block_size: BLOCK_SIZE) {
|
121
|
+
layout_data(:fill, :fill, true, true)
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
def start_moving_tetrominos_down
|
127
|
+
Async::Task.new do
|
128
|
+
work = lambda do
|
129
|
+
@game.down!
|
130
|
+
Async::Task.new(delay: @game.delay * 1000.0, &work) unless @game.game_over? || body_root.disposed?
|
131
|
+
end
|
132
|
+
Async::Task.new(delay: @game.delay * 1000.0, &work)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def show_high_score_dialog
|
137
|
+
return if @high_score_dialog&.visible?
|
138
|
+
@high_score_dialog = high_score_dialog(parent_shell: body_root, game: @game) #if @high_score_dialog.nil? || @high_score_dialog.disposed?
|
139
|
+
@high_score_dialog.show
|
140
|
+
end
|
141
|
+
|
142
|
+
def show_about_dialog
|
143
|
+
message_box {
|
144
|
+
text 'Glimmer Tetris'
|
145
|
+
message "Glimmer Tetris\n\nGlimmer DSL for SWT Sample\n\nLeft is A\nRight is D\nDown is S\nUp is W\nRotate Left is Q\nRotate Right is E\n\n for Left, Down, Right, Up\n\nCopyright (c) 2007-2021 Andy Maleh"
|
146
|
+
}.open
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
Tetris.launch
|
data/lib/glimmer-dsl-opal.rb
CHANGED