fox32os/applications/okmpaint/OkmPaint.okm

129 lines
4.1 KiB
Plaintext
Raw Normal View History

2023-06-26 01:46:42 +02:00
MODULE OkmPaint;
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,
save_state_and_yield_task, start_dragging_window, handle_widget_click, fill_window,
menu_update_event, menu_bar_click_event, close_menu: INT;
EXTERN eventArgs: ARRAY 8 OF INT;
EXTERN menuItemsRoot: POINTER TO CHAR;
EXTERN EVENT_TYPE_MOUSE_CLICK,
EVENT_TYPE_MOUSE_RELEASE,
EVENT_TYPE_BUTTON_CLICK,
EVENT_TYPE_MENU_BAR_CLICK,
EVENT_TYPE_MENU_UPDATE,
EVENT_TYPE_MENU_CLICK,
EVENT_TYPE_MENU_ACK,
WIDGET_TYPE_BUTTON: INT;
TYPE Fox32OSButtonWidget = RECORD
next, id, type, text, fgColor, bgColor, width: INT;
x, y: SHORT;
END;
VAR running: CHAR;
drawing: CHAR;
size: CHAR;
color: INT;
canvasWindow: ARRAY 36 OF CHAR;
PROCEDURE Main();
BEGIN
running := 1;
drawing := 0;
size := 2;
color := 0FFFFFFFFH;
new_window(PTROF(canvasWindow), "OkmPaint canvas", 256, 256, 128, 128, PTROF(menuItemsRoot), 0);
WHILE running DO
GetNextWindowEvent(PTROF(canvasWindow));
(* mouse click event *)
IF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_CLICK) THEN
IF (eventArgs[1] <| 8) & (eventArgs[2] <| 16) THEN
(* clicked the window's close box *)
destroy_window(PTROF(canvasWindow));
running := 0;
ELSIF eventArgs[2] <| 16 THEN
(* clicked the window's title bar *)
start_dragging_window(PTROF(canvasWindow));
ELSE
drawing := 1;
END;
(* mouse release event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_RELEASE) THEN
drawing := 0;
(* menu bar click event *)
ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_BAR_CLICK) THEN
menu_bar_click_event(PTROF(menuItemsRoot));
(* 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(menuItemsRoot));
END;
IF drawing THEN
DrawPixel();
END;
save_state_and_yield_task();
END;
END;
PROCEDURE MenuClickEvent(rootIndex, itemIndex: INT;);
BEGIN
IF rootIndex = 0 THEN
(* Canvas menu *)
IF itemIndex = 0 THEN
(* Clear to Black *)
fill_window(0FF000000H, PTROF(canvasWindow));
ELSIF itemIndex = 1 THEN
(* Clear to White *)
fill_window(0FFFFFFFFH, PTROF(canvasWindow));
END;
ELSIF rootIndex = 1 THEN
(* Brush menu *)
IF itemIndex = 0 THEN
(* 2x2 *)
size := 2;
ELSIF itemIndex = 1 THEN
(* 4x4 *)
size := 4;
ELSIF itemIndex = 2 THEN
(* 8x8 *)
size := 8;
ELSIF itemIndex = 3 THEN
(* 16x16 *)
size := 16;
END;
ELSIF rootIndex = 2 THEN
(* Color menu *)
IF itemIndex = 0 THEN
(* Black *)
color := 0FF000000H;
ELSIF itemIndex = 1 THEN
(* White *)
color := 0FFFFFFFFH;
ELSIF itemIndex = 2 THEN
(* Red *)
color := 0FF0000FFH;
ELSIF itemIndex = 3 THEN
(* Green *)
color := 0FF00FF00H;
ELSIF itemIndex = 3 THEN
(* Blue *)
color := 0FFFF0000H;
END;
END;
END;
END.