Class: Glimmer::SWT::Custom::Shape::Polyline

Inherits:
Glimmer::SWT::Custom::Shape show all
Defined in:
lib/glimmer/swt/custom/shape/polyline.rb

Constant Summary

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

String

Instance Attribute Summary

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

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

Instance Method Summary collapse

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, #calculate_args!, #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?, #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?, #dispose, #drag_and_move, #drag_and_move=, #drag_source, #drag_source=, #draw?, drop_shapes, #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_with_children?, #initialize, #inspect, #inverse_transform_point, keywords, #location, #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?, #rotate, #rotation_angle, #round?, #set_attribute, #set_data, #set_parameter_attribute, #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

Dynamic Method Handling

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

Instance Method Details

#[](index) ⇒ Object



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

def [](index)
  point_array = args.size > 1 ? args : self.point_array
  index = 0 if index == point_count
  org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
end

#absolute_point_arrayObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 69

def absolute_point_array
  point_array = args.size > 1 ? args : self.point_array
  if parent.is_a?(Shape)
    point_array.each_with_index.map do |coordinate, i|
      if i.even?
        parent.absolute_x + coordinate
      else
        parent.absolute_y + coordinate
      end
    end
  else
    point_array
  end
end

#absolute_point_xy_arrayObject



92
93
94
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 92

def absolute_point_xy_array
  absolute_x_array.zip(absolute_y_array)
end

#absolute_x_arrayObject



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

def absolute_x_array
  absolute_point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
end

#absolute_y_arrayObject



88
89
90
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 88

def absolute_y_array
  absolute_point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
end

#boundsObject



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

def bounds
  shape_bounds = geometry.getBounds2D
  org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
end

#geometryObject



106
107
108
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 106

def geometry
  java.awt.Polygon.new(absolute_x_array.to_java(:int), absolute_y_array.to_java(:int), point_count)
end

#heightObject



128
129
130
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 128

def height
  bounds.height
end

#include?(x, y) ⇒ Boolean Also known as: contain?

Returns:

  • (Boolean)


132
133
134
135
136
137
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 132

def include?(x, y)
  x, y = inverse_transform_point(x, y)
  comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
  comparison_lines.pop # ignore last pair since you don't want to compare last point with first point
  comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
end

#irregular?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 144

def irregular?
  true
end

#location_parameter_namesObject



40
41
42
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 40

def location_parameter_names
  parameter_names
end

#move_by(x_delta, y_delta) ⇒ Object



140
141
142
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 140

def move_by(x_delta, y_delta)
  self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
end

#parameter_namesObject



36
37
38
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 36

def parameter_names
  [:point_array]
end

#point_countObject



44
45
46
47
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 44

def point_count
  point_array = args.size > 1 ? args : self.point_array
  point_array.count / 2
end

#point_xy_arrayObject



65
66
67
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 65

def point_xy_array
  x_array.zip(y_array)
end

#sizeObject



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

def size
  shape_bounds = geometry.getBounds2D
  org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
end

#widthObject



124
125
126
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 124

def width
  bounds.width
end

#xObject

Logical x coordinate relative to parent



111
112
113
114
115
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 111

def x
  x_value = bounds.x
  x_value -= parent.absolute_x if parent.is_a?(Shape)
  x_value
end

#x_arrayObject



55
56
57
58
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 55

def x_array
  point_array = args.size > 1 ? args : self.point_array
  point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
end

#yObject

Logical y coordinate relative to parent



118
119
120
121
122
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 118

def y
  y_value = bounds.y
  y_value -= parent.absolute_y if parent.is_a?(Shape)
  y_value
end

#y_arrayObject



60
61
62
63
# File 'lib/glimmer/swt/custom/shape/polyline.rb', line 60

def y_array
  point_array = args.size > 1 ? args : self.point_array
  point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
end