glimmer-dsl-libui 0.1.1 → 0.1.5
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 +1215 -30
- data/VERSION +1 -1
- data/examples/area_gallery.rb +50 -0
- data/examples/area_gallery2.rb +111 -0
- data/examples/area_gallery3.rb +52 -0
- data/examples/area_gallery4.rb +113 -0
- data/examples/basic_area2.rb +1 -1
- data/examples/basic_table_progress_bar.rb +13 -3
- data/examples/basic_transform.rb +27 -0
- data/examples/dynamic_area.rb +1 -1
- data/examples/dynamic_area2.rb +97 -0
- data/examples/histogram.rb +119 -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/libui/{rectangle_proxy.rb → arc.rb} +11 -26
- data/lib/glimmer/libui/area_proxy.rb +21 -11
- data/lib/glimmer/libui/bezier.rb +36 -0
- data/lib/glimmer/libui/box.rb +1 -1
- data/lib/glimmer/libui/color_button_proxy.rb +67 -15
- data/lib/glimmer/libui/control_proxy.rb +10 -14
- data/lib/glimmer/libui/figure.rb +52 -0
- data/lib/glimmer/libui/form_proxy.rb +1 -1
- data/lib/glimmer/libui/grid_proxy.rb +1 -1
- data/lib/glimmer/libui/line.rb +36 -0
- data/lib/glimmer/libui/matrix_proxy.rb +145 -0
- data/lib/glimmer/libui/parent.rb +36 -0
- data/lib/glimmer/libui/path_proxy.rb +35 -18
- data/lib/glimmer/libui/rectangle.rb +36 -0
- data/lib/glimmer/libui/shape.rb +143 -0
- data/lib/glimmer/libui/square.rb +36 -0
- data/lib/glimmer/libui/transformable.rb +72 -0
- data/lib/glimmer/libui/window_proxy.rb +8 -1
- data/lib/glimmer/libui.rb +50 -0
- data/lib/glimmer-dsl-libui.rb +1 -0
- metadata +23 -5
@@ -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
|
+
module Glimmer
|
23
|
+
module LibUI
|
24
|
+
# Parent controls and shapes who have children and add child post_initialize_child
|
25
|
+
module Parent
|
26
|
+
# Subclasses can override and must call super (passing add_child: false to cancel adding child to children)
|
27
|
+
def post_initialize_child(child, add_child: true)
|
28
|
+
children << child if add_child
|
29
|
+
end
|
30
|
+
|
31
|
+
def children
|
32
|
+
@children ||= []
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -20,6 +20,9 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/libui/control_proxy'
|
23
|
+
require 'glimmer/libui/area_proxy'
|
24
|
+
require 'glimmer/libui/parent'
|
25
|
+
require 'glimmer/libui/transformable'
|
23
26
|
|
24
27
|
module Glimmer
|
25
28
|
module LibUI
|
@@ -27,6 +30,9 @@ module Glimmer
|
|
27
30
|
#
|
28
31
|
# Follows the Proxy Design Pattern
|
29
32
|
class PathProxy < ControlProxy
|
33
|
+
include Parent
|
34
|
+
prepend Transformable
|
35
|
+
|
30
36
|
# TODO support mode without parent proxy
|
31
37
|
def initialize(keyword, parent, args, &block)
|
32
38
|
@keyword = keyword
|
@@ -37,23 +43,17 @@ module Glimmer
|
|
37
43
|
post_add_content if @block.nil?
|
38
44
|
end
|
39
45
|
|
40
|
-
def post_initialize_child(child)
|
41
|
-
super
|
42
|
-
children << child
|
43
|
-
end
|
44
|
-
|
45
46
|
def post_add_content
|
46
47
|
super
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@children ||= []
|
48
|
+
if @parent_proxy.nil? && AreaProxy.current_area_draw_params
|
49
|
+
draw(AreaProxy.current_area_draw_params)
|
50
|
+
destroy
|
51
|
+
end
|
52
52
|
end
|
53
53
|
|
54
54
|
def draw(area_draw_params)
|
55
55
|
build_control
|
56
|
-
children.each {|child| child.draw(area_draw_params)}
|
56
|
+
children.dup.each {|child| child.draw(area_draw_params)}
|
57
57
|
::LibUI.draw_path_end(@libui)
|
58
58
|
::LibUI.draw_fill(area_draw_params[:context], @libui, fill_draw_brush.to_ptr) unless fill.empty?
|
59
59
|
::LibUI.draw_stroke(area_draw_params[:context], @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
|
@@ -69,6 +69,14 @@ module Glimmer
|
|
69
69
|
@fill ||= {}
|
70
70
|
else
|
71
71
|
@fill = args
|
72
|
+
@fill[:a] = 1.0 if @fill[:a].nil?
|
73
|
+
@parent_proxy&.queue_redraw_all
|
74
|
+
end
|
75
|
+
@fill.tap do
|
76
|
+
@fill_observer ||= Glimmer::DataBinding::Observer.proc do
|
77
|
+
@parent_proxy&.queue_redraw_all
|
78
|
+
end
|
79
|
+
@fill_observer.observe(@fill)
|
72
80
|
end
|
73
81
|
end
|
74
82
|
alias fill= fill
|
@@ -85,6 +93,14 @@ module Glimmer
|
|
85
93
|
@stroke ||= {}
|
86
94
|
else
|
87
95
|
@stroke = args
|
96
|
+
@stroke[:a] = 1.0 if @stroke[:a].nil?
|
97
|
+
@parent_proxy&.queue_redraw_all
|
98
|
+
end
|
99
|
+
@stroke.tap do
|
100
|
+
@stroke_observer ||= Glimmer::DataBinding::Observer.proc do
|
101
|
+
@parent_proxy&.queue_redraw_all
|
102
|
+
end
|
103
|
+
@stroke_observer.observe(@stroke)
|
88
104
|
end
|
89
105
|
end
|
90
106
|
alias stroke= stroke
|
@@ -109,15 +125,15 @@ module Glimmer
|
|
109
125
|
@draw_stroke_params
|
110
126
|
end
|
111
127
|
|
112
|
-
# returns area_draw_params if built inside on_draw listener (not needed if declared outside)
|
113
|
-
def area_draw_params
|
114
|
-
@args[0] if @parent_proxy.nil?
|
115
|
-
end
|
116
|
-
|
117
128
|
def destroy
|
118
|
-
@parent_proxy
|
129
|
+
@parent_proxy&.children&.delete(self)
|
130
|
+
ControlProxy.control_proxies.delete(self)
|
119
131
|
end
|
120
|
-
|
132
|
+
|
133
|
+
def redraw
|
134
|
+
@parent_proxy&.queue_redraw_all
|
135
|
+
end
|
136
|
+
|
121
137
|
private
|
122
138
|
|
123
139
|
def build_control
|
@@ -139,6 +155,7 @@ module Glimmer
|
|
139
155
|
else
|
140
156
|
draw_brush.Type = 0
|
141
157
|
end
|
158
|
+
draw_brush_args = draw_brush_args.merge(Glimmer::LibUI.hex_to_rgb(draw_brush_args[:color])) if draw_brush_args[:color]
|
142
159
|
draw_brush.R = (draw_brush_args[:r] || draw_brush_args[:red]).to_f / 255.0
|
143
160
|
draw_brush.G = (draw_brush_args[:g] || draw_brush_args[:green]).to_f / 255.0
|
144
161
|
draw_brush.B = (draw_brush_args[:b] || draw_brush_args[:blue]).to_f / 255.0
|
@@ -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/libui/shape'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
class Rectangle < Shape
|
27
|
+
parameters :x, :y, :width, :height
|
28
|
+
parameter_defaults 0, 0, 0, 0
|
29
|
+
|
30
|
+
def draw(area_draw_params)
|
31
|
+
::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,143 @@
|
|
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/parent'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
# Represents LibUI lightweight shape objects nested under path (e.g. line, rectangle, arc, bezier)
|
27
|
+
class Shape
|
28
|
+
class << self
|
29
|
+
def exists?(keyword)
|
30
|
+
Glimmer::LibUI.constants.include?(constant_symbol(keyword)) and
|
31
|
+
shape_class(keyword).respond_to?(:ancestors) and
|
32
|
+
shape_class(keyword).ancestors.include?(Shape)
|
33
|
+
end
|
34
|
+
|
35
|
+
def create(keyword, parent, args, &block)
|
36
|
+
shape_class(keyword).new(keyword, parent, args, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def shape_class(keyword)
|
40
|
+
Glimmer::LibUI.const_get(constant_symbol(keyword))
|
41
|
+
end
|
42
|
+
|
43
|
+
def parameters(*params)
|
44
|
+
if params.empty?
|
45
|
+
@parameters
|
46
|
+
else
|
47
|
+
@parameters = params
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def parameter_defaults(*defaults)
|
52
|
+
if defaults.empty?
|
53
|
+
@parameter_defaults
|
54
|
+
else
|
55
|
+
@parameter_defaults = defaults
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def constant_symbol(keyword)
|
62
|
+
"#{keyword.camelcase(:upper)}".to_sym
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
include Parent
|
67
|
+
|
68
|
+
attr_reader :parent, :args, :keyword, :block
|
69
|
+
|
70
|
+
def initialize(keyword, parent, args, &block)
|
71
|
+
@keyword = keyword
|
72
|
+
@parent = parent
|
73
|
+
@args = args
|
74
|
+
@block = block
|
75
|
+
set_parameter_defaults
|
76
|
+
post_add_content if @block.nil?
|
77
|
+
end
|
78
|
+
|
79
|
+
# Subclasses may override to perform post add_content work (normally must call super)
|
80
|
+
def post_add_content
|
81
|
+
@parent&.post_initialize_child(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
|
85
|
+
def draw(area_draw_params)
|
86
|
+
destroy if area_proxy.nil?
|
87
|
+
end
|
88
|
+
|
89
|
+
def redraw
|
90
|
+
area_proxy&.queue_redraw_all
|
91
|
+
end
|
92
|
+
|
93
|
+
def destroy
|
94
|
+
@parent.children.delete(self)
|
95
|
+
end
|
96
|
+
|
97
|
+
def area_proxy
|
98
|
+
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(AreaProxy) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def path_proxy
|
102
|
+
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(PathProxy) }
|
103
|
+
end
|
104
|
+
|
105
|
+
def respond_to?(method_name, *args, &block)
|
106
|
+
self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
|
107
|
+
super(method_name, true)
|
108
|
+
end
|
109
|
+
|
110
|
+
def method_missing(method_name, *args, &block)
|
111
|
+
method_name_parameter = method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym
|
112
|
+
if self.class.parameters.include?(method_name_parameter)
|
113
|
+
method_name = method_name.to_s
|
114
|
+
parameter_index = self.class.parameters.index(method_name_parameter)
|
115
|
+
if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
|
116
|
+
@args[parameter_index] = args.first
|
117
|
+
area_proxy&.queue_redraw_all
|
118
|
+
else
|
119
|
+
@args[parameter_index]
|
120
|
+
end
|
121
|
+
else
|
122
|
+
super
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def set_parameter_defaults
|
129
|
+
self.class.parameter_defaults.each_with_index do |default, i|
|
130
|
+
@args[i] ||= default
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def find_parent_in_ancestors(&condition)
|
135
|
+
found = self
|
136
|
+
until condition.call(found)
|
137
|
+
found = found.respond_to?(:parent_proxy) ? found.parent_proxy : found.parent
|
138
|
+
end
|
139
|
+
found
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -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/libui/shape'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
class Square < Shape
|
27
|
+
parameters :x, :y, :length
|
28
|
+
parameter_defaults 0, 0, 0
|
29
|
+
|
30
|
+
def draw(area_draw_params)
|
31
|
+
::LibUI.draw_path_add_rectangle(path_proxy.libui, *@args, length)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,72 @@
|
|
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 LibUI
|
24
|
+
# This is meant to be prepended (not included) because it changes behavior of instance draw method
|
25
|
+
# Adds transform property to controls/shapes
|
26
|
+
# Automatically applies transform property at the beginning of draw operation and undoes it at the end
|
27
|
+
# Stacks up with Parent module (must include Parent beforehand)
|
28
|
+
# Expects transformable to implement redraw method
|
29
|
+
module Transformable
|
30
|
+
def post_initialize_child(child, add_child: true)
|
31
|
+
if child.is_a?(MatrixProxy)
|
32
|
+
super(child, add_child: false)
|
33
|
+
self.transform = child if child.keyword == 'transform'
|
34
|
+
else
|
35
|
+
super(child, add_child: add_child)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns transform or sets it. Expects transformable to implement redraw method (delegating work to area).
|
40
|
+
def transform(matrix = nil)
|
41
|
+
if matrix.nil?
|
42
|
+
@transform
|
43
|
+
else
|
44
|
+
@transform = matrix
|
45
|
+
redraw
|
46
|
+
end
|
47
|
+
end
|
48
|
+
alias transform= transform
|
49
|
+
alias set_transform transform
|
50
|
+
|
51
|
+
# Apply transform matrix to coordinate system
|
52
|
+
def apply_transform(area_draw_params)
|
53
|
+
::LibUI.draw_transform(area_draw_params[:context], @transform.libui) unless @transform.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
# Inverse of apply_transform (applies inverse transformation to undo initial transformation)
|
57
|
+
def undo_transform(area_draw_params)
|
58
|
+
unless @transform.nil?
|
59
|
+
inverse_transform = @transform.clone
|
60
|
+
inverse_transform.invert
|
61
|
+
::LibUI.draw_transform(area_draw_params[:context], inverse_transform.libui)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def draw(area_draw_params)
|
66
|
+
apply_transform(area_draw_params)
|
67
|
+
super(area_draw_params)
|
68
|
+
undo_transform(area_draw_params)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/libui/control_proxy'
|
23
|
+
require 'glimmer/libui/area_proxy'
|
23
24
|
|
24
25
|
module Glimmer
|
25
26
|
module LibUI
|
@@ -33,6 +34,12 @@ module Glimmer
|
|
33
34
|
DEFAULT_HAS_MENUBAR = 1
|
34
35
|
|
35
36
|
def post_initialize_child(child)
|
37
|
+
if child.is_a?(AreaProxy)
|
38
|
+
vertical_box_parent = ControlProxy.create('vertical_box', self, [])
|
39
|
+
child.instance_variable_set(:@parent_proxy, vertical_box_parent)
|
40
|
+
vertical_box_parent.post_initialize_child(child)
|
41
|
+
child = vertical_box_parent
|
42
|
+
end
|
36
43
|
::LibUI.window_set_child(@libui, child.libui)
|
37
44
|
end
|
38
45
|
|
@@ -104,7 +111,7 @@ module Glimmer
|
|
104
111
|
construction_args[1] = DEFAULT_WIDTH if construction_args.size == 1
|
105
112
|
construction_args[2] = DEFAULT_HEIGHT if construction_args.size == 2
|
106
113
|
construction_args[3] = DEFAULT_HAS_MENUBAR if construction_args.size == 3
|
107
|
-
construction_args[3] =
|
114
|
+
construction_args[3] = Glimmer::LibUI.boolean_to_integer(construction_args[3]) if construction_args.size == 4 && (construction_args[3].is_a?(TrueClass) || construction_args[3].is_a?(FalseClass))
|
108
115
|
@libui = ControlProxy.new_control(@keyword, construction_args)
|
109
116
|
@libui.tap do
|
110
117
|
handle_listener('on_closing') do
|
@@ -0,0 +1,50 @@
|
|
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 LibUI
|
24
|
+
class << self
|
25
|
+
def integer_to_boolean(int, allow_nil: true)
|
26
|
+
int.nil? ? (allow_nil ? nil : false) : int == 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def boolean_to_integer(bool, allow_nil: true)
|
30
|
+
bool.nil? ? (allow_nil ? nil : 0) : (bool ? 1 : 0)
|
31
|
+
end
|
32
|
+
|
33
|
+
def hex_to_rgb(value)
|
34
|
+
if value.is_a?(String)
|
35
|
+
value = "0x#{value}" if !value.start_with?('0x')
|
36
|
+
value = value.to_i(16)
|
37
|
+
end
|
38
|
+
if value.is_a?(Integer)
|
39
|
+
hex_value = value
|
40
|
+
value = {
|
41
|
+
r: ((hex_value >> 16) & 0xFF),
|
42
|
+
g: ((hex_value >> 8) & 0xFF),
|
43
|
+
b: (hex_value & 0xFF),
|
44
|
+
}
|
45
|
+
end
|
46
|
+
value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/glimmer-dsl-libui.rb
CHANGED
@@ -34,6 +34,7 @@ require 'libui'
|
|
34
34
|
# require 'ext/glimmer/config'
|
35
35
|
# require 'ext/glimmer'
|
36
36
|
require 'glimmer/dsl/libui/dsl'
|
37
|
+
require 'glimmer/libui'
|
37
38
|
Glimmer::Config.loop_max_count = -1
|
38
39
|
Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
|
39
40
|
method = method_symbol.to_s
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: os
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,6 +194,10 @@ files:
|
|
194
194
|
- VERSION
|
195
195
|
- bin/girb
|
196
196
|
- bin/girb_runner.rb
|
197
|
+
- examples/area_gallery.rb
|
198
|
+
- examples/area_gallery2.rb
|
199
|
+
- examples/area_gallery3.rb
|
200
|
+
- examples/area_gallery4.rb
|
197
201
|
- examples/basic_area.rb
|
198
202
|
- examples/basic_area2.rb
|
199
203
|
- examples/basic_button.rb
|
@@ -205,18 +209,21 @@ files:
|
|
205
209
|
- examples/basic_table_image.rb
|
206
210
|
- examples/basic_table_image_text.rb
|
207
211
|
- examples/basic_table_progress_bar.rb
|
212
|
+
- examples/basic_transform.rb
|
208
213
|
- examples/basic_window.rb
|
209
214
|
- examples/basic_window2.rb
|
210
215
|
- examples/color_button.rb
|
211
216
|
- examples/control_gallery.rb
|
212
217
|
- examples/date_time_picker.rb
|
213
218
|
- examples/dynamic_area.rb
|
219
|
+
- examples/dynamic_area2.rb
|
214
220
|
- examples/editable_column_table.rb
|
215
221
|
- examples/editable_table.rb
|
216
222
|
- examples/font_button.rb
|
217
223
|
- examples/form.rb
|
218
224
|
- examples/form_table.rb
|
219
225
|
- examples/grid.rb
|
226
|
+
- examples/histogram.rb
|
220
227
|
- examples/meta_example.rb
|
221
228
|
- examples/midi_player.rb
|
222
229
|
- examples/simple_notepad.rb
|
@@ -229,10 +236,14 @@ files:
|
|
229
236
|
- lib/glimmer/dsl/libui/open_file_expression.rb
|
230
237
|
- lib/glimmer/dsl/libui/property_expression.rb
|
231
238
|
- lib/glimmer/dsl/libui/save_file_expression.rb
|
239
|
+
- lib/glimmer/dsl/libui/shape_expression.rb
|
232
240
|
- lib/glimmer/dsl/libui/tab_item_expression.rb
|
233
241
|
- lib/glimmer/fiddle_consumer.rb
|
242
|
+
- lib/glimmer/libui.rb
|
234
243
|
- lib/glimmer/libui/about_menu_item_proxy.rb
|
244
|
+
- lib/glimmer/libui/arc.rb
|
235
245
|
- lib/glimmer/libui/area_proxy.rb
|
246
|
+
- lib/glimmer/libui/bezier.rb
|
236
247
|
- lib/glimmer/libui/box.rb
|
237
248
|
- lib/glimmer/libui/button_column_proxy.rb
|
238
249
|
- lib/glimmer/libui/button_proxy.rb
|
@@ -250,6 +261,7 @@ files:
|
|
250
261
|
- lib/glimmer/libui/editable_column.rb
|
251
262
|
- lib/glimmer/libui/editable_combobox_proxy.rb
|
252
263
|
- lib/glimmer/libui/enableable_column.rb
|
264
|
+
- lib/glimmer/libui/figure.rb
|
253
265
|
- lib/glimmer/libui/font_button_proxy.rb
|
254
266
|
- lib/glimmer/libui/form_proxy.rb
|
255
267
|
- lib/glimmer/libui/grid_proxy.rb
|
@@ -260,21 +272,27 @@ files:
|
|
260
272
|
- lib/glimmer/libui/image_proxy.rb
|
261
273
|
- lib/glimmer/libui/image_text_column_proxy.rb
|
262
274
|
- lib/glimmer/libui/label_proxy.rb
|
275
|
+
- lib/glimmer/libui/line.rb
|
276
|
+
- lib/glimmer/libui/matrix_proxy.rb
|
263
277
|
- lib/glimmer/libui/menu_item_proxy.rb
|
264
278
|
- lib/glimmer/libui/menu_proxy.rb
|
265
279
|
- lib/glimmer/libui/multiline_entry_proxy.rb
|
266
280
|
- lib/glimmer/libui/non_wrapping_multiline_entry_proxy.rb
|
281
|
+
- lib/glimmer/libui/parent.rb
|
267
282
|
- lib/glimmer/libui/path_proxy.rb
|
268
283
|
- lib/glimmer/libui/preferences_menu_item_proxy.rb
|
269
284
|
- lib/glimmer/libui/progress_bar_column_proxy.rb
|
270
285
|
- lib/glimmer/libui/quit_menu_item_proxy.rb
|
271
286
|
- lib/glimmer/libui/radio_buttons_proxy.rb
|
272
|
-
- lib/glimmer/libui/
|
287
|
+
- lib/glimmer/libui/rectangle.rb
|
273
288
|
- lib/glimmer/libui/separator_menu_item_proxy.rb
|
289
|
+
- lib/glimmer/libui/shape.rb
|
290
|
+
- lib/glimmer/libui/square.rb
|
274
291
|
- lib/glimmer/libui/tab_item_proxy.rb
|
275
292
|
- lib/glimmer/libui/table_proxy.rb
|
276
293
|
- lib/glimmer/libui/text_column_proxy.rb
|
277
294
|
- lib/glimmer/libui/time_picker_proxy.rb
|
295
|
+
- lib/glimmer/libui/transformable.rb
|
278
296
|
- lib/glimmer/libui/vertical_box_proxy.rb
|
279
297
|
- lib/glimmer/libui/window_proxy.rb
|
280
298
|
homepage: http://github.com/AndyObtiva/glimmer-dsl-libui
|