glimmer-dsl-libui 0.0.28 → 0.1.3
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 +31 -0
- data/README.md +712 -21
- data/VERSION +1 -1
- data/examples/area_gallery.rb +52 -0
- data/examples/basic_area.rb +17 -0
- data/examples/basic_area2.rb +19 -0
- data/examples/dynamic_area.rb +99 -0
- data/examples/dynamic_area2.rb +97 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/control_expression.rb +1 -1
- data/lib/glimmer/dsl/libui/dsl.rb +1 -0
- data/lib/glimmer/dsl/libui/property_expression.rb +5 -1
- data/lib/glimmer/dsl/libui/shape_expression.rb +56 -0
- data/lib/glimmer/fiddle_consumer.rb +33 -0
- data/lib/glimmer/libui/arc.rb +40 -0
- data/lib/glimmer/libui/area_proxy.rb +105 -0
- data/lib/glimmer/libui/bezier.rb +35 -0
- data/lib/glimmer/libui/button_column_proxy.rb +6 -1
- data/lib/glimmer/libui/control_proxy.rb +10 -6
- data/lib/glimmer/libui/figure.rb +51 -0
- data/lib/glimmer/libui/line.rb +35 -0
- data/lib/glimmer/libui/path_proxy.rb +169 -0
- data/lib/glimmer/libui/rectangle.rb +35 -0
- data/lib/glimmer/libui/shape.rb +129 -0
- data/lib/glimmer/libui/square.rb +35 -0
- data/lib/glimmer/libui/table_proxy.rb +8 -15
- data/lib/glimmer/libui/window_proxy.rb +7 -1
- metadata +20 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.3
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Area Gallery', 400, 400) {
|
6
|
+
vertical_box {
|
7
|
+
area {
|
8
|
+
path { # declarative stable path
|
9
|
+
square(0, 0, 100)
|
10
|
+
square(100, 100, 400)
|
11
|
+
|
12
|
+
fill r: 102, g: 102, b: 204
|
13
|
+
}
|
14
|
+
path { # declarative stable path
|
15
|
+
rectangle(0, 100, 100, 400)
|
16
|
+
rectangle(100, 0, 400, 100)
|
17
|
+
|
18
|
+
fill r: 204, g: 102, b: 204
|
19
|
+
}
|
20
|
+
path { # declarative stable path
|
21
|
+
figure(100, 100) {
|
22
|
+
line(100, 400)
|
23
|
+
line(400, 100)
|
24
|
+
line(400, 400)
|
25
|
+
|
26
|
+
closed true
|
27
|
+
}
|
28
|
+
|
29
|
+
fill r: 202, g: 102, b: 104, a: 0.5
|
30
|
+
stroke thickness: 1, r: 0, g: 0, b: 0
|
31
|
+
}
|
32
|
+
path { # declarative stable path
|
33
|
+
figure(0, 0) {
|
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
|
+
}
|
40
|
+
|
41
|
+
fill r: 202, g: 102, b: 204, a: 0.5
|
42
|
+
stroke thickness: 2, r: 0, g: 0, b: 0
|
43
|
+
}
|
44
|
+
path { # declarative stable path
|
45
|
+
arc(200, 200, 90, 0, 360, false)
|
46
|
+
|
47
|
+
fill r: 202, g: 102, b: 204, a: 0.5
|
48
|
+
stroke thickness: 2, r: 0, g: 0, b: 0
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}.show
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Basic Area', 400, 400) {
|
6
|
+
margined true
|
7
|
+
|
8
|
+
vertical_box {
|
9
|
+
area {
|
10
|
+
path { # a stable path is added declaratively
|
11
|
+
rectangle(0, 0, 400, 400)
|
12
|
+
|
13
|
+
fill r: 102, g: 102, b: 204, a: 1.0
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}.show
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Basic Area', 400, 400) {
|
6
|
+
margined true
|
7
|
+
|
8
|
+
vertical_box {
|
9
|
+
area {
|
10
|
+
on_draw do |area_draw_params|
|
11
|
+
path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
|
12
|
+
rectangle(0, 0, 400, 400)
|
13
|
+
|
14
|
+
fill r: 102, g: 102, b: 204, a: 1.0
|
15
|
+
}
|
16
|
+
end
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}.show
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Dynamic Area', 240, 600) {
|
6
|
+
margined true
|
7
|
+
|
8
|
+
vertical_box {
|
9
|
+
label('Rectangle Properties') {
|
10
|
+
stretchy false
|
11
|
+
}
|
12
|
+
|
13
|
+
form {
|
14
|
+
stretchy false
|
15
|
+
|
16
|
+
@x_spinbox = spinbox(0, 1000) {
|
17
|
+
label 'x'
|
18
|
+
value 25
|
19
|
+
|
20
|
+
on_changed do
|
21
|
+
@area.queue_redraw_all
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
@y_spinbox = spinbox(0, 1000) {
|
26
|
+
label 'y'
|
27
|
+
value 25
|
28
|
+
|
29
|
+
on_changed do
|
30
|
+
@area.queue_redraw_all
|
31
|
+
end
|
32
|
+
}
|
33
|
+
|
34
|
+
@width_spinbox = spinbox(0, 1000) {
|
35
|
+
label 'width'
|
36
|
+
value 150
|
37
|
+
|
38
|
+
on_changed do
|
39
|
+
@area.queue_redraw_all
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
@height_spinbox = spinbox(0, 1000) {
|
44
|
+
label 'height'
|
45
|
+
value 150
|
46
|
+
|
47
|
+
on_changed do
|
48
|
+
@area.queue_redraw_all
|
49
|
+
end
|
50
|
+
}
|
51
|
+
|
52
|
+
@red_spinbox = spinbox(0, 255) {
|
53
|
+
label 'red'
|
54
|
+
value 102
|
55
|
+
|
56
|
+
on_changed do
|
57
|
+
@area.queue_redraw_all
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
@green_spinbox = spinbox(0, 255) {
|
62
|
+
label 'green'
|
63
|
+
value 102
|
64
|
+
|
65
|
+
on_changed do
|
66
|
+
@area.queue_redraw_all
|
67
|
+
end
|
68
|
+
}
|
69
|
+
|
70
|
+
@blue_spinbox = spinbox(0, 255) {
|
71
|
+
label 'blue'
|
72
|
+
value 204
|
73
|
+
|
74
|
+
on_changed do
|
75
|
+
@area.queue_redraw_all
|
76
|
+
end
|
77
|
+
}
|
78
|
+
|
79
|
+
@alpha_spinbox = spinbox(0, 100) {
|
80
|
+
label 'alpha'
|
81
|
+
value 100
|
82
|
+
|
83
|
+
on_changed do
|
84
|
+
@area.queue_redraw_all
|
85
|
+
end
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
@area = area {
|
90
|
+
on_draw do |area_draw_params|
|
91
|
+
path(area_draw_params) { # a dynamic path is added semi-declaratively inside on_draw block
|
92
|
+
rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
93
|
+
|
94
|
+
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
95
|
+
}
|
96
|
+
end
|
97
|
+
}
|
98
|
+
}
|
99
|
+
}.show
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'glimmer-dsl-libui'
|
2
|
+
|
3
|
+
include Glimmer
|
4
|
+
|
5
|
+
window('Dynamic Area', 240, 600) {
|
6
|
+
margined true
|
7
|
+
|
8
|
+
vertical_box {
|
9
|
+
label('Rectangle Properties') {
|
10
|
+
stretchy false
|
11
|
+
}
|
12
|
+
|
13
|
+
form {
|
14
|
+
stretchy false
|
15
|
+
|
16
|
+
@x_spinbox = spinbox(0, 1000) {
|
17
|
+
label 'x'
|
18
|
+
value 25
|
19
|
+
|
20
|
+
on_changed do
|
21
|
+
@rectangle.x = @x_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
22
|
+
end
|
23
|
+
}
|
24
|
+
|
25
|
+
@y_spinbox = spinbox(0, 1000) {
|
26
|
+
label 'y'
|
27
|
+
value 25
|
28
|
+
|
29
|
+
on_changed do
|
30
|
+
@rectangle.y = @y_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
31
|
+
end
|
32
|
+
}
|
33
|
+
|
34
|
+
@width_spinbox = spinbox(0, 1000) {
|
35
|
+
label 'width'
|
36
|
+
value 150
|
37
|
+
|
38
|
+
on_changed do
|
39
|
+
@rectangle.width = @width_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
@height_spinbox = spinbox(0, 1000) {
|
44
|
+
label 'height'
|
45
|
+
value 150
|
46
|
+
|
47
|
+
on_changed do
|
48
|
+
@rectangle.height = @height_spinbox.value # updating properties automatically triggers area.queue_redraw_all
|
49
|
+
end
|
50
|
+
}
|
51
|
+
|
52
|
+
@red_spinbox = spinbox(0, 255) {
|
53
|
+
label 'red'
|
54
|
+
value 102
|
55
|
+
|
56
|
+
on_changed do
|
57
|
+
@path.fill[:r] = @red_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
58
|
+
end
|
59
|
+
}
|
60
|
+
|
61
|
+
@green_spinbox = spinbox(0, 255) {
|
62
|
+
label 'green'
|
63
|
+
value 102
|
64
|
+
|
65
|
+
on_changed do
|
66
|
+
@path.fill[:g] = @green_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
67
|
+
end
|
68
|
+
}
|
69
|
+
|
70
|
+
@blue_spinbox = spinbox(0, 255) {
|
71
|
+
label 'blue'
|
72
|
+
value 204
|
73
|
+
|
74
|
+
on_changed do
|
75
|
+
@path.fill[:b] = @blue_spinbox.value # updating hash properties automatically triggers area.queue_redraw_all
|
76
|
+
end
|
77
|
+
}
|
78
|
+
|
79
|
+
@alpha_spinbox = spinbox(0, 100) {
|
80
|
+
label 'alpha'
|
81
|
+
value 100
|
82
|
+
|
83
|
+
on_changed do
|
84
|
+
@path.fill[:a] = @alpha_spinbox.value / 100.0 # updating hash properties automatically triggers area.queue_redraw_all
|
85
|
+
end
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
area {
|
90
|
+
@path = path { # stable path
|
91
|
+
@rectangle = rectangle(@x_spinbox.value, @y_spinbox.value, @width_spinbox.value, @height_spinbox.value)
|
92
|
+
|
93
|
+
fill r: @red_spinbox.value, g: @green_spinbox.value, b: @blue_spinbox.value, a: @alpha_spinbox.value / 100.0
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}.show
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -29,7 +29,7 @@ module Glimmer
|
|
29
29
|
include ParentExpression
|
30
30
|
|
31
31
|
def can_interpret?(parent, keyword, *args, &block)
|
32
|
-
Glimmer::LibUI::ControlProxy.
|
32
|
+
Glimmer::LibUI::ControlProxy.exists?(keyword)
|
33
33
|
end
|
34
34
|
|
35
35
|
def interpret(parent, keyword, *args, &block)
|
@@ -21,13 +21,17 @@
|
|
21
21
|
|
22
22
|
require 'glimmer/dsl/expression'
|
23
23
|
require 'glimmer/libui/control_proxy'
|
24
|
+
require 'glimmer/libui/shape'
|
24
25
|
|
25
26
|
module Glimmer
|
26
27
|
module DSL
|
27
28
|
module Libui
|
28
29
|
class PropertyExpression < Expression
|
29
30
|
def can_interpret?(parent, keyword, *args, &block)
|
30
|
-
|
31
|
+
(
|
32
|
+
parent.is_a?(Glimmer::LibUI::ControlProxy) or
|
33
|
+
parent.is_a?(Glimmer::LibUI::Shape)
|
34
|
+
) and
|
31
35
|
block.nil? and
|
32
36
|
parent.respond_to?(keyword, *args)
|
33
37
|
end
|
@@ -0,0 +1,56 @@
|
|
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/dsl/parent_expression'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module DSL
|
27
|
+
module Libui
|
28
|
+
class ShapeExpression < Expression
|
29
|
+
include ParentExpression
|
30
|
+
|
31
|
+
def can_interpret?(parent, keyword, *args, &block)
|
32
|
+
Glimmer::LibUI::Shape.exists?(keyword) and
|
33
|
+
(
|
34
|
+
parent.is_a?(Glimmer::LibUI::PathProxy) or
|
35
|
+
parent.is_a?(Glimmer::LibUI::Shape)
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def interpret(parent, keyword, *args, &block)
|
40
|
+
Glimmer::LibUI::Shape.create(keyword, parent, args, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_content(parent, keyword, *args, &block)
|
44
|
+
super
|
45
|
+
parent.post_add_content
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# TODO Consider moving all shapes underneath Shape namespace
|
54
|
+
require 'glimmer/libui/path_proxy'
|
55
|
+
require 'glimmer/libui/shape'
|
56
|
+
Dir[File.expand_path('../../libui/*.rb', __dir__)].each {|f| require f}
|
@@ -0,0 +1,33 @@
|
|
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
|
+
module Glimmer
|
23
|
+
module FiddleConsumer
|
24
|
+
# Protects Fiddle::Closure::BlockCaller objects from garbage collection.
|
25
|
+
def fiddle_closure_block_caller(*args, &block)
|
26
|
+
@blockcaller ||= []
|
27
|
+
args << [0] if args.size == 1 # Argument types are ommited
|
28
|
+
blockcaller = ::Fiddle::Closure::BlockCaller.new(*args, &block)
|
29
|
+
@blockcaller << blockcaller
|
30
|
+
blockcaller
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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/libui/shape'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
class Arc < Shape
|
27
|
+
parameters :x_center, :y_center, :radius, :start_angle, :sweep, :is_negative
|
28
|
+
|
29
|
+
def draw(area_draw_params)
|
30
|
+
@args[5] ||= ControlProxy.boolean_to_integer(@args[5], allow_nil: false)
|
31
|
+
if parent.is_a?(Figure) && parent.x.nil? && parent.y.nil?
|
32
|
+
::LibUI.draw_path_new_figure_with_arc(path_proxy.libui, *@args)
|
33
|
+
else
|
34
|
+
::LibUI.draw_path_arc_to(path_proxy.libui, *@args)
|
35
|
+
end
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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/libui/control_proxy'
|
23
|
+
require 'glimmer/fiddle_consumer'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module LibUI
|
27
|
+
# Proxy for LibUI area objects
|
28
|
+
#
|
29
|
+
# Follows the Proxy Design Pattern
|
30
|
+
class AreaProxy < ControlProxy
|
31
|
+
include Glimmer::FiddleConsumer
|
32
|
+
|
33
|
+
attr_reader :area_handler
|
34
|
+
|
35
|
+
def post_initialize_child(child)
|
36
|
+
super
|
37
|
+
children << child
|
38
|
+
end
|
39
|
+
|
40
|
+
def post_add_content
|
41
|
+
super
|
42
|
+
install_listeners
|
43
|
+
end
|
44
|
+
|
45
|
+
def children
|
46
|
+
@children ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
def on_draw(&block)
|
50
|
+
@on_draw_procs ||= []
|
51
|
+
if block.nil?
|
52
|
+
@on_draw_procs
|
53
|
+
else
|
54
|
+
@on_draw_procs << block
|
55
|
+
block
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def can_handle_listener?(listener_name)
|
60
|
+
listener_name == 'on_draw' || super
|
61
|
+
end
|
62
|
+
|
63
|
+
def handle_listener(listener_name, &listener)
|
64
|
+
case listener_name
|
65
|
+
when 'on_draw'
|
66
|
+
on_draw(&listener)
|
67
|
+
else
|
68
|
+
super
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def build_control
|
75
|
+
@area_handler = ::LibUI::FFI::AreaHandler.malloc
|
76
|
+
@libui = ::LibUI.new_area(@area_handler)
|
77
|
+
end
|
78
|
+
|
79
|
+
def install_listeners
|
80
|
+
@area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params|
|
81
|
+
area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params)
|
82
|
+
area_draw_params = area_draw_params_hash(area_draw_params)
|
83
|
+
children.each {|child| child.draw(area_draw_params)}
|
84
|
+
on_draw.each {|listener| listener.call(area_draw_params) }
|
85
|
+
end
|
86
|
+
@area_handler.MouseEvent = fiddle_closure_block_caller(0, [0]) {}
|
87
|
+
@area_handler.MouseCrossed = fiddle_closure_block_caller(0, [0]) {}
|
88
|
+
@area_handler.DragBroken = fiddle_closure_block_caller(0, [0]) {}
|
89
|
+
@area_handler.KeyEvent = fiddle_closure_block_caller(0, [0]) {}
|
90
|
+
end
|
91
|
+
|
92
|
+
def area_draw_params_hash(area_draw_params)
|
93
|
+
{
|
94
|
+
context: area_draw_params.Context,
|
95
|
+
area_width: area_draw_params.AreaWidth,
|
96
|
+
area_height: area_draw_params.AreaHeight,
|
97
|
+
clip_x: area_draw_params.ClipX,
|
98
|
+
clip_y: area_draw_params.ClipY,
|
99
|
+
clip_width: area_draw_params.ClipWidth,
|
100
|
+
clip_height: area_draw_params.ClipHeight,
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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/libui/shape'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
class Bezier < Shape
|
27
|
+
parameters :c1_x, :c1_y, :c2_x, :c2_y, :end_x, :end_y
|
28
|
+
|
29
|
+
def draw(area_draw_params)
|
30
|
+
::LibUI.draw_path_bezier_to(path_proxy.libui, *@args)
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -35,7 +35,12 @@ module Glimmer
|
|
35
35
|
def on_clicked(&block)
|
36
36
|
# TODO consider generalizing into custom listeners and moving to ControlProxy
|
37
37
|
@on_clicked_procs ||= []
|
38
|
-
|
38
|
+
if block.nil?
|
39
|
+
@on_clicked_procs
|
40
|
+
else
|
41
|
+
@on_clicked_procs << block
|
42
|
+
block
|
43
|
+
end
|
39
44
|
end
|
40
45
|
|
41
46
|
def can_handle_listener?(listener_name)
|
@@ -26,7 +26,7 @@ module Glimmer
|
|
26
26
|
# Follows the Proxy Design Pattern
|
27
27
|
class ControlProxy
|
28
28
|
class << self
|
29
|
-
def
|
29
|
+
def exists?(keyword)
|
30
30
|
::LibUI.respond_to?("new_#{keyword}") ||
|
31
31
|
::LibUI.respond_to?(keyword) ||
|
32
32
|
Glimmer::LibUI.constants.include?("#{keyword.camelcase(:upper)}Proxy".to_sym)
|
@@ -55,12 +55,12 @@ module Glimmer
|
|
55
55
|
control_proxies.find {|c| c.is_a?(Glimmer::LibUI::WindowProxy)}
|
56
56
|
end
|
57
57
|
|
58
|
-
def integer_to_boolean(int)
|
59
|
-
int.nil? ? nil : int == 1
|
58
|
+
def integer_to_boolean(int, allow_nil: true)
|
59
|
+
int.nil? ? (allow_nil ? nil : false) : int == 1
|
60
60
|
end
|
61
61
|
|
62
|
-
def boolean_to_integer(bool)
|
63
|
-
bool.nil? ? nil : (bool ? 1 : 0)
|
62
|
+
def boolean_to_integer(bool, allow_nil: true)
|
63
|
+
bool.nil? ? (allow_nil ? nil : 0) : (bool ? 1 : 0)
|
64
64
|
end
|
65
65
|
|
66
66
|
def menu_proxies
|
@@ -92,7 +92,7 @@ module Glimmer
|
|
92
92
|
]
|
93
93
|
|
94
94
|
# libui returns the contained LibUI object
|
95
|
-
attr_reader :parent_proxy, :libui, :args, :keyword
|
95
|
+
attr_reader :parent_proxy, :libui, :args, :keyword, :block
|
96
96
|
|
97
97
|
def initialize(keyword, parent, args, &block)
|
98
98
|
@keyword = keyword
|
@@ -258,6 +258,10 @@ module Glimmer
|
|
258
258
|
alias set_visible visible
|
259
259
|
alias visible= visible
|
260
260
|
|
261
|
+
def content(&block)
|
262
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ControlExpression.new, @keyword, &block)
|
263
|
+
end
|
264
|
+
|
261
265
|
private
|
262
266
|
|
263
267
|
def build_control
|