glimmer-dsl-swt 4.18.1.0 → 4.18.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/README.md +136 -46
- data/VERSION +1 -1
- data/glimmer-dsl-swt.gemspec +10 -4
- data/lib/glimmer/dsl/swt/display_expression.rb +3 -3
- data/lib/glimmer/dsl/swt/property_expression.rb +2 -1
- data/lib/glimmer/dsl/swt/shape_expression.rb +1 -1
- data/lib/glimmer/rake_task/list.rb +5 -5
- data/lib/glimmer/rake_task/package.rb +9 -9
- data/lib/glimmer/rake_task/scaffold.rb +36 -36
- data/lib/glimmer/swt/custom/animation.rb +163 -36
- data/lib/glimmer/swt/custom/code_text.rb +2 -1
- data/lib/glimmer/swt/custom/shape.rb +83 -18
- data/lib/glimmer/swt/display_proxy.rb +2 -1
- data/lib/glimmer/swt/widget_proxy.rb +4 -6
- data/lib/glimmer/ui/custom_shell.rb +13 -0
- data/samples/elaborate/meta_sample.rb +22 -1
- data/samples/elaborate/tetris.rb +102 -0
- data/samples/elaborate/tetris/model/block.rb +48 -0
- data/samples/elaborate/tetris/model/game.rb +116 -0
- data/samples/elaborate/tetris/model/tetromino.rb +228 -0
- data/samples/elaborate/tetris/view/block.rb +45 -0
- data/samples/elaborate/tetris/view/playfield.rb +49 -0
- data/samples/hello/hello_canvas.rb +7 -6
- data/samples/hello/hello_canvas_animation.rb +1 -1
- metadata +22 -14
@@ -0,0 +1,228 @@
|
|
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
|
+
require 'matrix'
|
25
|
+
|
26
|
+
class Tetris
|
27
|
+
module Model
|
28
|
+
class Tetromino
|
29
|
+
ORIENTATIONS = [:north, :east, :south, :west]
|
30
|
+
|
31
|
+
LETTER_COLORS = {
|
32
|
+
I: :cyan,
|
33
|
+
J: :blue,
|
34
|
+
L: :dark_yellow,
|
35
|
+
O: :yellow,
|
36
|
+
S: :green,
|
37
|
+
T: :magenta,
|
38
|
+
Z: :red,
|
39
|
+
}
|
40
|
+
|
41
|
+
attr_reader :letter
|
42
|
+
attr_accessor :orientation, :blocks, :row, :column
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
@letter = LETTER_COLORS.keys.sample
|
46
|
+
@orientation = :north
|
47
|
+
@blocks = default_blocks
|
48
|
+
new_row = 1 - height
|
49
|
+
new_column = (PLAYFIELD_WIDTH - width)/2
|
50
|
+
update_playfield(new_row, new_column)
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_playfield(new_row = nil, new_column = nil)
|
54
|
+
remove_from_playfield
|
55
|
+
if !new_row.nil? && !new_column.nil?
|
56
|
+
@row = new_row
|
57
|
+
@column = new_column
|
58
|
+
add_to_playfield
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_to_playfield
|
63
|
+
update_playfield_block do |playfield_row, playfield_column, row_index, column_index|
|
64
|
+
Game.playfield[playfield_row][playfield_column].color = blocks[row_index][column_index].color if playfield_row >= 0 && Game.playfield[playfield_row][playfield_column].clear? && !blocks[row_index][column_index].clear?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def remove_from_playfield
|
69
|
+
return if @row.nil? || @column.nil?
|
70
|
+
update_playfield_block do |playfield_row, playfield_column, row_index, column_index|
|
71
|
+
Game.playfield[playfield_row][playfield_column].clear if playfield_row >= 0 && !blocks[row_index][column_index].clear? && Game.playfield[playfield_row][playfield_column].color == color
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def stopped?(blocks: nil)
|
76
|
+
blocks ||= @blocks
|
77
|
+
playfield_remaining_heights = Game.playfield_remaining_heights(self)
|
78
|
+
result = bottom_blocks(blocks).any? do |bottom_block|
|
79
|
+
playfield_column = @column + bottom_block[:column_index]
|
80
|
+
!bottom_block[:block].clear? &&
|
81
|
+
(@row + bottom_block[:row]) >= playfield_remaining_heights[playfield_column] - 1
|
82
|
+
end
|
83
|
+
Game.consider_eliminating_lines if result
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns blocks at the bottom of a tetromino, which could be from multiple rows depending on shape (e.g. T)
|
88
|
+
def bottom_blocks(blocks = nil)
|
89
|
+
blocks ||= @blocks
|
90
|
+
width.times.map do |column_index|
|
91
|
+
row_blocks_with_row_index = @blocks.each_with_index.to_a.reverse.detect do |row_blocks, row_index|
|
92
|
+
!row_blocks[column_index].clear?
|
93
|
+
end
|
94
|
+
bottom_block = row_blocks_with_row_index[0][column_index]
|
95
|
+
bottom_block_row = row_blocks_with_row_index[1]
|
96
|
+
{
|
97
|
+
block: bottom_block,
|
98
|
+
row: bottom_block_row,
|
99
|
+
column_index: column_index
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def bottom_block_for_column(column)
|
105
|
+
bottom_blocks.detect {|bottom_block| (@column + bottom_block[:column_index]) == column}
|
106
|
+
end
|
107
|
+
|
108
|
+
def right_blocked?
|
109
|
+
(@column == PLAYFIELD_WIDTH - width) || Game.playfield[row][column + width].occupied?
|
110
|
+
end
|
111
|
+
|
112
|
+
def left_blocked?
|
113
|
+
(@column == 0) || Game.playfield[row][column - 1].occupied?
|
114
|
+
end
|
115
|
+
|
116
|
+
def width
|
117
|
+
@blocks[0].size
|
118
|
+
end
|
119
|
+
|
120
|
+
def height
|
121
|
+
@blocks.size
|
122
|
+
end
|
123
|
+
|
124
|
+
def down
|
125
|
+
unless stopped?
|
126
|
+
new_row = @row + 1
|
127
|
+
update_playfield(new_row, @column)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def left
|
132
|
+
unless left_blocked?
|
133
|
+
new_column = @column - 1
|
134
|
+
update_playfield(@row, new_column)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def right
|
139
|
+
unless right_blocked?
|
140
|
+
new_column = @column + 1
|
141
|
+
update_playfield(@row, new_column)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# Rotate in specified direcation, which can be :right (clockwise) or :left (counterclockwise)
|
146
|
+
def rotate(direction)
|
147
|
+
return if stopped?
|
148
|
+
array_rotation_value = direction == :right ? -1 : 1
|
149
|
+
self.orientation = ORIENTATIONS[ORIENTATIONS.rotate(array_rotation_value).index(@orientation)]
|
150
|
+
new_blocks = Matrix[*@blocks].transpose.to_a
|
151
|
+
if direction == :right
|
152
|
+
new_blocks = new_blocks.map(&:reverse)
|
153
|
+
else
|
154
|
+
new_blocks = new_blocks.reverse
|
155
|
+
end
|
156
|
+
new_blocks = Matrix[*new_blocks].to_a
|
157
|
+
unless stopped?(blocks: new_blocks) || right_blocked? || left_blocked?
|
158
|
+
remove_from_playfield
|
159
|
+
self.blocks = new_blocks
|
160
|
+
update_playfield(@row, @column)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def default_blocks
|
165
|
+
case @letter
|
166
|
+
when :I
|
167
|
+
[
|
168
|
+
[block, block, block, block]
|
169
|
+
]
|
170
|
+
when :J
|
171
|
+
[
|
172
|
+
[block, block, block],
|
173
|
+
[empty, empty, block],
|
174
|
+
]
|
175
|
+
when :L
|
176
|
+
[
|
177
|
+
[block, block, block],
|
178
|
+
[block, empty, empty],
|
179
|
+
]
|
180
|
+
when :O
|
181
|
+
[
|
182
|
+
[block, block],
|
183
|
+
[block, block],
|
184
|
+
]
|
185
|
+
when :S
|
186
|
+
[
|
187
|
+
[empty, block, block],
|
188
|
+
[block, block, empty],
|
189
|
+
]
|
190
|
+
when :T
|
191
|
+
[
|
192
|
+
[block, block, block],
|
193
|
+
[empty, block, empty],
|
194
|
+
]
|
195
|
+
when :Z
|
196
|
+
[
|
197
|
+
[block, block, empty],
|
198
|
+
[empty, block, block],
|
199
|
+
]
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def color
|
204
|
+
LETTER_COLORS[@letter]
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
|
209
|
+
def block
|
210
|
+
Block.new(color)
|
211
|
+
end
|
212
|
+
|
213
|
+
def empty
|
214
|
+
Block.new
|
215
|
+
end
|
216
|
+
|
217
|
+
def update_playfield_block(&updater)
|
218
|
+
@row.upto(@row + height - 1) do |playfield_row|
|
219
|
+
@column.upto(@column + width - 1) do |playfield_column|
|
220
|
+
row_index = playfield_row - @row
|
221
|
+
column_index = playfield_column - @column
|
222
|
+
updater.call(playfield_row, playfield_column, row_index, column_index)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 Block
|
25
|
+
include Glimmer::UI::CustomWidget
|
26
|
+
|
27
|
+
options :block_size, :row, :column
|
28
|
+
|
29
|
+
body {
|
30
|
+
composite {
|
31
|
+
layout nil
|
32
|
+
layout_data {
|
33
|
+
width_hint block_size
|
34
|
+
height_hint block_size
|
35
|
+
}
|
36
|
+
background bind(Model::Game.playfield[row][column], :color)
|
37
|
+
rectangle(0, 0, block_size, block_size)
|
38
|
+
rectangle(3, 3, block_size - 6, block_size - 6) {
|
39
|
+
foreground :gray
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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 :playfield_width, :playfield_height, :block_size
|
30
|
+
|
31
|
+
body {
|
32
|
+
composite {
|
33
|
+
grid_layout(playfield_width, true) {
|
34
|
+
margin_width block_size
|
35
|
+
margin_height block_size
|
36
|
+
horizontal_spacing 0
|
37
|
+
vertical_spacing 0
|
38
|
+
}
|
39
|
+
|
40
|
+
playfield_height.times { |row|
|
41
|
+
playfield_width.times { |column|
|
42
|
+
block(block_size: block_size, row: row, column: column)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -30,19 +30,19 @@ shell {
|
|
30
30
|
rectangle(0, 0, 220, 400, fill: true) {
|
31
31
|
background :red
|
32
32
|
}
|
33
|
-
|
33
|
+
rectangle(50, 20, 300, 150, 30, 50, round: true, fill: true) {
|
34
34
|
background :magenta
|
35
35
|
}
|
36
|
-
|
36
|
+
rectangle(150, 200, 100, 70, true, gradient: true) {
|
37
37
|
background :dark_magenta
|
38
38
|
foreground :yellow
|
39
39
|
}
|
40
|
-
|
40
|
+
rectangle(50, 200, 30, 70, false, gradient: true) {
|
41
41
|
background :magenta
|
42
42
|
foreground :dark_blue
|
43
43
|
}
|
44
|
-
rectangle(
|
45
|
-
foreground
|
44
|
+
rectangle(205, 50, 88, 96) {
|
45
|
+
foreground :yellow
|
46
46
|
}
|
47
47
|
text('Picasso', 60, 80) {
|
48
48
|
background :yellow
|
@@ -55,8 +55,9 @@ shell {
|
|
55
55
|
arc(210, 210, 100, 100, 30, -77, fill: true) {
|
56
56
|
background :red
|
57
57
|
}
|
58
|
-
polygon(
|
58
|
+
polygon(250, 210, 260, 170, 270, 210, 290, 230, fill: true) {
|
59
59
|
background :dark_yellow
|
60
60
|
}
|
61
|
+
polyline(250, 110, 260, 70, 270, 110, 290, 130, 250, 110)
|
61
62
|
}
|
62
63
|
}.open
|
@@ -35,7 +35,7 @@ shell {
|
|
35
35
|
oval(0, 0, 400, 400) { # x, y, width, height
|
36
36
|
foreground :black # sets oval background color
|
37
37
|
}
|
38
|
-
arc(0, 0, 400, 400, -1*index%360, 10, fill: true) { # x, y, width, height, start angle, arc angle
|
38
|
+
arc(0, 0, 400, 400, -1.4*index%360, 10, fill: true) { # x, y, width, height, start angle, arc angle
|
39
39
|
background rgb(200, 200, 50) # sets arc background color
|
40
40
|
}
|
41
41
|
}
|
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.18.
|
4
|
+
version: 4.18.2.3
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -330,18 +330,20 @@ dependencies:
|
|
330
330
|
version: 0.7.0
|
331
331
|
description: Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) is a native-GUI
|
332
332
|
cross-platform desktop development library written in JRuby, an OS-threaded faster
|
333
|
-
version of Ruby. Glimmer's main innovation is a declarative Ruby DSL that enables
|
334
|
-
productive and efficient authoring of desktop application user-interfaces
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
333
|
+
JVM version of Ruby. Glimmer's main innovation is a declarative Ruby DSL that enables
|
334
|
+
productive and efficient authoring of desktop application user-interfaces by relying
|
335
|
+
on the robust Eclipse SWT library. Glimmer additionally innovates by having built-in
|
336
|
+
data-binding support, which greatly facilitates synchronizing the GUI with domain
|
337
|
+
models, thus achieving true decoupling of object oriented components and enabling
|
338
|
+
developers to solve business problems (test-first) without worrying about GUI concerns,
|
339
|
+
or alternatively drive development GUI-first, and then write clean business models
|
340
|
+
(test-first) afterwards. Not only does Glimmer provide a large set of GUI widgets,
|
341
|
+
but it also supports drawing Canvas Graphics like Shapes and Animations. To get
|
342
|
+
started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets.
|
343
|
+
Glimmer also includes native-executable packaging support, sorely lacking in other
|
344
|
+
libraries, thus enabling the delivery of desktop apps written in Ruby as truly native
|
345
|
+
DMG/PKG/APP files on the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged
|
346
|
+
Shell Scripts on Linux.
|
345
347
|
email: andy.am@gmail.com
|
346
348
|
executables:
|
347
349
|
- glimmer
|
@@ -463,6 +465,12 @@ files:
|
|
463
465
|
- samples/elaborate/contact_manager/contact_repository.rb
|
464
466
|
- samples/elaborate/login.rb
|
465
467
|
- samples/elaborate/meta_sample.rb
|
468
|
+
- samples/elaborate/tetris.rb
|
469
|
+
- samples/elaborate/tetris/model/block.rb
|
470
|
+
- samples/elaborate/tetris/model/game.rb
|
471
|
+
- samples/elaborate/tetris/model/tetromino.rb
|
472
|
+
- samples/elaborate/tetris/view/block.rb
|
473
|
+
- samples/elaborate/tetris/view/playfield.rb
|
466
474
|
- samples/elaborate/tic_tac_toe.rb
|
467
475
|
- samples/elaborate/tic_tac_toe/board.rb
|
468
476
|
- samples/elaborate/tic_tac_toe/cell.rb
|