Module: Glimmer::SWT::Custom::Shape::PathSegment
Overview
Represents path segments like point, line, quad, and cubic curves Shapes could mix in
Instance Method Summary collapse
- #add_to_geometry(geometry) ⇒ Object
- #add_to_swt_path(swt_path) ⇒ Object
-
#default_connected_path_segment_arg_count ⇒ Object
Subclasses must override to indicate expected count of args when previous point IS connected (e.g. 2 for line, 4 for quad, 6 for cubic).
-
#default_path_segment_arg_count ⇒ Object
Subclasses must override to indicate expected complete count of args when previous point is NOT connected (e.g. 4 for line, 6 for quad, 8 for cubic).
- #dispose(redraw: true) ⇒ Object
- #first_path_segment? ⇒ Boolean
-
#part_of_path? ⇒ Boolean
this is needed to indicate if a shape is part of a path or not (e.g. line and point could be either).
- #path ⇒ Object
-
#path_segment_args ⇒ Object
Subclasses must override and implement to indicate args to pass when invoking SWT Path object method.
-
#path_segment_geometry_args ⇒ Object
Subclasses must override and implement to indicate args to pass when invoking SWT Path object method.
-
#path_segment_geometry_method_name ⇒ Object
Subclasses may override to provide name of method to invoke for geometry object obtained from the Java AWT library java.awt.geom.Path2D.Double (e.g. curveTo vs cubicTo).
-
#path_segment_method_name ⇒ Object
Subclasses must override and implement to indicate method name to invoke on SWT Path object to add segment.
- #previous_path_segment ⇒ Object
-
#previous_point_connected? ⇒ Boolean
Subclasses must override to indicate otherwise.
- #root_path ⇒ Object
Instance Method Details
#add_to_geometry(geometry) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 115 def add_to_geometry(geometry) the_path_segment_geometry_args = path_segment_geometry_args.dup if !is_a?(Point) && self.class != Path if !previous_point_connected? if the_path_segment_geometry_args.count == default_path_segment_arg_count point = the_path_segment_geometry_args.shift, the_path_segment_geometry_args.shift geometry.moveTo(point[0], point[1]) elsif first_path_segment? point = the_path_segment_geometry_args[0..1] geometry.moveTo(point[0], point[1]) end end end geometry.send(path_segment_geometry_method_name, *the_path_segment_geometry_args) end |
#add_to_swt_path(swt_path) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 99 def add_to_swt_path(swt_path) the_path_segment_args = path_segment_args.dup if !is_a?(Point) && self.class != Path if !previous_point_connected? if the_path_segment_args.count == default_path_segment_arg_count point = the_path_segment_args.shift, the_path_segment_args.shift swt_path.moveTo(*point) elsif first_path_segment? point = the_path_segment_args[0..1] swt_path.moveTo(*point) end end end swt_path.send(path_segment_method_name, *the_path_segment_args) end |
#default_connected_path_segment_arg_count ⇒ Object
Subclasses must override to indicate expected count of args when previous point IS connected (e.g. 2 for line, 4 for quad, 6 for cubic)
63 64 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 63 def default_connected_path_segment_arg_count end |
#default_path_segment_arg_count ⇒ Object
Subclasses must override to indicate expected complete count of args when previous point is NOT connected (e.g. 4 for line, 6 for quad, 8 for cubic)
60 61 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 60 def default_path_segment_arg_count end |
#dispose(redraw: true) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 78 def dispose(redraw: true) Glimmer::SWT::DisplayProxy.instance.auto_exec do # including classes could override to dispose of resources first # afterwards, parent removes from its path segments with post_dispose_content parent.post_dispose_content(self) if parent.is_a?(Path) if part_of_path? drawable.redraw if redraw && !drawable.is_a?(ImageProxy) else super(redraw: redraw) end end end |
#first_path_segment? ⇒ Boolean
91 92 93 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 91 def first_path_segment? parent.path_segments.first == self end |
#part_of_path? ⇒ Boolean
this is needed to indicate if a shape is part of a path or not (e.g. line and point could be either)
48 49 50 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 48 def part_of_path? !!root_path end |
#path ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 39 def path current_parent = parent until current_parent.class == Path current_parent = current_parent.parent return current_parent if current_parent.nil? end current_parent end |
#path_segment_args ⇒ Object
Subclasses must override and implement to indicate args to pass when invoking SWT Path object method
56 57 58 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 56 def path_segment_args [] end |
#path_segment_geometry_args ⇒ Object
Subclasses must override and implement to indicate args to pass when invoking SWT Path object method
70 71 72 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 70 def path_segment_geometry_args path_segment_args end |
#path_segment_geometry_method_name ⇒ Object
Subclasses may override to provide name of method to invoke for geometry object obtained from the Java AWT library java.awt.geom.Path2D.Double (e.g. curveTo vs cubicTo)
66 67 68 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 66 def path_segment_geometry_method_name path_segment_method_name end |
#path_segment_method_name ⇒ Object
Subclasses must override and implement to indicate method name to invoke on SWT Path object to add segment
52 53 54 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 52 def path_segment_method_name nil end |
#previous_path_segment ⇒ Object
95 96 97 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 95 def previous_path_segment parent.path_segments[parent.path_segments.index(self) - 1] || self end |
#previous_point_connected? ⇒ Boolean
Subclasses must override to indicate otherwise
74 75 76 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 74 def previous_point_connected? true end |
#root_path ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/glimmer/swt/custom/shape/path_segment.rb', line 31 def root_path current_parent = parent until current_parent.class == Path && !current_parent.parent.is_a?(Path) current_parent = current_parent.parent return current_parent if current_parent.nil? end current_parent end |