class Glimmer::SWT::Custom::Shape
Represents a shape (graphics) to be drawn on a control/widget/canvas/display That is because Shape
is drawn on a parent as graphics and doesn't have an SWT
widget for itself
Constants
- String
Public Class Methods
create(parent, keyword, args, &property_block)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 40 def create(parent, keyword, args, &property_block) potential_shape_class_name = keyword.to_s.camelcase(:upper).to_sym if constants.include?(potential_shape_class_name) const_get(potential_shape_class_name).new(parent, args, &property_block) else new(parent, args, &property_block) end end
keywords()
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 54 def keywords constants.select do |constant| constant_value = const_get(constant) constant_value.respond_to?(:ancestors) && constant_value.ancestors.include?(Glimmer::SWT::Custom::Shape) end.map {|constant| constant.to_s.underscore} end
valid?(parent, keyword, args, &block)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 49 def valid?(parent, keyword, args, &block) return true if keyword.to_s == 'shape' keywords.include?(keyword.to_s) end
Public Instance Methods
attach(the_parent_dom_element)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 170 def attach(the_parent_dom_element) the_parent_dom_element.html("#{the_parent_dom_element.html()}\n#{@dom}") end
background=(value)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 63 def background=(value) value = ColorProxy.new(value) if value.is_a?(String) || value.is_a?(Symbol) @background = value dom_element.css('fill', background.to_css) unless background.nil? end
current_parameter_name?(attribute_name)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 107 def current_parameter_name?(attribute_name) parameter_names.include?(attribute_name.to_s.to_sym) end
dom()
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 178 def dom shape_id = id shape_class = name @dom ||= xml { g(id: shape_id, class: shape_class) { } }.to_s end
element()
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 174 def element 'g' end
foreground=(value)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 69 def foreground=(value) value = ColorProxy.new(value) if value.is_a?(String) || value.is_a?(Symbol) @foreground = value dom_element.css('stroke', foreground.to_css) unless foreground.nil? dom_element.css('fill', 'transparent') if background.nil? end
get_attribute(attribute_name)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 140 def get_attribute(attribute_name) if parameter_name?(attribute_name) arg_index = parameter_index(attribute_name) @args[arg_index] if arg_index elsif (respond_to?(attribute_name, super: true) and respond_to?(attribute_setter(attribute_name), super: true)) self.send(attribute_name) end end
get_parameter_attribute(attribute_name)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 115 def get_parameter_attribute(attribute_name) @args[parameter_index(attribute_getter(attribute_name))] end
has_attribute?(attribute_name, *args)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 123 def has_attribute?(attribute_name, *args) parameter_name?(attribute_name) or (respond_to?(attribute_name, super: true) and respond_to?(attribute_setter(attribute_name), super: true)) end
location_parameter_names()
click to toggle source
subclasses may override to specify location parameter names if different from x and y (e.g. all polygon points are location parameters) used in calculating movement changes
# File lib/glimmer/swt/custom/shape.rb, line 95 def location_parameter_names [:x, :y] end
method_missing(method_name, *args, &block)
click to toggle source
TODO look why image is not working with the method_missing
and respond_to? on shape
Calls superclass method
# File lib/glimmer/swt/custom/shape.rb, line 150 def method_missing(method_name, *args, &block) if method_name.to_s.end_with?('=') set_attribute(method_name, *args) elsif has_attribute?(method_name) && args.empty? get_attribute(method_name) else # TODO support proxying calls to handle_observation_request for listeners just like WidgetProxy super(method_name, *args, &block) end end
parameter_index(attribute_name)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 111 def parameter_index(attribute_name) parameter_names.index(attribute_name.to_s.to_sym) end
parameter_name?(attribute_name)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 103 def parameter_name?(attribute_name) possible_parameter_names.map(&:to_s).include?(attribute_getter(attribute_name)) end
parameter_names()
click to toggle source
parameter names for arguments to pass to SWT
GC.xyz method for rendering shape (e.g. draw_image(image, x, y) yields :image, :x, :y parameter names)
# File lib/glimmer/swt/custom/shape.rb, line 89 def parameter_names [:x, :y, :width, :height] end
possible_parameter_names()
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 99 def possible_parameter_names parameter_names end
post_add_content()
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 76 def post_add_content # TODO avoid rendering unless args changed from initialize args (due to setting of piecemeal attributes) render end
render(custom_parent_dom_element: nil, brand_new: false)
click to toggle source
Calls superclass method
# File lib/glimmer/swt/custom/shape.rb, line 81 def render(custom_parent_dom_element: nil, brand_new: false) super(custom_parent_dom_element: nil, brand_new: false) self.background = background self.foreground = foreground self.font = font end
respond_to?(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/glimmer/swt/custom/shape.rb, line 160 def respond_to?(method_name, *args, &block) options = args.last if args.last.is_a?(Hash) super_invocation = options && options[:super] if !super_invocation && has_attribute?(method_name) true else super(method_name, *args, &block) end end
set_attribute(attribute_name, *args)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 128 def set_attribute(attribute_name, *args) attribute_getter_name = attribute_getter(attribute_name) attribute_setter_name = attribute_setter(attribute_name) if parameter_name?(attribute_name) return if attribute_getter_name == (args.size == 1 ? args.first : args) set_parameter_attribute(attribute_getter_name, *args) elsif (respond_to?(attribute_name, super: true) and respond_to?(attribute_setter_name, super: true)) return if self.send(attribute_getter_name) == (args.size == 1 ? args.first : args) self.send(attribute_setter_name, *args) end end
set_parameter_attribute(attribute_name, *args)
click to toggle source
# File lib/glimmer/swt/custom/shape.rb, line 119 def set_parameter_attribute(attribute_name, *args) @args[parameter_index(attribute_getter(attribute_name))] = args.size == 1 ? args.first : args end