glimmer-dsl-libui 0.2.14 → 0.2.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +532 -121
- data/VERSION +1 -1
- data/bin/girb +0 -0
- data/examples/area_gallery.rb +11 -18
- data/examples/area_gallery2.rb +31 -7
- data/examples/area_gallery3.rb +14 -21
- data/examples/area_gallery4.rb +34 -10
- data/examples/basic_transform.rb +8 -2
- data/examples/color_button.rb +1 -1
- data/examples/color_the_circles.rb +11 -9
- data/examples/histogram.rb +6 -13
- data/examples/meta_example.rb +5 -3
- data/examples/tetris/model/block.rb +48 -0
- data/examples/tetris/model/game.rb +306 -0
- data/examples/tetris/model/past_game.rb +39 -0
- data/examples/tetris/model/tetromino.rb +329 -0
- data/examples/tetris.rb +155 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/shape_expression.rb +1 -0
- data/lib/glimmer/libui/control_proxy/area_proxy.rb +25 -0
- data/lib/glimmer/libui/control_proxy/path_proxy.rb +19 -7
- data/lib/glimmer/libui/shape/figure.rb +4 -2
- data/lib/glimmer/libui/shape/polybezier.rb +45 -0
- data/lib/glimmer/libui/shape/polygon.rb +46 -0
- data/lib/glimmer/libui/shape/polyline.rb +45 -0
- data/lib/glimmer/libui/shape.rb +9 -3
- data/lib/glimmer/libui.rb +2 -2
- metadata +10 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.18
|
data/bin/girb
CHANGED
File without changes
|
data/examples/area_gallery.rb
CHANGED
@@ -18,31 +18,24 @@ window('Area Gallery', 400, 400) {
|
|
18
18
|
fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
|
19
19
|
}
|
20
20
|
path { # declarative stable path
|
21
|
-
|
22
|
-
|
23
|
-
line(400, 100)
|
24
|
-
line(400, 400)
|
25
|
-
|
26
|
-
closed true
|
27
|
-
}
|
28
|
-
|
21
|
+
polygon(100, 100, 100, 400, 400, 100, 400, 400)
|
22
|
+
|
29
23
|
fill r: 202, g: 102, b: 104, a: 0.5
|
30
24
|
stroke r: 0, g: 0, b: 0
|
31
25
|
}
|
32
26
|
path { # declarative stable path
|
33
|
-
|
34
|
-
bezier(200, 100, 100, 200, 400, 100)
|
35
|
-
bezier(300, 100, 100, 300, 100, 400)
|
36
|
-
bezier(100, 300, 300, 100, 400, 400)
|
37
|
-
|
38
|
-
closed true
|
39
|
-
}
|
27
|
+
polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
|
40
28
|
|
41
29
|
fill r: 202, g: 102, b: 204, a: 0.5
|
42
30
|
stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
|
43
31
|
}
|
44
32
|
path { # declarative stable path
|
45
|
-
|
33
|
+
polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
|
34
|
+
|
35
|
+
stroke r: 0, g: 0, b: 0, thickness: 2
|
36
|
+
}
|
37
|
+
path { # declarative stable path
|
38
|
+
arc(404, 216, 190, 90, 90, false)
|
46
39
|
|
47
40
|
# radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
|
48
41
|
fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
|
@@ -54,9 +47,9 @@ window('Area Gallery', 400, 400) {
|
|
54
47
|
fill r: 202, g: 102, b: 204, a: 0.5
|
55
48
|
stroke r: 0, g: 0, b: 0, thickness: 2
|
56
49
|
}
|
57
|
-
text(
|
50
|
+
text(161, 40, 100) { # x, y, width
|
58
51
|
string('Area Gallery') {
|
59
|
-
font family: '
|
52
|
+
font family: 'Arial', size: 14
|
60
53
|
color :black
|
61
54
|
}
|
62
55
|
}
|
data/examples/area_gallery2.rb
CHANGED
@@ -88,18 +88,42 @@ window('Area Gallery', 400, 400) {
|
|
88
88
|
end_x 400
|
89
89
|
end_y 400
|
90
90
|
}
|
91
|
-
|
92
|
-
closed true
|
93
91
|
}
|
94
92
|
|
95
93
|
fill r: 202, g: 102, b: 204, a: 0.5
|
96
94
|
stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
|
97
95
|
}
|
96
|
+
path { # declarative stable path
|
97
|
+
polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
|
98
|
+
figure {
|
99
|
+
x 100
|
100
|
+
y 100
|
101
|
+
|
102
|
+
line {
|
103
|
+
x 400
|
104
|
+
y 100
|
105
|
+
}
|
106
|
+
line {
|
107
|
+
x 100
|
108
|
+
y 400
|
109
|
+
}
|
110
|
+
line {
|
111
|
+
x 400
|
112
|
+
y 400
|
113
|
+
}
|
114
|
+
line {
|
115
|
+
x 0
|
116
|
+
y 0
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
stroke r: 0, g: 0, b: 0, thickness: 2
|
121
|
+
}
|
98
122
|
path { # declarative stable path
|
99
123
|
arc {
|
100
|
-
x_center
|
101
|
-
y_center
|
102
|
-
radius
|
124
|
+
x_center 404
|
125
|
+
y_center 216
|
126
|
+
radius 190
|
103
127
|
start_angle 90
|
104
128
|
sweep 90
|
105
129
|
is_negative false
|
@@ -120,12 +144,12 @@ window('Area Gallery', 400, 400) {
|
|
120
144
|
stroke r: 0, g: 0, b: 0, thickness: 2
|
121
145
|
}
|
122
146
|
text {
|
123
|
-
x
|
147
|
+
x 161
|
124
148
|
y 40
|
125
149
|
width 100
|
126
150
|
|
127
151
|
string {
|
128
|
-
font family: '
|
152
|
+
font family: 'Arial', size: 14
|
129
153
|
color :black
|
130
154
|
|
131
155
|
'Area Gallery'
|
data/examples/area_gallery3.rb
CHANGED
@@ -8,42 +8,35 @@ window('Area Gallery', 400, 400) {
|
|
8
8
|
path { # a dynamic path is added semi-declaratively inside on_draw block
|
9
9
|
square(0, 0, 100)
|
10
10
|
square(100, 100, 400)
|
11
|
-
|
11
|
+
|
12
12
|
fill r: 102, g: 102, b: 204
|
13
13
|
}
|
14
14
|
path { # a dynamic path is added semi-declaratively inside on_draw block
|
15
15
|
rectangle(0, 100, 100, 400)
|
16
16
|
rectangle(100, 0, 400, 100)
|
17
|
-
|
17
|
+
|
18
18
|
# linear gradient (has x0, y0, x1, y1, and stops)
|
19
19
|
fill x0: 10, y0: 10, x1: 350, y1: 350, stops: [{pos: 0.25, r: 204, g: 102, b: 204}, {pos: 0.75, r: 102, g: 102, b: 204}]
|
20
20
|
}
|
21
21
|
path { # a dynamic path is added semi-declaratively inside on_draw block
|
22
|
-
|
23
|
-
|
24
|
-
line(400, 100)
|
25
|
-
line(400, 400)
|
26
|
-
|
27
|
-
closed true
|
28
|
-
}
|
29
|
-
|
22
|
+
polygon(100, 100, 100, 400, 400, 100, 400, 400)
|
23
|
+
|
30
24
|
fill r: 202, g: 102, b: 104, a: 0.5
|
31
25
|
stroke r: 0, g: 0, b: 0
|
32
26
|
}
|
33
27
|
path { # a dynamic path is added semi-declaratively inside on_draw block
|
34
|
-
|
35
|
-
|
36
|
-
bezier(300, 100, 100, 300, 100, 400)
|
37
|
-
bezier(100, 300, 300, 100, 400, 400)
|
38
|
-
|
39
|
-
closed true
|
40
|
-
}
|
41
|
-
|
28
|
+
polybezier(0, 0, 200, 100, 100, 200, 400, 100, 300, 100, 100, 300, 100, 400, 100, 300, 300, 100, 400, 400)
|
29
|
+
|
42
30
|
fill r: 202, g: 102, b: 204, a: 0.5
|
43
31
|
stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
|
44
32
|
}
|
45
33
|
path { # a dynamic path is added semi-declaratively inside on_draw block
|
46
|
-
|
34
|
+
polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
|
35
|
+
|
36
|
+
stroke r: 0, g: 0, b: 0, thickness: 2
|
37
|
+
}
|
38
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
39
|
+
arc(404, 216, 190, 90, 90, false)
|
47
40
|
|
48
41
|
# radial gradient (has an outer_radius in addition to x0, y0, x1, y1, and stops)
|
49
42
|
fill outer_radius: 90, x0: 0, y0: 0, x1: 500, y1: 500, stops: [{pos: 0.25, r: 102, g: 102, b: 204, a: 0.5}, {pos: 0.75, r: 204, g: 102, b: 204}]
|
@@ -55,9 +48,9 @@ window('Area Gallery', 400, 400) {
|
|
55
48
|
fill r: 202, g: 102, b: 204, a: 0.5
|
56
49
|
stroke r: 0, g: 0, b: 0, thickness: 2
|
57
50
|
}
|
58
|
-
text(
|
51
|
+
text(161, 40, 100) { # x, y, width
|
59
52
|
string('Area Gallery') {
|
60
|
-
font family: '
|
53
|
+
font family: 'Arial', size: 14
|
61
54
|
color :black
|
62
55
|
}
|
63
56
|
}
|
data/examples/area_gallery4.rb
CHANGED
@@ -53,10 +53,10 @@ window('Area Gallery', 400, 400) {
|
|
53
53
|
x 400
|
54
54
|
y 400
|
55
55
|
}
|
56
|
-
|
56
|
+
|
57
57
|
closed true
|
58
58
|
}
|
59
|
-
|
59
|
+
|
60
60
|
fill r: 202, g: 102, b: 104, a: 0.5
|
61
61
|
stroke r: 0, g: 0, b: 0
|
62
62
|
}
|
@@ -89,18 +89,42 @@ window('Area Gallery', 400, 400) {
|
|
89
89
|
end_x 400
|
90
90
|
end_y 400
|
91
91
|
}
|
92
|
-
|
93
|
-
closed true
|
94
92
|
}
|
95
|
-
|
93
|
+
|
96
94
|
fill r: 202, g: 102, b: 204, a: 0.5
|
97
95
|
stroke r: 0, g: 0, b: 0, thickness: 2, dashes: [50, 10, 10, 10], dash_phase: -50.0
|
98
96
|
}
|
97
|
+
path { # a dynamic path is added semi-declaratively inside on_draw block
|
98
|
+
polyline(100, 100, 400, 100, 100, 400, 400, 400, 0, 0)
|
99
|
+
figure {
|
100
|
+
x 100
|
101
|
+
y 100
|
102
|
+
|
103
|
+
line {
|
104
|
+
x 400
|
105
|
+
y 100
|
106
|
+
}
|
107
|
+
line {
|
108
|
+
x 100
|
109
|
+
y 400
|
110
|
+
}
|
111
|
+
line {
|
112
|
+
x 400
|
113
|
+
y 400
|
114
|
+
}
|
115
|
+
line {
|
116
|
+
x 0
|
117
|
+
y 0
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
stroke r: 0, g: 0, b: 0, thickness: 2
|
122
|
+
}
|
99
123
|
path { # a dynamic path is added semi-declaratively inside on_draw block
|
100
124
|
arc {
|
101
|
-
x_center
|
102
|
-
y_center
|
103
|
-
radius
|
125
|
+
x_center 404
|
126
|
+
y_center 216
|
127
|
+
radius 190
|
104
128
|
start_angle 90
|
105
129
|
sweep 90
|
106
130
|
is_negative false
|
@@ -121,12 +145,12 @@ window('Area Gallery', 400, 400) {
|
|
121
145
|
stroke r: 0, g: 0, b: 0, thickness: 2
|
122
146
|
}
|
123
147
|
text {
|
124
|
-
x
|
148
|
+
x 161
|
125
149
|
y 40
|
126
150
|
width 100
|
127
151
|
|
128
152
|
string {
|
129
|
-
font family: '
|
153
|
+
font family: 'Arial', size: 14
|
130
154
|
color :black
|
131
155
|
|
132
156
|
'Area Gallery'
|
data/examples/basic_transform.rb
CHANGED
@@ -16,10 +16,16 @@ window('Basic Transform', 350, 350) {
|
|
16
16
|
fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
|
17
17
|
stroke :black, thickness: 2
|
18
18
|
transform {
|
19
|
-
|
20
|
-
|
19
|
+
unless OS.windows?
|
20
|
+
skew 0.15, 0.15
|
21
|
+
translate 50, 50
|
22
|
+
end
|
21
23
|
rotate 100, 100, -9 * n
|
22
24
|
scale 1.1, 1.1
|
25
|
+
if OS.windows?
|
26
|
+
skew 0.15, 0.15
|
27
|
+
translate 50, 50
|
28
|
+
end
|
23
29
|
}
|
24
30
|
}
|
25
31
|
end
|
data/examples/color_button.rb
CHANGED
@@ -27,15 +27,17 @@ class ColorTheCircles
|
|
27
27
|
|
28
28
|
def register_observers
|
29
29
|
observer = Glimmer::DataBinding::Observer.proc do |new_score|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
Glimmer::LibUI.queue_main do
|
31
|
+
@score_label.text = new_score.to_s
|
32
|
+
if new_score == -20
|
33
|
+
@game_over = true
|
34
|
+
msg_box('You Lost!', 'Sorry! Your score reached -20')
|
35
|
+
restart_game
|
36
|
+
elsif new_score == 0
|
37
|
+
@game_over = true
|
38
|
+
msg_box('You Won!', 'Congratulations! Your score reached 0')
|
39
|
+
restart_game
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
observer.observe(self, :score) # automatically enhances self to become Glimmer::DataBinding::ObservableModel and notify observer on score attribute changes
|
data/examples/histogram.rb
CHANGED
@@ -31,20 +31,13 @@ end
|
|
31
31
|
|
32
32
|
# method-based custom control representing a graph path
|
33
33
|
def graph_path(width, height, should_extend, &block)
|
34
|
-
locations = point_locations(width, height)
|
34
|
+
locations = point_locations(width, height).flatten
|
35
35
|
path {
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
if should_extend
|
42
|
-
line(width, height)
|
43
|
-
line(0, height)
|
44
|
-
|
45
|
-
closed true
|
46
|
-
end
|
47
|
-
}
|
36
|
+
if should_extend
|
37
|
+
polygon(locations + [width, height, 0, height])
|
38
|
+
else
|
39
|
+
polyline(locations)
|
40
|
+
end
|
48
41
|
|
49
42
|
# apply a transform to the coordinate space for this path so (0, 0) is the top-left corner of the graph
|
50
43
|
transform {
|
data/examples/meta_example.rb
CHANGED
@@ -11,7 +11,7 @@ class MetaExample
|
|
11
11
|
|
12
12
|
def examples
|
13
13
|
if @examples.nil?
|
14
|
-
example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '
|
14
|
+
example_files = Dir.glob(File.join(File.expand_path('.', __dir__), '*.rb'))
|
15
15
|
example_file_names = example_files.map { |f| File.basename(f, '.rb') }
|
16
16
|
example_file_names = example_file_names.reject { |f| f == 'meta_example' || f.match(/\d$/) }
|
17
17
|
@examples = example_file_names.map { |f| f.underscore.titlecase }
|
@@ -46,12 +46,12 @@ class MetaExample
|
|
46
46
|
command = "ruby -r #{glimmer_dsl_libui_file} #{example} 2>&1"
|
47
47
|
result = ''
|
48
48
|
IO.popen(command) do |f|
|
49
|
-
sleep(0.
|
49
|
+
sleep(0.0001) # yield to main thread
|
50
50
|
f.each_line do |line|
|
51
51
|
result << line
|
52
52
|
puts line
|
53
53
|
$stdout.flush # for Windows
|
54
|
-
sleep(0.
|
54
|
+
sleep(0.0001) # yield to main thread
|
55
55
|
end
|
56
56
|
end
|
57
57
|
Glimmer::LibUI.queue_main { msg_box('Error Running Example', result) } if result.downcase.include?('error')
|
@@ -110,6 +110,8 @@ class MetaExample
|
|
110
110
|
FileUtils.mkdir_p(parent_dir)
|
111
111
|
example_file = File.join(parent_dir, "#{selected_example.underscore}.rb")
|
112
112
|
File.write(example_file, @code_entry.text)
|
113
|
+
example_supporting_directory = File.expand_path(selected_example.underscore, __dir__)
|
114
|
+
FileUtils.cp_r(example_supporting_directory, parent_dir) if Dir.exist?(example_supporting_directory)
|
113
115
|
FileUtils.cp_r(File.expand_path('../icons', __dir__), File.dirname(parent_dir))
|
114
116
|
FileUtils.cp_r(File.expand_path('../sounds', __dir__), File.dirname(parent_dir))
|
115
117
|
run_example(example_file)
|
@@ -0,0 +1,48 @@
|
|
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 Model
|
24
|
+
class Block
|
25
|
+
COLOR_CLEAR = :white
|
26
|
+
|
27
|
+
attr_accessor :color
|
28
|
+
|
29
|
+
# Initializes with color. Default color (gray) signifies an empty block
|
30
|
+
def initialize(color = COLOR_CLEAR)
|
31
|
+
@color = color
|
32
|
+
end
|
33
|
+
|
34
|
+
# Clears block color. `quietly` option indicates if it should not notify observers by setting value quietly via variable not attribute writer.
|
35
|
+
def clear
|
36
|
+
self.color = COLOR_CLEAR unless self.color == COLOR_CLEAR
|
37
|
+
end
|
38
|
+
|
39
|
+
def clear?
|
40
|
+
self.color == COLOR_CLEAR
|
41
|
+
end
|
42
|
+
|
43
|
+
def occupied?
|
44
|
+
!clear?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|