Class: Glimmer::SWT::Custom::Shape::Polygon

Inherits:
Glimmer::SWT::Custom::Shape show all
Defined in:
lib/glimmer/swt/custom/shape/polygon.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, #shapes

Instance Method Summary collapse

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, #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, keywords, #location, #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, #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

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



48
49
50
51
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 48

def [](index)
  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



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 65

def absolute_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



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

def absolute_point_xy_array
  absolute_x_array.zip(absolute_y_array)
end

#absolute_x_arrayObject



79
80
81
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 79

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

#absolute_y_arrayObject



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

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

#boundsObject



91
92
93
94
95
96
97
98
99
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 91

def bounds
  the_point_array = point_array
  if the_point_array != @bounds_point_array
    @bounds_point_array = point_array
    shape_bounds = geometry.getBounds2D
    @bounds = org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
  end
  @bounds
end

#contain?(x, y) ⇒ Boolean



142
143
144
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 142

def contain?(x, y)
  geometry.contains(x, y)
end

#geometryObject



111
112
113
114
115
116
117
118
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 111

def geometry
  the_point_array = point_array
  if the_point_array != @geometry_point_array
    @geometry_point_array = point_array
    @geometry = java.awt.Polygon.new(absolute_x_array.to_java(:int), absolute_y_array.to_java(:int), point_count)
  end
  @geometry
end

#heightObject



138
139
140
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 138

def height
  size.y
end

#include?(x, y) ⇒ Boolean



146
147
148
149
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 146

def include?(x, y)
  comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
  comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
end

#irregular?Boolean



155
156
157
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 155

def irregular?
  true
end

#location_parameter_namesObject



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

def location_parameter_names
  parameter_names
end

#move_by(x_delta, y_delta) ⇒ Object



151
152
153
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 151

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/polygon.rb', line 36

def parameter_names
  [:point_array]
end

#point_countObject



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

def point_count
  point_array.count / 2
end

#point_xy_arrayObject



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

def point_xy_array
  x_array.zip(y_array)
end

#sizeObject



101
102
103
104
105
106
107
108
109
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 101

def size
  the_point_array = point_array
  if the_point_array != @size_point_array
    @size_point_array = point_array
    shape_bounds = geometry.getBounds2D
    @size = org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
  end
  @size
end

#widthObject



134
135
136
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 134

def width
  size.x
end

#xObject

Logical x coordinate relative to parent



121
122
123
124
125
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 121

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

#x_arrayObject



53
54
55
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 53

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

#yObject

Logical y coordinate relative to parent



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

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

#y_arrayObject



57
58
59
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 57

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