glimmer-dsl-gtk 0.0.5 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/README.md +699 -51
- data/VERSION +1 -1
- data/glimmer-dsl-gtk.gemspec +0 -0
- data/lib/glimmer/gtk/shape/path.rb +51 -0
- data/lib/glimmer/gtk/shape.rb +56 -22
- data/lib/glimmer/gtk/transformable.rb +93 -0
- data/lib/glimmer/gtk/widget_proxy/drawing_area_proxy.rb +8 -1
- data/lib/glimmer/gtk/widget_proxy.rb +15 -3
- data/samples/cairo/arc.rb +44 -0
- data/samples/cairo/arc_negative.rb +44 -0
- data/samples/cairo/clip.rb +34 -0
- data/samples/cairo/clip_image.rb +33 -0
- data/samples/cairo/curve_to.rb +39 -0
- data/samples/cairo/dashes.rb +30 -0
- data/samples/cairo/fill_and_stroke2.rb +36 -0
- data/samples/cairo/fill_style.rb +43 -0
- data/samples/cairo/gradient.rb +31 -0
- data/samples/cairo/image.rb +28 -0
- data/samples/cairo/image_gradient.rb +37 -0
- data/samples/cairo/multi_segment_caps.rb +27 -0
- data/samples/cairo/rounded_rectangle.rb +20 -0
- data/samples/cairo/set_line_cap.rb +53 -0
- data/samples/cairo/set_line_join.rb +43 -0
- data/samples/cairo/text.rb +46 -0
- data/samples/elaborate/tetris/model/game.rb +28 -34
- data/samples/elaborate/tetris.rb +66 -20
- data/samples/elaborate/widget_gallery.rb +18 -7
- data/samples/hello/hello_button.rb +2 -2
- data/samples/hello/hello_entry.rb +2 -2
- metadata +21 -3
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Fill Style'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
path {
|
13
|
+
rectangle 12, 12, 232, 70
|
14
|
+
path { # sub-path
|
15
|
+
arc 64, 64, 40, 0, 2*Math::PI
|
16
|
+
}
|
17
|
+
path { # sub-path
|
18
|
+
arc_negative 192, 64, 40, 0, -2*Math::PI
|
19
|
+
}
|
20
|
+
|
21
|
+
fill_rule Cairo::FILL_RULE_EVEN_ODD
|
22
|
+
line_width 6
|
23
|
+
fill 0, 178.5, 0
|
24
|
+
stroke 0, 0, 0
|
25
|
+
}
|
26
|
+
|
27
|
+
path {
|
28
|
+
rectangle 12, 12, 232, 70
|
29
|
+
path { # sub-path
|
30
|
+
arc 64, 64, 40, 0, 2*Math::PI
|
31
|
+
}
|
32
|
+
path { # sub-path
|
33
|
+
arc_negative 192, 64, 40, 0, -2*Math::PI
|
34
|
+
}
|
35
|
+
|
36
|
+
translate 0, 128
|
37
|
+
fill_rule Cairo::FILL_RULE_WINDING
|
38
|
+
line_width 6
|
39
|
+
fill 0, 0, 229.5
|
40
|
+
stroke 0, 0, 0
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}.show
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Gradient'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
# Create the Linear Pattern
|
13
|
+
rectangle(0, 0, 256, 256) {
|
14
|
+
pat = Cairo::LinearPattern.new(0.0, 0.0, 0.0, 256.0)
|
15
|
+
pat.add_color_stop_rgba(1, 0, 0, 0, 1)
|
16
|
+
pat.add_color_stop_rgba(0, 1, 1, 1, 1)
|
17
|
+
|
18
|
+
fill pat
|
19
|
+
}
|
20
|
+
|
21
|
+
# Create the radial pattern
|
22
|
+
arc(128.0, 128.0, 76.8, 0, 2 * Math::PI) {
|
23
|
+
pat = Cairo::RadialPattern.new(115.2, 102.4, 25.6,
|
24
|
+
102.4, 102.4, 128.0)
|
25
|
+
pat.add_color_stop_rgba(0, 1, 1, 1, 1)
|
26
|
+
pat.add_color_stop_rgba(1, 0, 0, 0, 1)
|
27
|
+
|
28
|
+
fill pat
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}.show
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
image_content = Net::HTTP.get(URI('https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-gtk/master/images/breaking-blue-wave.png'))
|
5
|
+
image_file = File.join(Dir.home, 'breaking-blue-wave.png')
|
6
|
+
File.write(image_file, image_content)
|
7
|
+
|
8
|
+
include Glimmer
|
9
|
+
|
10
|
+
window {
|
11
|
+
title 'Image'
|
12
|
+
default_size 256, 256
|
13
|
+
|
14
|
+
drawing_area {
|
15
|
+
paint 242.25, 242.25, 242.25
|
16
|
+
|
17
|
+
image = Cairo::ImageSurface.from_png(image_file)
|
18
|
+
w = image.width
|
19
|
+
h = image.height
|
20
|
+
|
21
|
+
translate 128.0, 128.0
|
22
|
+
rotate 45*Math::PI/180
|
23
|
+
scale 256.0/w, 256.0/h
|
24
|
+
translate -0.5*w, -0.5*h
|
25
|
+
|
26
|
+
paint image, 0, 0
|
27
|
+
}
|
28
|
+
}.show
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
image_content = Net::HTTP.get(URI('https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-gtk/master/images/breaking-blue-wave.png'))
|
5
|
+
image_file = File.join(Dir.home, 'breaking-blue-wave.png')
|
6
|
+
File.write(image_file, image_content)
|
7
|
+
|
8
|
+
include Glimmer
|
9
|
+
|
10
|
+
window {
|
11
|
+
title 'Image Gradient'
|
12
|
+
default_size 256, 256
|
13
|
+
|
14
|
+
drawing_area {
|
15
|
+
paint 242.25, 242.25, 242.25
|
16
|
+
|
17
|
+
image = Cairo::ImageSurface.from_png(image_file)
|
18
|
+
w = image.width
|
19
|
+
h = image.height
|
20
|
+
|
21
|
+
# Load the image as a surface pattern
|
22
|
+
pattern = Cairo::SurfacePattern.new(image)
|
23
|
+
pattern.extend = Cairo::EXTEND_REPEAT
|
24
|
+
|
25
|
+
# Set up the scale matrix
|
26
|
+
pattern.matrix = Cairo::Matrix.scale(w/256.0 * 5.0, h/256.0 * 5.0)
|
27
|
+
|
28
|
+
rectangle(0, 0, 256, 256) {
|
29
|
+
translate 128.0, 128.0
|
30
|
+
rotate Math::PI / 4
|
31
|
+
scale 1/Math.sqrt(2), 1/Math.sqrt(2)
|
32
|
+
translate -128.0, -128.0
|
33
|
+
|
34
|
+
fill pattern
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}.show
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Multi Segment Caps'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
path {
|
13
|
+
move_to 50.0, 75.0
|
14
|
+
line_to 200.0, 75.0
|
15
|
+
|
16
|
+
move_to 50.0, 125.0
|
17
|
+
line_to 200.0, 125.0
|
18
|
+
|
19
|
+
move_to 50.0, 175.0
|
20
|
+
line_to 200.0, 175.0
|
21
|
+
|
22
|
+
line_width 30
|
23
|
+
line_cap Cairo::LINE_CAP_ROUND
|
24
|
+
stroke 0, 0, 0
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}.show
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Rounded Rectangle'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
path {
|
13
|
+
rounded_rectangle(25.6, 25.6, 204.8, 204.8, 20)
|
14
|
+
|
15
|
+
fill 127.5, 127.5, 255
|
16
|
+
line_width 10.0
|
17
|
+
stroke 127.5, 0, 0, 0.5
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}.show
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Set line cap'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
# The main code
|
13
|
+
path {
|
14
|
+
move_to 64.0, 50.0
|
15
|
+
line_to 64.0, 200.0
|
16
|
+
|
17
|
+
line_cap Cairo::LINE_CAP_BUTT # default
|
18
|
+
line_width 30
|
19
|
+
stroke 0, 0, 0
|
20
|
+
}
|
21
|
+
|
22
|
+
path {
|
23
|
+
move_to 128.0, 50.0
|
24
|
+
line_to 128.0, 200.0
|
25
|
+
|
26
|
+
line_cap Cairo::LINE_CAP_ROUND
|
27
|
+
line_width 30
|
28
|
+
stroke 0, 0, 0
|
29
|
+
}
|
30
|
+
|
31
|
+
path {
|
32
|
+
move_to 192.0, 50.0
|
33
|
+
line_to 192.0, 200.0
|
34
|
+
|
35
|
+
line_cap Cairo::LINE_CAP_SQUARE
|
36
|
+
line_width 30
|
37
|
+
stroke 0, 0, 0
|
38
|
+
}
|
39
|
+
|
40
|
+
# draw helping lines */
|
41
|
+
path {
|
42
|
+
move_to 64.0, 50.0
|
43
|
+
line_to 64.0, 200.0
|
44
|
+
move_to 128.0, 50.0
|
45
|
+
line_to 128.0, 200.0
|
46
|
+
move_to 192.0, 50.0
|
47
|
+
line_to 192.0, 200.0
|
48
|
+
|
49
|
+
line_width 2.56
|
50
|
+
stroke 255, 51, 51
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}.show
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Set line join'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
# The main code
|
13
|
+
path {
|
14
|
+
move_to 76.8, 84.48
|
15
|
+
rel_line_to 51.2, -51.2
|
16
|
+
rel_line_to 51.2, 51.2
|
17
|
+
|
18
|
+
line_join Cairo::LINE_JOIN_MITER # default
|
19
|
+
line_width 40.96
|
20
|
+
stroke 0, 0, 0
|
21
|
+
}
|
22
|
+
|
23
|
+
path {
|
24
|
+
move_to 76.8, 161.28
|
25
|
+
rel_line_to 51.2, -51.2
|
26
|
+
rel_line_to 51.2, 51.2
|
27
|
+
|
28
|
+
line_join Cairo::LINE_JOIN_BEVEL
|
29
|
+
line_width 40.96
|
30
|
+
stroke 0, 0, 0
|
31
|
+
}
|
32
|
+
|
33
|
+
path {
|
34
|
+
move_to 76.8, 238.08
|
35
|
+
rel_line_to 51.2, -51.2
|
36
|
+
rel_line_to 51.2, 51.2
|
37
|
+
|
38
|
+
line_join Cairo::LINE_JOIN_ROUND
|
39
|
+
line_width 40.96
|
40
|
+
stroke 0, 0, 0
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}.show
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'glimmer-dsl-gtk'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window {
|
6
|
+
title 'Text'
|
7
|
+
default_size 256, 256
|
8
|
+
|
9
|
+
drawing_area {
|
10
|
+
paint 242.25, 242.25, 242.25
|
11
|
+
|
12
|
+
font_family = OS.linux? ? 'Sans' : (OS.mac? ? 'Helvetica' : 'Arial')
|
13
|
+
|
14
|
+
# The main code
|
15
|
+
path {
|
16
|
+
move_to 10.0, 135.0
|
17
|
+
show_text 'Hello'
|
18
|
+
|
19
|
+
font_face font_family, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD
|
20
|
+
font_size 90.0
|
21
|
+
line_width 2.56
|
22
|
+
fill 0, 0, 0
|
23
|
+
stroke 0, 0, 0
|
24
|
+
}
|
25
|
+
|
26
|
+
path {
|
27
|
+
move_to 70.0, 165.0
|
28
|
+
text_path 'void'
|
29
|
+
|
30
|
+
font_face font_family, Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD
|
31
|
+
font_size 90.0
|
32
|
+
line_width 2.56
|
33
|
+
fill 127.5, 127.5, 255
|
34
|
+
stroke 0, 0, 0
|
35
|
+
}
|
36
|
+
|
37
|
+
# draw helping lines
|
38
|
+
path {
|
39
|
+
arc 10.0, 135.0, 5.12, 0, 2*Math::PI
|
40
|
+
close_path
|
41
|
+
arc 70.0, 165.0, 5.12, 0, 2*Math::PI
|
42
|
+
|
43
|
+
fill 255, 51, 51, 0.6
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}.show
|
@@ -36,21 +36,27 @@ class Tetris
|
|
36
36
|
PREVIEW_PLAYFIELD_WIDTH = 4
|
37
37
|
PREVIEW_PLAYFIELD_HEIGHT = 2
|
38
38
|
SCORE_MULTIPLIER = {1 => 40, 2 => 100, 3 => 300, 4 => 1200}
|
39
|
+
UP_ARROW_ACTIONS = %i[instant_down rotate_right rotate_left]
|
40
|
+
SPEEDS = %i[snail sloth turtle rabbit gorilla bear horse gazelle cheetah falcon]
|
41
|
+
SPEED_INITIAL_DELAYS = SPEEDS.each_with_index.inject({}) {|hash, speed_index_pair| hash.merge(speed_index_pair.first => 1.1 - speed_index_pair.last*(0.1)) }
|
39
42
|
|
40
43
|
attr_reader :playfield_width, :playfield_height
|
41
|
-
attr_accessor :game_over, :paused, :preview_tetromino, :lines, :score, :level, :high_scores, :beeping, :added_high_score, :show_high_scores, :up_arrow_action
|
44
|
+
attr_accessor :game_over, :paused, :preview_tetromino, :lines, :score, :level, :high_scores, :beeping, :added_high_score, :show_high_scores, :up_arrow_action, :show_preview_tetromino, :initial_delay
|
42
45
|
alias game_over? game_over
|
43
46
|
alias paused? paused
|
44
47
|
alias beeping? beeping
|
45
48
|
alias added_high_score? added_high_score
|
49
|
+
alias show_preview_tetromino? show_preview_tetromino
|
46
50
|
|
47
51
|
def initialize(playfield_width = PLAYFIELD_WIDTH, playfield_height = PLAYFIELD_HEIGHT)
|
52
|
+
@initial_delay = SPEED_INITIAL_DELAYS[:snail]
|
48
53
|
@playfield_width = playfield_width
|
49
54
|
@playfield_height = playfield_height
|
50
55
|
@high_scores = []
|
51
56
|
@show_high_scores = false
|
52
57
|
@beeping = true
|
53
58
|
@up_arrow_action = :rotate_left
|
59
|
+
@show_preview_tetromino = true
|
54
60
|
load_high_scores!
|
55
61
|
end
|
56
62
|
|
@@ -200,47 +206,35 @@ class Tetris
|
|
200
206
|
end
|
201
207
|
|
202
208
|
def delay
|
203
|
-
[
|
209
|
+
[@initial_delay - (level.to_i * 0.1), 0.001].max
|
204
210
|
end
|
205
211
|
|
206
212
|
def beep
|
207
213
|
@beeper&.call if beeping
|
208
214
|
end
|
209
215
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
def instant_down_on_up!
|
219
|
-
self.up_arrow_action = :instant_down
|
220
|
-
end
|
221
|
-
|
222
|
-
def rotate_right_on_up=(value)
|
223
|
-
self.up_arrow_action = :rotate_right if value
|
224
|
-
end
|
225
|
-
|
226
|
-
def rotate_right_on_up
|
227
|
-
self.up_arrow_action == :rotate_right
|
228
|
-
end
|
229
|
-
|
230
|
-
def rotate_right_on_up!
|
231
|
-
self.up_arrow_action = :rotate_right
|
232
|
-
end
|
233
|
-
|
234
|
-
def rotate_left_on_up=(value)
|
235
|
-
self.up_arrow_action = :rotate_left if value
|
236
|
-
end
|
237
|
-
|
238
|
-
def rotate_left_on_up
|
239
|
-
self.up_arrow_action == :rotate_left
|
216
|
+
SPEED_INITIAL_DELAYS.each do |speed, speed_initial_day|
|
217
|
+
define_method("speed_#{speed}=") do |is_true|
|
218
|
+
self.initial_delay = speed_initial_day if is_true
|
219
|
+
end
|
220
|
+
|
221
|
+
define_method("speed_#{speed}") do
|
222
|
+
self.initial_delay == speed_initial_day
|
223
|
+
end
|
240
224
|
end
|
241
225
|
|
242
|
-
|
243
|
-
|
226
|
+
UP_ARROW_ACTIONS.each do |up_arrow_action_symbol|
|
227
|
+
define_method("#{up_arrow_action_symbol}_on_up=") do |is_true|
|
228
|
+
self.up_arrow_action = up_arrow_action_symbol if is_true
|
229
|
+
end
|
230
|
+
|
231
|
+
define_method("#{up_arrow_action_symbol}_on_up") do
|
232
|
+
self.up_arrow_action == up_arrow_action_symbol
|
233
|
+
end
|
234
|
+
|
235
|
+
define_method("#{up_arrow_action_symbol}_on_up!") do
|
236
|
+
self.up_arrow_action = up_arrow_action_symbol
|
237
|
+
end
|
244
238
|
end
|
245
239
|
|
246
240
|
def reset_tetrominoes
|
data/samples/elaborate/tetris.rb
CHANGED
@@ -94,17 +94,32 @@ class Tetris
|
|
94
94
|
|
95
95
|
Model::Game::PREVIEW_PLAYFIELD_HEIGHT.times do |row|
|
96
96
|
Model::Game::PREVIEW_PLAYFIELD_WIDTH.times do |column|
|
97
|
-
|
98
|
-
color = new_color
|
97
|
+
preview_updater = proc do
|
99
98
|
block = @preview_playfield_blocks[row][column]
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
if @game.show_preview_tetromino?
|
100
|
+
new_color = @game.preview_playfield[row][column].color
|
101
|
+
block[:background_square].fill = new_color
|
102
|
+
block[:top_bevel_edge].fill = [new_color[0] + 4*BEVEL_CONSTANT, new_color[1] + 4*BEVEL_CONSTANT, new_color[2] + 4*BEVEL_CONSTANT]
|
103
|
+
block[:right_bevel_edge].fill = [new_color[0] - BEVEL_CONSTANT, new_color[1] - BEVEL_CONSTANT, new_color[2] - BEVEL_CONSTANT]
|
104
|
+
block[:bottom_bevel_edge].fill = [new_color[0] - BEVEL_CONSTANT, new_color[1] - BEVEL_CONSTANT, new_color[2] - BEVEL_CONSTANT]
|
105
|
+
block[:left_bevel_edge].fill = [new_color[0] - BEVEL_CONSTANT, new_color[1] - BEVEL_CONSTANT, new_color[2] - BEVEL_CONSTANT]
|
106
|
+
block[:border_square].stroke = new_color == Model::Block::COLOR_CLEAR ? COLOR_GRAY : new_color
|
107
|
+
@next_label.text = 'Next'
|
108
|
+
else
|
109
|
+
transparent_color = [0, 0, 0, 0]
|
110
|
+
block[:background_square].fill = transparent_color
|
111
|
+
block[:top_bevel_edge].fill = transparent_color
|
112
|
+
block[:right_bevel_edge].fill = transparent_color
|
113
|
+
block[:bottom_bevel_edge].fill = transparent_color
|
114
|
+
block[:left_bevel_edge].fill = transparent_color
|
115
|
+
block[:border_square].stroke = transparent_color
|
116
|
+
@next_label.text = ''
|
117
|
+
end
|
106
118
|
block[:drawing_area].queue_draw
|
107
119
|
end
|
120
|
+
|
121
|
+
observe(@game.preview_playfield[row][column], :color, &preview_updater)
|
122
|
+
observe(@game, :show_preview_tetromino, &preview_updater)
|
108
123
|
end
|
109
124
|
end
|
110
125
|
|
@@ -150,6 +165,16 @@ class Tetris
|
|
150
165
|
|
151
166
|
menu_item(label: 'View') { |mi|
|
152
167
|
m = menu {
|
168
|
+
check_menu_item(label: 'Show Next Block Preview') {
|
169
|
+
active @game.show_preview_tetromino?
|
170
|
+
|
171
|
+
on(:activate) do
|
172
|
+
@game.show_preview_tetromino = !@game.show_preview_tetromino?
|
173
|
+
end
|
174
|
+
}
|
175
|
+
|
176
|
+
separator_menu_item
|
177
|
+
|
153
178
|
menu_item(label: 'Show High Scores') {
|
154
179
|
on(:activate) do
|
155
180
|
show_high_score_dialog
|
@@ -165,6 +190,27 @@ class Tetris
|
|
165
190
|
mi.submenu = m.gtk
|
166
191
|
}
|
167
192
|
|
193
|
+
menu_item(label: 'Speed') { |mi|
|
194
|
+
m = menu {
|
195
|
+
rmi = radio_menu_item(nil, Model::Game::SPEEDS.first.to_s.capitalize) {
|
196
|
+
active true
|
197
|
+
|
198
|
+
on(:activate) do
|
199
|
+
@game.send("speed_#{Model::Game::SPEEDS.first}=", true)
|
200
|
+
end
|
201
|
+
}
|
202
|
+
|
203
|
+
Model::Game::SPEEDS.drop(1).each do |speed|
|
204
|
+
radio_menu_item(rmi.group, speed.to_s.capitalize) {
|
205
|
+
on(:activate) do
|
206
|
+
@game.send("speed_#{speed}=", true)
|
207
|
+
end
|
208
|
+
}
|
209
|
+
end
|
210
|
+
}
|
211
|
+
mi.submenu = m.gtk
|
212
|
+
}
|
213
|
+
|
168
214
|
menu_item(label: 'Options') { |mi|
|
169
215
|
m = menu {
|
170
216
|
rmi = radio_menu_item(nil, 'Instant Down on Up') {
|
@@ -189,7 +235,7 @@ class Tetris
|
|
189
235
|
mi.submenu = m.gtk
|
190
236
|
}
|
191
237
|
|
192
|
-
menu_item(label: '
|
238
|
+
menu_item(label: 'Help') { |mi|
|
193
239
|
m = menu {
|
194
240
|
menu_item(label: 'About') {
|
195
241
|
on(:activate) do
|
@@ -205,6 +251,7 @@ class Tetris
|
|
205
251
|
def score_board
|
206
252
|
box(:vertical) {
|
207
253
|
label
|
254
|
+
@next_label = label('Next')
|
208
255
|
@preview_playfield_blocks = playfield(playfield_width: Model::Game::PREVIEW_PLAYFIELD_WIDTH, playfield_height: Model::Game::PREVIEW_PLAYFIELD_HEIGHT, block_size: BLOCK_SIZE)
|
209
256
|
|
210
257
|
label
|
@@ -278,29 +325,29 @@ class Tetris
|
|
278
325
|
def start_moving_tetrominos_down
|
279
326
|
unless @tetrominos_start_moving_down
|
280
327
|
@tetrominos_start_moving_down = true
|
281
|
-
|
328
|
+
tetromino_move = proc do
|
282
329
|
@game.down! if !@game.game_over? && !@game.paused?
|
283
|
-
|
330
|
+
GLib::Timeout.add(@game.delay*1000, &tetromino_move)
|
331
|
+
false # do not repeat
|
284
332
|
end
|
333
|
+
GLib::Timeout.add(@game.delay*1000, &tetromino_move)
|
285
334
|
end
|
286
335
|
end
|
287
336
|
|
288
337
|
def show_game_over_dialog
|
289
|
-
|
338
|
+
@game.paused = true
|
339
|
+
message_dialog(parent: @main_window) { |md|
|
290
340
|
title 'Game Over!'
|
291
341
|
text "Score: #{@game.high_scores.first.score}\nLines: #{@game.high_scores.first.lines}\nLevel: #{@game.high_scores.first.level}"
|
292
342
|
|
293
343
|
on(:response) do
|
344
|
+
@game.restart!
|
294
345
|
md.destroy
|
295
346
|
end
|
296
347
|
}.show
|
297
|
-
|
298
|
-
@game.restart!
|
299
|
-
false
|
300
348
|
end
|
301
349
|
|
302
350
|
def show_high_score_dialog
|
303
|
-
game_paused = !!@game.paused
|
304
351
|
@game.paused = true
|
305
352
|
|
306
353
|
if @game.high_scores.empty?
|
@@ -311,20 +358,19 @@ class Tetris
|
|
311
358
|
end.join("\n")
|
312
359
|
end
|
313
360
|
|
314
|
-
message_dialog(@main_window) { |md|
|
361
|
+
message_dialog(parent: @main_window) { |md|
|
315
362
|
title 'High Scores'
|
316
363
|
text high_scores_string
|
317
364
|
|
318
365
|
on(:response) do
|
366
|
+
@game.paused = false
|
319
367
|
md.destroy
|
320
368
|
end
|
321
369
|
}.show
|
322
|
-
|
323
|
-
@game.paused = game_paused
|
324
370
|
end
|
325
371
|
|
326
372
|
def show_about_dialog
|
327
|
-
message_dialog(@main_window) { |md|
|
373
|
+
message_dialog(parent: @main_window) { |md|
|
328
374
|
title 'About'
|
329
375
|
text "Glimmer Tetris\n\nGlimmer DSL for GTK\n\nElaborate Sample\n\nCopyright (c) 2021-2022 Andy Maleh"
|
330
376
|
|
@@ -4,7 +4,7 @@ include Glimmer
|
|
4
4
|
|
5
5
|
application('org.glimmer.hello-application') {
|
6
6
|
on(:activate) do |app|
|
7
|
-
application_window(app) {
|
7
|
+
application_window(app) { |aw|
|
8
8
|
title 'Widget Gallery'
|
9
9
|
|
10
10
|
notebook { |n|
|
@@ -46,13 +46,24 @@ application('org.glimmer.hello-application') {
|
|
46
46
|
spacing 10
|
47
47
|
|
48
48
|
label('Button')
|
49
|
-
button('Push Me')
|
49
|
+
button(label: 'Push Me') {
|
50
|
+
on(:clicked) do
|
51
|
+
message_dialog(parent: aw) { |md|
|
52
|
+
title 'Information'
|
53
|
+
text 'You clicked the button'
|
54
|
+
|
55
|
+
on(:response) do
|
56
|
+
md.destroy
|
57
|
+
end
|
58
|
+
}.show
|
59
|
+
end
|
60
|
+
}
|
50
61
|
|
51
62
|
label('Radio Button')
|
52
63
|
box(:horizontal) {
|
53
|
-
rb = radio_button('One')
|
54
|
-
radio_button(
|
55
|
-
radio_button(
|
64
|
+
rb = radio_button(label: 'One')
|
65
|
+
radio_button(label: 'Two', member: rb)
|
66
|
+
radio_button(label: 'Three', member: rb)
|
56
67
|
}
|
57
68
|
|
58
69
|
label('Check Button')
|
@@ -74,12 +85,12 @@ application('org.glimmer.hello-application') {
|
|
74
85
|
spacing 10
|
75
86
|
|
76
87
|
label('Horizontal Scale')
|
77
|
-
|
88
|
+
scale(:horizontal, 1, 100, 1) {
|
78
89
|
visible true
|
79
90
|
}
|
80
91
|
|
81
92
|
label('Vertical Scale')
|
82
|
-
|
93
|
+
scale(:vertical, 1, 100, 1) {
|
83
94
|
visible true
|
84
95
|
height_request 200
|
85
96
|
}
|