Class: Glimmer::LibUI::ControlProxy::ImageProxy

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

Overview

Proxy for LibUI image object and Glimmer custom control

Follows the Proxy Design Pattern

Constant Summary

Constants inherited from Glimmer::LibUI::ControlProxy

BOOLEAN_PROPERTIES, KEYWORD_ALIASES, STRING_PROPERTIES, TransformProxy

Instance Attribute Summary collapse

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) ⇒ ImageProxy

Returns a new instance of ImageProxy.



42
43
44
45
46
47
48
49
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 42

def initialize(keyword, parent, args, &block)
  @keyword = keyword
  @parent_proxy = parent
  @args = args
  @block = block
  @enabled = true
  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 Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



40
41
42
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 40

def data
  @data
end

#pixelsObject (readonly)

Returns the value of attribute pixels.



40
41
42
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 40

def pixels
  @pixels
end

#shapesObject (readonly)

Returns the value of attribute shapes.



40
41
42
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 40

def shapes
  @shapes
end

Instance Method Details

#area_image?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 125

def area_image?
  @area_image ||= !!(@parent_proxy&.is_a?(AreaProxy) || AreaProxy.current_area_draw_params)
end

#destroyObject



129
130
131
132
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 129

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

#draw(area_draw_params) ⇒ Object



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

def draw(area_draw_params)
  if @shapes.nil?
    load_image
    parse_pixels
    calculate_shapes
  end
  ImagePathRenderer.new(@parent_proxy, @shapes).render
end

#file(value = nil) ⇒ Object Also known as: file=, set_file



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 66

def file(value = nil)
  if value.nil?
    @args[0]
  else
    @args[0] = value
    if @content_added
      post_add_content
      request_auto_redraw
    end
  end
end

#height(value = nil) ⇒ Object Also known as: height=, set_height



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 94

def height(value = nil)
  if value.nil?
    @args[2]
  else
    @args[2] = value
    if area_image? && @content_added
      post_add_content
      request_auto_redraw
    end
  end
end

#post_add_contentObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 51

def post_add_content
  if area_image?
    @shapes = nil
    super
    if @parent_proxy.nil? && AreaProxy.current_area_draw_params
      draw(AreaProxy.current_area_draw_params)
      destroy
    end
    @content_added = true
  else # image object not control
    build_control
    super
  end
end

#redrawObject



108
109
110
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 108

def redraw
  @parent_proxy&.redraw
end

#request_auto_redrawObject



112
113
114
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 112

def request_auto_redraw
  @parent_proxy&.request_auto_redraw if area_image?
end

#width(value = nil) ⇒ Object Also known as: width=, set_width



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 80

def width(value = nil)
  if value.nil?
    @args[1]
  else
    @args[1] = value
    if area_image? && @content_added
      post_add_content
      request_auto_redraw
    end
  end
end