Browse Source

Experimenting with UI mouse input...

master
parent
commit
fd581b20e0
2 changed files with 75 additions and 67 deletions
  1. +70
    -62
      source/ui.adb
  2. +5
    -5
      source/ui.ads

+ 70
- 62
source/ui.adb View File

@@ -58,49 +58,57 @@ package body ui is

------------------------------------------------------------------------------------------

procedure draw (index : in element := none;
x : in integer := 0;
y : in integer := 0;
width : in integer := 0;
height : in integer := 0) is
procedure draw (index : in element := none;
x : in integer := 0;
y : in integer := 0;
width : in integer := 0;
height : in integer := 0;
action : core.pointer := core.idle'access) is
save_zoom : natural := core.zoom;
begin
core.zoom := 1;
core.draw (sprite (active, index), x, y, 0, 0, width, height);
core.zoom := save_zoom;
--
if core.cursor.x > x and core.cursor.x < x + width
and core.cursor.y > y and core.cursor.y < y + height
and core.cursor_mode = 1 then
action.all;
core.cursor_mode := 0;
end if;
end draw;

------------------------------------------------------------------------------------------

procedure draw_horizontally (index : in element; x, y, width : in integer) is
procedure draw_horizontally (index : in element; x, y, width : in integer; action : core.pointer := core.idle'access) is
step : constant integer := sprite (active, index).width;
begin
for move in 0 .. width / step - 1 loop
draw (index, x + move * step, y);
draw (index, x + move * step,y, action => action);
end loop;
--
if width mod step > 0 then
draw (index, x + (width / step) * step, y, width mod step, sprite (active, index).height);
draw (index, x + (width / step) * step, y, width mod step, sprite (active, index).height, action);
end if;
end draw_horizontally;

------------------------------------------------------------------------------------------

procedure draw_vertically (index : in element; x, y, height : in integer) is
procedure draw_vertically (index : in element; x, y, height : in integer; action : core.pointer := core.idle'access) is
step : constant integer := sprite (active, index).height;
begin
for move in 0 .. height / step - 1 loop
draw (index, x, y + move * step);
draw (index, x, y + move * step, action => action);
end loop;
--
if height mod step > 0 then
draw (index, x, y + (height / step) * step, sprite (active, index).width, height mod step);
draw (index, x, y + (height / step) * step, sprite (active, index).width, height mod step, action);
end if;
end draw_vertically;

------------------------------------------------------------------------------------------

procedure draw_background (index : in element; x, y, width, height : in integer) is
procedure draw_background (index : in element; x, y, width, height : in integer; action : core.pointer := core.idle'access) is
base_width : integer := sprite (active, index).width;
base_height : integer := sprite (active, index).height;
crop_width : integer := width mod base_width;
@@ -108,22 +116,22 @@ package body ui is
begin
for move_y in 0 .. height / base_height - 1 loop
for move_x in 0 .. width / base_width - 1 loop
draw (index, x + move_x * base_width, y + move_y * base_height);
draw (index, x + move_x * base_width, y + move_y * base_height, action => action);
end loop;
--
if width mod base_width > 0 then
draw (index, x + width - crop_width, y + move_y * base_height, crop_width, base_height);
draw (index, x + width - crop_width, y + move_y * base_height, crop_width, base_height, action => action);
end if;
end loop;
--
for move_x in 0 .. width / base_width - 1 loop
if height mod base_height > 0 then
draw (index, x + move_x * base_width, y + height - crop_height, base_width, crop_height);
draw (index, x + move_x * base_width, y + height - crop_height, base_width, crop_height, action => action);
end if;
end loop;
--
if width mod base_width > 0 and height mod base_height > 0 then
draw (index, x + width - crop_width, y + height - crop_height, crop_width, crop_height);
draw (index, x + width - crop_width, y + height - crop_height, crop_width, crop_height, action => action);
end if;
end draw_background;

@@ -148,29 +156,21 @@ package body ui is

------------------------------------------------------------------------------------------

procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : access procedure := core.idle'access) is
procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access) is
save_zoom : natural := core.zoom;
begin
select_text_box (description, x, y, core.icon, core.icon);
--
draw (icon, x, y);
draw (icon, x, y, action => action);
--
core.zoom := 1;
core.draw (data, x, y);
core.zoom := save_zoom;
--
if core.cursor.x > x and core.cursor.x < x + core.icon
and core.cursor.y > y and core.cursor.y < y + core.icon
and core.cursor_mode = 1 then
action.all;
core.cursor_mode := 0;
return;
end if;
end draw_icon;

------------------------------------------------------------------------------------------

procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer) is
procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access) is
save_zoom : natural := core.zoom;
begin
select_text_box (description, x, y, core.icon, core.icon);
@@ -179,25 +179,25 @@ package body ui is
core.draw (data, x, y);
core.zoom := save_zoom;
--
draw (overicon, x, y);
draw (overicon, x, y, action => action);
end draw_overicon;

------------------------------------------------------------------------------------------

procedure draw_text_box (x, y, width, height : in integer) is
procedure draw_text_box (x, y, width, height : in integer; action : core.pointer := core.idle'access) is
offset : constant integer := sprite (active, text_middle).width;
begin
draw_background (text_middle, x + offset, y + offset, width - 2 * offset, height - 2 * offset);
draw_background (text_middle, x + offset, y + offset, width - 2 * offset, height - 2 * offset, action => action);
--
draw_horizontally (text_upper, x + offset, y, width - 2 * offset);
draw_horizontally (text_lower, x + offset, y + height - offset, width - 2 * offset);
draw_vertically (text_left, x, y + offset, height - 2 * offset);
draw_vertically (text_right, x + width - offset, y + offset, height - 2 * offset);
draw_horizontally (text_upper, x + offset, y, width - 2 * offset, action => action);
draw_horizontally (text_lower, x + offset, y + height - offset, width - 2 * offset, action => action);
draw_vertically (text_left, x, y + offset, height - 2 * offset, action => action);
draw_vertically (text_right, x + width - offset, y + offset, height - 2 * offset, action => action);
--
draw (text_upper_left, x, y);
draw (text_upper_right, x + width - offset, y);
draw (text_lower_left, x, y + height - offset);
draw (text_lower_right, x + width - offset, y + height - offset);
draw (text_upper_left, x, y, action => action);
draw (text_upper_right, x + width - offset, y, action => action);
draw (text_lower_left, x, y + height - offset, action => action);
draw (text_lower_right, x + width - offset, y + height - offset, action => action);
--
core.write (core.read_text_box, x, y, font (active));
--
@@ -206,7 +206,7 @@ package body ui is

------------------------------------------------------------------------------------------

procedure draw_frame (description : in string; x, y, width, height : in integer) is
procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle'access) is
offset_x : constant integer := sprite (active, frame_middle).width;
offset_y : constant integer := sprite (active, frame_middle).height;
begin
@@ -214,17 +214,17 @@ package body ui is
return;
end if;
--
draw_background (frame_middle, x + offset_x, y + offset_y, width - 2 * offset_x, height - 2 * offset_y);
draw_background (frame_middle, x + offset_x, y + offset_y, width - 2 * offset_x, height - 2 * offset_y, action => action);
--
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_horizontally (frame_upper, x + offset_x, y, width - 2 * offset_x, action => action);
draw_horizontally (frame_lower, x + offset_x, y + height - offset_y, width - 2 * offset_x, action => action);
draw_vertically (frame_left, x, y + offset_y, height - 2 * offset_y, action => action);
draw_vertically (frame_right, x + width - offset_x, y + offset_y, height - 2 * offset_y, action => action);
--
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);
draw (frame_upper_left, x, y, action => action);
draw (frame_upper_right, x + width - sprite (active, frame_upper_right).width, y, action => action);
draw (frame_lower_left, x, y + height - sprite (active, frame_lower_left).height, action => action);
draw (frame_lower_right, x + width - sprite (active, frame_lower_right).width, y + height - sprite (active, frame_lower_right).height, action => action);
--
select_text_box (description, x, y, width, height);
end draw_frame;
@@ -265,10 +265,10 @@ package body ui is
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);
draw_horizontally (border_upper, x + sprite (active, corner_upper_left).width, y, upper, action => core.move_camera_up'access);
draw_horizontally (border_lower, x + sprite (active, corner_lower_left).width, y + height - sprite (active, border_lower).height, lower, action => core.move_camera_down'access);
draw_vertically (border_left, x, y + sprite (active, corner_upper_left).height, left, action => core.move_camera_left'access);
draw_vertically (border_right, x + width - sprite (active, border_right).width, y + sprite (active, corner_upper_right).height, right, action => core.move_camera_right'access);
end;
--
draw (corner_upper_left, x, y);
@@ -284,6 +284,13 @@ package body ui is
procedure draw_tiny_menu (x, y, width, height : in integer) is
offset : constant integer := sprite (active, none).width;
begin
--~if core.cursor.x > x and core.cursor.x < x + width
--~and core.cursor.y > y and core.cursor.y < y + height
--~and core.cursor_mode = 2 then
--~return;
--~core.cursor_mode := 0;
--~end if;
--
draw_background (main_background, x + offset, y + offset, width - 2 * offset, height - 2 * offset);
--
declare upper : constant integer := width - sprite (active, tiny_corner_upper_left).width - sprite (active, tiny_corner_upper_right).width;
@@ -307,23 +314,24 @@ package body ui is

------------------------------------------------------------------------------------------

procedure draw_icon_menu (description : in string; x, y, width, height : in integer) is
procedure draw_icon_menu (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle'access) is
offset_x : constant integer := sprite (active, icon_upper_left).width;
offset_y : constant integer := sprite (active, icon_upper_left).height;
begin
if height < 2 * sprite (active, icon_upper_left).height or width < 2 * sprite (active, icon_upper_left).width then
if height < 2 * sprite (active, icon_upper_left).height
or width < 2 * sprite (active, icon_upper_left).width then
return;
end if;
--
draw_horizontally (icon_upper, x + offset_x, y, width - 2 * offset_x);
draw_horizontally (icon_lower, x + offset_x, y + height - offset_y, width - 2 * offset_x);
draw_vertically (icon_left, x, y + offset_y, height - 2 * offset_y);
draw_vertically (icon_right, x + width - offset_x, y + offset_y, height - 2 * offset_y);
draw_horizontally (icon_upper, x + offset_x, y, width - 2 * offset_x, action => action);
draw_horizontally (icon_lower, x + offset_x, y + height - offset_y, width - 2 * offset_x, action => action);
draw_vertically (icon_left, x, y + offset_y, height - 2 * offset_y, action => action);
draw_vertically (icon_right, x + width - offset_x, y + offset_y, height - 2 * offset_y, action => action);
--
draw (icon_upper_left, x, y);
draw (icon_upper_right, x + width - sprite (active, icon_upper_right).width, y);
draw (icon_lower_left, x, y + height - sprite (active, icon_lower_left).height);
draw (icon_lower_right, x + width - sprite (active, icon_lower_right).width, y + height - sprite (active, icon_lower_right).height);
draw (icon_upper_left, x, y, action => action);
draw (icon_upper_right, x + width - sprite (active, icon_upper_right).width, y, action => action);
draw (icon_lower_left, x, y + height - sprite (active, icon_lower_left).height, action => action);
draw (icon_lower_right, x + width - sprite (active, icon_lower_right).width, y + height - sprite (active, icon_lower_right).height, action => action);
--
select_text_box (description, x, y, width, height);
end draw_icon_menu;


+ 5
- 5
source/ui.ads View File

@@ -21,12 +21,12 @@ package ui is

procedure configure;

procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : access procedure := core.idle'access);
procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer);
procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access);
procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access);

procedure draw_text_box (x, y, width, height : in integer);
procedure draw_text_box (x, y, width, height : in integer; action : core.pointer := core.idle'access);

procedure draw_frame (description : in string; x, y, width, height : in integer);
procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle'access);

procedure draw_title_bar (x, y, width : in integer; title : in string);
procedure draw_scroll_bar (x, y, height : in integer; offset : in integer);
@@ -34,7 +34,7 @@ package ui is
procedure draw_menu (x, y, width, height : in integer);
procedure draw_tiny_menu (x, y, width, height : in integer);

procedure draw_icon_menu (description : in string; x, y, width, height : in integer);
procedure draw_icon_menu (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle'access);

procedure draw_state_box (x, y : in integer);



Loading…
Cancel
Save