; ***************************************************************************
; copyright   : (C) 2026 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_GUI2_IMAGEBUTTON_ASM
#define AQH_AVR_GUI2_IMAGEBUTTON_ASM


; ***************************************************************************
; code

.cseg



; ---------------------------------------------------------------------------
; @routine ImageButton_new
;
; @param X       parent
; @param r16     value for OBJECT_OFFS_OPTS
; @param r17     value for WIDGET_OFFS_PACK
; @param r21:r20 img ressource
; @param r22     selector (target will be parent, can be overridden later)
; @param r23     button mode
; @return CFLAG  set if new object created, cleared on error
; @return Y      button created
; @clobbers any, !X

ImageButton_new:
  push xl
    push xh
      push r20
        push r21
          push r22
            mov r20, r23
            bigcall Button_new
          pop r22
        pop r21
      pop r20
      brcc ImageButton_new_done
      mov xl, yl
      mov xh, yh
      push xl    ; Button
        push xh
          push r22
            ldi r16, 0
            ldi r17, (WIDGET_PACK_BEGIN<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_BEGIN<<WIDGET_PACK_VSELF0_BIT) ; PACK
            bigcall ImageView_new
          pop r22
        pop yh   ; pop button into Y
      pop yl
      brcc ImageButton_new_done
    pop xh
  pop xl  
  std Y+OBJECT_OFFS_TARGET_LO, xl
  std Y+OBJECT_OFFS_TARGET_HI, xh
  std Y+OBJECT_OFFS_SELECTOR, r22
  rjmp ImageButton_new_ret
ImageButton_new_done:
    pop xh
  pop xl
ImageButton_new_ret:
  ret
; @end




#endif


