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, #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_width, #calculated_x, #calculated_y, #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, #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, 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



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

Returns:

  • (Boolean)


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

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



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

def height
  size.y
end

#include?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


158
159
160
161
162
163
164
165
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 158

def include?(x, y)
  if filled?
    contain?(x, y)
  else
    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
end

#irregular?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 171

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



167
168
169
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 167

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



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

def width
  size.x
end

#xObject

Logical x coordinate relative to parent



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 121

def x
  x_dependencies = [bounds.x, parent.is_a?(Shape) && parent.absolute_x]
  if x_dependencies != @x_dependencies
    # avoid recalculating values
    bounds_x, parent_absolute_x = @x_dependencies = x_dependencies
    x_value = bounds_x
    x_value -= parent_absolute_x if parent.is_a?(Shape)
    @x = x_value
  end
  @x
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



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/glimmer/swt/custom/shape/polygon.rb', line 134

def y
  y_dependencies = [bounds.y, parent.is_a?(Shape) && parent.absolute_y]
  if y_dependencies != @y_dependencies
    # avoid recalculating values
    bounds_y, parent_absolute_y = @y_dependencies = y_dependencies
    y_value = bounds_y
    y_value -= parent_absolute_y if parent.is_a?(Shape)
    @y = y_value
  end
  @y
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