From 39adbed93a0cab91fa649cdb1bc60491ec23150c Mon Sep 17 00:00:00 2001 From: Ry Date: Sat, 15 Jun 2024 21:27:11 -0700 Subject: [PATCH] kernel: Label widget --- fox32os.def | 2 +- kernel/widget/label.asm | 50 ++++++++++++++++++++++++++++++++++++++++ kernel/widget/widget.asm | 29 +++++++++++++++++++++++ kernel/window/event.asm | 1 - 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 kernel/widget/label.asm diff --git a/fox32os.def b/fox32os.def index e612a71..b1e44a1 100644 --- a/fox32os.def +++ b/fox32os.def @@ -63,11 +63,11 @@ get_resource: jmp [0x00000F10] ; event types const EVENT_TYPE_BUTTON_CLICK: 0x80000000 -const EVENT_TYPE_TEXTBOX_REFRESH: 0x80000001 ; widget types const WIDGET_TYPE_BUTTON: 0x00000000 const WIDGET_TYPE_TEXTBOX_SL: 0x00000001 +const WIDGET_TYPE_LABEL: 0x00000002 ; window flags const WINDOW_FLAG_ALWAYS_BACKGROUND: 1 diff --git a/kernel/widget/label.asm b/kernel/widget/label.asm new file mode 100644 index 0000000..0f79046 --- /dev/null +++ b/kernel/widget/label.asm @@ -0,0 +1,50 @@ +; label widget routines + +; label widget struct: +; data.32 next_ptr - pointer to next widget, or 0 for none +; data.32 id - the ID number of this widget +; data.32 type - the type of this widget +; data.32 text_ptr - pointer to null-terminated text string +; data.32 foreground_color - text foreground color +; data.32 background_color - text background color +; data.16 reserved_1 +; data.16 reserved_2 +; data.16 x_pos - X coordinate of this widget +; data.16 y_pos - Y coordinate of this widget + +const LABEL_WIDGET_STRUCT_SIZE: 32 ; 8 words = 32 bytes + +; draw a label widget to a window +; inputs: +; r0: pointer to window struct +; r1: pointer to a null-terminated string +; r2: foreground color +; r3: background color +; r4: X coordinate +; r5: Y coordinate +; outputs: +; none +draw_label_widget: + push r0 + push r1 + push r2 + push r3 + push r4 + push r5 + + call get_window_overlay_number + mov r2, r5 + mov r5, r0 + mov r0, r1 + mov r1, r4 + mov r4, r3 + mov r3, r2 + call draw_str_to_overlay + + pop r5 + pop r4 + pop r3 + pop r2 + pop r1 + pop r0 + ret diff --git a/kernel/widget/widget.asm b/kernel/widget/widget.asm index 3f55069..f9a7a87 100644 --- a/kernel/widget/widget.asm +++ b/kernel/widget/widget.asm @@ -3,6 +3,7 @@ ; widget types const WIDGET_TYPE_BUTTON: 0x00000000 const WIDGET_TYPE_TEXTBOX_SL: 0x00000001 +const WIDGET_TYPE_LABEL: 0x00000002 ; widget struct: ; data.32 next_ptr - pointer to next widget, or 0 for none @@ -27,6 +28,8 @@ draw_widgets_to_window_next: ifz call draw_widgets_to_window_button cmp [r10], WIDGET_TYPE_TEXTBOX_SL ifz call draw_widgets_to_window_textbox_sl + cmp [r10], WIDGET_TYPE_LABEL + ifz call draw_widgets_to_window_label ; point to the next widget, if any sub r10, 8 @@ -97,6 +100,31 @@ draw_widgets_to_window_textbox_sl: pop r2 pop r1 ret +draw_widgets_to_window_label: + push r1 + push r2 + push r3 + push r4 + push r5 + push r6 + push r7 + + ; put label parameters in registers for the drawing routine + mov r1, [r10+4] ; text_ptr + mov r2, [r10+8] ; foreground_color + mov r3, [r10+12] ; background_color + movz.16 r4, [r10+20] ; x_pos + movz.16 r5, [r10+22] ; y_pos + call draw_label_widget + + pop r7 + pop r6 + pop r5 + pop r4 + pop r3 + pop r2 + pop r1 + ret ; check if a widget was clicked and if so, add an event to the window's event queue ; inputs: @@ -477,4 +505,5 @@ handle_widget_key_up_textbox_sl: ; include widget types #include "widget/button.asm" + #include "widget/label.asm" #include "widget/textbox_sl.asm" diff --git a/kernel/window/event.asm b/kernel/window/event.asm index 63ff5d6..a0f4b43 100644 --- a/kernel/window/event.asm +++ b/kernel/window/event.asm @@ -2,7 +2,6 @@ ; event types const EVENT_TYPE_BUTTON_CLICK: 0x80000000 -const EVENT_TYPE_TEXTBOX_REFRESH: 0x80000001 const WINDOW_EVENT_SIZE: 32