Class: Glimmer::LibUI::ControlProxy::PathProxy

Inherits:
Glimmer::LibUI::ControlProxy show all
Includes:
Parent, Transformable
Defined in:
lib/glimmer/libui/control_proxy/path_proxy.rb

Overview

Proxy for LibUI path objects

Follows the Proxy Design Pattern

Constant Summary

Constants inherited from Glimmer::LibUI::ControlProxy

BOOLEAN_PROPERTIES, STRING_PROPERTIES, TransformProxy

Instance Attribute Summary

Attributes inherited from Glimmer::LibUI::ControlProxy

#args, #block, #keyword, #libui, #parent_proxy

Instance Method Summary collapse

Methods included from Parent

#children, #post_initialize_child

Methods included from Transformable

#apply_transform, #post_initialize_child, #transform, #undo_transform

Methods inherited from Glimmer::LibUI::ControlProxy

#append_properties, #append_property, #can_handle_listener?, constant_symbol, #content, control_proxies, create, #custom_listener_aliases, #custom_listeners, #default_destroy, descendant_keyword_constant_map, #destroy_child, #enabled, exists?, #handle_custom_listener, #handle_listener, #has_custom_listener?, image_proxies, keyword, #libui_api_keyword, main_window_proxy, map_descendant_keyword_constants_for, menu_proxies, #method_missing, new_control, #post_initialize_child, reset_descendant_keyword_constant_map, #respond_to?, #respond_to_libui?, #send_to_libui, #visible, widget_proxy_class, #window_proxy

Constructor Details

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

Returns a new instance of PathProxy.



37
38
39
40
41
42
43
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 37

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

Dynamic Method Handling

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

Instance Method Details

#destroyObject



136
137
138
139
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 136

def destroy
  @parent_proxy&.children&.delete(self)
  ControlProxy.control_proxies.delete(self)
end

#draw(area_draw_params) ⇒ Object



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

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_modeObject



62
63
64
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 62

def draw_fill_mode
  @args[0].is_a?(Integer) ? @args[0] : @args[0].to_s == 'alternate' ? 1 : 0
end

#draw_line_capObject



128
129
130
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 128

def draw_line_cap
  Glimmer::LibUI.enum_symbol_to_value(:draw_line_cap, @stroke && @stroke[:cap])
end

#draw_line_joinObject



132
133
134
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 132

def draw_line_join
  Glimmer::LibUI.enum_symbol_to_value(:draw_line_join, @stroke && @stroke[:join])
end

#draw_stroke_paramsObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 116

def draw_stroke_params
  @draw_stroke_params ||= ::LibUI::FFI::DrawStrokeParams.malloc
  @draw_stroke_params.Cap = draw_line_cap # flat
  @draw_stroke_params.Join = draw_line_join # miter
  @draw_stroke_params.Thickness = @stroke[:thickness] || 1
  @draw_stroke_params.MiterLimit = @stroke[:miter_limit] || 10 # DEFAULT_MITER_LIMIT
  @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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 66

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
    @fill = Glimmer::LibUI.interpret_color(args)
    @fill[:a] = 1.0 if @fill.is_a?(Hash) && @fill[:a].nil?
    @parent_proxy&.queue_redraw_all
  end
  @fill.tap do
    @fill_observer ||= Glimmer::DataBinding::Observer.proc do
      @parent_proxy&.queue_redraw_all
    end
    @fill_observer.observe(@fill)
  end
end

#fill_draw_brushObject



85
86
87
88
89
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 85

def fill_draw_brush
  @fill_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
  init_draw_brush(@fill_draw_brush, @fill)
  @fill_draw_brush
end

#post_add_contentObject



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

def post_add_content
  super
  if @parent_proxy.nil? && AreaProxy.current_area_draw_params
    draw(AreaProxy.current_area_draw_params)
    destroy
  end
end

#redrawObject



141
142
143
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 141

def redraw
  @parent_proxy&.queue_redraw_all
end

#stroke(*args) ⇒ Object Also known as: stroke=, set_stroke



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 91

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
    @stroke = Glimmer::LibUI.interpret_color(args)
    @stroke[:a] = 1.0 if @stroke.is_a?(Hash) && @stroke[:a].nil?
    @parent_proxy&.queue_redraw_all
  end
  @stroke.tap do
    @stroke_observer ||= Glimmer::DataBinding::Observer.proc do
      @parent_proxy&.queue_redraw_all
    end
    @stroke_observer.observe(@stroke)
  end
end

#stroke_draw_brushObject



110
111
112
113
114
# File 'lib/glimmer/libui/control_proxy/path_proxy.rb', line 110

def stroke_draw_brush
  @stroke_draw_brush ||= ::LibUI::FFI::DrawBrush.malloc
  init_draw_brush(@stroke_draw_brush, @stroke)
  @stroke_draw_brush
end