gui2: main windows basically work now!

This commit is contained in:
Martin Preuss
2026-03-09 13:56:51 +01:00
parent e3ae1f9b35
commit cc7f2dc1db
6 changed files with 251 additions and 53 deletions

View File

@@ -256,23 +256,22 @@ test:
bigcall GuiApp_GetRootWindow bigcall GuiApp_GetRootWindow
brcc DEBUG_STOP brcc DEBUG_STOP
sts rootWindow, r18 push yl
sts rootWindow+1, r19 push yh
mov xl, r18 mov xl, r18
mov xh, r19 mov xh, r19
ldi r16, 0 ; OPTS ldi r16, 0 ; OPTS
ldi r17, (WIDGET_PACK_FILLED<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_FILLED<<WIDGET_PACK_VSELF0_BIT) ; PACK ldi r17, (WIDGET_PACK_FILLED<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_FILLED<<WIDGET_PACK_VSELF0_BIT) ; PACK
ldi r20, LOW(RESSSOURCE_TXT_LIVINGROOM) ldi r20, LOW(RESSSOURCE_TXT_LIVINGROOM)
ldi r21, HIGH(RESSSOURCE_TXT_LIVINGROOM) ldi r21, HIGH(RESSSOURCE_TXT_LIVINGROOM)
bigcall MainWindow_new bigcall MainWindow_new
mov xl, yl
mov xh, yh
pop yh
pop yl
brcc DEBUG_STOP brcc DEBUG_STOP
bigcall GuiApp_EnterWindow
sts mainWin1, yl brcc DEBUG_STOP3
sts mainWin1+1, yh
ldd r16, Y+OBJECT_OFFS_FLAGS
sbr r16, (1<<WIDGET_FLAGS_VISIBLE_BIT) | (1<<WIDGET_FLAGS_LAYOUT_BIT) | (1<<WIDGET_FLAGS_DIRTY_BIT)
std Y+OBJECT_OFFS_FLAGS, r16
ret ret

View File

