From 5be8b6af530fe2e6c7f25c8a421a7c4d7d5f707a Mon Sep 17 00:00:00 2001 From: xolatile Date: Tue, 7 May 2024 09:59:26 -0400 Subject: [PATCH] Refactored UI code a lot, more to come with new record... --- source/attribute.adb | 6 +++--- source/core.adb | 2 -- source/resource.adb | 6 +++--- source/ui.adb | 54 ++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/source/attribute.adb b/source/attribute.adb index f411070..c3c00a8 100644 --- a/source/attribute.adb +++ b/source/attribute.adb @@ -20,10 +20,10 @@ package body attribute is structure.title := "Attribute Menu "; structure.toggle := core.signal_a; structure.show := false; - structure.center := true; + structure.center := false; structure.resize := true; - structure.x := 880; - structure.y := (core.window_height - 320) / 2; + structure.x := 60; + structure.y := 80; structure.gui_n := count; -- ui.add_structure (structure); diff --git a/source/core.adb b/source/core.adb index 3d30672..5014d7b 100644 --- a/source/core.adb +++ b/source/core.adb @@ -299,8 +299,6 @@ package body core is cursor.x := ray.get_mouse_x; cursor.y := ray.get_mouse_y; -- - ray.draw_fps (window_width - 100, window_height - 100); - -- ray.end_drawing; -- if ray.exit_key_is_pressed then diff --git a/source/resource.adb b/source/resource.adb index 39339d9..2d68e32 100644 --- a/source/resource.adb +++ b/source/resource.adb @@ -20,10 +20,10 @@ package body resource is structure.title := "Resource Menu "; structure.toggle := core.signal_r; structure.show := false; - structure.center := true; + structure.center := false; structure.resize := true; - structure.x := 480; - structure.y := (core.window_height - 320) / 2; + structure.x := 60; + structure.y := 480; structure.gui_n := count; -- ui.add_structure (structure); diff --git a/source/ui.adb b/source/ui.adb index 411a13a..487f871 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -43,6 +43,12 @@ package body ui is ------------------------------------------------------------------------------------------ + type rectangle is record + x, y, width, height : integer; + end record; + + ------------------------------------------------------------------------------------------ + structure_limit : constant natural := 12; sprite : array (style, element) of core.sprite; @@ -153,34 +159,50 @@ package body ui is ------------------------------------------------------------------------------------------ procedure draw_structure (data : in structure) is - offset : constant integer := core.icon / 4; - new_width : constant integer := (if data.resize then 320 else data.width); - new_height : constant integer := (if data.resize then data.gui_n * (core.icon + 2 * offset) + 2 * core.icon else data.height); - new_x : constant integer := (if data.center then (core.window_width - new_width) / 2 else data.x); - new_y : constant integer := (if data.center then (core.window_height - new_height) / 2 else data.y); + offset : constant integer := core.icon / 4; + orients : natural := 0; -- - at_x : integer := new_x + core.icon; - at_y : integer := new_y + core.icon; + frame_data : rectangle := (others => 0); + button_data : rectangle := (others => 0); begin - draw_tiny_menu (new_x, new_y, new_width, new_height); - draw_title_bar (new_x, new_y, new_width, data.title); + for index in 0 .. data.gui_n - 1 loop + if data.gui_list (index).kind = gui_orient then + orients := orients + 1; + end if; + end loop; + -- + frame_data.width := (if data.resize then 320 else data.width) * (orients + 1) - offset * orients; + frame_data.height := (if data.resize then data.gui_n * (core.icon + 2 * offset) + 2 * core.icon else data.height) / (orients + 1) + offset * orients; + frame_data.x := (if data.center then (core.window_width - frame_data.width) / 2 else data.x); + frame_data.y := (if data.center then (core.window_height - frame_data.height) / 2 else data.y); + button_data.width := frame_data.width / (orients + 1) - 2 * core.icon; + button_data.height := core.icon + 2 * offset; + button_data.x := frame_data.x + core.icon; + button_data.y := frame_data.y + core.icon; + -- + draw_tiny_menu (frame_data.x, frame_data.y, frame_data.width, frame_data.height); + draw_title_bar (frame_data.x, frame_data.y, frame_data.width, data.title); -- for x in 0 .. data.gui_n - 1 loop case data.gui_list (x).kind is when gui_button => - draw_frame (data.gui_list (x).info, at_x, at_y, new_width - 2 * core.icon, core.icon + 2 * offset); - draw_icon (data.gui_list (x).image, data.gui_list (x).info, at_x + offset, at_y + offset); - write (data.gui_list (x).text, at_x + core.icon + offset, at_y + offset + 2); + draw_frame (data.gui_list (x).info, button_data.x, button_data.y, button_data.width, button_data.height); + draw_icon (data.gui_list (x).image, data.gui_list (x).info, button_data.x + offset, button_data.y + offset); + write (data.gui_list (x).text, button_data.x + offset + core.icon, button_data.y + offset + 2); --~if cursor_inside (at_x, at_y, new_width - 2 * offset - core.icon - 2, 3 * core.icon / 2) then --~draw (cursor, at_x + new_width - 96, at_y); --~end if; - at_y := at_y + core.icon + 2 * offset; + button_data.y := button_data.y + button_data.height; when gui_orient => - at_x := at_x + new_width - 2 * core.icon + offset; - at_y := new_y + core.icon; + button_data.x := button_data.x + frame_data.width / (orients + 1) - 2 * core.icon + offset; + button_data.y := frame_data.y + core.icon; when others => null; end case; end loop; + -- + if orients > 0 then + draw_scroll_bar (frame_data.x + frame_data.width - 2 * core.icon, frame_data.y + core.icon, frame_data.height - 2 * core.icon, 4); + end if; end draw_structure; ------------------------------------------------------------------------------------------ @@ -357,7 +379,7 @@ package body ui is ------------------------------------------------------------------------------------------ - procedure draw_scroll_bar (x, y, height : in integer; offset : in integer) is + procedure draw_scroll_bar (x, y, height, offset : in integer) is middle_height : constant integer := height - sprite (active, scroll_bar_upper).height - sprite (active, scroll_bar_lower).height; begin draw (scroll_bar_upper, x, y);