Class: RedBird::UIBox
Overview
User Interface Box works as a visual background for texts, menus, or anything else.
Defined Under Namespace
Classes: Style
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#height ⇒ Integer
The height is defined by
num_vertical_sprites
plus two (the borders). -
#initialize(style, pos_x, pos_y, num_vertical_sprites, num_horizontal_sprites) ⇒ UIBox
constructor
A new instance of UIBox.
-
#render ⇒ Object
Renders to the screen.
-
#width ⇒ Integer
The height is defined by
num_horizontal_sprites
plus two (the borders).
Methods inherited from Entity
#cursor_down, #cursor_hover, #cursor_up, #tick
Constructor Details
#initialize(style, pos_x, pos_y, num_vertical_sprites, num_horizontal_sprites) ⇒ UIBox
Returns a new instance of UIBox.
76 77 78 79 80 81 82 83 |
# File 'lib/red_bird/uibox.rb', line 76 def initialize(style, pos_x, pos_y, num_vertical_sprites, num_horizontal_sprites) @style = style @pos_x = pos_x @pos_y = pos_y @num_vertical_sprites = num_vertical_sprites @num_horizontal_sprites = num_horizontal_sprites end |
Instance Method Details
#height ⇒ Integer
The height is defined by num_vertical_sprites
plus two (the borders). The height of each sprite is defined by the style used.
99 100 101 |
# File 'lib/red_bird/uibox.rb', line 99 def height @style.sprite_height * (@num_vertical_sprites + 2) end |
#render ⇒ Object
Renders to the screen.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/red_bird/uibox.rb', line 106 def render Render.set_color(@style.bg_color) Render.fill_rect(@pos_x, @pos_y, self.width, self.height) # Draw the corners. @style.sprites[:box_top_left].render_to_screen(@pos_x, @pos_y) @style.sprites[:box_top_right].render_to_screen( @style.sprite_width * (@num_horizontal_sprites + 1) + @pos_x, @pos_y) @style.sprites[:box_bottom_left].render_to_screen( @pos_x, @style.sprite_height * (@num_vertical_sprites + 1) + @pos_y) @style.sprites[:box_bottom_right].render_to_screen( @style.sprite_width * (@num_horizontal_sprites + 1) + @pos_x, @style.sprite_height * (@num_vertical_sprites + 1) + @pos_y) # Draw the edges. @num_horizontal_sprites.times do |i| # Top @style.sprites[:box_top].render_to_screen( @style.sprite_width * (i + 1) + @pos_x, @pos_y) # Bottom @style.sprites[:box_bottom].render_to_screen( @style.sprite_width * (i + 1) + @pos_x, @style.sprite_height * (@num_vertical_sprites + 1) + @pos_y) end @num_vertical_sprites.times do |i| # Left @style.sprites[:box_left].render_to_screen( @pos_x, @style.sprite_height * (i + 1) + @pos_y) # Right @style.sprites[:box_right].render_to_screen( @style.sprite_width * (@num_horizontal_sprites + 1) + @pos_x, @style.sprite_height * (i + 1) + @pos_y) end end |
#width ⇒ Integer
The height is defined by num_horizontal_sprites
plus two (the borders). The width of each sprite is defined by the style used.
90 91 92 |
# File 'lib/red_bird/uibox.rb', line 90 def width @style.sprite_width * (@num_horizontal_sprites + 2) end |