@@ -14,6 +14,8 @@
; *************************************************************************** ; ***************************************************************************
; defines ; defines
.equ GUIAPP_WINDOWSTACK_ENTRIES = 8
; Widget in flash ; Widget in flash
.equ GUIAPP_OFFS_BEGIN = OBJECT_SIZE .equ GUIAPP_OFFS_BEGIN = OBJECT_SIZE
@@ -26,7 +28,9 @@
.equ GUIAPP_OFFS_TOUCHWIDGET_LO = GUIAPP_OFFS_BEGIN+6 .equ GUIAPP_OFFS_TOUCHWIDGET_LO = GUIAPP_OFFS_BEGIN+6
.equ GUIAPP_OFFS_TOUCHWIDGET_HI = GUIAPP_OFFS_BEGIN+7 .equ GUIAPP_OFFS_TOUCHWIDGET_HI = GUIAPP_OFFS_BEGIN+7
.equ GUIAPP_OFFS_GUITIMER = GUIAPP_OFFS_BEGIN+8 .equ GUIAPP_OFFS_GUITIMER = GUIAPP_OFFS_BEGIN+8
.equ GUIAPP_SIZE = WIDGET_OFFS_BEGIN+9 .equ GUIAPP_OFFS_WINDOWSTACK_POS = GUIAPP_OFFS_BEGIN+9
.equ GUIAPP_OFFS_WINDOWSTACK_BEGIN = GUIAPP_OFFS_BEGIN+10
.equ GUIAPP_SIZE = GUIAPP_OFFS_WINDOWSTACK_BEGIN+(GUIAPP_WINDOWSTACK_ENTRIES*2)
.equ GUIAPP_GUITIMER = 2 .equ GUIAPP_GUITIMER = 2
@@ -111,10 +115,6 @@ GuiApp_Init:
std Y+GUIAPP_OFFS_ROOTWINDOW_LO, xl std Y+GUIAPP_OFFS_ROOTWINDOW_LO, xl
std Y+GUIAPP_OFFS_ROOTWINDOW_HI, xh std Y+GUIAPP_OFFS_ROOTWINDOW_HI, xh
; debug
std Y+GUIAPP_OFFS_CURRENTWINDOW_LO, xl
std Y+GUIAPP_OFFS_CURRENTWINDOW_HI, xh
ldi r16, GUIAPP_GUITIMER ldi r16, GUIAPP_GUITIMER
std Y+GUIAPP_OFFS_GUITIMER, r16 std Y+GUIAPP_OFFS_GUITIMER, r16
@@ -271,7 +271,9 @@ GuiApp_SetRootWindow:
; @routine GuiApp_GetCurrentWindow @global ; @routine GuiApp_GetCurrentWindow @global
; ;
; @param Y address of object in SDRAM ; @param Y address of object in SDRAM
; @param CFLAG set if response is not a NULL pointer ; @return CFLAG set if response is not a NULL pointer
; @return r19:r18 current window
; @clobbers none
GuiApp_GetCurrentWindow: GuiApp_GetCurrentWindow:
ldd r18, Y+GUIAPP_OFFS_CURRENTWINDOW_LO ldd r18, Y+GUIAPP_OFFS_CURRENTWINDOW_LO
@@ -288,20 +290,6 @@ GuiApp_GetCurrentWindow_ret:
; ---------------------------------------------------------------------------
; @routine GuiApp_SetCurrentWindow @global
;
; @param Y address of object in SDRAM
; @param X address of new window
GuiApp_SetCurrentWindow:
std Y+GUIAPP_OFFS_CURRENTWINDOW_LO, xl
std Y+GUIAPP_OFFS_CURRENTWINDOW_HI, xh
ret
; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine GuiApp_GetScreenSaver @global ; @routine GuiApp_GetScreenSaver @global
; ;
@@ -402,6 +390,173 @@ GuiApp_OnTouch:
; ---------------------------------------------------------------------------
; @routine GuiApp_EnterWindow
;
; @param Y address of object in SDRAM
; @param X main window to enter
; @return CFLAG set if new window active
GuiApp_EnterWindow:
rcall GuiApp_GetCurrentWindow ; r19:r18=current window
brcc GuiApp_EnterWindow_l1 ; jmp if no current window
push xl
push xh
push yl
push yh
mov yl, r18
mov yh, r19
ldi r16, WIDGET_SIGNAL_HIDE
clr r17
bigcall OBJ_TreeHandleSignalChildenFirst
mov xl, yl
mov xh, yh
pop yh
pop yl
rcall guiAppPushMainWindow ; push current window onto stack
pop xh
pop xl
brcc GuiApp_EnterWindow_ret
GuiApp_EnterWindow_l1:
rcall guiAppSetCurrentWindow
push yl
push yh
mov yl, xl
mov yh, xh
ldi r16, WIDGET_SIGNAL_SHOW
clr r17
bigcall OBJ_TreeHandleSignal
pop yh
pop yl
sec
GuiApp_EnterWindow_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine GuiApp_LeaveWindow
;
; @param Y address of object in SDRAM
GuiApp_LeaveWindow:
rcall GuiApp_GetCurrentWindow ; r19:r18=current window
brcc GuiApp_LeaveWindow_ret ; jmp if no current window
push yl
push yh
mov yl, r18
mov yh, r19
ldi r16, WIDGET_SIGNAL_HIDE
clr r17
bigcall OBJ_TreeHandleSignalChildenFirst
pop yh
pop yl
GuiApp_LeaveWindow_l1:
rcall guiAppPopMainWindow ; X=popped window
brcc GuiApp_LeaveWindow_noPrevious
rcall guiAppSetCurrentWindow
push yl
push yh
mov yl, xl
mov yh, xh
ldi r16, WIDGET_SIGNAL_SHOW
clr r17
bigcall OBJ_TreeHandleSignal
pop yh
pop yl
rjmp GuiApp_LeaveWindow_ret
GuiApp_LeaveWindow_noPrevious:
clr xl
clr xh
rcall guiAppSetCurrentWindow
GuiApp_LeaveWindow_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine guiAppSetCurrentWindow
;
; @param Y address of object in SDRAM
; @param X address of new window
guiAppSetCurrentWindow:
std Y+GUIAPP_OFFS_CURRENTWINDOW_LO, xl
std Y+GUIAPP_OFFS_CURRENTWINDOW_HI, xh
ret
; @end
; ---------------------------------------------------------------------------
; @routine guiAppPushMainWindow
;
; @param Y address of object in SDRAM
; @param X window to push on stack and activate
; @return CFLAG set if pushed, cleared on error
guiAppPushMainWindow:
ldd r16, Y+GUIAPP_OFFS_WINDOWSTACK_POS
cpi r16, GUIAPP_WINDOWSTACK_ENTRIES
brcc GuiApp_PushMainWindow_ret
mov zl, yl
mov zh, yh
adiw zh:zl, GUIAPP_OFFS_WINDOWSTACK_BEGIN
clr r17
lsl r16
rol r17
add zl, r16
adc zh, r17
st Z+, xl
st Z, xh
ldd r16, Y+GUIAPP_OFFS_WINDOWSTACK_POS
inc r16
std Y+GUIAPP_OFFS_WINDOWSTACK_POS, r16
sec
GuiApp_PushMainWindow_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine guiAppPopMainWindow
;
; @param Y address of object in SDRAM
; @return CFLAG set if popped, cleared on error
; @return X window popped from stack
guiAppPopMainWindow:
ldd r16, Y+GUIAPP_OFFS_WINDOWSTACK_POS
tst r16
clc
breq guiAppPopMainWindow_ret
dec r16
std Y+GUIAPP_OFFS_WINDOWSTACK_POS, r16
mov zl, yl
mov zh, yh
adiw zh:zl, GUIAPP_OFFS_WINDOWSTACK_BEGIN
clr r17
lsl r16
rol r17
add zl, r16
adc zh, r17
ld xl, Z+
ld xh, Z
sec
guiAppPopMainWindow_ret:
ret
; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine guiAppSendTimerEvents ; @routine guiAppSendTimerEvents
@@ -432,7 +587,7 @@ guiAppSendTimerEvents:
guiAppCheckSendGuiEvents: guiAppCheckSendGuiEvents:
push yl push yl
push yh push yh
rcall GuiApp_GetCurrentWindow rcall GuiApp_GetRootWindow
brcc guiAppCheckSendGuiEvents_done brcc guiAppCheckSendGuiEvents_done
ldd r16, Y+GUIAPP_OFFS_GUITIMER ldd r16, Y+GUIAPP_OFFS_GUITIMER
@@ -602,7 +757,7 @@ GuiApp_DefaultSignalmap:
; header ; header
.dw Object_DefaultSignalmap*2 ; next table to use .dw Object_DefaultSignalmap*2 ; next table to use
; entries ; entries
.db 0, OBJECT_SIGNAL_TIMER, LOW(GuiApp_OnTimer), HIGH(GuiApp_OnTimer) .db 0, OBJECT_SIGNAL_TIMER, LOW(GuiApp_OnTimer), HIGH(GuiApp_OnTimer)
.db 0, OBJECT_SIGNAL_DESTROY, LOW(GuiApp_OnDestroy), HIGH(GuiApp_OnDestroy) .db 0, OBJECT_SIGNAL_DESTROY, LOW(GuiApp_OnDestroy), HIGH(GuiApp_OnDestroy)
.db 0, 0, 0, 0 ; end of table .db 0, 0, 0, 0 ; end of table

