class Glimmer::LibUI::ControlProxy::AreaProxy
Proxy for LibUI
area objects
Follows the Proxy Design Pattern
Constants
- CUSTOM_LISTENER_NAMES
- CUSTOM_LISTENER_NAME_ALIASES
- DragBroken
- Draw
- KeyEvent
- MouseCrossed
- MouseEvent
- SHIFTED_KEY_CODE_CHARS
Attributes
current_area_draw_params[RW]
this attribute is only populated during on_draw call
area_handler[R]
Public Instance Methods
auto_redraw_enabled(value = nil)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 120 def auto_redraw_enabled(value = nil) if value.nil? @auto_redraw_enabled = true if @auto_redraw_enabled.nil? @auto_redraw_enabled else @auto_redraw_enabled = !!value end end
draw(area_draw_params)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 106 def draw(area_draw_params) children.dup.each {|child| child.draw(area_draw_params)} notify_custom_listeners('on_draw', area_draw_params) end
libui_api_keyword()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 83 def libui_api_keyword 'area' end
pause_auto_redraw()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 132 def pause_auto_redraw self.auto_redraw_enabled = false end
post_add_content()
click to toggle source
Calls superclass method
Glimmer::LibUI::ControlProxy#post_add_content
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 87 def post_add_content if OS.linux? && parent_proxy.is_a?(WindowProxy) unless @content_added original_parent_proxy = @parent_proxy @vertical_box_parent_proxy = ControlProxy.create('vertical_box', parent_proxy, []) {} # block prevents calling post add content append_properties.each do |property| @vertical_box_parent_proxy.append_property(property, append_property(property)) end @vertical_box_parent_proxy.post_add_content @parent_proxy = @vertical_box_parent_proxy @vertical_box_parent_proxy.post_initialize_child(self) @content_added = true end else super end install_listeners end
redraw()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 111 def redraw queue_redraw_all end
request_auto_redraw()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 115 def request_auto_redraw # TODO implement functionality to delay queuing area redraws until post_add_content has been called (area definition is done). Maybe offer an option to enable redrawing before area is closed too. queue_redraw_all if auto_redraw_enabled? end
resume_auto_redraw()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 136 def resume_auto_redraw self.auto_redraw_enabled = true end
Private Instance Methods
area_draw_params_hash(area_draw_params)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 196 def area_draw_params_hash(area_draw_params) { context: area_draw_params.Context, area_width: area_draw_params.AreaWidth, area_height: area_draw_params.AreaHeight, clip_x: area_draw_params.ClipX, clip_y: area_draw_params.ClipY, clip_width: area_draw_params.ClipWidth, clip_height: area_draw_params.ClipHeight, } end
area_key_event_hash(area_key_event)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 222 def area_key_event_hash(area_key_event) modifiers = modifiers_to_symbols(area_key_event.Modifiers) { key: key_to_char(area_key_event.Key, modifiers), key_value: area_key_event.Key, key_code: area_key_event.Key, ext_key: ext_key_to_symbol(area_key_event.ExtKey), ext_key_value: area_key_event.ExtKey, modifier: modifiers_to_symbols(area_key_event.Modifier).first, modifiers: modifiers, up: Glimmer::LibUI.integer_to_boolean(area_key_event.Up), } end
area_mouse_event_hash(area_mouse_event)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 208 def area_mouse_event_hash(area_mouse_event) { x: area_mouse_event.X, y: area_mouse_event.Y, area_width: area_mouse_event.AreaWidth, area_height: area_mouse_event.AreaHeight, down: area_mouse_event.Down, up: area_mouse_event.Up, count: area_mouse_event.Count, modifers: modifiers_to_symbols(area_mouse_event.Modifiers), held: area_mouse_event.Held1To64, } end
build_control()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 142 def build_control @area_handler = ::LibUI::FFI::AreaHandler.malloc @libui = ::LibUI.new_area(@area_handler) end
ext_key_to_symbol(ext_key_value)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 247 def ext_key_to_symbol(ext_key_value) Glimmer::LibUI.enum_value_to_symbol(:ext_key, ext_key_value) end
extract_symbol_from_modifiers_value(modifiers_value, symbols: )
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 257 def extract_symbol_from_modifiers_value(modifiers_value, symbols: ) if modifiers_value >= 8 symbols << :command modifiers_value -= 8 elsif modifiers_value >= 4 symbols << :shift modifiers_value -= 4 elsif modifiers_value >= 2 symbols << :alt modifiers_value -= 2 elsif modifiers_value >= 1 symbols << :control modifiers_value -= 1 end end
install_listeners()
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 147 def install_listeners unless @listeners_installed @area_handler.Draw = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_draw_params| area_draw_params = ::LibUI::FFI::AreaDrawParams.new(area_draw_params) area_draw_params = area_draw_params_hash(area_draw_params) AreaProxy.current_area_draw_params = area_draw_params draw(area_draw_params) AreaProxy.current_area_draw_params = nil end @area_handler.MouseEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_mouse_event| area_mouse_event = ::LibUI::FFI::AreaMouseEvent.new(area_mouse_event) area_mouse_event = area_mouse_event_hash(area_mouse_event) notify_custom_listeners('on_mouse_event', area_mouse_event) notify_custom_listeners('on_mouse_move', area_mouse_event) if area_mouse_event[:x].between?(0, area_mouse_event[:area_width]) && area_mouse_event[:y].between?(0, area_mouse_event[:area_height]) unless @last_area_mouse_event.nil? notify_custom_listeners('on_mouse_down', area_mouse_event) if area_mouse_event[:down] > 0 && @last_area_mouse_event[:down] == 0 notify_custom_listeners('on_mouse_up', area_mouse_event) if area_mouse_event[:up] > 0 && @last_area_mouse_event[:up] == 0 notify_custom_listeners('on_mouse_drag_start', area_mouse_event) if area_mouse_event[:held] > 0 && @last_area_mouse_event[:held] == 0 notify_custom_listeners('on_mouse_drag', area_mouse_event) if area_mouse_event[:held] > 0 notify_custom_listeners('on_mouse_drop', area_mouse_event) if area_mouse_event[:held] == 0 && @last_area_mouse_event[:held] > 0 end @last_area_mouse_event = area_mouse_event end @area_handler.MouseCrossed = fiddle_closure_block_caller(0, [1, 1, 4]) do |_, _, left| left = Glimmer::LibUI.integer_to_boolean(left) notify_custom_listeners('on_mouse_crossed', left) if left notify_custom_listeners('on_mouse_exit', left) else notify_custom_listeners('on_mouse_enter', left) end end @area_handler.DragBroken = fiddle_closure_block_caller(0, [1, 1]) do |_, _| notify_custom_listeners('on_drag_broken') end @area_handler.KeyEvent = fiddle_closure_block_caller(0, [1, 1, 1]) do |_, _, area_key_event| area_key_event = ::LibUI::FFI::AreaKeyEvent.new(area_key_event) area_key_event = area_key_event_hash(area_key_event) notify_custom_listeners('on_key_event', area_key_event) if area_key_event[:up] notify_custom_listeners('on_key_up', area_key_event) else notify_custom_listeners('on_key_down', area_key_event) end end @listeners_installed = true end end
key_to_char(key, modifiers = [])
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 236 def key_to_char(key, modifiers = []) if key > 0 char = key.chr if modifiers == [:shift] SHIFTED_KEY_CODE_CHARS[char] else char end end end
modifiers_to_symbols(modifiers_value)
click to toggle source
# File lib/glimmer/libui/control_proxy/area_proxy.rb, line 251 def modifiers_to_symbols(modifiers_value) symbols = [] modifiers_value = extract_symbol_from_modifiers_value(modifiers_value, symbols: symbols) while modifiers_value > 0 symbols end