Class: Glimmer::LibUI::Shape
- Inherits:
-
Object
- Object
- Glimmer::LibUI::Shape
show all
- Includes:
- ContentBindable, 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,
lib/glimmer/libui/shape/composite_shape.rb
Overview
Represents LibUI lightweight shape objects nested under path (e.g. line, rectangle, arc, bezier)
Direct Known Subclasses
Arc, Bezier, Circle, CompositeShape, Figure, Line, Polybezier, Polygon, Polyline, Rectangle, Square
Defined Under Namespace
Classes: Arc, Bezier, Circle, CompositeShape, Figure, Line, Polybezier, Polygon, Polyline, Rectangle, Square
Constant Summary
collapse
- KEYWORD_ALIASES =
{
'shape' => 'composite_shape',
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#absolute_c1_x ⇒ Object
-
#absolute_c1_y ⇒ Object
-
#absolute_c2_x ⇒ Object
-
#absolute_c2_y ⇒ Object
-
#absolute_end_x ⇒ Object
-
#absolute_end_y ⇒ Object
-
#absolute_point_array ⇒ Object
-
#absolute_x ⇒ Object
-
#absolute_x_center ⇒ Object
-
#absolute_y ⇒ Object
-
#absolute_y_center ⇒ Object
-
#area_proxy ⇒ Object
-
#can_handle_listener?(listener_name) ⇒ Boolean
-
#composite_shape ⇒ Object
-
#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
-
#implicit_path? ⇒ Boolean
indicates if nested directly under area or on_draw event (having an implicit path not an explicit path parent).
-
#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)
#bind_content
#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
#bounding_box, #contain?, #include?, #move, #move_by, #perfect_shape, #perfect_shape_dependencies
Methods included from Parent
#children
Constructor Details
#initialize(keyword, parent, args, &block) ⇒ Shape
Returns a new instance of Shape.
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/glimmer/libui/shape.rb', line 85
def initialize(keyword, parent, args, &block)
keyword = KEYWORD_ALIASES[keyword] || keyword
@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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/glimmer/libui/shape.rb', line 301
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.
82
83
84
|
# File 'lib/glimmer/libui/shape.rb', line 82
def args
@args
end
|
#block ⇒ Object
Returns the value of attribute block.
82
83
84
|
# File 'lib/glimmer/libui/shape.rb', line 82
def block
@block
end
|
#content_added ⇒ Object
Also known as:
content_added?
Returns the value of attribute content_added.
82
83
84
|
# File 'lib/glimmer/libui/shape.rb', line 82
def content_added
@content_added
end
|
#keyword ⇒ Object
Returns the value of attribute keyword.
82
83
84
|
# File 'lib/glimmer/libui/shape.rb', line 82
def keyword
@keyword
end
|
#parent ⇒ Object
Returns the value of attribute parent.
82
83
84
|
# File 'lib/glimmer/libui/shape.rb', line 82
def parent
@parent
end
|
Class Method Details
.constant_symbol(keyword) ⇒ Object
67
68
69
70
|
# File 'lib/glimmer/libui/shape.rb', line 67
def constant_symbol(keyword)
keyword = KEYWORD_ALIASES[keyword] || keyword
"#{keyword.camelcase(:upper)}".to_sym
end
|
.create(keyword, parent, args, &block) ⇒ Object
41
42
43
44
|
# File 'lib/glimmer/libui/shape.rb', line 41
def create(keyword, parent, args, &block)
keyword = KEYWORD_ALIASES[keyword] || keyword
shape_class(keyword).new(keyword, parent, args, &block)
end
|
.exists?(keyword) ⇒ Boolean
34
35
36
37
38
39
|
# File 'lib/glimmer/libui/shape.rb', line 34
def exists?(keyword)
keyword = KEYWORD_ALIASES[keyword] || 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
59
60
61
62
63
64
65
|
# File 'lib/glimmer/libui/shape.rb', line 59
def parameter_defaults(*defaults)
if defaults.empty?
@parameter_defaults
else
@parameter_defaults = defaults
end
end
|
.parameters(*params) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/glimmer/libui/shape.rb', line 51
def parameters(*params)
if params.empty?
@parameters
else
@parameters = params
end
end
|
.shape_class(keyword) ⇒ Object
46
47
48
49
|
# File 'lib/glimmer/libui/shape.rb', line 46
def shape_class(keyword)
keyword = KEYWORD_ALIASES[keyword] || keyword
Shape.const_get(constant_symbol(keyword))
end
|
Instance Method Details
#absolute_c1_x ⇒ Object
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/glimmer/libui/shape.rb', line 220
def absolute_c1_x
return unless respond_to?(:c1_x)
if composite_shape
composite_shape.relative_x(c1_x)
else
c1_x
end
end
|
#absolute_c1_y ⇒ Object
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/glimmer/libui/shape.rb', line 231
def absolute_c1_y
return unless respond_to?(:c1_y)
if composite_shape
composite_shape.relative_x(c1_y)
else
c1_y
end
end
|
#absolute_c2_x ⇒ Object
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/glimmer/libui/shape.rb', line 242
def absolute_c2_x
return unless respond_to?(:c2_x)
if composite_shape
composite_shape.relative_x(c2_x)
else
c2_x
end
end
|
#absolute_c2_y ⇒ Object
253
254
255
256
257
258
259
260
261
262
|
# File 'lib/glimmer/libui/shape.rb', line 253
def absolute_c2_y
return unless respond_to?(:c2_y)
if composite_shape
composite_shape.relative_x(c2_y)
else
c2_y
end
end
|
#absolute_end_x ⇒ Object
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/glimmer/libui/shape.rb', line 264
def absolute_end_x
return unless respond_to?(:end_x)
if composite_shape
composite_shape.relative_x(end_x)
else
end_x
end
end
|
#absolute_end_y ⇒ Object
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/glimmer/libui/shape.rb', line 275
def absolute_end_y
return unless respond_to?(:end_y)
if composite_shape
composite_shape.relative_x(end_y)
else
end_y
end
end
|
#absolute_point_array ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/glimmer/libui/shape.rb', line 182
def absolute_point_array
return unless respond_to?(:point_array)
point_array = self.point_array || []
require 'perfect-shape'
point_array = PerfectShape::MultiPoint.normalize_point_array(point_array)
point_array.map do |point|
if composite_shape
composite_shape.relative_point(*point)
else
point
end
end
end
|
#absolute_x ⇒ Object
166
167
168
169
170
171
172
|
# File 'lib/glimmer/libui/shape.rb', line 166
def absolute_x
if composite_shape
composite_shape.relative_x(x)
else
x
end
end
|
#absolute_x_center ⇒ Object
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/glimmer/libui/shape.rb', line 198
def absolute_x_center
return unless respond_to?(:x_center)
if composite_shape
composite_shape.relative_x(x_center)
else
x_center
end
end
|
#absolute_y ⇒ Object
174
175
176
177
178
179
180
|
# File 'lib/glimmer/libui/shape.rb', line 174
def absolute_y
if composite_shape
composite_shape.relative_y(y)
else
y
end
end
|
#absolute_y_center ⇒ Object
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/glimmer/libui/shape.rb', line 209
def absolute_y_center
return unless respond_to?(:y_center)
if composite_shape
composite_shape.relative_y(y_center)
else
y_center
end
end
|
#area_proxy ⇒ Object
136
137
138
|
# File 'lib/glimmer/libui/shape.rb', line 136
def area_proxy
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::AreaProxy) }
end
|
#can_handle_listener?(listener_name) ⇒ Boolean
286
287
288
|
# File 'lib/glimmer/libui/shape.rb', line 286
def can_handle_listener?(listener_name)
area_proxy&.can_handle_listener?(listener_name)
end
|
#composite_shape ⇒ Object
144
145
146
|
# File 'lib/glimmer/libui/shape.rb', line 144
def composite_shape
find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(CompositeShape) }
end
|
#content(&block) ⇒ Object
113
114
115
116
|
# File 'lib/glimmer/libui/shape.rb', line 113
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
131
132
133
134
|
# File 'lib/glimmer/libui/shape.rb', line 131
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
119
120
121
|
# File 'lib/glimmer/libui/shape.rb', line 119
def draw(area_draw_params)
destroy if area_proxy.nil?
end
|
#fill(*args) ⇒ Object
Also known as:
fill=, set_fill
148
149
150
|
# File 'lib/glimmer/libui/shape.rb', line 148
def fill(*args)
path_proxy.fill(*args)
end
|
#handle_listener(listener_name, &listener) ⇒ Object
290
291
292
293
294
|
# File 'lib/glimmer/libui/shape.rb', line 290
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
|
#implicit_path? ⇒ Boolean
indicates if nested directly under area or on_draw event (having an implicit path not an explicit path parent)
#path_proxy ⇒ Object
140
141
142
|
# File 'lib/glimmer/libui/shape.rb', line 140
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)
97
98
99
100
101
102
103
|
# File 'lib/glimmer/libui/shape.rb', line 97
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
105
106
107
108
109
110
111
|
# File 'lib/glimmer/libui/shape.rb', line 105
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
123
124
125
|
# File 'lib/glimmer/libui/shape.rb', line 123
def redraw
area_proxy&.redraw
end
|
#request_auto_redraw ⇒ Object
127
128
129
|
# File 'lib/glimmer/libui/shape.rb', line 127
def request_auto_redraw
area_proxy&.request_auto_redraw
end
|
#respond_to?(method_name, *args, &block) ⇒ Boolean
296
297
298
299
|
# File 'lib/glimmer/libui/shape.rb', line 296
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
154
155
156
|
# File 'lib/glimmer/libui/shape.rb', line 154
def stroke(*args)
path_proxy.stroke(*args)
end
|
160
161
162
|
# File 'lib/glimmer/libui/shape.rb', line 160
def transform(matrix = nil)
path_proxy.transform(matrix)
end
|