Class: Glimmer::LibUI::Shape

Inherits:
Object
  • Object
show all
Includes:
Parent
Defined in:
lib/glimmer/libui/shape.rb,
lib/glimmer/libui/shape/arc.rb,
lib/glimmer/libui/shape/line.rb,
lib/glimmer/libui/shape/bezier.rb,
lib/glimmer/libui/shape/circle.rb,
lib/glimmer/libui/shape/figure.rb,
lib/glimmer/libui/shape/square.rb,
lib/glimmer/libui/shape/rectangle.rb

Overview

Represents LibUI lightweight shape objects nested under path (e.g. line, rectangle, arc, bezier)

Direct Known Subclasses

Arc, Bezier, Circle, Figure, Line, Rectangle, Square

Defined Under Namespace

Classes: Arc, Bezier, Circle, Figure, Line, Rectangle, Square

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parent

#children, #post_initialize_child

Constructor Details

#initialize(keyword, parent, args, &block) ⇒ Shape

Returns a new instance of Shape.



70
71
72
73
74
75
76
77
# File 'lib/glimmer/libui/shape.rb', line 70

def initialize(keyword, parent, args, &block)
  @keyword = keyword
  @parent = parent
  @args = args
  @block = block
  set_parameter_defaults
  post_add_content if @block.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/glimmer/libui/shape.rb', line 110

def method_missing(method_name, *args, &block)
  method_name_parameter = method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym
  if self.class.parameters.include?(method_name_parameter)
    method_name = method_name.to_s
    parameter_index = self.class.parameters.index(method_name_parameter)
    if method_name.start_with?('set_') || method_name.end_with?('=') || !args.empty?
      @args[parameter_index] = args.first
      area_proxy&.queue_redraw_all
    else
      @args[parameter_index]
    end
  else
    super
  end
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



68
69
70
# File 'lib/glimmer/libui/shape.rb', line 68

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



68
69
70
# File 'lib/glimmer/libui/shape.rb', line 68

def block
  @block
end

#keywordObject (readonly)

Returns the value of attribute keyword.



68
69
70
# File 'lib/glimmer/libui/shape.rb', line 68

def keyword
  @keyword
end

#parentObject (readonly)

Returns the value of attribute parent.



68
69
70
# File 'lib/glimmer/libui/shape.rb', line 68

def parent
  @parent
end

Class Method Details

.constant_symbol(keyword) ⇒ Object



61
62
63
# File 'lib/glimmer/libui/shape.rb', line 61

def constant_symbol(keyword)
  "#{keyword.camelcase(:upper)}".to_sym
end

.create(keyword, parent, args, &block) ⇒ Object



37
38
39
# File 'lib/glimmer/libui/shape.rb', line 37

def create(keyword, parent, args, &block)
  shape_class(keyword).new(keyword, parent, args, &block)
end

.exists?(keyword) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/glimmer/libui/shape.rb', line 31

def exists?(keyword)
  Shape.constants.include?(constant_symbol(keyword)) and
    shape_class(keyword).respond_to?(:ancestors) and
    shape_class(keyword).ancestors.include?(Shape)
end

.parameter_defaults(*defaults) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/glimmer/libui/shape.rb', line 53

def parameter_defaults(*defaults)
  if defaults.empty?
    @parameter_defaults
  else
    @parameter_defaults = defaults
  end
end

.parameters(*params) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/glimmer/libui/shape.rb', line 45

def parameters(*params)
  if params.empty?
    @parameters
  else
    @parameters = params
  end
end

.shape_class(keyword) ⇒ Object



41
42
43
# File 'lib/glimmer/libui/shape.rb', line 41

def shape_class(keyword)
  Shape.const_get(constant_symbol(keyword))
end

Instance Method Details

#area_proxyObject



97
98
99
# File 'lib/glimmer/libui/shape.rb', line 97

def area_proxy
  find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::AreaProxy) }
end

#destroyObject



93
94
95
# File 'lib/glimmer/libui/shape.rb', line 93

def destroy
  @parent.children.delete(self)
end

#draw(area_draw_params) ⇒ Object

Subclasses must override to perform draw work and call super afterwards to ensure calling destroy when semi-declarative in an on_draw method



85
86
87
# File 'lib/glimmer/libui/shape.rb', line 85

def draw(area_draw_params)
  destroy if area_proxy.nil?
end

#path_proxyObject



101
102
103
# File 'lib/glimmer/libui/shape.rb', line 101

def path_proxy
  find_parent_in_ancestors { |parent| parent.nil? || parent.is_a?(ControlProxy::PathProxy) }
end

#post_add_contentObject

Subclasses may override to perform post add_content work (normally must call super)



80
81
82
# File 'lib/glimmer/libui/shape.rb', line 80

def post_add_content
  @parent&.post_initialize_child(self)
end

#redrawObject



89
90
91
# File 'lib/glimmer/libui/shape.rb', line 89

def redraw
  area_proxy&.queue_redraw_all
end

#respond_to?(method_name, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/glimmer/libui/shape.rb', line 105

def respond_to?(method_name, *args, &block)
  self.class.parameters.include?(method_name.to_s.sub(/=$/, '').sub(/^set_/, '').to_sym) or
    super(method_name, true)
end