Fetcher: Add support for "open file" dialogs

This commit is contained in:
Ry 2023-10-12 21:14:29 -07:00
parent f6fed505cc
commit 6072f41442
5 changed files with 115 additions and 6 deletions

View File

@ -25,10 +25,10 @@ base_image/terminal.fxf: applications/terminal/main.asm $(wildcard applications/
$(FOX32ASM) $< $@ $(FOX32ASM) $< $@
base_image/fetcher.fxf: applications/fetcher/Fetcher.okm $(wildcard applications/fetcher/*.okm) base_image/fetcher.fxf: applications/fetcher/Fetcher.okm $(wildcard applications/fetcher/*.okm)
$(GFX2INC) 32 32 applications/fetcher/icons/disk.png applications/fetcher/icons/disk.inc
lua $(OKAMERON) -arch=fox32 -startup=applications/fetcher/start.asm $< \ lua $(OKAMERON) -arch=fox32 -startup=applications/fetcher/start.asm $< \
applications/fetcher/About.okm \ applications/fetcher/About.okm \
applications/fetcher/Browser.okm \ applications/fetcher/Browser.okm \
applications/fetcher/BrowserOpen.okm \
applications/fetcher/Desktop.okm \ applications/fetcher/Desktop.okm \
applications/fetcher/OS.okm \ applications/fetcher/OS.okm \
> applications/fetcher/fetcher.asm > applications/fetcher/fetcher.asm

View File

@ -0,0 +1,101 @@
MODULE BrowserOpen;
IMPORT OS, About, Browser;
VAR browserOpenReturnFileNamePtr: POINTER TO CHAR;
browserOpenReturnDiskIdPtr: POINTER TO INT;
EXTERN browserMenuItemsRoot: POINTER TO CHAR;
PROCEDURE BrowserOpenMain(returnFileName, returnDiskId: PTR; hasIcons: CHAR; iconsResPtr: PTR;);
BEGIN
browserRunning := 1;
browserPage := 0;
browserDiskId := get_current_disk_id();
browserHasIcons := hasIcons;
browserIconsResPtr := iconsResPtr;
browserOpenReturnFileNamePtr := returnFileName;
browserOpenReturnDiskIdPtr := returnDiskId;
(* first, before we do anything, check to make sure the selected disk is available *)
IF browserDiskId >| 4 THEN
new_messagebox(0, "Invalid disk ID!", 0, 128, 128, 144);
end_current_task();
ELSIF browserDiskId = 4 THEN
IF IsRomDiskAvailable() = 0 THEN
new_messagebox(0, "ROM disk not available!", 0, 128, 128, 200);
end_current_task();
END;
ELSE
IF PortIn(080001000H OR browserDiskId) = 0 THEN
new_messagebox(0, "Disk not inserted!", 0, 128, 128, 160);
end_current_task();
END;
END;
(* create the window and draw its initial contents *)
new_window(PTROF(browserWindow), "Select a file - Fetcher", 384, 192, 64, 64, PTROF(browserMenuItemsRoot), PTROF(browserIcons));
DrawBrowserWindow();
WHILE browserRunning DO
GetNextWindowEvent(PTROF(browserWindow));
(* mouse click event *)
IF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_CLICK) THEN
IF (eventArgs[1] <| 8) & (eventArgs[2] <| 16) THEN
browserRunning := 0;
ELSIF eventArgs[2] <| 16 THEN
start_dragging_window(PTROF(browserWindow));
END;
handle_widget_click(PTROF(browserWindow), eventArgs[1], eventArgs[2]);
(* menu bar click event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_BAR_CLICK) THEN
menu_bar_click_event(PTROF(browserMenuItemsRoot));
(* menu update event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_UPDATE) THEN
menu_update_event();
(* menu click event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_CLICK) THEN
MenuClickEvent(eventArgs[2], eventArgs[3]);
(* menu ack event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_ACK) THEN
close_menu(PTROF(browserMenuItemsRoot));
(* button click event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_BUTTON_CLICK) THEN
HandleIconClickOpen(eventArgs[1]);
END;
save_state_and_yield_task();
END;
destroy_window(PTROF(browserWindow));
END;
PROCEDURE HandleIconClickOpen(buttonId: INT;);
BEGIN
IF buttonId = 128 THEN
(* next page button *)
IncrementBrowserPage();
ELSIF buttonId = 129 THEN
(* previous page button *)
DecrementBrowserPage();
ELSE
(* an icon was clicked! *)
ReturnFromIcon(buttonId);
END;
END;
PROCEDURE ReturnFromIcon(buttonId: INT;);
VAR icon: POINTER TO Fox32OSButtonWidget;
BEGIN
icon := PTROF(browserIcons[buttonId]);
IF CompareString(icon^.text, "<empty>") THEN RETURN(); END;
browserOpenReturnDiskIdPtr^ := browserDiskId;
copy_string(icon^.text, browserOpenReturnFileNamePtr);
browserRunning := 0;
END;
END.

View File

@ -1,5 +1,5 @@
MODULE Fetcher; MODULE Fetcher;
IMPORT OS, Browser, Desktop; IMPORT OS, Browser, BrowserOpen, Desktop;
EXTERN terminalStreamPtr: POINTER TO CHAR; EXTERN terminalStreamPtr: POINTER TO CHAR;
EXTERN arg0Ptr: POINTER TO CHAR; EXTERN arg0Ptr: POINTER TO CHAR;
@ -26,6 +26,9 @@ MODULE Fetcher;
IF (terminalStreamPtr = 0) & (arg0Ptr = 0) THEN IF (terminalStreamPtr = 0) & (arg0Ptr = 0) THEN
(* probably launched from startup.cfg *) (* probably launched from startup.cfg *)
DesktopMain(hasIcons, iconsRes); DesktopMain(hasIcons, iconsRes);
ELSIF (CompareString("open", arg0Ptr)) & (arg1Ptr # 0) & (arg2Ptr # 0) THEN
(* launched from an application wanting to open a file *)
BrowserOpenMain(arg1Ptr, arg2Ptr, hasIcons, iconsRes);
ELSIF arg0Ptr <|= 5 THEN ELSIF arg0Ptr <|= 5 THEN
(* launched from an existing instance of fetcher *) (* launched from an existing instance of fetcher *)
BrowserMain(arg0Ptr, arg1Ptr, arg2Ptr, arg3Ptr, hasIcons, iconsRes); BrowserMain(arg0Ptr, arg1Ptr, arg2Ptr, arg3Ptr, hasIcons, iconsRes);

View File

@ -7,13 +7,12 @@ MODULE OS;
EXTERN PROCEDURE new_window, destroy_window, draw_str_to_overlay, get_window_overlay_number, EXTERN PROCEDURE new_window, destroy_window, draw_str_to_overlay, get_window_overlay_number,
draw_widgets_to_window, draw_filled_rectangle_to_overlay, GetNextWindowEvent, DrawPixel, draw_widgets_to_window, draw_filled_rectangle_to_overlay, GetNextWindowEvent, DrawPixel,
save_state_and_yield_task, start_dragging_window, handle_widget_click, fill_window, fill_overlay, save_state_and_yield_task, start_dragging_window, handle_widget_click, fill_window, fill_overlay,
set_window_flags, menu_update_event, menu_bar_click_event, close_menu, new_messagebox, set_window_flags, menu_update_event, menu_bar_click_event, close_menu, new_messagebox, get_current_disk_id,
launch_fxf_from_disk, get_boot_disk_id, string_to_int, set_tilemap, draw_tile_to_overlay, launch_fxf_from_disk, get_boot_disk_id, string_to_int, set_tilemap, draw_tile_to_overlay,
ryfs_get_file_list, copy_memory_bytes, IsRomDiskAvailable, end_current_task, sleep_task, ryfs_get_file_list, copy_memory_bytes, IsRomDiskAvailable, end_current_task, sleep_task, CompareString,
open, read, get_size, get_boot_disk_id, get_resource, allocate_memory, free_memory, string_length: INT; open, read, get_size, get_boot_disk_id, get_resource, allocate_memory, free_memory, string_length, copy_string: INT;
EXTERN PROCEDURE brk: INT; EXTERN PROCEDURE brk: INT;
EXTERN PROCEDURE PortIn: INT; EXTERN PROCEDURE PortIn: INT;
EXTERN EVENT_TYPE_MOUSE_CLICK, EXTERN EVENT_TYPE_MOUSE_CLICK,

View File

@ -30,6 +30,12 @@ IsRomDiskAvailable:
ifnz mov r0, 0 ifnz mov r0, 0
ret ret
CompareString:
call compare_string
ifz mov r0, 1
ifnz mov r0, 0
ret
brk: brk:
brk brk
ret ret