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, #content_added, #custom_control, #keyword, #libui, #parent_custom_control, #parent_proxy, #slot

Class Method Summary collapse

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, #bind_content, #can_handle_listener?, constant_symbol, #content, control_proxies, control_proxy_class, #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

Methods included from DataBindable

#data_bind, #data_bind_read, #data_bind_write, #data_binding_model_attribute_observer_registrations

Constructor Details

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

Returns a new instance of ImageProxy.



59
60
61
62
63
64
65
66
67
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 59

def initialize(keyword, parent, args, &block)
  @keyword = keyword
  @parent_proxy = parent
  @options = args.last.is_a?(Hash) ? args.pop : {}
  @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.



57
58
59
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 57

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



57
58
59
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 57

def options
  @options
end

#pixelsObject (readonly)

Returns the value of attribute pixels.



57
58
59
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 57

def pixels
  @pixels
end

#shapesObject (readonly)

Returns the value of attribute shapes.



57
58
59
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 57

def shapes
  @shapes
end

Class Method Details

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

creates or returns existing instance for passed in arguments if parent is nil and block is nil



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

def create(keyword, parent, args, &block)
  if parent.nil? && block.nil?
    instances[args] ||= new(keyword, parent, args.dup, &block)
  else
    new(keyword, parent, args, &block)
  end
end

.instancesObject



47
48
49
50
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 47

def instances
  @@instances = {} unless defined? @@instances
  @@instances
end

Instance Method Details

#area_image?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 178

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

#destroyObject



182
183
184
185
186
187
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 182

def destroy
  return if ControlProxy.main_window_proxy&.destroying?
  deregister_all_custom_listeners
  @parent_proxy&.children&.delete(self)
  ControlProxy.control_proxies.delete(self)
end

#draw(area_draw_params) ⇒ Object



169
170
171
172
173
174
175
176
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 169

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



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 83

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

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



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 147

def height(value = nil)
  if value.nil?
    @args.size > 3 ? @args[4] : (@options[:height] || @args[2])
  else
    set_height_variable(value)
    if area_image? && @content_added
      post_add_content
      request_auto_redraw
    end
  end
end

#post_add_contentObject



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

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
  else # image object not control
    build_control unless @content_added
    super
  end
end

#redrawObject



161
162
163
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 161

def redraw
  @parent_proxy&.redraw
end

#request_auto_redrawObject



165
166
167
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 165

def request_auto_redraw
  @parent_proxy&.request_auto_redraw if area_image?
end

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



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 133

def width(value = nil)
  if value.nil?
    @args.size > 3 ? @args[3] : (@options[:width] || @args[1])
  else
    set_width_variable(value)
    if area_image? && @content_added
      post_add_content
      request_auto_redraw
    end
  end
end

#x(value = nil) ⇒ Object Also known as: x=, set_x



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 97

def x(value = nil)
  if value.nil?
    @args.size > 3 ? @args[1] : (@options[:x] || 0)
  else
    if @args.size > 3
      @args[1] = value
    else
      @options[:x] = value
    end
    if area_image? && @content_added
      post_add_content
      request_auto_redraw
    end
  end
end

#y(value = nil) ⇒ Object Also known as: y=, set_y



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/glimmer/libui/control_proxy/image_proxy.rb', line 115

def y(value = nil)
  if value.nil?
    @args.size > 3 ? @args[2] : (@options[:y] || 0)
  else
    if @args.size > 3
      @args[2] = value
    else
      @options[:y] = value
    end
    if area_image? && @content_added
      post_add_content
      request_auto_redraw
    end
  end
end