Class: Glimmer::SWT::Custom::Shape::Cubic

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

Constant Summary

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

String

Instance Attribute Summary

Attributes inherited from Path

#calculated_path_args, #path_segments, #swt_path

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

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

Instance Method Summary collapse

Methods inherited from Path

#add_shape, #bounds, #calculate_args!, #clear, #dispose, #height, #initialize, #irregular?, #path_segment_geometry_args, #post_dispose_content, #size, #width, #x, #y

Methods included from PathSegment

#add_to_geometry, #add_to_swt_path, #dispose, #first_path_segment?, #part_of_path?, #path, #path_segment_geometry_args, #previous_path_segment, #root_path

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

#absolute_x, #absolute_y, #add_shape, #all_parent_properties, #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_args!, #calculate_paint_args!, #calculated_args?, #calculated_args_changed!, #calculated_args_changed_for_defaults!, #calculated_height, #calculated_width, #calculated_x, #calculated_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?, #dispose, #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?, #has_attribute?, #has_some_background?, #has_some_foreground?, #height_delta, #height_delta=, #initialize, #inspect, #irregular?, 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, #respond_to?, #round?, #set_attribute, #set_data, #set_parameter_attribute, #size, #tolerate_shape_extra_args!, 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

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

Returns:

  • (Boolean)


52
53
54
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 52

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

#default_connected_path_segment_arg_countObject



93
94
95
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 93

def default_connected_path_segment_arg_count
  6
end

#default_path_segment_arg_countObject



89
90
91
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 89

def default_path_segment_arg_count
  8
end

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

Returns:

  • (Boolean)


105
106
107
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 105

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

#geometryObject



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

def geometry
  the_point_array = point_array
  if the_point_array != @geometry_point_array
    @geometry_point_array = the_point_array
    @geometry = Java::JavaAwtGeom::Path2D::Double.new
    add_to_geometry(@geometry)
  end
  @geometry
end

#hashObject



110
111
112
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 110

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)

Returns:

  • (Boolean)


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

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.curveTo(*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



74
75
76
77
78
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 74

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



38
39
40
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 38

def parameter_names
  [:point_array]
end

#path_segment_argsObject



84
85
86
87
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 84

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_geometry_method_nameObject



97
98
99
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 97

def path_segment_geometry_method_name
  'curveTo'
end

#path_segment_method_nameObject



80
81
82
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 80

def path_segment_method_name
  'cubicTo'
end

#previous_point_connected?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/glimmer/swt/custom/shape/cubic.rb', line 101

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