glimmer-dsl-libui 0.0.27 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +451 -7
- data/VERSION +1 -1
- data/examples/basic_area.rb +17 -0
- data/examples/basic_area2.rb +19 -0
- data/examples/basic_table_checkbox_text.rb +1 -3
- data/examples/dynamic_area.rb +99 -0
- data/examples/dynamic_area2.rb +97 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/fiddle_consumer.rb +33 -0
- data/lib/glimmer/libui/area_proxy.rb +105 -0
- data/lib/glimmer/libui/button_column_proxy.rb +6 -1
- data/lib/glimmer/libui/checkbox_column_proxy.rb +2 -2
- data/lib/glimmer/libui/checkbox_text_column_proxy.rb +34 -2
- data/lib/glimmer/libui/control_proxy.rb +4 -0
- data/lib/glimmer/libui/path_proxy.rb +167 -0
- data/lib/glimmer/libui/rectangle_proxy.rb +100 -0
- data/lib/glimmer/libui/table_proxy.rb +16 -19
- data/lib/glimmer/libui/window_proxy.rb +7 -1
- metadata +12 -4
@@ -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
|
@@ -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,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
|
@@ -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)
|
@@ -30,12 +30,12 @@ module Glimmer
|
|
30
30
|
# Follows the Proxy Design Pattern
|
31
31
|
class CheckboxColumnProxy < ControlProxy
|
32
32
|
include Column
|
33
|
-
|
33
|
+
include EditableColumn
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
37
|
def build_control
|
38
|
-
@parent_proxy.append_checkbox_column(name, column_index,
|
38
|
+
@parent_proxy.append_checkbox_column(name, column_index, editable_value)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -32,12 +32,44 @@ module Glimmer
|
|
32
32
|
class CheckboxTextColumnProxy < ControlProxy
|
33
33
|
include Column
|
34
34
|
include DualColumn
|
35
|
-
include EditableColumn
|
35
|
+
include EditableColumn
|
36
36
|
|
37
|
+
def editable_checkbox(value = nil)
|
38
|
+
if value.nil?
|
39
|
+
@editable_checkbox = false if @editable_checkbox.nil?
|
40
|
+
@editable_checkbox
|
41
|
+
else
|
42
|
+
@editable_checkbox = !!value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
alias editable_checkbox= editable_checkbox
|
46
|
+
alias set_editable_checkbox editable_checkbox
|
47
|
+
alias editable_checkbox? editable_checkbox
|
48
|
+
|
49
|
+
def editable_text(value = nil)
|
50
|
+
if value.nil?
|
51
|
+
@editable_text = false if @editable_text.nil?
|
52
|
+
@editable_text
|
53
|
+
else
|
54
|
+
@editable_text = !!value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias editable_text= editable_text
|
58
|
+
alias set_editable_text editable_text
|
59
|
+
alias editable_text? editable_text
|
60
|
+
|
37
61
|
private
|
38
62
|
|
39
63
|
def build_control
|
40
|
-
@parent_proxy.append_checkbox_text_column(name, column_index,
|
64
|
+
@parent_proxy.append_checkbox_text_column(name, column_index, editable_checkbox_value, second_column_index, editable_text_value)
|
65
|
+
end
|
66
|
+
|
67
|
+
def editable_checkbox_value
|
68
|
+
(@parent_proxy.editable? || editable? || editable_checkbox?) ? -2 : -1
|
69
|
+
end
|
70
|
+
|
71
|
+
def editable_text_value
|
72
|
+
(@parent_proxy.editable? || editable? || editable_text?) ? -2 : -1
|
41
73
|
end
|
42
74
|
end
|
43
75
|
end
|
@@ -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
|
@@ -0,0 +1,167 @@
|
|
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
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
# Proxy for LibUI path objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class PathProxy < ControlProxy
|
30
|
+
# TODO support mode without parent proxy
|
31
|
+
def initialize(keyword, parent, args, &block)
|
32
|
+
@keyword = keyword
|
33
|
+
@parent_proxy = parent
|
34
|
+
@args = args
|
35
|
+
@block = block
|
36
|
+
@enabled = true
|
37
|
+
post_add_content if @block.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def post_initialize_child(child)
|
41
|
+
super
|
42
|
+
children << child
|
43
|
+
end
|
44
|
+
|
45
|
+
def post_add_content
|
46
|
+
super
|
47
|
+
if @parent_proxy.nil? && area_draw_params
|
48
|
+
draw(area_draw_params)
|
49
|
+
destroy
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def children
|
54
|
+
@children ||= []
|
55
|
+
end
|
56
|
+
|
57
|
+
def draw(area_draw_params)
|
58
|
+
build_control
|
59
|
+
children.each {|child| child.draw(area_draw_params)}
|
60
|
+
::LibUI.draw_path_end(@libui)
|
61
|
+
::LibUI.draw_fill(area_draw_params[:context], @libui, fill_draw_brush.to_ptr) unless fill.empty?
|
62
|
+
::LibUI.draw_stroke(area_draw_params[:context], @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
|
63
|
+
::LibUI.draw_free_path(@libui)
|
64
|
+
end
|
65
|
+
|
66
|
+
def draw_fill_mode
|
67
|
+
@args[0].is_a?(Integer) ? @args[0] : @args[0].to_s == 'alternate' ? 1 : 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def fill(args = nil)
|
71
|
+
if args.nil?
|
72
|
+
@fill ||= {}
|
73
|
+
else
|
74
|
+
@fill = args
|
75
|
+
@parent_proxy&.queue_redraw_all
|
76
|
+
end
|
77
|
+
@fill.tap do
|
78
|
+
@fill_observer ||= Glimmer::DataBinding::Observer.proc do
|
79
|
+
@parent_proxy&.queue_redraw_all
|
80
|
+
end
|
81
|
+
@fill_observer.observe(@fill)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
alias fill= fill
|
85
|
+
alias set_fill fill
|
86
|
+
|
87
|
+
def fill_draw_brush
|
88
|
+
@fill_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
|
89
|
+
init_draw_brush(@fill_draw_brush, @fill)
|
90
|
+
@fill_draw_brush
|
91
|
+
end
|
92
|
+
|
93
|
+
def stroke(args = nil)
|
94
|
+
if args.nil?
|
95
|
+
@stroke ||= {}
|
96
|
+
else
|
97
|
+
@stroke = args
|
98
|
+
@parent_proxy&.queue_redraw_all
|
99
|
+
end
|
100
|
+
@stroke.tap do
|
101
|
+
@stroke_observer ||= Glimmer::DataBinding::Observer.proc do
|
102
|
+
@parent_proxy&.queue_redraw_all
|
103
|
+
end
|
104
|
+
@stroke_observer.observe(@stroke)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
alias stroke= stroke
|
108
|
+
alias set_stroke stroke
|
109
|
+
|
110
|
+
def stroke_draw_brush
|
111
|
+
@stroke_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
|
112
|
+
init_draw_brush(@stroke_draw_brush, @stroke)
|
113
|
+
@stroke_draw_brush
|
114
|
+
end
|
115
|
+
|
116
|
+
def draw_stroke_params
|
117
|
+
@draw_stroke_params ||= ::LibUI::FFI::DrawStrokeParams.malloc
|
118
|
+
@draw_stroke_params.Cap = @stroke[:cap] || 0 # flat
|
119
|
+
@draw_stroke_params.Join = @stroke[:join] || 0 # miter
|
120
|
+
@draw_stroke_params.Thickness = @stroke[:thickness] || 1
|
121
|
+
@draw_stroke_params.MiterLimit = @stroke[:miter_limit] || 10 # DEFAULT_MITER_LIMIT
|
122
|
+
@draw_stroke_params_dashes ||= Fiddle::Pointer.malloc(8)
|
123
|
+
@draw_stroke_params.Dashes = @draw_stroke_params_dashes
|
124
|
+
@draw_stroke_params.NumDashes = @stroke[:num_dashes] || 0 # TODO reimplement this line correctly (perhaps no need to pass num dashes, yet dashes themselves and use their count here)
|
125
|
+
@draw_stroke_params.DashPhase = @stroke[:dash_phase] || 0
|
126
|
+
@draw_stroke_params
|
127
|
+
end
|
128
|
+
|
129
|
+
# returns area_draw_params if built inside on_draw listener (not needed if declared outside)
|
130
|
+
def area_draw_params
|
131
|
+
@args[0] if @parent_proxy.nil?
|
132
|
+
end
|
133
|
+
|
134
|
+
def destroy
|
135
|
+
@parent_proxy.children.delete(self) unless @parent_proxy.nil?
|
136
|
+
ControlProxy.control_proxies.delete(self)
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def build_control
|
142
|
+
@libui = ::LibUI.draw_new_path(draw_fill_mode)
|
143
|
+
end
|
144
|
+
|
145
|
+
def init_draw_brush(draw_brush, draw_brush_args)
|
146
|
+
case draw_brush_args[:type]
|
147
|
+
when Integer
|
148
|
+
draw_brush.Type = draw_brush_args[:type]
|
149
|
+
when :solid, 'solid'
|
150
|
+
draw_brush.Type = 0
|
151
|
+
when :linear_gradient, 'linear_gradient'
|
152
|
+
draw_brush.Type = 1
|
153
|
+
when :radial_gradient, 'radial_gradient'
|
154
|
+
draw_brush.Type = 2
|
155
|
+
when :image, 'image'
|
156
|
+
draw_brush.Type = 3
|
157
|
+
else
|
158
|
+
draw_brush.Type = 0
|
159
|
+
end
|
160
|
+
draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
|
161
|
+
draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
|
162
|
+
draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
|
163
|
+
draw_brush.A = (draw_brush_args[:a] || draw_brush_args[:alpha])
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,100 @@
|
|
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
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
# Proxy for LibUI rectangle objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class RectangleProxy < ControlProxy
|
30
|
+
def initialize(keyword, parent, args, &block)
|
31
|
+
@keyword = keyword
|
32
|
+
@parent_proxy = parent
|
33
|
+
@args = args
|
34
|
+
@block = block
|
35
|
+
@enabled = true
|
36
|
+
post_add_content if @block.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw(area_draw_params)
|
40
|
+
::LibUI.draw_path_add_rectangle(@parent_proxy.libui, *@args)
|
41
|
+
destroy if @parent_proxy.parent_proxy.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
@parent_proxy.children.delete(self) unless @parent_proxy.nil?
|
46
|
+
ControlProxy.control_proxies.delete(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def x(value = nil)
|
50
|
+
if value.nil?
|
51
|
+
@args[0]
|
52
|
+
else
|
53
|
+
@args[0] = value
|
54
|
+
@parent_proxy.parent_proxy&.queue_redraw_all
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias x= x
|
58
|
+
alias set_x x
|
59
|
+
|
60
|
+
def y(value = nil)
|
61
|
+
if value.nil?
|
62
|
+
@args[1]
|
63
|
+
else
|
64
|
+
@args[1] = value
|
65
|
+
@parent_proxy.parent_proxy&.queue_redraw_all
|
66
|
+
end
|
67
|
+
end
|
68
|
+
alias y= y
|
69
|
+
alias set_y y
|
70
|
+
|
71
|
+
def width(value = nil)
|
72
|
+
if value.nil?
|
73
|
+
@args[2]
|
74
|
+
else
|
75
|
+
@args[2] = value
|
76
|
+
@parent_proxy.parent_proxy&.queue_redraw_all
|
77
|
+
end
|
78
|
+
end
|
79
|
+
alias width= width
|
80
|
+
alias set_width width
|
81
|
+
|
82
|
+
def height(value = nil)
|
83
|
+
if value.nil?
|
84
|
+
@args[3]
|
85
|
+
else
|
86
|
+
@args[3] = value
|
87
|
+
@parent_proxy.parent_proxy&.queue_redraw_all
|
88
|
+
end
|
89
|
+
end
|
90
|
+
alias height= height
|
91
|
+
alias set_height height
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def build_control
|
96
|
+
# No Op
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|