From 788c8216050bff07e868069aff2e3981e7c36e3e Mon Sep 17 00:00:00 2001 From: xolatile Date: Sat, 8 Jun 2024 04:38:28 -0400 Subject: [PATCH] Adding draw_text procedure and text size... --- source/chad.ads | 2 ++ source/core.adb | 32 ++++++++++++++++++++++++++++++++ source/core.ads | 5 ++++- source/main.adb | 2 ++ source/ui.adb | 10 ++++++++++ source/ui.ads | 2 ++ 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/source/chad.ads b/source/chad.ads index 4f3f39a..3d20d5f 100644 --- a/source/chad.ads +++ b/source/chad.ads @@ -53,6 +53,8 @@ package chad is ------------------------------------------------------------------------------------------ + -- Knight Cleric Ranger Druid Alchemist Wizard Heretic Demoniac Necromancer Death-Knight Overlord Warlock Barbarian Battlemage Beast-Tamer Witch + count : constant natural := enumeration'pos (enumeration'last) + 1; description : constant array (enumeration) of definition := ( diff --git a/source/core.adb b/source/core.adb index fced265..13bac0f 100644 --- a/source/core.adb +++ b/source/core.adb @@ -171,6 +171,38 @@ package body core is ------------------------------------------------------------------------------------------ + function string_width (data : in string) return natural is + maximum_width : natural := 0; + width : natural := 0; + begin + for index in data'range loop + width := width + 1; + -- + if data (index) = character'val (10) then + maximum_width := (if width > maximum_width then width - 1 else maximum_width); + width := 0; + end if; + end loop; + -- + return maximum_width; + end string_width; + + ------------------------------------------------------------------------------------------ + + function string_height (data : in string) return natural is + height : natural := 0; + begin + for index in data'range loop + if data (index) = character'val (10) then + height := height + 1; + end if; + end loop; + -- + return height + 1; + end string_height; + + ------------------------------------------------------------------------------------------ + function random (minimum, maximum : in integer) return integer is begin return ray.get_random (minimum, maximum); diff --git a/source/core.ads b/source/core.ads index ad7d3fd..0b0907e 100644 --- a/source/core.ads +++ b/source/core.ads @@ -140,7 +140,10 @@ package core is function c_string (ada_string : in string) return string; - function random (minimum, maximum : in integer) return integer; + function string_width (data : in string) return natural; + function string_height (data : in string) return natural; + + function random (minimum, maximum : in integer) return integer; procedure clip (value : in out integer; minimum, maximum : in integer); diff --git a/source/main.adb b/source/main.adb index 24178bc..bd8f06b 100644 --- a/source/main.adb +++ b/source/main.adb @@ -259,6 +259,8 @@ procedure main is y => at_y + index_y * core.icon); end loop; end loop; + -- + ui.draw_text ("Heyo world!" & character'val (10) & "Goodcyaa world!", 600, 600); end player_information; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/ui.adb b/source/ui.adb index 393fc9f..2ce86cc 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -324,6 +324,16 @@ package body ui is ------------------------------------------------------------------------------------------ + procedure draw_text (text : in string; x, y : in integer; tint : in core.colour := (others => 255)) is + offset : constant integer := 10; + begin + draw_text_box (x, y, 9 * core.string_width (text) + 2 * offset, 15 * core.string_height (text) + 2 * offset); + write (text, x + offset, y + offset, tint, code => true); + write (natural'image (core.string_width (text)) & natural'image (core.string_height (text)), x-20, y-20, tint, code => true); + end draw_text; + + ------------------------------------------------------------------------------------------ + procedure draw_check_box (x, y : in integer; on : in out boolean; text : in string) is begin draw ((if on then check_box_on else check_box_off), x, y); diff --git a/source/ui.ads b/source/ui.ads index 40a3f5e..9d33903 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -44,6 +44,8 @@ package ui is procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle_skip'access); procedure draw_button (text, description : in string; icon : in core.sprite; x, y, width, height : in integer; action : core.pointer := core.idle_skip'access); + procedure draw_text (text : in string; x, y : in integer; tint : in core.colour := (others => 255)); + procedure draw_check_box (x, y : in integer; on : in out boolean; text : in string); procedure draw_title_bar (x, y, width : in integer; title : in string);