Module: Glimmer::LibUI::Transformable
- Included in:
- ControlProxy::AreaProxy, ControlProxy::ImageProxy, ControlProxy::PathProxy, ControlProxy::TextProxy
- Defined in:
- lib/glimmer/libui/control_proxy/transformable.rb
Overview
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
Instance Method Summary collapse
-
#apply_transform(area_draw_params) ⇒ Object
Apply transform matrix to coordinate system.
- #draw(area_draw_params) ⇒ Object
- #post_initialize_child(child, add_child: true) ⇒ Object
-
#transform(matrix = nil) ⇒ Object
(also: #transform=, #set_transform)
Returns transform or sets it.
-
#undo_transform(area_draw_params) ⇒ Object
Inverse of apply_transform (applies inverse transformation to undo initial transformation).
Instance Method Details
#apply_transform(area_draw_params) ⇒ Object
Apply transform matrix to coordinate system
54 55 56 |
# 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) ⇒ Object
67 68 69 70 71 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 |
# 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) ⇒ Object Also known as: transform=, set_transform
Returns transform or sets it. Expects transformable to implement redraw method (delegating work to area).
42 43 44 45 46 47 48 49 |
# File 'lib/glimmer/libui/control_proxy/transformable.rb', line 42 def transform(matrix = nil) if matrix.nil? @transform else @transform = matrix redraw end end |
#undo_transform(area_draw_params) ⇒ Object
Inverse of apply_transform (applies inverse transformation to undo initial transformation)
59 60 61 62 63 64 65 |
# 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 |