Class: Glimmer::SWT::Custom::Shape::Image

Inherits:
Glimmer::SWT::Custom::Shape show all
Defined in:
lib/glimmer/swt/custom/shape/image.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_delta, #default_x_delta=, #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?, #include?, #initialize, #inspect, keywords, #location_parameter_names, #method_missing, method_name, #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

#default_x?Boolean

Returns:

  • (Boolean)


81
82
83
84
# File 'lib/glimmer/swt/custom/shape/image.rb', line 81

def default_x?
  super ||
    current_parameter_name?(:dest_x) && (dest_x.nil? || dest_x.to_s == 'default')
end

#default_y?Boolean

Returns:

  • (Boolean)


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

def default_y?
  super ||
    current_parameter_name?(:dest_y) && (dest_y.nil? || dest_y.to_s == 'default')
end

#heightObject



77
78
79
# File 'lib/glimmer/swt/custom/shape/image.rb', line 77

def height
  dest_height || image.bounds.height
end

#image_part_parameter_namesObject



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

def image_part_parameter_names
  [:image, :src_x, :src_y, :src_width, :src_height, :dest_x, :dest_y, :dest_width, :dest_height]
end

#image_whole_parameter_namesObject



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

def image_whole_parameter_names
  [:image, :x, :y]
end

#move_by(x_delta, y_delta) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/glimmer/swt/custom/shape/image.rb', line 91

def move_by(x_delta, y_delta)
  if default_x?
    self.default_x_delta += x_delta
  elsif dest_x
    self.dest_x += x_delta
  else
    self.x += x_delta
  end
  
  if default_y?
    self.default_y_delta += y_delta
  elsif dest_y
    self.dest_y += y_delta
  else
    self.y += y_delta
  end
end

#parameter_index(attribute_name) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/glimmer/swt/custom/shape/image.rb', line 56

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

#parameter_namesObject



36
37
38
39
40
41
42
# File 'lib/glimmer/swt/custom/shape/image.rb', line 36

def parameter_names
  if @args.to_a.size > 3
    image_part_parameter_names
  else
    image_whole_parameter_names
  end
end

#possible_parameter_namesObject



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

def possible_parameter_names
  (image_part_parameter_names + image_whole_parameter_names).uniq
end

#widthObject



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

def width
  dest_width || image.bounds.width
end

#xObject



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

def x
  dest_x || get_attribute('x')
end

#yObject



69
70
71
# File 'lib/glimmer/swt/custom/shape/image.rb', line 69

def y
  dest_y || get_attribute('y')
end