Class: Glimmer::LibUI::ControlProxy::PathProxy
  
  
  
Overview
  
    
Proxy for LibUI path objects
Follows the Proxy Design Pattern
   
 
  
  Constant Summary
  
  
  BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy
  Instance Attribute Summary
  
  
  #args, #block, #content_added, #custom_control, #keyword, #libui, #options, #parent_custom_control, #parent_proxy, #slot
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #bounding_box, #contain?, #include?, #move
  
  
  
  
  
  
  
  
  
  Methods included from Parent
  #children, #post_initialize_child
  
  
  
  
  
  
  
  
  
  #apply_transform, #post_initialize_child, #transform, #undo_transform
  
  
  
  
  
  
  
  
  
  #append_properties, #append_property, #bind_content, #can_handle_listener?, constant_symbol, #content, control_proxies, control_proxy_class, create, #custom_listener_name_aliases, #custom_listener_names, #default_destroy, #deregister_all_custom_listeners, #deregister_custom_listeners, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #handle_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, #listeners, #listeners_for, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #notify_custom_listeners, #post_initialize_child, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, #window_proxy
  
  
  
  
  
  
  
  
  
  #data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations
  Constructor Details
  
    
  
  
    #initialize(keyword, parent, args, &block)  ⇒ PathProxy 
  
  
  
  
    
Returns a new instance of PathProxy.
   
 
  
  
    
      
39
40
41
42
43
44
45 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 39
def initialize(keyword, parent, args, &block)
  @keyword = keyword
  @parent_proxy = parent
  @args = args
  @block = block
  post_add_content if @block.nil?
end 
     | 
  
 
  
 
  
    Instance Method Details
    
      
    
      
  
  
    #draw(area_draw_params)  ⇒ Object 
  
  
  
  
    
      
55
56
57
58
59
60
61
62 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 55
def draw(area_draw_params)
  build_control
  children.dup.each {|child| child.draw(area_draw_params)}
  ::LibUI.draw_path_end(@libui)
  ::LibUI.draw_fill(area_draw_params[:context], @libui, fill_draw_brush.to_ptr) unless fill.empty?
  ::LibUI.draw_stroke(area_draw_params[:context], @libui, stroke_draw_brush, draw_stroke_params) unless stroke.empty?
  ::LibUI.draw_free_path(@libui)
end
     | 
  
 
    
      
  
  
    #draw_fill_mode  ⇒ Object 
  
  
  
  
    
      
64
65
66 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 64
def draw_fill_mode
  @args[0].is_a?(Integer) ? (@args[0] == 0 ? :winding : :alternate ) : ((@args[0].is_a?(String) || @args[0].is_a?(Symbol)) ? @args[0].to_sym : :winding)
end 
     | 
  
 
    
      
  
  
    #draw_fill_mode_value  ⇒ Object 
  
  
  
  
    
      
68
69
70 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 68
def draw_fill_mode_value
  @args[0].is_a?(Integer) ? @args[0] : @args[0].to_s == 'alternate' ? 1 : 0
end 
     | 
  
 
    
      
  
  
    #draw_line_cap  ⇒ Object 
  
  
  
  
    
      
142
143
144 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 142
def draw_line_cap
  Glimmer::LibUI.enum_symbol_to_value(:draw_line_cap, @stroke && @stroke[:cap])
end 
     | 
  
 
    
      
  
  
    #draw_line_join  ⇒ Object 
  
  
  
  
    
      
146
147
148 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 146
def draw_line_join
  Glimmer::LibUI.enum_symbol_to_value(:draw_line_join, @stroke && @stroke[:join])
end 
     | 
  
 
    
      
  
  
    #draw_stroke_params  ⇒ Object 
  
  
  
  
    
      
130
131
132
133
134
135
136
137
138
139
140 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 130
def draw_stroke_params
  @draw_stroke_params ||= ::LibUI::FFI::DrawStrokeParams.malloc
  @draw_stroke_params.Cap = draw_line_cap   @draw_stroke_params.Join = draw_line_join   @draw_stroke_params.Thickness = @stroke[:thickness] || 1
  @draw_stroke_params.MiterLimit = @stroke[:miter_limit] || 10   @draw_stroke_params.Dashes = @stroke[:dashes].to_a.pack('d*')
  @draw_stroke_params.NumDashes = @stroke[:dashes].to_a.count
  @draw_stroke_params.DashPhase = @stroke[:dash_phase] || 0
  @draw_stroke_params
