Class: Engine::Components::UI::Rect
- Inherits:
-
Engine::Component
- Object
- Engine::Component
- Engine::Components::UI::Rect
- Defined in:
- lib/engine/components/ui/rect.rb
Instance Attribute Summary collapse
-
#bottom_offset ⇒ Object
readonly
Returns the value of attribute bottom_offset.
-
#bottom_ratio ⇒ Object
readonly
Returns the value of attribute bottom_ratio.
-
#flex_align ⇒ Object
readonly
Returns the value of attribute flex_align.
-
#flex_height ⇒ Object
readonly
Returns the value of attribute flex_height.
-
#flex_weight ⇒ Object
readonly
Returns the value of attribute flex_weight.
-
#flex_width ⇒ Object
readonly
Returns the value of attribute flex_width.
-
#left_offset ⇒ Object
readonly
Returns the value of attribute left_offset.
-
#left_ratio ⇒ Object
readonly
Returns the value of attribute left_ratio.
-
#mask ⇒ Object
readonly
Returns the value of attribute mask.
-
#right_offset ⇒ Object
readonly
Returns the value of attribute right_offset.
-
#right_ratio ⇒ Object
readonly
Returns the value of attribute right_ratio.
-
#top_offset ⇒ Object
readonly
Returns the value of attribute top_offset.
-
#top_ratio ⇒ Object
readonly
Returns the value of attribute top_ratio.
Attributes inherited from Engine::Component
Class Method Summary collapse
Instance Method Summary collapse
- #ancestor_masks ⇒ Object
- #awake ⇒ Object
- #computed_rect ⇒ Object
- #destroy ⇒ Object
- #parent_rect ⇒ Object
- #screen_rect ⇒ Object
- #start ⇒ Object
- #z_layer ⇒ Object
- #z_layer=(value) ⇒ Object
Methods inherited from Engine::Component
#_erase!, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #ui_renderer?, #update
Methods included from Serializable
allowed_class?, get_class, included, register_class, #uuid
Instance Attribute Details
#bottom_offset ⇒ Object (readonly)
Returns the value of attribute bottom_offset.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def bottom_offset @bottom_offset end |
#bottom_ratio ⇒ Object (readonly)
Returns the value of attribute bottom_ratio.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def bottom_ratio @bottom_ratio end |
#flex_align ⇒ Object (readonly)
Returns the value of attribute flex_align.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def flex_align @flex_align end |
#flex_height ⇒ Object (readonly)
Returns the value of attribute flex_height.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def flex_height @flex_height end |
#flex_weight ⇒ Object (readonly)
Returns the value of attribute flex_weight.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def flex_weight @flex_weight end |
#flex_width ⇒ Object (readonly)
Returns the value of attribute flex_width.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def flex_width @flex_width end |
#left_offset ⇒ Object (readonly)
Returns the value of attribute left_offset.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def left_offset @left_offset end |
#left_ratio ⇒ Object (readonly)
Returns the value of attribute left_ratio.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def left_ratio @left_ratio end |
#mask ⇒ Object (readonly)
Returns the value of attribute mask.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def mask @mask end |
#right_offset ⇒ Object (readonly)
Returns the value of attribute right_offset.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def right_offset @right_offset end |
#right_ratio ⇒ Object (readonly)
Returns the value of attribute right_ratio.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def right_ratio @right_ratio end |
#top_offset ⇒ Object (readonly)
Returns the value of attribute top_offset.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def top_offset @top_offset end |
#top_ratio ⇒ Object (readonly)
Returns the value of attribute top_ratio.
11 12 13 |
# File 'lib/engine/components/ui/rect.rb', line 11 def top_ratio @top_ratio end |
Class Method Details
.draw_all ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/engine/components/ui/rect.rb', line 20 def self.draw_all rects.each do |rect| Rendering::UI::StencilManager.setup_for_rect(rect) rect.game_object.ui_renderers.each(&:draw) end Rendering::UI::StencilManager.reset end |
.rects ⇒ Object
16 17 18 |
# File 'lib/engine/components/ui/rect.rb', line 16 def self.rects @rects ||= [] end |
Instance Method Details
#ancestor_masks ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/engine/components/ui/rect.rb', line 92 def ancestor_masks masks = [] current = game_object.parent while current rect_component = current.component(UI::Rect) masks.unshift(rect_component) if rect_component&.mask current = current.parent end masks end |
#awake ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/engine/components/ui/rect.rb', line 28 def awake @left_ratio ||= 0.0 @right_ratio ||= 0.0 @bottom_ratio ||= 0.0 @top_ratio ||= 0.0 @left_offset ||= 0 @right_offset ||= 0 @bottom_offset ||= 0 @top_offset ||= 0 @flex_weight ||= 1 @mask ||= false end |
#computed_rect ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/engine/components/ui/rect.rb', line 76 def computed_rect # Check if parent has a layout component parent_flex = game_object.parent&.component(UI::Flex) return parent_flex.rect_for_child(self) if parent_flex pr = parent_rect # Y-down: top increases downward from parent top, bottom decreases upward from parent bottom Engine::UI::Rect.new( left: pr.left + (pr.width * @left_ratio) + @left_offset, right: pr.right - (pr.width * @right_ratio) - @right_offset, top: pr.top + (pr.height * @top_ratio) + @top_offset, bottom: pr.bottom - (pr.height * @bottom_ratio) - @bottom_offset ) end |
#destroy ⇒ Object
45 46 47 |
# File 'lib/engine/components/ui/rect.rb', line 45 def destroy Rect.rects.delete(self) end |
#parent_rect ⇒ Object
61 62 63 64 |
# File 'lib/engine/components/ui/rect.rb', line 61 def parent_rect parent_ui = game_object.parent&.component(UI::Rect) parent_ui&.computed_rect || screen_rect end |
#screen_rect ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/engine/components/ui/rect.rb', line 66 def screen_rect # Y-down: top=0, bottom=height Engine::UI::Rect.new( left: 0, right: Engine::Window.framebuffer_width, top: 0, bottom: Engine::Window.framebuffer_height ) end |
#start ⇒ Object
41 42 43 |
# File 'lib/engine/components/ui/rect.rb', line 41 def start insert_sorted end |
#z_layer ⇒ Object
54 55 56 57 58 59 |
# File 'lib/engine/components/ui/rect.rb', line 54 def z_layer return @z_layer if @z_layer parent_ui = game_object.parent&.component(UI::Rect) parent_ui ? parent_ui.z_layer + 10 : 0 end |
#z_layer=(value) ⇒ Object
49 50 51 52 |
# File 'lib/engine/components/ui/rect.rb', line 49 def z_layer=(value) @z_layer = value reposition end |