; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: TLabel object class
;
;  Target OS: Any
;
;  Dependencies:
;
;  Notes: Not finished.
;_________________________________________________________________________________________
module "TLabel library"



object TLabel, TWindow

; private fields
  ._textalign  dd ?

; parameters
  param .TextAlign, ._textalign, .SetTextAlign        ; text align flags.

; parameter methods
  method .SetTextAlign, .value

; other methods
  method .Create, .parent

  method .Paint

endobj



method TLabel.Create
begin
        push    eax ecx

        inherited [.parent]

        mov     eax, [.self]
        mov     [eax+TLabel._textalign], dtfAlignLeft or dtfAlignMiddle or dtfCRLF or dtfWordWrap

        pop     ecx eax
        return
endp


method TLabel.SetTextAlign
begin
        push    eax

        mov     eax, [.self]
        push    [.value]
        pop     [eax+TLabel._textalign]

;        exec    eax, TWindow:Refresh
        pop     eax
        return
endp



method TLabel.Paint
 .bounds TBounds
begin
        pushad

        mov     esi, [.self]
        mov     edi, [esi+TWindow._canvas]
        test    edi, edi
        jz      .finish

        xor     edx, edx
        mov     ecx, [esi+TLabel._width]
        mov     eax, [esi+TLabel._height]
        mov     [.bounds.x], edx
        mov     [.bounds.y], edx
        mov     [.bounds.width], ecx
        mov     [.bounds.height], eax

        lea     eax, [.bounds]
        stdcall [DrawBox], edi, eax, [GUI.clLabelBk], bxNone, [GUI.boxBorderWidth]

        mov     eax, [GUI.btnMarginX]
        mov     ecx, [GUI.btnMarginY]

        add     [.bounds.x], eax
        add     [.bounds.y], ecx

        shl     eax, 1
        shl     ecx, 1

        sub     [.bounds.width], eax
        sub     [.bounds.height], ecx

        get     eax, esi, TWindow:Caption
        test    eax, eax
        jz      .finish

        stdcall DrawTextBox, edi, eax, [.bounds.x], [.bounds.y], [.bounds.width], [.bounds.height], 2, [esi+TLabel._textalign], [GUI.DefaultFont], [GUI.clLabelTxt]
        stdcall StrDel, eax


.finish:
        inherited

        popad
        return
endp







endmodule