module Glimmer::LibUI::Transformable
This is meant to be prepended (not included) because it changes behavior of instance draw method Adds transform property to controls/shapes Automatically applies transform property at the beginning of draw operation and undoes it at the end Stacks up with Parent
module (must include Parent
beforehand) Expects transformable to implement redraw method
Public Instance Methods
apply_transform(area_draw_params)
click to toggle source
Apply transform matrix to coordinate system
# File lib/glimmer/libui/control_proxy/transformable.rb, line 54 def apply_transform(area_draw_params) ::LibUI.draw_transform(area_draw_params[:context], @transform.libui) unless @transform.nil? end
draw(area_draw_params)
click to toggle source
Calls superclass method
# File lib/glimmer/libui/control_proxy/transformable.rb, line 67 def draw(area_draw_params) apply_transform(area_draw_params) super(area_draw_params) undo_transform(area_draw_params) end
post_initialize_child(child, add_child: true)
click to toggle source
Calls superclass method
# File lib/glimmer/libui/control_proxy/transformable.rb, line 32 def post_initialize_child(child, add_child: true) if child.is_a?(ControlProxy::MatrixProxy) super(child, add_child: false) self.transform = child if child.keyword == 'transform' else super(child, add_child: add_child) end end
transform(matrix = nil)
click to toggle source
Returns transform or sets it. Expects transformable to implement redraw method (delegating work to area).
# File lib/glimmer/libui/control_proxy/transformable.rb, line 42 def transform(matrix = nil) if matrix.nil? @transform else @transform = matrix redraw end end
Also aliased as: transform=, set_transform
undo_transform(area_draw_params)
click to toggle source
Inverse of apply_transform
(applies inverse transformation to undo initial transformation)
# File lib/glimmer/libui/control_proxy/transformable.rb, line 59 def undo_transform(area_draw_params) unless @transform.nil? inverse_transform = @transform.clone inverse_transform.invert ::LibUI.draw_transform(area_draw_params[:context], inverse_transform.libui) end end