; _______________________________________________________________________________________
;|                                                                                       |
;| Portable GUI application in assembler.                                                |
;|_______________________________________________________________________________________|
;
;  Description: The main file of very simple example demonstrating how to write portable
;               GUI applications using FreshLib.
;
;  Target OS: Any
;
;  Dependencies: FreshLib - see includes in the source.
;_________________________________________________________________________________________

include '%lib%/freshlib.inc'
@BinaryType GUI

ThemeGUI equ win_gui            ; flat_gui, win_gui or any other theme in the "gui/themes/" directory.

include '%lib%/freshlib.asm'

options.FastEnter         = 0           ; enter/leave or push ebp/pop ebp approach to the procedures.
options.ShowSkipped       = 0           ; shows the procedures skiped because of no use.
options.ShowSizes         = 1           ; enable/disable work of DispSize macro.
options.DebugMode         = 0           ; enable/disable macroses of simpledebug library.


iglobal
  frmMainForm:
        ObjTemplate  tfParent or tfEnd, TForm, frmMain, \
                     x = 100,        \
                     y = 50,         \
                     width = 320,    \
                     height = 240,   \
                     Caption = 'FreshLib portable application.'

           ObjTemplate tfEnd, TButton, btnTest,  \
                       x = 50, y = 50,            \
                       width = 128, height = 24,   \
                       Visible = TRUE,           \
                       TextAlign = dtfAlignCenter or dtfAlignMiddle, \
                       IconPosition = AlignLeft,                     \
                       OnClick = procOnClick,                        \
                       Caption = 'Do something'
endg


uglobal
  ClickCount dd ?
endg

cCaption text 'Clicked: '

proc procOnClick, .self, .button
begin
; On click handler for the button.

        inc     [ClickCount]

        stdcall NumToStr, [ClickCount], ntsDec or ntsUnsigned
        push    eax
        push    eax
        stdcall StrDup, cCaption
        stdcall StrCat, eax ; second from the stack.
        stdcall StrDel ; from the stack.
        push    eax

        set     [btnTest], TButton:Caption, eax

        stdcall StrDel ; from the stack.

        return
endp



; Main Program
start:
        InitializeAll

        create  ebx, TApplication
        jc      .terminate

        mov     [pApplication], ebx

        call    GUI.Init

        stdcall CreateFromTemplate, frmMainForm, 0

        set     [pApplication], TApplication:MainWindow, frmMain

        set     [frmMain], TWindow:Visible, TRUE

        stdcall Run

.terminate:
        push    eax
        FinalizeAll

        stdcall TerminateAll    ; from the stack

; end of main program