View File

@@ -178,12 +178,6 @@ mainWindowCreateTitleWidget:
std Y+WIDGET_OFFS_STYLE_LO, r16 std Y+WIDGET_OFFS_STYLE_LO, r16
ldi r16, HIGH(MainWindow_TitleStyle*2) ldi r16, HIGH(MainWindow_TitleStyle*2)
std Y+WIDGET_OFFS_STYLE_HI, r16 std Y+WIDGET_OFFS_STYLE_HI, r16
; DEBUG
ldd r16, Y+OBJECT_OFFS_FLAGS
sbr r16, (1<<WIDGET_FLAGS_VISIBLE_BIT) | (1<<WIDGET_FLAGS_LAYOUT_BIT) | (1<<WIDGET_FLAGS_DIRTY_BIT)
std Y+OBJECT_OFFS_FLAGS, r16
sec sec
mainWindowCreateTitleWidget_done: mainWindowCreateTitleWidget_done:
pop yh pop yh
@@ -232,7 +226,6 @@ MainWindow_DefaultSignalmap:
; header ; header
.dw VLayout_DefaultSignalmap*2 ; next table to use .dw VLayout_DefaultSignalmap*2 ; next table to use
; entries ; entries
.db 0, WIDGET_SIGNAL_DRAW, LOW(Widget_OnDraw), HIGH(Widget_OnDraw)
.db WIDGET_VALUE_DEFAULT_WIDTH, WIDGET_SIGNAL_GETVALUE, LOW(MainWindow_OnGetDefaultWidth), HIGH(MainWindow_OnGetDefaultWidth) .db WIDGET_VALUE_DEFAULT_WIDTH, WIDGET_SIGNAL_GETVALUE, LOW(MainWindow_OnGetDefaultWidth), HIGH(MainWindow_OnGetDefaultWidth)
.db WIDGET_VALUE_DEFAULT_HEIGHT, WIDGET_SIGNAL_GETVALUE, LOW(MainWindow_OnGetDefaultHeight), HIGH(MainWindow_OnGetDefaultHeight) .db WIDGET_VALUE_DEFAULT_HEIGHT, WIDGET_SIGNAL_GETVALUE, LOW(MainWindow_OnGetDefaultHeight), HIGH(MainWindow_OnGetDefaultHeight)
@@ -242,7 +235,8 @@ MainWindow_DefaultSignalmap:
MainWindow_DefaultStyle: MainWindow_DefaultStyle:
.dw DISPLAY_COLOR_BLACK ; frontCol_norm .dw DISPLAY_COLOR_BLACK ; frontCol_norm
.dw DISPLAY_COLOR_LIGHTGREY ; backCol_norm ; .dw DISPLAY_COLOR_LIGHTGREY ; backCol_norm
.dw DISPLAY_COLOR_GREEN ; backCol_norm
.dw DISPLAY_COLOR_BLACK ; borderCol_norm .dw DISPLAY_COLOR_BLACK ; borderCol_norm
.dw DISPLAY_COLOR_WHITE ; shadowCol_norm .dw DISPLAY_COLOR_WHITE ; shadowCol_norm
@@ -279,7 +273,8 @@ MainWindow_TitleStyle:
MainWindow_ContentStyle: MainWindow_ContentStyle:
.dw DISPLAY_COLOR_BLACK ; frontCol_norm .dw DISPLAY_COLOR_BLACK ; frontCol_norm
.dw DISPLAY_COLOR_LIGHTGREY ; backCol_norm ; .dw DISPLAY_COLOR_LIGHTGREY ; backCol_norm
.dw DISPLAY_COLOR_RED ; backCol_norm
.dw DISPLAY_COLOR_BLACK ; borderCol_norm .dw DISPLAY_COLOR_BLACK ; borderCol_norm
.dw DISPLAY_COLOR_WHITE ; shadowCol_norm .dw DISPLAY_COLOR_WHITE ; shadowCol_norm

