glimmer-dsl-libui 0.3.2 → 0.4.0
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 +36 -0
- data/README.md +3859 -4006
- data/VERSION +1 -1
- data/bin/girb +0 -0
- data/examples/area_gallery.rb +19 -19
- data/examples/area_gallery2.rb +91 -89
- data/examples/area_gallery3.rb +19 -19
- data/examples/area_gallery4.rb +91 -89
- data/examples/basic_area.rb +1 -3
- data/examples/basic_area2.rb +1 -3
- data/examples/basic_area3.rb +17 -0
- data/examples/basic_area4.rb +19 -0
- data/examples/basic_scrolling_area.rb +79 -0
- data/examples/basic_transform.rb +3 -6
- data/examples/basic_transform2.rb +34 -0
- data/examples/color_the_circles.rb +1 -3
- data/examples/dynamic_area.rb +1 -3
- data/examples/dynamic_area2.rb +5 -7
- data/examples/form_table.rb +4 -0
- data/examples/grid.rb +4 -4
- data/examples/histogram.rb +4 -8
- data/examples/meta_example.rb +50 -10
- data/examples/midi_player.rb +2 -6
- data/examples/snake/model/game.rb +2 -2
- data/examples/snake.rb +9 -21
- data/examples/tetris.rb +15 -18
- data/examples/tic_tac_toe/board.rb +4 -2
- data/examples/tic_tac_toe.rb +4 -15
- data/examples/timer.rb +2 -6
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/bind_expression.rb +36 -0
- data/lib/glimmer/dsl/libui/data_binding_expression.rb +47 -0
- data/lib/glimmer/dsl/libui/dsl.rb +3 -0
- data/lib/glimmer/dsl/libui/observe_expression.rb +35 -0
- data/lib/glimmer/dsl/libui/shape_expression.rb +6 -1
- data/lib/glimmer/dsl/libui/shine_data_binding_expression.rb +42 -0
- data/lib/glimmer/dsl/libui/string_expression.rb +4 -5
- data/lib/glimmer/libui/attributed_string.rb +19 -6
- data/lib/glimmer/libui/control_proxy/area_proxy/scrolling_area_proxy.rb +35 -0
- data/lib/glimmer/libui/control_proxy/window_proxy.rb +20 -0
- data/lib/glimmer/libui/shape.rb +50 -2
- metadata +15 -7
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
class BasicScrollingArea
|
4
|
+
include Glimmer
|
5
|
+
|
6
|
+
SCROLLING_AREA_WIDTH = 800
|
7
|
+
SCROLLING_AREA_HEIGHT = 400
|
8
|
+
SCROLLING_AREA_PADDING_X = 20
|
9
|
+
SCROLLING_AREA_PADDING_Y = 20
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@x = SCROLLING_AREA_PADDING_X
|
13
|
+
@y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
|
14
|
+
create_gui
|
15
|
+
Glimmer::LibUI.timer(0.01) do
|
16
|
+
@x += SCROLLING_AREA_PADDING_X
|
17
|
+
@y = [[@y + rand(SCROLLING_AREA_PADDING_Y*4)*(rand(2) == 0 ? -1 : 1), SCROLLING_AREA_PADDING_Y].max, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y].min
|
18
|
+
@graph.content { # re-open @graph's content and add a line
|
19
|
+
line(@x, @y)
|
20
|
+
}
|
21
|
+
# if there is a need to enlarge scrolling area, call `@scrolling_area.set_size(new_width, new_height)`
|
22
|
+
# Note that `#scroll_to` does not seem to work on Linux, but normal scrolling does.
|
23
|
+
@scrolling_area.scroll_to(@x - (SCROLLING_AREA_WIDTH/2), @y) # 3rd and 4th arguments for width and height are assumed as those of main window by default if not supplied
|
24
|
+
# return false to stop timer once @x exceeds scrolling area width - padding
|
25
|
+
false if @x >= (SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def launch
|
30
|
+
@main_window.show
|
31
|
+
end
|
32
|
+
|
33
|
+
def x_axis
|
34
|
+
polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*2, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
|
35
|
+
stroke :black, thickness: 3
|
36
|
+
}
|
37
|
+
|
38
|
+
((SCROLLING_AREA_WIDTH - SCROLLING_AREA_PADDING_X*4) / SCROLLING_AREA_PADDING_X).times do |x_multiplier|
|
39
|
+
x = x_multiplier*SCROLLING_AREA_PADDING_X + SCROLLING_AREA_PADDING_X*2
|
40
|
+
y = SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y
|
41
|
+
|
42
|
+
polyline(x, y, x, y + SCROLLING_AREA_PADDING_Y/2) {
|
43
|
+
stroke :black, thickness: 2
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def y_axis
|
49
|
+
polyline(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_PADDING_Y, SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
|
50
|
+
stroke :black, thickness: 3
|
51
|
+
}
|
52
|
+
|
53
|
+
((SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y*3) / SCROLLING_AREA_PADDING_Y).times do |y_multiplier|
|
54
|
+
x = SCROLLING_AREA_PADDING_X
|
55
|
+
y = y_multiplier*SCROLLING_AREA_PADDING_Y + SCROLLING_AREA_PADDING_Y*2
|
56
|
+
|
57
|
+
polyline(x, y, x - SCROLLING_AREA_PADDING_X/2, y) {
|
58
|
+
stroke :black, thickness: 2
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_gui
|
64
|
+
@main_window = window('Basic Scrolling Area', SCROLLING_AREA_WIDTH / 2, SCROLLING_AREA_HEIGHT) {
|
65
|
+
resizable false
|
66
|
+
|
67
|
+
@scrolling_area = scrolling_area(SCROLLING_AREA_WIDTH, SCROLLING_AREA_HEIGHT) { # double width of window enables horizontal scrolling
|
68
|
+
x_axis
|
69
|
+
y_axis
|
70
|
+
|
71
|
+
@graph = figure(SCROLLING_AREA_PADDING_X, SCROLLING_AREA_HEIGHT - SCROLLING_AREA_PADDING_Y) {
|
72
|
+
stroke :blue, thickness: 2
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
BasicScrollingArea.new.launch
|
data/examples/basic_transform.rb
CHANGED
@@ -4,17 +4,14 @@ include Glimmer
|
|
4
4
|
|
5
5
|
window('Basic Transform', 350, 350) {
|
6
6
|
area {
|
7
|
-
|
8
|
-
square(0, 0, 350)
|
9
|
-
|
7
|
+
square(0, 0, 350) {
|
10
8
|
fill r: 255, g: 255, b: 0
|
11
9
|
}
|
12
10
|
40.times do |n|
|
13
|
-
|
14
|
-
square(0, 0, 100)
|
15
|
-
|
11
|
+
square(0, 0, 100) {
|
16
12
|
fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
|
17
13
|
stroke :black, thickness: 2
|
14
|
+
|
18
15
|
transform {
|
19
16
|
unless OS.windows?
|
20
17
|
skew 0.15, 0.15
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Basic Transform', 350, 350) {
|
6
|
+
area {
|
7
|
+
path {
|
8
|
+
square(0, 0, 350)
|
9
|
+
|
10
|
+
fill r: 255, g: 255, b: 0
|
11
|
+
}
|
12
|
+
40.times do |n|
|
13
|
+
path {
|
14
|
+
square(0, 0, 100)
|
15
|
+
|
16
|
+
fill r: [255 - n*5, 0].max, g: [n*5, 255].min, b: 0, a: 0.5
|
17
|
+
stroke :black, thickness: 2
|
18
|
+
|
19
|
+
transform {
|
20
|
+
unless OS.windows?
|
21
|
+
skew 0.15, 0.15
|
22
|
+
translate 50, 50
|
23
|
+
end
|
24
|
+
rotate 100, 100, -9 * n
|
25
|
+
scale 1.1, 1.1
|
26
|
+
if OS.windows?
|
27
|
+
skew 0.15, 0.15
|
28
|
+
translate 50, 50
|
29
|
+
end
|
30
|
+
}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
}
|
34
|
+
}.show
|
@@ -201,9 +201,7 @@ class ColorTheCircles
|
|
201
201
|
}
|
202
202
|
|
203
203
|
@circles_data.each do |circle_data|
|
204
|
-
|
205
|
-
circle_data[:circle] = circle(*circle_data[:args])
|
206
|
-
|
204
|
+
circle_data[:circle] = circle(*circle_data[:args]) {
|
207
205
|
fill circle_data[:fill]
|
208
206
|
stroke circle_data[:stroke]
|
209
207
|
}
|
data/examples/dynamic_area.rb
CHANGED
@@ -88,9 +88,7 @@ window('Dynamic Area', 240, 600) {
|
|
88
88
|
|
89
89
|
@area = area {
|
90
90
|
on_draw do |area_draw_params|
|
91
|
-
|
92
|
-
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
93
|
-
|
91
|
+
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # a dynamic path is added semi-declaratively inside on_draw block
|
94
92
|
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
95
93
|
}
|
96
94
|
end
|
data/examples/dynamic_area2.rb
CHANGED
@@ -54,7 +54,7 @@ window('Dynamic Area', 240, 600) {
|
|
54
54
|
value 102
|
55
55
|
|
56
56
|
on_changed do
|
57
|
-
@
|
57
|
+
@rectangle.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
58
58
|
end
|
59
59
|
}
|
60
60
|
|
@@ -63,7 +63,7 @@ window('Dynamic Area', 240, 600) {
|
|
63
63
|
value 102
|
64
64
|
|
65
65
|
on_changed do
|
66
|
-
@
|
66
|
+
@rectangle.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
67
67
|
end
|
68
68
|
}
|
69
69
|
|
@@ -72,7 +72,7 @@ window('Dynamic Area', 240, 600) {
|
|
72
72
|
value 204
|
73
73
|
|
74
74
|
on_changed do
|
75
|
-
@
|
75
|
+
@rectangle.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
76
76
|
end
|
77
77
|
}
|
78
78
|
|
@@ -81,15 +81,13 @@ window('Dynamic Area', 240, 600) {
|
|
81
81
|
value 100
|
82
82
|
|
83
83
|
on_changed do
|
84
|
-
@
|
84
|
+
@rectangle.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
|
85
85
|
end
|
86
86
|
}
|
87
87
|
}
|
88
88
|
|
89
89
|
area {
|
90
|
-
@
|
91
|
-
@rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
92
|
-
|
90
|
+
@rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value) { # stable path
|
93
91
|
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
94
92
|
}
|
95
93
|
}
|
data/examples/form_table.rb
CHANGED
@@ -22,15 +22,19 @@ window('Contacts', 600, 600) { |w|
|
|
22
22
|
@name_entry = entry {
|
23
23
|
label 'Name'
|
24
24
|
}
|
25
|
+
|
25
26
|
@email_entry = entry {
|
26
27
|
label 'Email'
|
27
28
|
}
|
29
|
+
|
28
30
|
@phone_entry = entry {
|
29
31
|
label 'Phone'
|
30
32
|
}
|
33
|
+
|
31
34
|
@city_entry = entry {
|
32
35
|
label 'City'
|
33
36
|
}
|
37
|
+
|
34
38
|
@state_entry = entry {
|
35
39
|
label 'State'
|
36
40
|
}
|
data/examples/grid.rb
CHANGED
@@ -8,16 +8,16 @@ window('Grid') {
|
|
8
8
|
tab {
|
9
9
|
tab_item('Span') {
|
10
10
|
grid {
|
11
|
-
4.times
|
12
|
-
4.times
|
11
|
+
4.times do |top_value|
|
12
|
+
4.times do |left_value|
|
13
13
|
label("(#{left_value}, #{top_value}) xspan1\nyspan1") {
|
14
14
|
left left_value
|
15
15
|
top top_value
|
16
16
|
hexpand true
|
17
17
|
vexpand true
|
18
18
|
}
|
19
|
-
|
20
|
-
|
19
|
+
end
|
20
|
+
end
|
21
21
|
label("(0, 4) xspan2\nyspan1 more text fits horizontally") {
|
22
22
|
left 0
|
23
23
|
top 4
|
data/examples/histogram.rb
CHANGED
@@ -79,19 +79,15 @@ window('histogram example', 640, 480) {
|
|
79
79
|
|
80
80
|
@area = area {
|
81
81
|
on_draw do |area_draw_params|
|
82
|
-
|
83
|
-
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height])
|
84
|
-
|
82
|
+
rectangle(0, 0, area_draw_params[:area_width], area_draw_params[:area_height]) {
|
85
83
|
fill 0xFFFFFF
|
86
84
|
}
|
87
85
|
|
88
86
|
graph_width, graph_height = *graph_size(area_draw_params[:area_width], area_draw_params[:area_height])
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
94
|
-
}
|
88
|
+
figure(X_OFF_LEFT, Y_OFF_TOP) {
|
89
|
+
line(X_OFF_LEFT, Y_OFF_TOP + graph_height)
|
90
|
+
line(X_OFF_LEFT + graph_width, Y_OFF_TOP + graph_height)
|
95
91
|
|
96
92
|
stroke 0x000000, thickness: 2, miter_limit: 10
|
97
93
|
}
|
data/examples/meta_example.rb
CHANGED
@@ -5,8 +5,10 @@ require 'fileutils'
|
|
5
5
|
class MetaExample
|
6
6
|
include Glimmer
|
7
7
|
|
8
|
+
ADDITIONAL_BASIC_EXAMPLES = ['Color Button', 'Font Button', 'Form', 'Date Time Picker', 'Simple Notepad']
|
9
|
+
|
8
10
|
def initialize
|
9
|
-
@selected_example_index =
|
11
|
+
@selected_example_index = examples_with_versions.index(basic_examples_with_versions.first)
|
10
12
|
end
|
11
13
|
|
12
14
|
def examples
|
@@ -25,6 +27,14 @@ class MetaExample
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
30
|
+
def basic_examples_with_versions
|
31
|
+
examples_with_versions.select {|example| example.start_with?('Basic') || ADDITIONAL_BASIC_EXAMPLES.include?(example) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def advanced_examples_with_versions
|
35
|
+
examples_with_versions - basic_examples_with_versions
|
36
|
+
end
|
37
|
+
|
28
38
|
def file_path_for(example)
|
29
39
|
File.join(File.expand_path('.', __dir__), "#{example.underscore}.rb")
|
30
40
|
end
|
@@ -66,17 +76,47 @@ class MetaExample
|
|
66
76
|
vertical_box {
|
67
77
|
stretchy false
|
68
78
|
|
69
|
-
|
79
|
+
tab {
|
70
80
|
stretchy false
|
71
|
-
items examples_with_versions
|
72
|
-
selected @selected_example_index
|
73
81
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
tab_item('Basic') {
|
83
|
+
vertical_box {
|
84
|
+
@basic_example_radio_buttons = radio_buttons {
|
85
|
+
stretchy false
|
86
|
+
items basic_examples_with_versions
|
87
|
+
selected basic_examples_with_versions.index(examples_with_versions[@selected_example_index])
|
88
|
+
|
89
|
+
on_selected do
|
90
|
+
@selected_example_index = examples_with_versions.index(basic_examples_with_versions[@basic_example_radio_buttons.selected])
|
91
|
+
example = selected_example
|
92
|
+
@code_entry.text = File.read(file_path_for(example))
|
93
|
+
@version_spinbox.value = 1
|
94
|
+
end
|
95
|
+
}
|
96
|
+
|
97
|
+
label # filler
|
98
|
+
label # filler
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
tab_item('Advanced') {
|
103
|
+
vertical_box {
|
104
|
+
@advanced_example_radio_buttons = radio_buttons {
|
105
|
+
stretchy false
|
106
|
+
items advanced_examples_with_versions
|
107
|
+
|
108
|
+
on_selected do
|
109
|
+
@selected_example_index = examples_with_versions.index(advanced_examples_with_versions[@advanced_example_radio_buttons.selected])
|
110
|
+
example = selected_example
|
111
|
+
@code_entry.text = File.read(file_path_for(example))
|
112
|
+
@version_spinbox.value = 1
|
113
|
+
end
|
114
|
+
}
|
115
|
+
|
116
|
+
label # filler
|
117
|
+
label # filler
|
118
|
+
}
|
119
|
+
}
|
80
120
|
}
|
81
121
|
|
82
122
|
horizontal_box {
|
data/examples/midi_player.rb
CHANGED
@@ -6,8 +6,8 @@ require_relative 'apple'
|
|
6
6
|
class Snake
|
7
7
|
module Model
|
8
8
|
class Game
|
9
|
-
WIDTH_DEFAULT =
|
10
|
-
HEIGHT_DEFAULT =
|
9
|
+
WIDTH_DEFAULT = 20
|
10
|
+
HEIGHT_DEFAULT = 20
|
11
11
|
FILE_HIGH_SCORE = File.expand_path(File.join(Dir.home, '.glimmer-snake'))
|
12
12
|
|
13
13
|
attr_reader :width, :height
|
data/examples/snake.rb
CHANGED
@@ -21,50 +21,38 @@ class Snake
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def register_observers
|
24
|
-
@game
|
25
|
-
@game.width.times do |column|
|
26
|
-
Glimmer::DataBinding::Observer.proc do |new_color|
|
27
|
-
@cell_grid[row][column].fill = new_color
|
28
|
-
end.observe(@grid.cells[row][column], :color)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
Glimmer::DataBinding::Observer.proc do |game_over|
|
24
|
+
observe(@game, :over) do |game_over|
|
33
25
|
Glimmer::LibUI.queue_main do
|
34
26
|
if game_over
|
35
27
|
msg_box('Game Over!', "Score: #{@game.score} | High Score: #{@game.high_score}")
|
36
28
|
@game.start
|
37
29
|
end
|
38
30
|
end
|
39
|
-
end
|
31
|
+
end
|
40
32
|
|
41
33
|
Glimmer::LibUI.timer(SNAKE_MOVE_DELAY) do
|
42
|
-
unless @game.over?
|
43
|
-
@game.snake.move
|
44
|
-
@main_window.title = "Glimmer Snake (Score: #{@game.score} | High Score: #{@game.high_score})"
|
45
|
-
end
|
34
|
+
@game.snake.move unless @game.over?
|
46
35
|
end
|
47
36
|
end
|
48
37
|
|
49
38
|
def create_gui
|
50
|
-
@
|
51
|
-
|
39
|
+
@main_window = window {
|
40
|
+
# data-bind window title to game score, converting it to a title string on read from the model
|
41
|
+
title <= [@game, :score, on_read: -> (score) {"Glimmer Snake (Score: #{@game.score})"}]
|
42
|
+
content_size @game.width * CELL_SIZE, @game.height * CELL_SIZE
|
52
43
|
resizable false
|
53
44
|
|
54
45
|
vertical_box {
|
55
46
|
padded false
|
56
47
|
|
57
48
|
@game.height.times do |row|
|
58
|
-
@cell_grid << []
|
59
49
|
horizontal_box {
|
60
50
|
padded false
|
61
51
|
|
62
52
|
@game.width.times do |column|
|
63
53
|
area {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
fill Presenter::Cell::COLOR_CLEAR
|
54
|
+
square(0, 0, CELL_SIZE) {
|
55
|
+
fill <= [@grid.cells[row][column], :color]
|
68
56
|
}
|
69
57
|
|
70
58
|
on_key_up do |area_key_event|
|
data/examples/tetris.rb
CHANGED
@@ -203,34 +203,31 @@ class Tetris
|
|
203
203
|
bevel_pixel_size = 0.16 * block_size.to_f
|
204
204
|
color = Glimmer::LibUI.interpret_color(Model::Block::COLOR_CLEAR)
|
205
205
|
area {
|
206
|
-
block[:background_square] =
|
207
|
-
square(0, 0, block_size)
|
208
|
-
|
206
|
+
block[:background_square] = square(0, 0, block_size) {
|
209
207
|
fill color
|
210
208
|
}
|
211
|
-
|
212
|
-
|
213
|
-
|
209
|
+
|
210
|
+
block[:top_bevel_edge] = polygon {
|
211
|
+
point_array 0, 0, block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size, bevel_pixel_size
|
214
212
|
fill r: color[:r] + 4*BEVEL_CONSTANT, g: color[:g] + 4*BEVEL_CONSTANT, b: color[:b] + 4*BEVEL_CONSTANT
|
215
213
|
}
|
216
|
-
|
217
|
-
|
218
|
-
|
214
|
+
|
215
|
+
block[:right_bevel_edge] = polygon {
|
216
|
+
point_array block_size, 0, block_size - bevel_pixel_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size, block_size
|
219
217
|
fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
|
220
218
|
}
|
221
|
-
|
222
|
-
|
223
|
-
|
219
|
+
|
220
|
+
block[:bottom_bevel_edge] = polygon {
|
221
|
+
point_array block_size, block_size, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size, block_size - bevel_pixel_size
|
224
222
|
fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
|
225
223
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
224
|
+
|
225
|
+
block[:left_bevel_edge] = polygon {
|
226
|
+
point_array 0, 0, 0, block_size, bevel_pixel_size, block_size - bevel_pixel_size, bevel_pixel_size, bevel_pixel_size
|
229
227
|
fill r: color[:r] - BEVEL_CONSTANT, g: color[:g] - BEVEL_CONSTANT, b: color[:b] - BEVEL_CONSTANT
|
230
228
|
}
|
231
|
-
|
232
|
-
|
233
|
-
|
229
|
+
|
230
|
+
block[:border_square] = square(0, 0, block_size) {
|
234
231
|
stroke COLOR_GRAY
|
235
232
|
}
|
236
233
|
|
@@ -38,8 +38,10 @@ class TicTacToe
|
|
38
38
|
|
39
39
|
#row and column numbers are 1-based
|
40
40
|
def mark(row, column)
|
41
|
-
self[row, column].
|
42
|
-
|
41
|
+
if self[row, column].empty
|
42
|
+
self[row, column].mark(current_sign)
|
43
|
+
game_over? #updates winning sign
|
44
|
+
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def current_sign
|
data/examples/tic_tac_toe.rb
CHANGED
@@ -16,17 +16,9 @@ class TicTacToe
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def register_observers
|
19
|
-
|
19
|
+
observe(@tic_tac_toe_board, :game_status) do |game_status|
|
20
20
|
display_win_message if game_status == Board::WIN
|
21
21
|
display_draw_message if game_status == Board::DRAW
|
22
|
-
end.observe(@tic_tac_toe_board, :game_status)
|
23
|
-
|
24
|
-
3.times.map do |row|
|
25
|
-
3.times.map do |column|
|
26
|
-
Glimmer::DataBinding::Observer.proc do |sign|
|
27
|
-
@cells[row][column].string = sign
|
28
|
-
end.observe(@tic_tac_toe_board[row + 1, column + 1], :sign) # board model is 1-based
|
29
|
-
end
|
30
22
|
end
|
31
23
|
end
|
32
24
|
|
@@ -34,25 +26,22 @@ class TicTacToe
|
|
34
26
|
@main_window = window('Tic-Tac-Toe', 180, 180) {
|
35
27
|
resizable false
|
36
28
|
|
37
|
-
@cells = []
|
38
29
|
vertical_box {
|
39
30
|
padded false
|
40
31
|
|
41
32
|
3.times.map do |row|
|
42
|
-
@cells << []
|
43
33
|
horizontal_box {
|
44
34
|
padded false
|
45
35
|
|
46
36
|
3.times.map do |column|
|
47
37
|
area {
|
48
|
-
|
49
|
-
square(0, 0, 60)
|
50
|
-
|
38
|
+
square(0, 0, 60) {
|
51
39
|
stroke :black, thickness: 2
|
52
40
|
}
|
53
41
|
text(23, 19) {
|
54
|
-
|
42
|
+
string {
|
55
43
|
font family: 'Arial', size: OS.mac? ? 20 : 16
|
44
|
+
string <= [@tic_tac_toe_board[row + 1, column + 1], :sign] # board model is 1-based
|
56
45
|
}
|
57
46
|
}
|
58
47
|
on_mouse_up do
|
data/examples/timer.rb
CHANGED
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (c) 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 'glimmer/dsl/static_expression'
|
23
|
+
require 'glimmer/dsl/bind_expression'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module DSL
|
27
|
+
module Libui
|
28
|
+
# Responsible for setting up the return value of the bind keyword (command symbol)
|
29
|
+
# as a ModelBinding. It is then used by another command handler like
|
30
|
+
# DataBindingExpression
|
31
|
+
class BindExpression < StaticExpression
|
32
|
+
include Glimmer::DSL::BindExpression
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright (c) 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 'glimmer/dsl/expression'
|
23
|
+
require 'glimmer/data_binding/model_binding'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module DSL
|
27
|
+
module Libui
|
28
|
+
# Responsible for wiring data-binding
|
29
|
+
# Depends on BindExpression
|
30
|
+
class DataBindingExpression < Expression
|
31
|
+
def can_interpret?(parent, keyword, *args, &block)
|
32
|
+
args.size == 1 and
|
33
|
+
args[0].is_a?(DataBinding::ModelBinding)
|
34
|
+
end
|
35
|
+
|
36
|
+
def interpret(parent, keyword, *args, &block)
|
37
|
+
model_binding = args[0]
|
38
|
+
model_attribute_observer = Glimmer::DataBinding::Observer.proc do
|
39
|
+
parent.send("#{keyword}=", model_binding.evaluate_property)
|
40
|
+
end
|
41
|
+
model_attribute_observer.observe(model_binding)
|
42
|
+
model_attribute_observer.call # initial update
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|