kernel: Window manager now manages the menu bar per-window

This commit is contained in:
Ry 2022-12-24 22:51:43 -08:00
parent b71d10ab63
commit 3b813afa72
4 changed files with 60 additions and 9 deletions

View File

@ -27,17 +27,17 @@ start_event_manager_task:
event_manager_task_loop:
call get_next_event
; HACK: put menu bar events back into the system event queue
cmp r0, EVENT_TYPE_MENU_BAR_CLICK
ifz call new_event
cmp r0, EVENT_TYPE_MENU_CLICK
ifz call new_event
cmp r0, EVENT_TYPE_MENU_UPDATE
ifz call new_event
cmp.8 [active_window_offset], 0xFF
ifz rjmp event_manager_task_loop_end
; menu bar
cmp r0, EVENT_TYPE_MENU_BAR_CLICK
ifz call add_event_to_active_window
cmp r0, EVENT_TYPE_MENU_CLICK
ifz call add_event_to_active_window
cmp r0, EVENT_TYPE_MENU_UPDATE
ifz call add_event_to_active_window
; mouse
cmp r0, EVENT_TYPE_MOUSE_CLICK
ifz call event_manager_task_mouse_event
@ -120,6 +120,17 @@ event_manager_task_mouse_event_inactive_window_was_clicked:
call search_for_window_list_entry
mov.8 [active_window_offset], r0
; set the menu bar for the newly active window
call window_list_offset_to_struct
call get_window_menu_bar_root_struct
call enable_menu_bar
cmp r0, 0
ifz call disable_menu_bar
call clear_menu_bar
mov r1, 0xFFFFFFFF
cmp r0, 0
ifnz call draw_menu_bar_root_items
pop r2
pop r1
pop r0

View File

@ -12,7 +12,7 @@
; data.8 overlay - overlay number of this window
; data.8 reserved_1
; data.16 reserved_2
; data.32 reserved_3
; data.32 menu_bar_ptr - pointer to this window's menu bar root struct, or 0 for none
const WINDOW_STRUCT_SIZE: 32 ; 8 words = 32 bytes
const TITLE_BAR_HEIGHT: 16
@ -25,6 +25,7 @@ const TITLE_BAR_HEIGHT: 16
; r3: window height, not including the title bar
; r4: initial X coordinate (top left corner of title bar)
; r5: initial Y coordinate (top left corner of title bar)
; r6: pointer to menu bar root struct, or 0x00000000 for no menu bar
; outputs:
; none
new_window:
@ -53,6 +54,9 @@ new_window:
mov.16 [r10], r4
add r10, 2
mov.16 [r10], r5
; menu bar root struct pointer
add r10, 6
mov [r10], r6
; then, allocate memory for the framebuffer
; the space required is width * (height + TITLE_BAR_HEIGHT) * 4
@ -123,6 +127,18 @@ new_window:
; then, draw the title bar
call draw_title_bar_to_window
; then, draw the menu bar
push r0
call enable_menu_bar
mov r0, r6
cmp r0, 0
ifz call disable_menu_bar
call clear_menu_bar
mov r1, 0xFFFFFFFF
cmp r0, 0
ifnz call draw_menu_bar_root_items
pop r0
; finally, add this window to the window list
push r0
mov r0, 0x00000000
@ -182,6 +198,17 @@ destroy_window:
call search_for_nonempty_window_list_entry
mov.8 [active_window_offset], r0
; set the menu bar for the newly active window
call window_list_offset_to_struct
call get_window_menu_bar_root_struct
call enable_menu_bar
cmp r0, 0
ifz call disable_menu_bar
call clear_menu_bar
mov r1, 0xFFFFFFFF
cmp r0, 0
ifnz call draw_menu_bar_root_items
pop r1
pop r0
ret
@ -333,6 +360,17 @@ get_window_overlay_number:
ret
; get the menu bar root struct used by a window
; inputs:
; r0: pointer to window struct
; outputs:
; r0: pointer to menu bar root struct, or 0x00000000 for no menu bar
get_window_menu_bar_root_struct:
add r0, 28
mov r0, [r0]
ret
; draw a window's title bar
; inputs:
; r0: pointer to window struct

View File

@ -17,6 +17,7 @@ about_dialog:
mov r3, 128
mov r4, 64
mov r5, 64
mov r6, 0
call new_window
; fill the window with the fox32 purple color

View File

@ -6,6 +6,7 @@
mov r3, 400
mov r4, 32
mov r5, 32
mov r6, 0
call new_window
call get_unused_task_id