View File

@@ -589,20 +589,20 @@ OBJ_TreeHandleSignal:
push r17 push r17
push xl push xl
push xh push xh
rcall OBJ_HandleSignal ; (any, !Y) rcall OBJ_HandleSignal ; (any, !Y)
pop xh pop xh
pop xl pop xl
pop r17 pop r17
pop r16 pop r16
; handle children ; handle children
rcall OBJ_GetFirstChild ; r19:r18=object (none) rcall OBJ_GetFirstChild ; r19:r18=object (none)
brcc OBJ_TreeHandleSignal_done
OBJ_TreeHandleSignal_loop: OBJ_TreeHandleSignal_loop:
brcc OBJ_TreeHandleSignal_done
mov yl, r18 mov yl, r18
mov yh, r19 mov yh, r19
rcall OBJ_TreeHandleSignal ; recursion! rcall OBJ_TreeHandleSignal ; recursion!
rcall OBJ_GetNext ; r19:r18=object (none) rcall OBJ_GetNext ; r19:r18=object (none)
rjmp OBJ_TreeHandleSignal_loop brcs OBJ_TreeHandleSignal_loop
OBJ_TreeHandleSignal_done: OBJ_TreeHandleSignal_done:
pop yh pop yh
pop yl pop yl

View File

@@ -236,6 +236,8 @@ vLayoutHorizontally:
; r23:r22=width of host widget ; r23:r22=width of host widget
push yl push yl
push yh push yh
mov xl, yl
mov xh, yh
bigcall OBJ_GetFirstChild bigcall OBJ_GetFirstChild
vLayoutHorizontally_loop: vLayoutHorizontally_loop:
brcc vLayoutHorizontally_loopEnd brcc vLayoutHorizontally_loopEnd
@@ -254,7 +256,13 @@ vLayoutHorizontally_loop:
vLayoutHorizontally_setWidth: vLayoutHorizontally_setWidth:
std Y+WIDGET_OFFS_WIDTH_LO, r12 std Y+WIDGET_OFFS_WIDTH_LO, r12
std Y+WIDGET_OFFS_WIDTH_HI, r13 std Y+WIDGET_OFFS_WIDTH_HI, r13
rcall Widget_PackSelfX ; R5:R4=new pos (r17, r18, r19, r20, r21) push yl
push yh
mov yl, xl
mov yh, xh
rcall Widget_PackSelfX ; R5:R4=new pos (r17, r18, r19, r20, r21)
pop yh
pop yl
std Y+WIDGET_OFFS_X_LO, r4 std Y+WIDGET_OFFS_X_LO, r4
std Y+WIDGET_OFFS_X_HI, r5 std Y+WIDGET_OFFS_X_HI, r5
rcall OBJ_GetNext rcall OBJ_GetNext

