From df533dc356358772572e48a3f4e3868dd67915bd Mon Sep 17 00:00:00 2001 From: xolatile Date: Mon, 19 Feb 2024 21:52:43 -0500 Subject: [PATCH] Added unscrolling scroll bar... --- source/menu.adb | 16 ++++++---------- source/ui.adb | 19 +++++++++++-------- source/ui.ads | 8 +++++++- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/source/menu.adb b/source/menu.adb index 294da39..4ed558c 100644 --- a/source/menu.adb +++ b/source/menu.adb @@ -71,14 +71,6 @@ package body menu is end if; -- if mouse_over_menu /= none then - --~for element_index in 0 .. limitation - 1 - --~loop - --~if core.cursor_y > trait (index).y + draw_offset + element_index * offset - --~and core.cursor_y < trait (index).y + draw_offset + element_index * offset + offset then - --~mouse_over_menu_element := element_index; - --~end if; - --~end loop; - --~return; for element_index in 0 .. limitation - 1 loop if core.cursor_x > trait (index).x + trait (index).elements (element_index).x @@ -96,8 +88,8 @@ package body menu is ------------------------------------------------------------------------------------------ procedure draw (index : in codex; x, y : in integer; center : in boolean) is - scroll_bar : constant boolean := (if trait (index).length < trait (index).height then false else true); - limitation : constant integer := (if trait (index).length < trait (index).height then trait (index).length else trait (index).height); + scroll_bar : constant boolean := (if trait (index).length > trait (index).height then true else false); + limitation : constant integer := (if trait (index).length > trait (index).height then trait (index).height else trait (index).length); width : constant integer := 2 * draw_offset + offset + 24 * 8; height : constant integer := limitation * offset + 2 * draw_offset; begin @@ -118,6 +110,10 @@ package body menu is core.draw (trait (index).elements (element_index).icon, trait (index).x + draw_offset + icon_offset, trait (index).y + draw_offset + icon_offset + element_index * offset); core.write (trait (index).elements (element_index).text, trait (index).x + draw_offset + offset, trait (index).y + draw_offset + 2 * icon_offset + element_index * offset); end loop; + -- + if scroll_bar then + ui.draw_scroll_bar (x + width - draw_offset, y + draw_offset, height - 2 * draw_offset, 0); + end if; end draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/ui.adb b/source/ui.adb index 1a38204..34b33a7 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -7,14 +7,6 @@ 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 @@ -158,6 +150,17 @@ package body ui is ------------------------------------------------------------------------------------------ + procedure draw_scroll_bar (x, y, height : in integer; 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); + draw (scroll_bar_lower, x, y + middle_height + sprite (active, scroll_bar_upper).height); + -- + draw_vertically (scroll_bar_middle, x, y + sprite (active, scroll_bar_upper).height, middle_height); + end draw_scroll_bar; + + ------------------------------------------------------------------------------------------ + procedure draw_menu (x, y, width, height : in integer; background : in boolean) is offset : constant integer := sprite (active, none).width; begin diff --git a/source/ui.ads b/source/ui.ads index 82aeded..c1f2e4d 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -26,6 +26,11 @@ package ui is ------------------------------------------------------------------------------------------ + type sprite_array is array (style, codex) of core.sprite; + + ------------------------------------------------------------------------------------------ + + sprite : sprite_array; active : style; ------------------------------------------------------------------------------------------ @@ -38,7 +43,8 @@ package ui is procedure draw_frame (x, y, width, height : in integer); - procedure draw_title_bar (x, y, width : in integer; title : in string); + procedure draw_title_bar (x, y, width : in integer; title : in string); + procedure draw_scroll_bar (x, y, height : in integer; offset : in integer); procedure draw_menu (x, y, width, height : in integer; background : in boolean); procedure draw_tiny_menu (x, y, width, height : in integer; background : in boolean);