Class: Glimmer::LibUI::Shape
- Inherits:
-
Object
- Object
- Glimmer::LibUI::Shape
show all
- Includes:
- DataBindable, Parent, PerfectShaped
- Defined in:
- lib/glimmer/libui/shape.rb,
lib/glimmer/libui/shape/arc.rb,
lib/glimmer/libui/shape/line.rb,
lib/glimmer/libui/shape/bezier.rb,
lib/glimmer/libui/shape/circle.rb,
lib/glimmer/libui/shape/figure.rb,
lib/glimmer/libui/shape/square.rb,
lib/glimmer/libui/shape/polygon.rb,
lib/glimmer/libui/shape/polyline.rb,
lib/glimmer/libui/shape/rectangle.rb,
lib/glimmer/libui/shape/polybezier.rb
Overview
Represents LibUI lightweight shape objects nested under path (e.g. line, rectangle, arc, bezier)
Defined Under Namespace
Classes: Arc, Bezier, Circle, Figure, Line, Polybezier, Polygon, Polyline, Rectangle, Square
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#area_proxy ⇒ Object
-
#can_handle_listener?(listener_name) ⇒ Boolean
-
#content(&block) ⇒ Object
-
#destroy ⇒ Object
-
#draw(area_draw_params) ⇒ Object
Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method.
-
#fill(*args) ⇒ Object
(also: #fill=, #set_fill)
-
#handle_listener(listener_name, &listener) ⇒ Object
-
#initialize(keyword, parent, args, &block) ⇒ Shape
constructor
-
#method_missing(method_name, *args, &block) ⇒ Object
-
#path_proxy ⇒ Object
-
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super).
-
#post_initialize_child(child, add_child: true) ⇒ Object
-
#redraw ⇒ Object
-
#request_auto_redraw ⇒ Object
-
#respond_to?(method_name, *args, &block) ⇒ Boolean
-
#stroke(*args) ⇒ Object
(also: #stroke=, #set_stroke)
-
#transform(matrix = nil) ⇒ Object
(also: #transform=, #set_transform)
#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
#bounding_box, #contain?, #include?, #move, #move_by, #perfect_shape
Methods included from Parent
#children
Constructor Details
#initialize(keyword, parent, args, &block) ⇒ Shape
Returns a new instance of Shape.
75
76
77
78
79
80
81
82
83
|
# File 'lib/glimmer/libui/shape.rb', line 75
def initialize(keyword, parent, args, &block)
@keyword = keyword
@parent = parent
@args = args
@block = block
set_parameter_defaults
build_control if implicit_path?
post_add_content if @block.nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/glimmer/libui/shape.rb', line 166
def method_missing(method_name, *args, &block)
method_name_parameter = method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym
if self.class.parameters.include?(method_name_parameter)
method_name = method_name.to_s
parameter_index = self.class.parameters.index(method_name_parameter)
if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
args = [args] if args.size > 1
if args.first != @args[parameter_index]
@args[parameter_index] = args.first
request_auto_redraw
end
else
@args[parameter_index]
end
else
super
end
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
72
73
74
|
# File 'lib/glimmer/libui/shape.rb', line 72
def args
@args
end
|
#block ⇒ Object
Returns the value of attribute block.
72
73
74
|
# File 'lib/glimmer/libui/shape.rb', line 72
def block
@block
end
|
#content_added ⇒ Object
Also known as:
content_added?
Returns the value of attribute content_added.
72
73
74
|
# File 'lib/glimmer/libui/shape.rb', line 72
def content_added
@content_added
end
|
#keyword ⇒ Object
Returns the value of attribute keyword.
72
73
74
|
# File 'lib/glimmer/libui/shape.rb', line 72
def keyword
@keyword
end
|
#parent ⇒ Object
Returns the value of attribute parent.
72
73
74
|
# File 'lib/glimmer/libui/shape.rb', line 72
def parent
@parent
end
|
Class Method Details
.constant_symbol(keyword) ⇒ Object
63
64
65
|
# File 'lib/glimmer/libui/shape.rb', line 63
def constant_symbol(keyword)
"#{keyword.camelcase(:upper)}".to_sym
end
|
.create(keyword, parent, args, &block) ⇒ Object
39
40
41
|
# File 'lib/glimmer/libui/shape.rb', line 39
def create(keyword, parent, args, &block)
shape_class(keyword).new(keyword, parent, args, &block)
end
|
.exists?(keyword) ⇒ Boolean
33
34
35
36
37
|
# File 'lib/glimmer/libui/shape.rb', line 33
def exists?(keyword)
Shape.constants.include?(constant_symbol(keyword)) and
shape_class(keyword).respond_to?(:ancestors) and
shape_class(keyword).ancestors.include?(Shape)
end
|
.parameter_defaults(*defaults) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/glimmer/libui/shape.rb', line 55
def parameter_defaults(*defaults)
if defaults.empty?
@parameter_defaults
else
@parameter_defaults = defaults
end
end
|
.parameters(*params) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/glimmer/libui/shape.rb', line 47
def parameters(*params)
if params.empty?
@parameters
else
@parameters = params
end
end
|
.shape_class(keyword) ⇒ Object
43
44
45
|
# File 'lib/glimmer/libui/shape.rb', line 43
def shape_class(keyword)
Shape.const_get(constant_symbol(keyword))
end
|
Instance Method Details
#area_proxy ⇒ Object
125
126
127
|
# File 'lib/glimmer/libui/shape.rb', line 125
def area_proxy
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::AreaProxy) }
end
|
#can_handle_listener?(listener_name) ⇒ Boolean
151
152
153
|
# File 'lib/glimmer/libui/shape.rb', line 151
def can_handle_listener?(listener_name)
area_proxy.can_handle_listener?(listener_name)
end
|
#content(&block) ⇒ Object
102
103
104
105
|
# File 'lib/glimmer/libui/shape.rb', line 102
def content(&block)
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Libui::ShapeExpression.new, @keyword, {post_add_content: @content_added}, &block)
request_auto_redraw
end
|
#destroy ⇒ Object
120
121
122
123
|
# File 'lib/glimmer/libui/shape.rb', line 120
def destroy
return if ControlProxy.main_window_proxy&.destroying?
@parent.children.delete(self)
end
|
#draw(area_draw_params) ⇒ Object
Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method
108
109
110
|
# File 'lib/glimmer/libui/shape.rb', line 108
def draw(area_draw_params)
destroy if area_proxy.nil?
end
|
#fill(*args) ⇒ Object
Also known as:
fill=, set_fill
133
134
135
|
# File 'lib/glimmer/libui/shape.rb', line 133
def fill(*args)
path_proxy.fill(*args)
end
|
#handle_listener(listener_name, &listener) ⇒ Object
155
156
157
158
159
|
# File 'lib/glimmer/libui/shape.rb', line 155
def handle_listener(listener_name, &listener)
area_proxy.handle_listener(listener_name) do |event|
listener.call(event) if include?(event[:x], event[:y])
end
end
|
#path_proxy ⇒ Object
129
130
131
|
# File 'lib/glimmer/libui/shape.rb', line 129
def path_proxy
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::PathProxy) }
end
|
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super)
86
87
88
89
90
91
92
|
# File 'lib/glimmer/libui/shape.rb', line 86
def post_add_content
unless @content_added
@parent&.post_initialize_child(self)
@parent.post_add_content if implicit_path? && dynamic?
@content_added = true
end
end
|
#post_initialize_child(child, add_child: true) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/glimmer/libui/shape.rb', line 94
def post_initialize_child(child, add_child: true)
if child.is_a?(ControlProxy::MatrixProxy)
path_proxy.post_initialize_child(child, add_child: add_child)
else
super(child, add_child: add_child)
end
end
|
#redraw ⇒ Object
112
113
114
|
# File 'lib/glimmer/libui/shape.rb', line 112
def redraw
area_proxy&.redraw
end
|
#request_auto_redraw ⇒ Object
116
117
118
|
# File 'lib/glimmer/libui/shape.rb', line 116
def request_auto_redraw
area_proxy&.request_auto_redraw
end
|
#respond_to?(method_name, *args, &block) ⇒ Boolean
161
162
163
164
|
# File 'lib/glimmer/libui/shape.rb', line 161
def respond_to?(method_name, *args, &block)
self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
super(method_name, true)
end
|
#stroke(*args) ⇒ Object
Also known as:
stroke=, set_stroke
139
140
141
|
# File 'lib/glimmer/libui/shape.rb', line 139
def stroke(*args)
path_proxy.stroke(*args)
end
|
145
146
147
|
# File 'lib/glimmer/libui/shape.rb', line 145
def transform(matrix = nil)
path_proxy.transform(matrix)
end
|