Class: Glimmer::SWT::Custom::Shape::Path
Overview
Represents a path to be drawn on a control/widget/canvas/display That is because Shape is drawn on a parent as graphics and doesn’t have an SWT widget for itself swt_path is not guaranteed to have any object in it till after rendering
Constant Summary
String
Instance Attribute Summary collapse
#args, #disposed, #drawable, #extent, #name, #options, #parent, #properties, #shapes, #widget_listener_proxies
Instance Method Summary
collapse
-
#add_shape(shape) ⇒ Object
-
#bounds ⇒ Object
-
#calculate_args! ⇒ Object
-
#clear ⇒ Object
-
#contain?(x, y) ⇒ Boolean
-
#dispose(dispose_images: true, dispose_patterns: true, redraw: true) ⇒ Object
-
#eql?(other) ⇒ Boolean
(also: #==)
-
#geometry ⇒ Object
-
#hash ⇒ Object
-
#height ⇒ Object
-
#include?(x, y, filled: nil) ⇒ Boolean
checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge).
-
#initialize(parent, keyword, *args, &property_block) ⇒ Path
constructor
-
#irregular? ⇒ Boolean
-
#move_by(x_delta, y_delta) ⇒ Object
-
#parameter_names ⇒ Object
-
#path_segment_args ⇒ Object
-
#path_segment_geometry_args ⇒ Object
-
#path_segment_geometry_method_name ⇒ Object
-
#path_segment_method_name ⇒ Object
-
#post_dispose_content(path_segment) ⇒ Object
-
#size ⇒ Object
-
#width ⇒ Object
-
#x ⇒ Object
Logical x coordinate relative to parent.
-
#y ⇒ Object
Logical y coordinate relative to parent.
#add_to_geometry, #add_to_swt_path, #default_connected_path_segment_arg_count, #default_path_segment_arg_count, #first_path_segment?, #part_of_path?, #path, #previous_path_segment, #previous_point_connected?, #root_path
#absolute_x, #absolute_y, #all_parent_properties, #amend_method_name_options_based_on_properties!, #any_potential_drop_targets?, #apply_property_arg_conversions, #apply_shape_arg_conversions!, #apply_shape_arg_defaults!, arg_options, #background_pattern_args, #bounds_contain?, #calculate_paint_args!, #calculated_args?, #calculated_args_changed!, #calculated_args_changed_for_defaults!, #calculated_height, #calculated_paint_args_changed!, #calculated_width, #calculated_x, #calculated_y, #can_handle_observation_request?, #cancel_dragging!, #center_x, #center_y, #clear_shapes, #composite?, #container?, #content, #convert_properties!, #converted_properties, create, #current_parameter_name?, #default_height, #default_height?, #default_width, #default_width?, #default_x, #default_x?, #default_y, #default_y?, #deregister_drag_listeners, #drag_and_move, #drag_and_move=, #drag_source, #drag_source=, #draw?, #ensure_extent, #expanded_shapes, #fill?, flyweight_method_names, flyweight_patterns, #foreground_pattern_args, gc_instance_methods, #get_attribute, #get_data, #get_parameter_attribute, #gradient?, #handle_observation_request, #has_attribute?, #has_some_background?, #has_some_foreground?, #height_delta, #height_delta=, #include_shape?, #include_with_children?, #inspect, #inverse_transform_point, keywords, #location, #location_parameter_names, #max_height, #max_height?, #max_width, #max_width?, #method_missing, method_name, #paint, #paint_children, #paint_self, #parameter_index, #parameter_name?, #parent_shape_composites, #parent_shape_containers, #parent_shapes, #pattern, pattern, #pattern_args, #possible_parameter_names, #post_add_content, #remove_shape_disposed_listener, #respond_to?, #rotate, #rotation_angle, #round?, #set_attribute, #set_data, #set_parameter_attribute, #shell_proxy, #tolerate_shape_extra_args!, #transform_point, valid?, #width_delta, #width_delta=, #x_delta, #x_delta=, #x_end, #y_delta, #y_delta=, #y_end
Methods included from Properties
attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter
Constructor Details
#initialize(parent, keyword, *args, &property_block) ⇒ Path
Returns a new instance of Path.
43
44
45
46
47
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 43
def initialize(parent, keyword, *args, &property_block)
super
@path_segments = []
@uncalculated_path_segments = []
end
|
Instance Attribute Details
#calculated_path_args ⇒ Object
Returns the value of attribute calculated_path_args.
41
42
43
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 41
def calculated_path_args
@calculated_path_args
end
|
#path_segments ⇒ Object
Returns the value of attribute path_segments.
40
41
42
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 40
def path_segments
@path_segments
end
|
#swt_path ⇒ Object
Returns the value of attribute swt_path.
40
41
42
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 40
def swt_path
@swt_path
end
|
Instance Method Details
#add_shape(shape) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 53
def add_shape(shape)
if shape.is_a?(PathSegment)
Glimmer::SWT::DisplayProxy.instance.auto_exec do
@path_segments << shape
@uncalculated_path_segments << shape
end
else
super
end
end
|
#bounds ⇒ Object
143
144
145
146
147
148
149
150
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 143
def bounds
if @path_segments != @bounds_path_segments
@bounds_path_segments = @path_segments
shape_bounds = geometry.getBounds2D
@bounds = org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
end
@bounds
end
|
#calculate_args! ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 111
def calculate_args!
new_swt_path = @swt_path.nil? || !@calculated_paint_args || !@calculated_path_args
if new_swt_path
Glimmer::SWT::DisplayProxy.instance.auto_exec do
@swt_path&.dispose
@swt_path = org.eclipse.swt.graphics.Path.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
@uncalculated_path_segments = @path_segments.dup
end
end
@args = [@swt_path]
@uncalculated_path_segments.dup.each do |path_segment|
Glimmer::SWT::DisplayProxy.instance.auto_exec do
path_segment.add_to_swt_path(@swt_path)
@uncalculated_path_segments.delete(path_segment)
end
end
@calculated_path_args = true
if new_swt_path
@path_calculated_args = super
else
@path_calculated_args
end
rescue => e
Glimmer::Config.logger.error {e.full_message}
@args
end
|
#clear ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 91
def clear
Glimmer::SWT::DisplayProxy.instance.auto_exec do
@path_segments.each { |path_segments| path_segments.class == Path && path_segments.dispose }
@path_segments.clear
@uncalculated_path_segments = @path_segments.dup
@swt_path&.dispose
@swt_path = nil
@args = []
calculated_args_changed!(children: false)
drawable.redraw unless drawable.is_a?(ImageProxy)
end
end
|
#contain?(x, y) ⇒ Boolean
64
65
66
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 64
def contain?(x, y)
include?(x, y, filled: true)
end
|
#dispose(dispose_images: true, dispose_patterns: true, redraw: true) ⇒ Object
104
105
106
107
108
109
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 104
def dispose(dispose_images: true, dispose_patterns: true, redraw: true)
Glimmer::SWT::DisplayProxy.instance.auto_exec do
clear if self.class == Path
super(dispose_images: dispose_images, dispose_patterns: dispose_patterns, redraw: redraw) if (parent.is_a?(Shape) && (!parent.is_a?(PathSegment) || !parent.part_of_path?)) || parent.is_a?(Drawable)
end
end
|
#eql?(other) ⇒ Boolean
Also known as:
==
219
220
221
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 219
def eql?(other)
(other.class == Path) && geometry.equals(other && other.respond_to?(:geometry) && other.geometry)
end
|
#geometry ⇒ Object
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 183
def geometry
if @path_segments != @geometry_path_segments
@geometry_path_segments = @path_segments
@geometry = Java::JavaAwtGeom::Path2D::Double.new
@path_segments.each do |path_segment|
path_segment.add_to_geometry(@geometry)
end
end
@geometry
end
|
#hash ⇒ Object
224
225
226
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 224
def hash
geometry.hashCode
end
|
#height ⇒ Object
179
180
181
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 179
def height
size.y
end
|
#include?(x, y, filled: nil) ⇒ Boolean
checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
69
70
71
72
73
74
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 69
def include?(x, y, filled: nil)
x, y = inverse_transform_point(x, y)
filled = filled? if filled.nil?
makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
@swt_path.contains(x.to_f, y.to_f, makeshift_gc, !filled)
end
|
#irregular? ⇒ Boolean
76
77
78
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 76
def irregular?
true
end
|
#move_by(x_delta, y_delta) ⇒ Object
139
140
141
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 139
def move_by(x_delta, y_delta)
@path_segments.each {|path_segment| path_segment.move_by(x_delta, y_delta)}
end
|
#parameter_names ⇒ Object
49
50
51
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 49
def parameter_names
[:swt_path]
end
|
#path_segment_args ⇒ Object
198
199
200
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 198
def path_segment_args
@args
end
|
#path_segment_geometry_args ⇒ Object
210
211
212
213
214
215
216
217
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 210
def path_segment_geometry_args
if self.class == Path
[geometry, false]
else
super
end
end
|
#path_segment_geometry_method_name ⇒ Object
202
203
204
205
206
207
208
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 202
def path_segment_geometry_method_name
if self.class == Path
'append'
else
super
end
end
|
#path_segment_method_name ⇒ Object
194
195
196
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 194
def path_segment_method_name
'addPath'
end
|
#post_dispose_content(path_segment) ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 80
def post_dispose_content(path_segment)
Glimmer::SWT::DisplayProxy.instance.auto_exec do
@path_segments.delete(path_segment)
@uncalculated_path_segments = @path_segments.dup
@swt_path&.dispose
@swt_path = nil
@args = []
calculated_args_changed!(children: false)
end
end
|
#size ⇒ Object
152
153
154
155
156
157
158
159
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 152
def size
if @path_segments != @size_path_segments
@size_path_segments = @path_segments
shape_bounds = geometry.getBounds2D
@size = org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
end
@size
end
|
#width ⇒ Object
175
176
177
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 175
def width
size.x
end
|
#x ⇒ Object
Logical x coordinate relative to parent
162
163
164
165
166
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 162
def x
x_value = bounds.x
x_value -= parent.absolute_x if parent.is_a?(Shape)
x_value
end
|
#y ⇒ Object
Logical y coordinate relative to parent
169
170
171
172
173
|
# File 'lib/glimmer/swt/custom/shape/path.rb', line 169
def y
y_value = bounds.y
y_value -= parent.absolute_y if parent.is_a?(Shape)
y_value
end
|