Your own drawing
Drawn
UI::Drawn is a component that draws itself, for a look no part has, such as a bar drawn by hand.
A class < UI::Drawn declares params and state like any component and, instead of render:
measure(width, height)answers its width and height for the room its parent gives (nilbefore the first layout); a sideniltakes what the layout gives. It is asked again whenever it renders or that room changes.draw(bitmap, rect)draws on the game's picture insiderect, its place there. Other parts share the picture, so draw only insiderect.roletells how the keys and the pointer treat it::none(the default) passes them over;:buttonis a key stop that confirm or a click presses, which calls itspressed;:slideris a key stop whoseplacesLeft and Right step through from itsplace, which callsmoved(place).
It draws again whenever it would render again: when its state changes or the caller gives it new
params. Read the game's values in the caller's render, such as UI::Game.hp_rate, and hand them in
as params, so it draws again as they change. A draw that fails is logged once with your file and
line.
Examples
An HP bar drawn by hand
class HpBar < UI::Drawn
param :rate, 1.0
def measure(width, height)
[width, 10]
end
def draw(bitmap, rect)
bitmap.fill_rect(rect, Color.new(40, 40, 40))
bitmap.fill_rect(rect.x + 1, rect.y + 1, ((rect.width - 2) * rate).round, rect.height - 2, Color.new(200, 60, 60))
end
end
# In render:
hp_bar rate: UI::Game.hp_rate(UI::Game.leader), width: 160
![]()
A part the player presses
class RestButton < UI::Drawn
event :rest
def measure(width, height)
[64, 24]
end
def role
:button
end
def pressed
emit :rest
end
end
rest_button on_rest: -> { rest_party } then takes confirm and a click like a button.