lib/glimmer/swt/custom/shape/line.rb in glimmer-dsl-swt-4.18.5.5 vs lib/glimmer/swt/custom/shape/line.rb in glimmer-dsl-swt-4.18.6.0

- old
+ new

@@ -18,10 +18,11 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. require 'glimmer/swt/custom/shape' +require 'glimmer/swt/custom/shape/path_segment' require 'glimmer/swt/swt_proxy' require 'glimmer/swt/display_proxy' require 'glimmer/swt/color_proxy' require 'glimmer/swt/font_proxy' require 'glimmer/swt/transform_proxy' @@ -31,10 +32,12 @@ module Custom # Represents a shape (graphics) 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 class Shape class Line < Shape + include PathSegment + class << self def include?(x1, y1, x2, y2, x, y) distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2) distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2) distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2) @@ -77,15 +80,15 @@ y_value -= parent.absolute_y if parent.is_a?(Shape) y_value end def width - bounds.width + size.x end def height - bounds.height + size.y end def absolute_x1 if parent.is_a?(Shape) parent.absolute_x + x1 @@ -102,19 +105,19 @@ end end def absolute_x2 if parent.is_a?(Shape) - parent.absolute_x + x2 + parent.absolute_x + x2.to_f else x2 end end def absolute_y2 if parent.is_a?(Shape) - parent.absolute_y + y1 + parent.absolute_y + y2.to_f else y2 end end @@ -132,10 +135,40 @@ end def irregular? true end + + def path_segment_method_name + 'lineTo' + end + def path_segment_args + # TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point + @args + end + + def path_segment_geometry_args + # TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point + @args[0..1] + end + + def previous_point_connected? + @args.compact.count == 2 && !first_path_segment? + end + + def eql?(other) + x1 == (other && other.respond_to?(:x1) && other.x1) && + y1 == (other && other.respond_to?(:y1) && other.y1) && + x2 == (other && other.respond_to?(:x2) && other.x2) && + y2 == (other && other.respond_to?(:y2) && other.y2) + end + alias == eql? + + def hash + [x1, y1, x2, y2].hash + end + end end end end end