Class: Glimmer::LibUI::Shape::Figure

Inherits:
Glimmer::LibUI::Shape show all
Defined in:
lib/glimmer/libui/shape/figure.rb

Overview

Represents a figure consisting of shapes (nested under path) Can optionally have ‘closed true` property (connecting last point to first point automatically)

Constant Summary

Constants inherited from Glimmer::LibUI::Shape

KEYWORD_ALIASES

Instance Attribute Summary

Attributes inherited from Glimmer::LibUI::Shape

#args, #block, #content_added, #keyword, #parent

Instance Method Summary collapse

Methods inherited from Glimmer::LibUI::Shape

#absolute_c1_x, #absolute_c1_y, #absolute_c2_x, #absolute_c2_y, #absolute_end_x, #absolute_end_y, #absolute_point_array, #absolute_x, #absolute_x_center, #absolute_y, #absolute_y_center, #area_proxy, #can_handle_listener?, #composite_shape, constant_symbol, #content, create, #destroy, exists?, #fill, #handle_listener, #implicit_path?, #initialize, #method_missing, parameter_defaults, parameters, #path_proxy, #post_add_content, #post_initialize_child, #redraw, #request_auto_redraw, #respond_to?, shape_class, #stroke, #transform

Methods included from DataBindable

#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations

Methods included from PerfectShaped

#bounding_box, #contain?, #include?, #move

Methods included from Parent

#children, #post_initialize_child

Constructor Details

This class inherits a constructor from Glimmer::LibUI::Shape

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::LibUI::Shape

Instance Method Details

#closed(value = nil) ⇒ Object Also known as: closed=, set_closed, closed?



40
41
42
43
44
45
46
47
48
49
# File 'lib/glimmer/libui/shape/figure.rb', line 40

def closed(value = nil)
  if value.nil?
    @closed
  else
    if !!value != !!@closed
      @closed = value
      request_auto_redraw
    end
  end
end

#draw(area_draw_params) ⇒ Object



33
34
35
36
37
38
# File 'lib/glimmer/libui/shape/figure.rb', line 33

def draw(area_draw_params)
  ::LibUI.draw_path_new_figure(path_proxy.libui, *@args) unless @args.compact.empty? # TODO if args empty then wait till there is an arc child and it starts the figure
  children.dup.each {|child| child.draw(area_draw_params)}
  ::LibUI.draw_path_close_figure(path_proxy.libui) if closed?
  super
end

#move_by(x_delta, y_delta) ⇒ Object



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

def move_by(x_delta, y_delta)
  self.x += x_delta
  self.y += y_delta
  children.each {|child| child.move_by(x_delta, y_delta)}
end

#perfect_shapeObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/glimmer/libui/shape/figure.rb', line 60

def perfect_shape
  require 'perfect-shape'
  the_perfect_shape_dependencies = perfect_shape_dependencies
  if the_perfect_shape_dependencies != @perfect_shape_dependencies
    absolute_x, absolute_y, closed, draw_fill_mode, children = @perfect_shape_dependencies = the_perfect_shape_dependencies
    path_shapes = [[absolute_x, absolute_y]]
    path_shapes += children.map(&:perfect_shape)
    winding_rule = draw_fill_mode == :winding ? :wind_non_zero : :wind_even_odd
    @perfect_shape = PerfectShape::Path.new(
      closed: closed,
      winding_rule: winding_rule,
      shapes: path_shapes,
      line_to_complex_shapes: true
    )
  end
  @perfect_shape
end

#perfect_shape_dependenciesObject



78
79
80
# File 'lib/glimmer/libui/shape/figure.rb', line 78

def perfect_shape_dependencies
  [absolute_x, absolute_y, closed, parent.draw_fill_mode, children]
end