fox32os/applications/fetcher/Desktop.okm
TalonFox aa60133fe0
Improve window dragging and add fetcher animation
Signed-off-by: TalonFox <105325988+TalonFox@users.noreply.github.com>
2023-07-12 12:41:11 -05:00

146 lines
5.4 KiB
Plaintext

MODULE Desktop;
IMPORT OS;
VAR desktopRunning: CHAR;
desktopWindow: ARRAY 36 OF CHAR;
desktopIcons: ARRAY 5 OF Fox32OSButtonWidget;
PROCEDURE DesktopMain();
BEGIN
desktopRunning := 1;
(* set up the desktop icon widgets *)
SetupDesktopIconStructs();
(* create the window and make it fully transparent, draw the button widgets to it, and mark it as "always background *)
new_window(PTROF(desktopWindow), "Desktop", 640, 448, 0, 16, 0, PTROF(desktopIcons));
fill_overlay(000000000H, get_window_overlay_number(PTROF(desktopWindow)));
draw_widgets_to_window(PTROF(desktopWindow));
set_window_flags(000000001H, PTROF(desktopWindow));
WHILE desktopRunning DO
GetNextWindowEvent(PTROF(desktopWindow));
(* mouse click event *)
IF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_CLICK) THEN
handle_widget_click(PTROF(desktopWindow), eventArgs[1], eventArgs[2]);
(* button click event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_BUTTON_CLICK) THEN
HandleDesktopIconClick(eventArgs[1]);
END;
save_state_and_yield_task();
END;
END;
PROCEDURE Eep(ms: INT;); (* the furry version of sleep :3 *)
VAR deadline: INT;
BEGIN
deadline := ms + PortIn(80000706H);
WHILE PortIn(80000706H) <| deadline DO
save_state_and_yield_task();
END;
END;
PROCEDURE DrawWireframeBox(overlay, x, y, w, h, color: INT;);
BEGIN
draw_filled_rectangle_to_overlay(x,y,w,1,color,overlay);
draw_filled_rectangle_to_overlay(x,y,1,h,color,overlay);
draw_filled_rectangle_to_overlay(x+w-1,y,1,h,color,overlay);
draw_filled_rectangle_to_overlay(x,y+h-1,w,1,color,overlay);
END;
PROCEDURE HandleDesktopIconClick(buttonId: INT;);
VAR i, x, y, w, h: INT;
icon: POINTER TO Fox32OSButtonWidget;
BEGIN
(* Draw the expanding box animation *)
i := 0;
icon := PTROF(desktopIcons[buttonId]);
WHILE i < 16 DO
x := RSH(icon^.x *| (16 - i) + 64 *| i,4);
y := RSH(icon^.y *| (16 - i) + 64 *| i,4);
w := RSH(32 *| (16 - i) + 384 *| i,4);
h := RSH(32 *| (16 - i) + 192 *| i,4);
DrawWireframeBox(get_window_overlay_number(PTROF(desktopWindow)),x,y,w,h,20F0F0F0H);
Eep(5);
draw_filled_rectangle_to_overlay(x,y,w,h,0,get_window_overlay_number(PTROF(desktopWindow)));
i := i + 1;
END;
draw_widgets_to_window(PTROF(desktopWindow));
IF launch_fxf_from_disk("fetcher.fxf", get_boot_disk_id(), 0FFFFFFFFH, buttonId, icon^.x, icon^.y, PTROF(desktopWindow)) = 0FFFFFFFFH THEN
new_messagebox("Failed to start new", "instance of fetcher.fxf", 0, 64, 64, 200);
END;
END;
PROCEDURE SetupDesktopIconStructs();
VAR desktopIcon: POINTER TO Fox32OSButtonWidget;
prevDesktopIcon: POINTER TO Fox32OSButtonWidget;
BEGIN
desktopIcon := PTROF(desktopIcons[0]);
desktopIcon^.type := WIDGET_TYPE_BUTTON;
desktopIcon^.next := PTROF(desktopIcons[1]);
desktopIcon^.id := 0;
desktopIcon^.text := "Disk 0";
desktopIcon^.fgColor := 0FF000000H;
desktopIcon^.bgColor := 0FFFFFFFFH;
desktopIcon^.width := 32;
desktopIcon^.height := 32 + 16;
desktopIcon^.x := 592;
desktopIcon^.y := 16;
prevDesktopIcon := desktopIcon;
desktopIcon := PTROF(desktopIcons[1]);
desktopIcon^.type := WIDGET_TYPE_BUTTON;
desktopIcon^.next := PTROF(desktopIcons[2]);
desktopIcon^.id := 1;
desktopIcon^.text := "Disk 1";
desktopIcon^.fgColor := 0FF000000H;
desktopIcon^.bgColor := 0FFFFFFFFH;
desktopIcon^.width := 32;
desktopIcon^.height := 32 + 16;
desktopIcon^.x := 592;
desktopIcon^.y := prevDesktopIcon^.y + 32 + 32;
prevDesktopIcon := desktopIcon;
desktopIcon := PTROF(desktopIcons[2]);
desktopIcon^.type := WIDGET_TYPE_BUTTON;
desktopIcon^.next := PTROF(desktopIcons[3]);
desktopIcon^.id := 2;
desktopIcon^.text := "Disk 2";
desktopIcon^.fgColor := 0FF000000H;
desktopIcon^.bgColor := 0FFFFFFFFH;
desktopIcon^.width := 32;
desktopIcon^.height := 32 + 16;
desktopIcon^.x := 592;
desktopIcon^.y := prevDesktopIcon^.y + 32 + 32;
prevDesktopIcon := desktopIcon;
desktopIcon := PTROF(desktopIcons[3]);
desktopIcon^.type := WIDGET_TYPE_BUTTON;
desktopIcon^.next := PTROF(desktopIcons[4]);
desktopIcon^.id := 3;
desktopIcon^.text := "Disk 3";
desktopIcon^.fgColor := 0FF000000H;
desktopIcon^.bgColor := 0FFFFFFFFH;
desktopIcon^.width := 32;
desktopIcon^.height := 32 + 16;
desktopIcon^.x := 592;
desktopIcon^.y := prevDesktopIcon^.y + 32 + 32;
prevDesktopIcon := desktopIcon;
desktopIcon := PTROF(desktopIcons[4]);
desktopIcon^.type := WIDGET_TYPE_BUTTON;
desktopIcon^.next := 0;
desktopIcon^.id := 4;
desktopIcon^.text := "Disk 4";
desktopIcon^.fgColor := 0FF000000H;
desktopIcon^.bgColor := 0FFFFFFFFH;
desktopIcon^.width := 32;
desktopIcon^.height := 32 + 16;
desktopIcon^.x := 592;
desktopIcon^.y := prevDesktopIcon^.y + 32 + 32;
END;
END.