Class: Glimmer::SWT::Custom::Shape::Line

Inherits:
Glimmer::SWT::Custom::Shape show all
Includes:
PathSegment
Defined in:
lib/glimmer/swt/custom/shape/line.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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PathSegment

#add_to_swt_path, #dispose, #first_path_segment?, #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, #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

Class Method Details

.include?(x1, y1, x2, y2, x, y) ⇒ Boolean

Returns:

  • (Boolean)


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

def include?(x1, y1, x2, y2, x, y)
  distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
  distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2)
  distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
  (distance1 + distance2).to_i == distance.to_i
end

Instance Method Details

#absolute_x1Object



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

def absolute_x1
  if parent.is_a?(Shape)
    parent.absolute_x + x1
  else
    x1
  end
end

#absolute_x2Object



108
109
110
111
112
113
114
# File 'lib/glimmer/swt/custom/shape/line.rb', line 108

def absolute_x2
  if parent.is_a?(Shape)
    parent.absolute_x + x2.to_f
  else
    x2
  end
end

#absolute_y1Object



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

def absolute_y1
  if parent.is_a?(Shape)
    parent.absolute_y + y1
  else
    y1
  end
end

#absolute_y2Object



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

def absolute_y2
  if parent.is_a?(Shape)
    parent.absolute_y + y2.to_f
  else
    y2
  end
end

#boundsObject



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

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

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

Returns:

  • (Boolean)


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

def eql?(other)
  x1 == (other && other.respond_to?(:x1) && other.x1) &&
    y1 == (other && other.respond_to?(:y1) && other.y1) &&
    x2 == (other && other.respond_to?(:x2) && other.x2) &&
    y2 == (other && other.respond_to?(:y2) && other.y2)
end

#geometryObject



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

def geometry
  java.awt.geom.Line2D::Double.new(absolute_x1, absolute_y1, absolute_x2, absolute_y2)
end

#hashObject



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

def hash
  [x1, y1, x2, y2].hash
end

#heightObject



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

def height
  size.y
end

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

Returns:

  • (Boolean)


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

def include?(x, y)
  # TODO must account for line width
  Line.include?(absolute_x1, absolute_y1, absolute_x2, absolute_y2, x, y)
end

#irregular?Boolean

Returns:

  • (Boolean)


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

def irregular?
  true
end

#location_parameter_namesObject



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

def location_parameter_names
  parameter_names
end

#move_by(x_delta, y_delta) ⇒ Object



130
131
132
133
134
135
# File 'lib/glimmer/swt/custom/shape/line.rb', line 130

def move_by(x_delta, y_delta)
  self.x1 += x_delta
  self.y1 += y_delta
  self.x2 += x_delta
  self.y2 += y_delta
end

#parameter_namesObject



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

def parameter_names
  [:x1, :y1, :x2, :y2]
end

#path_segment_argsObject



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

def path_segment_args
  # TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point
  @args
end

#path_segment_geometry_argsObject



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

def path_segment_geometry_args
  # TODO make args auto-infer first point if previous_point_connected is true or if there is only x1,y1 or x2,y2 (but not both), or if there is an x, y, or if there is a point_array with 1 point
  @args[0..1]
end

#path_segment_method_nameObject



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

def path_segment_method_name
  'lineTo'
end

#previous_point_connected?Boolean

Returns:

  • (Boolean)


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

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

#sizeObject



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

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

#widthObject



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

def width
  size.x
end

#xObject

Logical x coordinate relative to parent



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

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

#yObject

Logical y coordinate relative to parent



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

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