View File

@@ -193,6 +193,11 @@ Widget_Init_setDefaultSize:
or r16, xh or r16, xh
breq Widget_Init_ret breq Widget_Init_ret
bigcall OBJ_AddChild ; (r18, r19) bigcall OBJ_AddChild ; (r18, r19)
; parent needs to layout with the new child
adiw xh:xl, OBJECT_OFFS_FLAGS
ld r16, X
sbr r16, (1<<WIDGET_FLAGS_LAYOUT_BIT)
sbiw xh:xl, OBJECT_OFFS_FLAGS
; preset flags ; preset flags
ldd r16, Y+OBJECT_OFFS_FLAGS ldd r16, Y+OBJECT_OFFS_FLAGS
@@ -401,6 +406,40 @@ Widget_OnLayout:
; @end ; @end
; ---------------------------------------------------------------------------
; @routine Widget_OnShow @global
;
; @param Y address of widget
; @return CFLAG set if signal handled
; @clobbers any, !Y
Widget_OnShow:
ldd r16, Y+OBJECT_OFFS_FLAGS
sbr r16, (1<<WIDGET_FLAGS_VISIBLE_BIT) | (1<<WIDGET_FLAGS_DIRTY_BIT) | (1<<WIDGET_FLAGS_LAYOUT_BIT)
std Y+OBJECT_OFFS_FLAGS, r16
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine Widget_OnHide @global
;
; @param Y address of widget
; @return CFLAG set if signal handled
; @clobbers any, !Y
Widget_OnHide:
ldd r16, Y+OBJECT_OFFS_FLAGS
cbr r16, (1<<WIDGET_FLAGS_VISIBLE_BIT)
std Y+OBJECT_OFFS_FLAGS, r16
sec
ret
; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine Widget_OnGetValue @global ; @routine Widget_OnGetValue @global
; ;
@@ -1023,14 +1062,14 @@ widgetPack:
sub r18, r20 ; subtract border at begin sub r18, r20 ; subtract border at begin
sbc r19, r21 sbc r19, r21
sub r18, r20 ; subtract border at end sub r18, r20 ; subtract border at end
sbc r19, r21 sbc r19, r21 ; r19:r18=host size - (border*2)
andi r17, 3 ; only 2 bits pack mode andi r17, 3 ; only 2 bits pack mode
cpi r17, WIDGET_PACK_END cpi r17, WIDGET_PACK_END
breq widgetPack_end breq widgetPack_end
cpi r17, WIDGET_PACK_CENTER cpi r17, WIDGET_PACK_CENTER
breq widgetPack_center breq widgetPack_center
rjmp widgetPack_ret ; begin/filled, align at begin rjmp widgetPack_ret ; begin/filled, align at begin
widgetPack_end: widgetPack_end:
sub r18, r12 sub r18, r12
sbc r19, r13 sbc r19, r13
@@ -1063,6 +1102,8 @@ Widget_DefaultSignalmap:
.db 0, WIDGET_SIGNAL_DRAW, LOW(Widget_OnDraw), HIGH(Widget_OnDraw) .db 0, WIDGET_SIGNAL_DRAW, LOW(Widget_OnDraw), HIGH(Widget_OnDraw)
.db 0, WIDGET_SIGNAL_LAYOUT, LOW(Widget_OnLayout), HIGH(Widget_OnLayout) .db 0, WIDGET_SIGNAL_LAYOUT, LOW(Widget_OnLayout), HIGH(Widget_OnLayout)
.db 0, WIDGET_SIGNAL_GETVALUE, LOW(Widget_OnGetValue), HIGH(Widget_OnGetValue) ; handle any value here .db 0, WIDGET_SIGNAL_GETVALUE, LOW(Widget_OnGetValue), HIGH(Widget_OnGetValue) ; handle any value here
.db 0, WIDGET_SIGNAL_SHOW, LOW(Widget_OnShow), HIGH(Widget_OnShow)
.db 0, WIDGET_SIGNAL_HIDE, LOW(Widget_OnHide), HIGH(Widget_OnHide)
.db 0, 0, 0, 0 ; end of table .db 0, 0, 0, 0 ; end of table