xhads/source/ui.adb

186 lines
10 KiB
Ada
Raw Normal View History

2024-02-15 21:03:09 -05:00
--~with core, attribute, skill, menu;
with core, ui;
use ui;
package body ui is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type sprite_array is array (style, codex) of core.sprite;
------------------------------------------------------------------------------------------
sprite : sprite_array;
------------------------------------------------------------------------------------------
procedure configure is
procedure load_ui (index : in style; folder_path : in string) is
begin
for this in codex
loop
sprite (index, this) := core.load_sprite ("./sprite/ui/" & folder_path & core.lowercase (codex'image (this)) & ".png", 1, 1);
2024-02-15 21:03:09 -05:00
end loop;
end load_ui;
begin
load_ui (default, "default/");
load_ui (yd, "yd/");
2024-02-15 21:03:09 -05:00
load_ui (steam, "steam/");
--
active := default;
end configure;
------------------------------------------------------------------------------------------
procedure draw (index : in codex; x, y : in integer) is
begin
core.draw (sprite (active, index), x, y);
end draw;
------------------------------------------------------------------------------------------
procedure crop (index : in codex; x, y, u, v, width, height : in integer) is
begin
core.crop (sprite (active, index), x, y, u, v, width, height);
end crop;
------------------------------------------------------------------------------------------
procedure draw_horizontally (index : in codex; x, y, width : in integer) is
begin
for move in 0 .. width / sprite (active, index).width - 1
loop
draw (index, x + move * sprite (active, index).width, y);
end loop;
--
crop (index, x + (width / sprite (active, index).width) * sprite (active, index).width, y, 0, 0, width mod sprite (active, index).width, sprite (active, index).height);
end draw_horizontally;
------------------------------------------------------------------------------------------
procedure draw_vertically (index : in codex; x, y, height : in integer) is
begin
for move in 0 .. height / sprite (active, index).height - 1
loop
draw (index, x, y + move * sprite (active, index).height);
end loop;
--
crop (index, x, y + (height / sprite (active, index).height) * sprite (active, index).height, 0, 0, sprite (active, index).width, height mod sprite (active, index).height);
end draw_vertically;
------------------------------------------------------------------------------------------
procedure draw_background (index : in codex; x, y, width, height : in integer) is
crop_width : integer := width mod sprite (active, index).width;
crop_height : integer := height mod sprite (active, index).height;
begin
for move_y in 0 .. height / sprite (active, index).height - 1
loop
for move_x in 0 .. width / sprite (active, index).width - 1
loop
draw (index, x + move_x * sprite (active, index).width, y + move_y * sprite (active, index).height);
end loop;
--
crop (index, x + width - crop_width, y + move_y * sprite (active, index).height, 0, 0, crop_width, sprite (active, index).height);
end loop;
--
for move_x in 0 .. width / sprite (active, index).width - 1
loop
crop (index, x + move_x * sprite (active, index).width, y + height - crop_height, 0, 0, sprite (active, index).width, crop_height);
end loop;
--
crop (index, x + width - crop_width, y + height - crop_height, 0, 0, crop_width, crop_height);
end draw_background;
------------------------------------------------------------------------------------------
procedure draw_frame (x, y, width, height : in integer) is
offset_x : constant integer := sprite (active, frame_middle).width;
offset_y : constant integer := sprite (active, frame_middle).height;
begin
draw_background (frame_middle, x + offset_x, y + offset_y, width - 2 * offset_x, height - 2 * offset_y);
--
draw_horizontally (frame_upper, x + offset_x, y, width - 2 * offset_x);
draw_horizontally (frame_lower, x + offset_x, y + height - offset_y, width - 2 * offset_x);
draw_vertically (frame_left, x, y + offset_y, height - 2 * offset_y);
draw_vertically (frame_right, x + width - offset_x, y + offset_y, height - 2 * offset_y);
--
draw (frame_upper_left, x, y);
draw (frame_upper_right, x + width - sprite (active, frame_upper_right).width, y);
draw (frame_lower_left, x, y + height - sprite (active, frame_lower_left).height);
draw (frame_lower_right, x + width - sprite (active, frame_lower_right).width, y + height - sprite (active, frame_lower_right).height);
end draw_frame;
------------------------------------------------------------------------------------------
procedure draw_menu (x, y, width, height : in integer; background : in boolean) is
offset : constant integer := sprite (active, none).width;
begin
if width < sprite (active, corner_upper_left).width + sprite (active, corner_upper_right).width
or width < sprite (active, corner_lower_left).width + sprite (active, corner_lower_right).width
or height < sprite (active, corner_upper_left).height + sprite (active, corner_lower_left).height
or height < sprite (active, corner_upper_right).height + sprite (active, corner_lower_right).height
then return;
end if;
--
if background then
draw_background (main_background, x + offset, y + offset, width - 2 * offset, height - 2 * offset);
end if;
--
declare
upper : constant integer := width - sprite (active, corner_upper_left).width - sprite (active, corner_upper_right).width;
lower : constant integer := width - sprite (active, corner_lower_left).width - sprite (active, corner_lower_right).width;
left : constant integer := height - sprite (active, corner_upper_left).height - sprite (active, corner_lower_left).height;
right : constant integer := height - sprite (active, corner_upper_right).height - sprite (active, corner_lower_right).height;
begin
draw_horizontally (border_upper, x + sprite (active, corner_upper_left).width, y, upper);
draw_horizontally (border_lower, x + sprite (active, corner_lower_left).width, y + height - sprite (active, border_lower).height, lower);
draw_vertically (border_left, x, y + sprite (active, corner_upper_left).height, left);
draw_vertically (border_right, x + width - sprite (active, border_right).width, y + sprite (active, corner_upper_right).height, right);
end;
--
draw (corner_upper_left, x, y);
draw (corner_upper_right, x + width - sprite (active, corner_upper_right).width, y);
draw (corner_lower_left, x, y + height - sprite (active, corner_lower_left).height);
draw (corner_lower_right, x + width - sprite (active, corner_lower_right).width, y + height - sprite (active, corner_lower_right).height);
end draw_menu;
------------------------------------------------------------------------------------------
procedure draw_tiny_menu (x, y, width, height : in integer; background : in boolean) is
offset : constant integer := sprite (active, none).width;
begin
if width < sprite (active, tiny_corner_upper_left).width + sprite (active, tiny_corner_upper_right).width
or width < sprite (active, tiny_corner_lower_left).width + sprite (active, tiny_corner_lower_right).width
or height < sprite (active, tiny_corner_upper_left).height + sprite (active, tiny_corner_lower_left).height
or height < sprite (active, tiny_corner_upper_right).height + sprite (active, tiny_corner_lower_right).height
then return;
end if;
--
if background then
draw_background (main_background, x + offset, y + offset, width - 2 * offset, height - 2 * offset);
end if;
--
declare
upper : constant integer := width - sprite (active, tiny_corner_upper_left).width - sprite (active, tiny_corner_upper_right).width;
lower : constant integer := width - sprite (active, tiny_corner_lower_left).width - sprite (active, tiny_corner_lower_right).width;
left : constant integer := height - sprite (active, tiny_corner_upper_left).height - sprite (active, tiny_corner_lower_left).height;
right : constant integer := height - sprite (active, tiny_corner_upper_right).height - sprite (active, tiny_corner_lower_right).height;
begin
draw_horizontally (tiny_border_upper, x + sprite (active, tiny_corner_upper_left).width, y, upper);
draw_horizontally (tiny_border_lower, x + sprite (active, tiny_corner_lower_left).width, y + height - sprite (active, tiny_border_lower).height, lower);
draw_vertically (tiny_border_left, x, y + sprite (active, tiny_corner_upper_left).height, left);
draw_vertically (tiny_border_right, x + width - sprite (active, tiny_border_right).width, y + sprite (active, tiny_corner_upper_right).height, right);
end;
--
draw (tiny_corner_upper_left, x, y);
draw (tiny_corner_upper_right, x + width - sprite (active, tiny_corner_upper_right).width, y);
draw (tiny_corner_lower_left, x, y + height - sprite (active, tiny_corner_lower_left).height);
draw (tiny_corner_lower_right, x + width - sprite (active, tiny_corner_lower_right).width, y + height - sprite (active, tiny_corner_lower_right).height);
end draw_tiny_menu;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end ui;