; ***************************************************************************
; copyright   : (C) 2025 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************

#ifndef AQH_AVR_STATICGUI_TITLEWINDOW_ASM
#define AQH_AVR_STATICGUI_TITLEWINDOW_ASM


.cseg


; ---------------------------------------------------------------------------
; @routine TitleWindow_Init @global
;
; @param Y pointer to titledwindow data (size=TITLEWINDOW_SIZE)

TitleWindow_Init:
  bigcall Window_Init
  ret
; @end



; ---------------------------------------------------------------------------
; @routine TitleWindow_SetFullSize @global
;
; @param Y pointer to screen object in SDRAM
; @clobbers any, !Y

TitleWindow_SetFullSize:
  clr r16
  std Y+WIN_OFFS_X_LO, r16
  std Y+WIN_OFFS_X_HI, r16
  std Y+WIN_OFFS_Y_LO, r16
  std Y+WIN_OFFS_Y_HI, r16
  
  ldi r16, LOW(DISPLAY_WIDTH)
  std Y+WIN_OFFS_WIDTH_LO, r16
  ldi r16, HIGH(DISPLAY_WIDTH)
  std Y+WIN_OFFS_WIDTH_HI, r16
  
  ldi r16, LOW(DISPLAY_HEIGHT)
  std Y+WIN_OFFS_HEIGHT_LO, r16
  ldi r16, HIGH(DISPLAY_HEIGHT)
  std Y+WIN_OFFS_HEIGHT_HI, r16

  ret
; @enb



; ---------------------------------------------------------------------------
; @routine TitleWindow_SetStyleColors @global
;
; @param Y pointer to screen object in SDRAM
; @clobbers any, !Y

TitleWindow_SetStyleColors:
  ldi r16, LOW(STYLE_WIN_BACKGROUND)
  ldi r17, HIGH(STYLE_WIN_BACKGROUND)
  std Y+WIN_OFFS_BG_COL_LO, r16
  std Y+WIN_OFFS_BG_COL_HI, r17
  ldi r16, LOW(STYLE_WIN_FOREGROUND)
  ldi r17, HIGH(STYLE_WIN_FOREGROUND)
  std Y+WIN_OFFS_FG_COL_LO, r16
  std Y+WIN_OFFS_FG_COL_HI, r17

  ret
; @end



; ---------------------------------------------------------------------------
; @routine TitleWindow_DrawTitle @global
;
; @param Y pointer to screen object in SDRAM
; @param Z pointer to title
; @clobbers any, !Y

TitleWindow_DrawTitle:
  ; fill background of title area
  clr r4
  clr r5
  clr r6
  clr r7
  ldd r8, Y+WIN_OFFS_WIDTH_LO
  ldd r9, Y+WIN_OFFS_WIDTH_HI
  ldi r16, LOW(STYLE_WIN_TITLE_HEIGHT)
  ldi r17, HIGH(STYLE_WIN_TITLE_HEIGHT)
  mov r10, r16
  mov r11, r17
  ldi r16, LOW(STYLE_WIN_TITLE_BACKGROUND)
  mov r2, r16
  ldi r16, HIGH(STYLE_WIN_TITLE_BACKGROUND)
  mov r3, r16
  rcall Window_FillRect

  ; draw title
  ldi r16, 5     ; X
  mov r4, r16
  clr r5
  ldi r16, 2     ; Y
  mov r6, r16
  clr r7
  
  ldi r16, LOW(STYLE_WIN_TITLE_BACKGROUND)
  mov r0, r16
  ldi r16, HIGH(STYLE_WIN_TITLE_BACKGROUND)
  mov r1, r16

  ldi r16, LOW(STYLE_WIN_TITLE_FOREGROUND)
  mov r2, r16
  ldi r16, HIGH(STYLE_WIN_TITLE_FOREGROUND)
  mov r3, r16
  bigcall Window_DrawColorTextFlash

  ret
; @end



; ---------------------------------------------------------------------------
; @routine TitleWindow_ClearContentArea @global
;
; @param Y pointer to screen object in SDRAM
; @clobbers any, !Y

TitleWindow_ClearContentArea:
  clr r4
  clr r5
  ldi r16, LOW(STYLE_WIN_TITLE_HEIGHT)
  mov r6, r16
  ldi r16, HIGH(STYLE_WIN_TITLE_HEIGHT)
  mov r7, r16
  ldd r8, Y+WIN_OFFS_WIDTH_LO
  ldd r9, Y+WIN_OFFS_WIDTH_HI
  ldi r16, LOW(STYLE_WIN_TITLE_HEIGHT)
  ldi r17, HIGH(STYLE_WIN_TITLE_HEIGHT)
  ldd r10, Y+WIN_OFFS_HEIGHT_LO
  ldd r11, Y+WIN_OFFS_HEIGHT_HI
  sub r10, r16
  sbc r11, r17
  ldi r16, LOW(STYLE_WIN_BACKGROUND)
  ldd r2, Y+WIN_OFFS_BG_COL_LO
  ldd r3, Y+WIN_OFFS_BG_COL_HI
  rcall Window_FillRect
  ret
; @end



#endif ; AQH_AVR_STATICGUI_TITLEWINDOW2_ASM

