Skip to content

Commit

Permalink
kernel: Label widget
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed Jun 16, 2024
1 parent 7f90022 commit 39adbed
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fox32os.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 50 additions & 0 deletions kernel/widget/label.asm
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions kernel/widget/widget.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
1 change: 0 additions & 1 deletion kernel/window/event.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

; event types
const EVENT_TYPE_BUTTON_CLICK: 0x80000000
const EVENT_TYPE_TEXTBOX_REFRESH: 0x80000001

const WINDOW_EVENT_SIZE: 32

Expand Down

0 comments on commit 39adbed

Please sign in to comment.