Class: Glimmer::SWT::Custom::Shape::Quad

Inherits:
Path show all
Defined in:
lib/glimmer/swt/custom/shape/quad.rb

Constant Summary

Constants inherited from Glimmer::SWT::Custom::Shape

String

Instance Attribute Summary

Attributes inherited from Path

#closed, #flatness, #path_segments, #swt_path

Attributes inherited from Glimmer::SWT::Custom::Shape

#args, #drawable, #extent, #name, #options, #parent, #shapes

Instance Method Summary collapse

Methods inherited from Path

#add_shape, #bounds, #calculated_args, #calculated_args_changed!, #dispose, #height, #initialize, #irregular?, #path_segment_geometry_args, #path_segment_geometry_method_name, #post_dispose_content, #size, #width, #x, #y

Methods included from PathSegment

#add_to_swt_path, #dispose, #first_path_segment?, #path_segment_geometry_args, #path_segment_geometry_method_name, #previous_path_segment

Methods inherited from Glimmer::SWT::Custom::Shape

#absolute_x, #absolute_y, #add_shape, #amend_method_name_options_based_on_properties!, #apply_property_arg_conversions, #apply_shape_arg_conversions!, #apply_shape_arg_defaults!, arg_options, #background_pattern_args, #bounds, #calculate_paint_args!, #calculated_args, #calculated_args?, #calculated_args_changed!, #calculated_args_changed_for_defaults!, #calculated_height, #calculated_width, #calculated_x, #calculated_y, #content, create, #current_parameter_name?, #default_height, #default_height?, #default_height_delta, #default_height_delta=, #default_width, #default_width?, #default_width_delta, #default_width_delta=, #default_x, #default_x?, #default_x_delta, #default_x_delta=, #default_y, #default_y?, #default_y_delta, #default_y_delta=, #dispose, #draw?, #ensure_extent, #expanded_shapes, #fill?, flyweight_method_names, flyweight_patterns, #foreground_pattern_args, gc_instance_methods, #get_attribute, #gradient?, #has_attribute?, #has_some_background?, #has_some_foreground?, #initialize, #inspect, #irregular?, keywords, #location, #location_parameter_names, #method_missing, method_name, #paint, #paint_children, #paint_self, #parameter_index, #parameter_name?, #parent_shape_absolute_location_changed?, #pattern, pattern, #pattern_args, #possible_parameter_names, #post_add_content, #respond_to?, #round?, #set_attribute, #set_parameter_attribute, #size, #tolerate_shape_extra_args!, valid?

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

Methods included from Packages

included

Constructor Details

This class inherits a constructor from Glimmer::SWT::Custom::Shape::Path

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::Custom::Shape

Instance Method Details

#contain?(x, y) ⇒ Boolean



50
51
52
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 50

def contain?(x, y)
  include?(x, y, filled: true)
end

#eql?(other) ⇒ Boolean Also known as: ==



91
92
93
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 91

def eql?(other)
  point_array == (other && other.respond_to?(:point_array) && other.point_array)
end

#geometryObject



41
42
43
44
45
46
47
48
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 41

def geometry
  if @point_array != @geometry_point_array
    @geometry_point_array = @point_array
    @geometry = Java::JavaAwtGeom::Path2D::Double.new
    @geometry.send(path_segment_geometry_method_name, *path_segment_geometry_args)
  end
  @geometry
end

#hashObject



96
97
98
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 96

def hash
  point_array.hash
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)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 55

def include?(x, y, filled: nil)
  filled = filled? if filled.nil?
  makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
  swt_path = org.eclipse.swt.graphics.Path.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
  the_path_segment_args = path_segment_args.dup
  if previous_point_connected?
    the_previous_path_segment = previous_path_segment
    swt_path.moveTo(the_previous_path_segment.x, the_previous_path_segment.y)
  else
    swt_path.moveTo(the_path_segment_args.shift, the_path_segment_args.shift)
  end
  swt_path.quadTo(*the_path_segment_args)
  swt_path.contains(x.to_f, y.to_f, makeshift_gc, !filled)
ensure
  swt_path.dispose
end

#move_by(x_delta, y_delta) ⇒ Object



72
73
74
75
76
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 72

def move_by(x_delta, y_delta)
  the_point_array = @args.compact
  the_point_array = the_point_array.first if the_point_array.first.is_a?(Array)
  self.point_array = the_point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
end

#parameter_namesObject



37
38
39
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 37

def parameter_names
  [:point_array]
end

#path_segment_argsObject



82
83
84
85
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 82

def path_segment_args
  # TODO make args auto-infer control points if previous_point_connected is true or if there is only a point_array with 1 point
  @args.to_a
end

#path_segment_method_nameObject



78
79
80
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 78

def path_segment_method_name
  'quadTo'
end

#previous_point_connected?Boolean



87
88
89
# File 'lib/glimmer/swt/custom/shape/quad.rb', line 87

def previous_point_connected?
  @args.compact.count <= 4 && !first_path_segment?
end