Refactored UI package...
This commit is contained in:
parent
800a49c18c
commit
06cac284a2
@ -93,11 +93,6 @@ package body core is
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
function "+" (data : in string) return unstring is begin return core.unbound (data); end "+";
|
||||
function "-" (data : in unstring) return string is begin return core.bound (data); end "-";
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure echo (status : in echo_status;
|
||||
text : in string) is
|
||||
begin
|
||||
|
@ -127,9 +127,6 @@ package core is
|
||||
function "*" (data : in point; modifier : in natural) return point;
|
||||
function "/" (data : in point; modifier : in natural) return point;
|
||||
|
||||
function "+" (data : in string) return unstring;
|
||||
function "-" (data : in unstring) return string;
|
||||
|
||||
procedure echo ( status : in echo_status; text : in string);
|
||||
procedure echo_when (condition : in boolean; status : in echo_status; text : in string);
|
||||
|
||||
|
@ -285,26 +285,26 @@ begin
|
||||
|
||||
core.cursor_mode := core.cursor_none;
|
||||
|
||||
main_menu_loop: loop
|
||||
core.synchronize;
|
||||
--
|
||||
exit when core.signal_mode = core.signal_space or core.cursor_mode = core.cursor_right;
|
||||
--
|
||||
declare source_code_data : core.string_box_data;
|
||||
begin
|
||||
core.import_text (source_code_data, source_code (view_source_code).all);
|
||||
--
|
||||
if core.cursor_mode = core.cursor_left then
|
||||
view_source_code := (view_source_code + 1) mod 23;
|
||||
core.cursor_mode := core.cursor_none;
|
||||
core.wheel := 0.0;
|
||||
end if;
|
||||
--
|
||||
ui.write_ada_code (source_code_data, 0, integer (core.wheel) * 30);
|
||||
end;
|
||||
end loop main_menu_loop;
|
||||
--~main_menu_loop: loop
|
||||
--~core.synchronize;
|
||||
--~--
|
||||
--~exit when core.signal_mode = core.signal_space or core.cursor_mode = core.cursor_right;
|
||||
--~--
|
||||
--~declare source_code_data : core.string_box_data;
|
||||
--~begin
|
||||
--~core.import_text (source_code_data, source_code (view_source_code).all);
|
||||
--~--
|
||||
--~if core.cursor_mode = core.cursor_left then
|
||||
--~view_source_code := (view_source_code + 1) mod 23;
|
||||
--~core.cursor_mode := core.cursor_none;
|
||||
--~core.wheel := 0.0;
|
||||
--~end if;
|
||||
--~--
|
||||
--~ui.write_ada_code (source_code_data, 0, integer (core.wheel) * 30);
|
||||
--~end;
|
||||
--~end loop main_menu_loop;
|
||||
|
||||
core.cursor_mode := core.cursor_none;
|
||||
--~core.cursor_mode := core.cursor_none;
|
||||
|
||||
world.load ("heyo");
|
||||
|
||||
|
293
source/ui.adb
293
source/ui.adb
@ -4,13 +4,10 @@
|
||||
|
||||
with core;
|
||||
|
||||
with ada.strings.unbounded;
|
||||
|
||||
use type core.cursor_code;
|
||||
use type core.signal_code;
|
||||
use type core.point;
|
||||
|
||||
use type ada.strings.unbounded.unbounded_string;
|
||||
use type core.unstring;
|
||||
|
||||
package body ui is
|
||||
|
||||
@ -77,16 +74,12 @@ package body ui is
|
||||
sprite : array (style, element) of core.sprite;
|
||||
font : array (style) of core.font;
|
||||
|
||||
structure_array : array (0 .. structure_limit) of structure;
|
||||
|
||||
structure_count : natural := 0;
|
||||
|
||||
monospace : core.font;
|
||||
|
||||
console_message_limit : constant natural := 6;
|
||||
console_message_count : natural := 0;
|
||||
--
|
||||
console_message_array : array (0 .. console_message_limit - 1) of ada.strings.unbounded.unbounded_string;
|
||||
console_message_array : array (0 .. console_message_limit - 1) of core.unstring;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
@ -167,57 +160,6 @@ package body ui is
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure draw_structure (data : in structure) is
|
||||
offset : constant integer := core.icon / 4;
|
||||
orients : natural := 0;
|
||||
--
|
||||
frame_data : rectangle := (others => 0);
|
||||
button_data : rectangle := (others => 0);
|
||||
begin
|
||||
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_button (text => -(data.gui_list (x).text),
|
||||
description => -(data.gui_list (x).info),
|
||||
icon => data.gui_list (x).image,
|
||||
x => button_data.x,
|
||||
y => button_data.y,
|
||||
width => button_data.width,
|
||||
height => button_data.height);
|
||||
--
|
||||
button_data.y := button_data.y + button_data.height;
|
||||
when gui_orient =>
|
||||
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;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure configure is
|
||||
procedure load_ui (index : in style; folder_path : in string) is
|
||||
begin
|
||||
@ -243,21 +185,9 @@ package body ui is
|
||||
begin
|
||||
prioritize := false;
|
||||
--
|
||||
for index in 0 .. structure_count - 1 loop
|
||||
if signal_mode = structure_array (index).toggle then
|
||||
structure_array (index).show := not structure_array (index).show;
|
||||
end if;
|
||||
--
|
||||
if structure_array (index).show then
|
||||
draw_structure (structure_array (index));
|
||||
--
|
||||
prioritize := true;
|
||||
end if;
|
||||
end loop;
|
||||
--
|
||||
draw (cursor, core.cursor.x, core.cursor.y);
|
||||
--
|
||||
if read_text_box /= "--" then
|
||||
if core.cursor_mode = core.cursor_middle then
|
||||
draw_popup_box;
|
||||
end if;
|
||||
--
|
||||
@ -268,7 +198,7 @@ package body ui is
|
||||
|
||||
procedure echo (message : in string) is
|
||||
begin
|
||||
console_message_array (console_message_count) := ada.strings.unbounded.to_unbounded_string (message);
|
||||
console_message_array (console_message_count) := core.unbound (message);
|
||||
--
|
||||
console_message_count := (console_message_count + 1) mod console_message_limit;
|
||||
end echo;
|
||||
@ -628,7 +558,7 @@ package body ui is
|
||||
draw_text_box (x, y, width, height);
|
||||
--
|
||||
for index in 0 .. console_message_limit - 1 loop
|
||||
ui.write (text => ada.strings.unbounded.to_string (console_message_array ((index + console_message_count) mod console_message_limit)),
|
||||
ui.write (text => core.bound (console_message_array ((index + console_message_count) mod console_message_limit)),
|
||||
x => x + offset,
|
||||
y => y + offset + index * font_height,
|
||||
size => 15,
|
||||
@ -638,130 +568,95 @@ package body ui is
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure add_structure (data : in structure) is
|
||||
begin
|
||||
structure_array (structure_count) := data;
|
||||
structure_array (structure_count).gui_list := new gui_array (0 .. structure_array (structure_count).gui_n - 1);
|
||||
structure_array (structure_count).gui_n := 0;
|
||||
--
|
||||
core.increment (structure_count);
|
||||
end add_structure;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure add_structure_button (icon : in core.sprite; name : in core.unstring; text : in core.unstring) is
|
||||
index : natural renames structure_array (structure_count - 1).gui_n;
|
||||
begin
|
||||
structure_array (structure_count - 1).gui_list (index).kind := gui_button;
|
||||
structure_array (structure_count - 1).gui_list (index).text := name;
|
||||
structure_array (structure_count - 1).gui_list (index).info := text;
|
||||
structure_array (structure_count - 1).gui_list (index).number := 0;
|
||||
structure_array (structure_count - 1).gui_list (index).image := icon;
|
||||
--
|
||||
core.increment (index);
|
||||
end add_structure_button;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure add_structure_orient is
|
||||
index : natural renames structure_array (structure_count - 1).gui_n;
|
||||
begin
|
||||
structure_array (structure_count - 1).gui_list (index).kind := gui_orient;
|
||||
--
|
||||
core.increment (index);
|
||||
end add_structure_orient;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
procedure write_ada_code (text : in core.string_box_data; x, y : in integer) is
|
||||
word : ada.strings.unbounded.unbounded_string := ada.strings.unbounded.to_unbounded_string ("");
|
||||
--
|
||||
buffer : character := ' ';
|
||||
width : constant integer := 9;
|
||||
height : constant integer := 15;
|
||||
length : natural := 1;
|
||||
offset : core.vector := (x, y);
|
||||
subset : natural := 0;
|
||||
begin
|
||||
loop
|
||||
buffer := ada.strings.unbounded.element (text.text, length);
|
||||
offset.x := offset.x + width;
|
||||
--
|
||||
exit when buffer = character'val (0);
|
||||
--
|
||||
case buffer is
|
||||
when character'val (9) => offset.x := offset.x + 2 * width;
|
||||
when character'val (10) => offset.y := offset.y + 1 * height; offset.x := x;
|
||||
when ':' | ';' | '.' | ',' | '=' | '<' | '>' =>
|
||||
ui.write (buffer & "", offset.x, offset.y, (63, 127, 255, 255), height, code => true);
|
||||
when '+' | '*' | '/' | '|' | '&' =>
|
||||
ui.write (buffer & "", offset.x, offset.y, (63, 63, 255, 255), height, code => true);
|
||||
when '(' | ')' | ''' =>
|
||||
ui.write (buffer & "", offset.x, offset.y, (63, 255, 255, 255), height, code => true);
|
||||
when '"' =>
|
||||
ui.write (buffer & "", offset.x, offset.y, (127, 63, 127, 255), height, code => true);
|
||||
offset.x := offset.x + width;
|
||||
loop
|
||||
core.increment (length);
|
||||
buffer := ada.strings.unbounded.element (text.text, length);
|
||||
ui.write (buffer & "", offset.x, offset.y, (127, 63, 127, 255), height, code => true);
|
||||
offset.x := offset.x + width;
|
||||
exit when buffer = '"';
|
||||
end loop;
|
||||
offset.x := offset.x - width;
|
||||
when '-' =>
|
||||
if ada.strings.unbounded.element (text.text, length + 1) = '-' then
|
||||
ui.write (buffer & "", offset.x, offset.y, (127, 127, 127, 255), height, code => true);
|
||||
offset.x := offset.x + width;
|
||||
loop
|
||||
core.increment (length);
|
||||
buffer := ada.strings.unbounded.element (text.text, length);
|
||||
ui.write (buffer & "", offset.x, offset.y, (127, 127, 127, 255), height, code => true);
|
||||
offset.x := offset.x + width;
|
||||
exit when buffer = character'val (10);
|
||||
end loop;
|
||||
core.decrement (length);
|
||||
else
|
||||
ui.write (buffer & "", offset.x, offset.y, (63, 63, 255, 255), height, code => true);
|
||||
end if;
|
||||
when '0' .. '9' =>
|
||||
loop
|
||||
ui.write (buffer & "", offset.x, offset.y, (127, 63, 255, 255), height, code => true);
|
||||
core.increment (length);
|
||||
buffer := ada.strings.unbounded.element (text.text, length);
|
||||
exit when buffer = ' ' or buffer = ';' or buffer = ')' or buffer = ',';
|
||||
offset.x := offset.x + width;
|
||||
end loop;
|
||||
core.decrement (length);
|
||||
when 'a' .. 'z' | 'A' .. 'Z' =>
|
||||
word := ada.strings.unbounded.to_unbounded_string (buffer & "");
|
||||
subset := 1;
|
||||
loop
|
||||
buffer := ada.strings.unbounded.element (text.text, length + subset);
|
||||
exit when buffer = ' ' or buffer = '.' or buffer = '(' or buffer = ')' or buffer = ',' or buffer = ';' or buffer = '''
|
||||
or buffer = character'val (9) or buffer = character'val (10);
|
||||
word := word & ada.strings.unbounded.to_unbounded_string (buffer & "");
|
||||
core.increment (subset);
|
||||
end loop;
|
||||
if word = "type" or word = "begin" or word = "end" or word = "when" or word = "others" or word = "procedure" or word = "function"
|
||||
or word = "package" or word = "body" or word = "if" or word = "then" or word = "else" or word = "elsif" or word = "case" or word = "is"
|
||||
or word = "and" or word = "or" or word = "xor" or word = "exit" or word = "constant" or word = "access" or word = "range"
|
||||
or word = "subtype" or word = "array" or word = "in" or word = "out" or word = "return" or word = "for" or word = "with"
|
||||
or word = "loop" or word = "while" or word = "of" or word = "null" or word = "record" or word = "use" or word = "mod" or word = "new"
|
||||
or word = "aliased" or word = "all" then
|
||||
ui.write (ada.strings.unbounded.to_string (word), offset.x, offset.y, (255, 255, 0, 255), height, code => true);
|
||||
else
|
||||
ui.write (ada.strings.unbounded.to_string (word), offset.x, offset.y, (others => 255), height, code => true);
|
||||
end if;
|
||||
offset.x := offset.x + (subset - 1) * width;
|
||||
length := length + subset - 1;
|
||||
when others =>
|
||||
ui.write (buffer & "", offset.x, offset.y, (others => 255), height, code => true);
|
||||
end case;
|
||||
--
|
||||
core.increment (length);
|
||||
end loop;
|
||||
end write_ada_code;
|
||||
--~procedure write_ada_code (text : in core.string_box_data; x, y : in integer) is
|
||||
--~word : core.unstring := core.unbound ("");
|
||||
--~--
|
||||
--~buffer : character := ' ';
|
||||
--~width : constant integer := 9;
|
||||
--~height : constant integer := 15;
|
||||
--~length : natural := 1;
|
||||
--~offset : core.vector := (x, y);
|
||||
--~subset : natural := 0;
|
||||
--~begin
|
||||
--~loop
|
||||
--~buffer := (core.bound (text.text)) (length .. length);
|
||||
--~offset.x := offset.x + width;
|
||||
--~--
|
||||
--~exit when buffer = character'val (0);
|
||||
--~--
|
||||
--~case buffer is
|
||||
--~when character'val (9) => offset.x := offset.x + 2 * width;
|
||||
--~when character'val (10) => offset.y := offset.y + 1 * height; offset.x := x;
|
||||
--~when ':' | ';' | '.' | ',' | '=' | '<' | '>' =>
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (63, 127, 255, 255), height, code => true);
|
||||
--~when '+' | '*' | '/' | '|' | '&' =>
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (63, 63, 255, 255), height, code => true);
|
||||
--~when '(' | ')' | ''' =>
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (63, 255, 255, 255), height, code => true);
|
||||
--~when '"' =>
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (127, 63, 127, 255), height, code => true);
|
||||
--~offset.x := offset.x + width;
|
||||
--~loop
|
||||
--~core.increment (length);
|
||||
--~buffer := ada.strings.unbounded.element (text.text, length);
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (127, 63, 127, 255), height, code => true);
|
||||
--~offset.x := offset.x + width;
|
||||
--~exit when buffer = '"';
|
||||
--~end loop;
|
||||
--~offset.x := offset.x - width;
|
||||
--~when '-' =>
|
||||
--~if ada.strings.unbounded.element (text.text, length + 1) = '-' then
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (127, 127, 127, 255), height, code => true);
|
||||
--~offset.x := offset.x + width;
|
||||
--~loop
|
||||
--~core.increment (length);
|
||||
--~buffer := ada.strings.unbounded.element (text.text, length);
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (127, 127, 127, 255), height, code => true);
|
||||
--~offset.x := offset.x + width;
|
||||
--~exit when buffer = character'val (10);
|
||||
--~end loop;
|
||||
--~core.decrement (length);
|
||||
--~else
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (63, 63, 255, 255), height, code => true);
|
||||
--~end if;
|
||||
--~when '0' .. '9' =>
|
||||
--~loop
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (127, 63, 255, 255), height, code => true);
|
||||
--~core.increment (length);
|
||||
--~buffer := ada.strings.unbounded.element (text.text, length);
|
||||
--~exit when buffer = ' ' or buffer = ';' or buffer = ')' or buffer = ',';
|
||||
--~offset.x := offset.x + width;
|
||||
--~end loop;
|
||||
--~core.decrement (length);
|
||||
--~when 'a' .. 'z' | 'A' .. 'Z' =>
|
||||
--~word := ada.strings.unbounded.to_unbounded_string (buffer & "");
|
||||
--~subset := 1;
|
||||
--~loop
|
||||
--~buffer := ada.strings.unbounded.element (text.text, length + subset);
|
||||
--~exit when buffer = ' ' or buffer = '.' or buffer = '(' or buffer = ')' or buffer = ',' or buffer = ';' or buffer = '''
|
||||
--~or buffer = character'val (9) or buffer = character'val (10);
|
||||
--~word := word & ada.strings.unbounded.to_unbounded_string (buffer & "");
|
||||
--~core.increment (subset);
|
||||
--~end loop;
|
||||
--~if word = "type" or word = "begin" or word = "end" or word = "when" or word = "others" or word = "procedure" or word = "function"
|
||||
--~or word = "package" or word = "body" or word = "if" or word = "then" or word = "else" or word = "elsif" or word = "case" or word = "is"
|
||||
--~or word = "and" or word = "or" or word = "xor" or word = "exit" or word = "constant" or word = "access" or word = "range"
|
||||
--~or word = "subtype" or word = "array" or word = "in" or word = "out" or word = "return" or word = "for" or word = "with"
|
||||
--~or word = "loop" or word = "while" or word = "of" or word = "null" or word = "record" or word = "use" or word = "mod" or word = "new"
|
||||
--~or word = "aliased" or word = "all" then
|
||||
--~ui.write (ada.strings.unbounded.to_string (word), offset.x, offset.y, (255, 255, 0, 255), height, code => true);
|
||||
--~else
|
||||
--~ui.write (ada.strings.unbounded.to_string (word), offset.x, offset.y, (others => 255), height, code => true);
|
||||
--~end if;
|
||||
--~offset.x := offset.x + (subset - 1) * width;
|
||||
--~length := length + subset - 1;
|
||||
--~when others =>
|
||||
--~ui.write (buffer & "", offset.x, offset.y, (others => 255), height, code => true);
|
||||
--~end case;
|
||||
--~--
|
||||
--~core.increment (length);
|
||||
--~end loop;
|
||||
--~end write_ada_code;
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
-- GNU General Public Licence (version 3 or later)
|
||||
|
||||
with core;
|
||||
use core;
|
||||
|
||||
package ui is
|
||||
|
||||
@ -21,34 +20,6 @@ package ui is
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
type gui_data is record
|
||||
kind : enumeration := gui_none;
|
||||
text : core.unstring := +("--");
|
||||
info : core.unstring := +("--");
|
||||
number : integer := 0;
|
||||
image : core.sprite := (others => 0);
|
||||
end record;
|
||||
|
||||
empty : gui_data;
|
||||
|
||||
type gui_array is array (natural range <>) of gui_data;
|
||||
|
||||
type structure is record
|
||||
title : core.short_string := "-- ";
|
||||
toggle : core.signal_code := core.signal_space;
|
||||
show : boolean := false;
|
||||
center : boolean := false;
|
||||
resize : boolean := false;
|
||||
x : integer := 0;
|
||||
y : integer := 0;
|
||||
width : integer := 0;
|
||||
height : integer := 0;
|
||||
gui_n : natural := 0;
|
||||
gui_list : access gui_array := null;
|
||||
end record;
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
style_count : constant natural := style'pos (style'last) + 1;
|
||||
|
||||
active : style := main;
|
||||
@ -90,12 +61,7 @@ package ui is
|
||||
procedure draw_state_box (x, y : in integer);
|
||||
procedure draw_console_box (x, y, width, height : in integer);
|
||||
|
||||
procedure add_structure (data : in structure);
|
||||
|
||||
procedure add_structure_button (icon : in core.sprite; name : in core.unstring; text : in core.unstring);
|
||||
procedure add_structure_orient;
|
||||
|
||||
procedure write_ada_code (text : in core.string_box_data; x, y : in integer);
|
||||
--~procedure write_ada_code (text : in core.string_box_data; x, y : in integer);
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user