Class: Glimmer::SWT::Custom::Shape::Rectangle

Inherits:
Glimmer::SWT::Custom::Shape show all
Defined in:
lib/glimmer/swt/custom/shape/rectangle.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, #bounds, #calculate_paint_args!, #calculated_args, #calculated_args?, #calculated_args_changed!, #calculated_args_changed_for_default_size!, #calculated_height, #calculated_width, #calculated_x, #calculated_y, #contain?, 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_parameter_names, #method_missing, method_name, #move_by, #paint, #paint_children, #paint_self, #parameter_name?, #parent_shape_absolute_location_changed?, #pattern, pattern, #pattern_args, #post_add_content, #respond_to?, #round?, #set_attribute, #set_parameter_attribute, #size, #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

#absolute_point_xy_arrayObject



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

def absolute_point_xy_array
  [[absolute_x, absolute_y], [absolute_x + calculated_width, absolute_y], [absolute_x + calculated_width, absolute_y + calculated_height], [absolute_x, absolute_y + calculated_height]]
end

#include?(x, y) ⇒ 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)



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

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

#parameter_index(attribute_name) ⇒ Object



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

def parameter_index(attribute_name)
  ####TODO refactor and improve this method through meta-programming (and share across other shapes)
  if rectangle_round_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    rectangle_round_parameter_names.map(&:to_s).index(attribute_name.to_s)
  elsif rectangle_gradient_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    rectangle_gradient_parameter_names.map(&:to_s).index(attribute_name.to_s)
  elsif rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    rectangle_parameter_names.map(&:to_s).index(attribute_name.to_s)
  elsif rectangle_rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
    rectangle_rectangle_parameter_names.map(&:to_s).index(attribute_name.to_s)
  end
end

#parameter_namesObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/glimmer/swt/custom/shape/rectangle.rb', line 36

def parameter_names
  # TODO consider optimizing just like text where it is set upon updating attribute and here you just return a variable
  if @args.to_a.size >= 6
    rectangle_round_parameter_names
  elsif @args.to_a.size == 5
    rectangle_gradient_parameter_names
  elsif @args.to_a.size == 1
    rectangle_rectangle_parameter_names
  else
    rectangle_parameter_names
  end
end

#point_xy_arrayObject



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

def point_xy_array
  [[x, y], [x + calculated_width, y], [x + calculated_width, y + calculated_height], [x, y + calculated_height]]
end

#possible_parameter_namesObject



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

def possible_parameter_names
  # TODO refactor and improve this method through meta-programming (and share across other shapes)
  (rectangle_round_parameter_names + rectangle_gradient_parameter_names + rectangle_parameter_names + rectangle_rectangle_parameter_names).uniq
end

#rectangle_gradient_parameter_namesObject



58
59
60
# File 'lib/glimmer/swt/custom/shape/rectangle.rb', line 58

def rectangle_gradient_parameter_names
  [:x, :y, :width, :height, :vertical]
end

#rectangle_parameter_namesObject



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

def rectangle_parameter_names
  [:x, :y, :width, :height]
end

#rectangle_rectangle_parameter_namesObject



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

def rectangle_rectangle_parameter_names
  # this receives a Rectangle object
  [:rectangle]
end

#rectangle_round_parameter_namesObject



54
55
56
# File 'lib/glimmer/swt/custom/shape/rectangle.rb', line 54

def rectangle_round_parameter_names
  [:x, :y, :width, :height, :arc_width, :arc_height]
end