Class: Engine::Components::UI::Rect

Inherits:
Engine::Component show all
Defined in:
lib/engine/components/ui/rect.rb

Instance Attribute Summary collapse

Attributes inherited from Engine::Component

#game_object

Class Method Summary collapse

Instance Method Summary collapse

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_offsetObject (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_ratioObject (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_alignObject (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_heightObject (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_weightObject (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_widthObject (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_offsetObject (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_ratioObject (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

#maskObject (readonly)

Returns the value of attribute mask.



11
12
13
# File 'lib/engine/components/ui/rect.rb', line 11

def mask
  @mask
end

#right_offsetObject (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_ratioObject (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_offsetObject (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_ratioObject (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_allObject



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

.rectsObject



16
17
18
# File 'lib/engine/components/ui/rect.rb', line 16

def self.rects
  @rects ||= []
end

Instance Method Details

#ancestor_masksObject



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

#awakeObject



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_rectObject



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

#destroyObject



45
46
47
# File 'lib/engine/components/ui/rect.rb', line 45

def destroy
  Rect.rects.delete(self)
end

#parent_rectObject



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_rectObject



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

#startObject



41
42
43
# File 'lib/engine/components/ui/rect.rb', line 41

def start
  insert_sorted
end

#z_layerObject



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