end
     | 
  
 
    
      
  
  
    #fill(*args)  ⇒ Object 
  
  
    Also known as:
    fill=, set_fill
    
  
  
  
    
      
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 72
def fill(*args)
  args = args.first if args.size == 1 && (args.first.is_a?(Array) || args.first.is_a?(Hash) || args.first.is_a?(String) || args.first.is_a?(Symbol))
  if args.empty?
    @fill ||= {}
  else
    new_color = Glimmer::LibUI.interpret_color(args)
    if new_color != @fill
            @fill_observer&.unobserve(@fill, attribute_writer_type: [:attribute=, :set_attribute]) if @fill
      @fill = new_color
      request_auto_redraw
    end
  end
  @fill.tap do
    @fill_observer ||= Glimmer::DataBinding::Observer.proc do
      request_auto_redraw
    end
    @fill_observer.observe(@fill, attribute_writer_type: [:attribute=, :set_attribute])
  end
end
     | 
  
 
    
      
  
  
    #fill_draw_brush  ⇒ Object 
  
  
  
  
    
      
95
96
97
98
99 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 95
def fill_draw_brush
  @fill_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
  init_draw_brush(@fill_draw_brush, @fill)
  @fill_draw_brush
end 
     | 
  
 
    
      
  
  
    #move_by(x_delta, y_delta)  ⇒ Object 
  
  
  
  
    
      
165
166
167 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 165
def move_by(x_delta, y_delta)
  children.each {|child| child.move_by(x_delta, y_delta)}
end
     | 
  
 
    
      
  
  
    #perfect_shape  ⇒ Object 
  
  
  
  
    
      
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 169
def perfect_shape
  require 'perfect-shape'
  the_perfect_shape_dependencies = perfect_shape_dependencies
  if the_perfect_shape_dependencies != @perfect_shape_dependencies
    draw_fill_mode, _ = @perfect_shape_dependencies = the_perfect_shape_dependencies
    shapes = children.map(&:perfect_shape)
    new_shapes = []
    shapes.each do |shape|
      if shape.is_a?(PerfectShape::Path)
        new_shapes += shape.basic_shapes
      else
        new_shapes << shape
      end
    end
    shapes = new_shapes
    winding_rule = draw_fill_mode == :winding ? :wind_non_zero : :wind_even_odd
    @perfect_shape = PerfectShape::Path.new(
      shapes: shapes,
      winding_rule: winding_rule,
      line_to_complex_shapes: true
    )
  end
  @perfect_shape
end
     | 
  
 
    
      
  
  
    #perfect_shape_dependencies  ⇒ Object 
  
  
  
  
    
      
194
195
196 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 194
def perfect_shape_dependencies
  [draw_fill_mode, children.map(&:perfect_shape_dependencies)]
end 
     | 
  
 
    
      
  
  
    #post_add_content  ⇒ Object 
  
  
  
 
    
      
  
  
    #redraw  ⇒ Object 
  
  
  
  
    
      
157
158
159 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 157
def redraw
  @parent_proxy&.redraw
end 
     | 
  
 
    
      
  
  
    #request_auto_redraw  ⇒ Object 
  
  
  
  
    
      
161
162
163 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 161
def request_auto_redraw
  @parent_proxy&.request_auto_redraw
end 
     | 
  
 
    
      
  
  
    #stroke(*args)  ⇒ Object 
  
  
    Also known as:
    stroke=, set_stroke
    
  
  
  
    
      
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 101
def stroke(*args)
  args = args.first if args.size == 1 && (args.first.is_a?(Array) || args.first.is_a?(Hash) || args.first.is_a?(String) || args.first.is_a?(Symbol))
  if args.empty?
    @stroke ||= {}
  else
    new_color = Glimmer::LibUI.interpret_color(args)
    if new_color != @stroke
            @stroke_observer&.unobserve(@stroke, attribute_writer_type: [:attribute=, :set_attribute]) if @stroke
      @stroke = Glimmer::LibUI.interpret_color(args)
      request_auto_redraw
    end
  end
  @stroke.tap do
    @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
      request_auto_redraw
    end
    @stroke_observer.observe(@stroke, attribute_writer_type: [:attribute=, :set_attribute])
  end
end
     | 
  
 
    
      
  
  
    #stroke_draw_brush  ⇒ Object 
  
  
  
  
    
      
124
125
126
127
128 
     | 
    
      # File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 124
def stroke_draw_brush
  @stroke_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
  init_draw_brush(@stroke_draw_brush, @stroke)
  @stroke_draw_brush
end 
     |