; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: TImageLabel object class
;
;  Target OS: Any
;
;  Dependencies:
;
;  Notes: Represents GUI picture or image.
;_________________________________________________________________________________________
module "TImageLabel library"


iaLeft = 0
iaRight = 1
iaCenter = 2
iaStretchH = 3

iaTop = $0
iaBottom = $100
iaMiddle = $200
iaStrechV = $300


object TImageLabel, TWindow
  ._ImageAlign dd ?
  ._Image      dd ?

  param .ImageAlign, ._ImageAlign, .SetImageAlign       ; image align flags.
  param .Image, ._Image, .SetImage                      ; TImage object

  method .SetImageAlign, .value
  method .SetImage, .value

  method .Paint
endobj


method TImageLabel.SetImageAlign
begin
        push    eax

        mov     eax, [.self]
        push    [.value]
        pop     [eax+TImageLabel._ImageAlign]

;        exec    eax, TWindow:Refresh
        pop     eax
        return
endp



method TImageLabel.SetImage
begin
        push    eax

        mov     eax, [.self]
        push    [.value]
        pop     [eax+TImageLabel._Image]

;        exec    eax, TWindow:Refresh
        pop     eax
        return
endp



method TImageLabel.Paint
begin
        pushad

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

        mov     ecx, [esi+TImageLabel._width]
        mov     edx, [esi+TImageLabel._height]
        xor     eax, eax

        stdcall DrawSolidRect, edi, eax, eax, ecx, edx, eax    ; clear with transparency.

        mov     eax, [esi+TImageLabel._ImageAlign]
        mov     esi, [esi+TImageLabel._Image]

        test    esi, esi
        jz      .finish

        sub     ecx, [esi+TImage.width]
        sub     edx, [esi+TImage.height]

        cmp     al, iaRight
        je      .x_ok

        cmp     al, iaCenter
        je      .x_center

        xor     ecx, ecx
        jmp     .x_ok

.x_center:
        sar     ecx, 1

.x_ok:
        cmp     ah, iaBottom /256
        je      .y_ok

        cmp     ah, iaMiddle / 256
        je      .y_center

        xor     edx, edx
        jmp     .y_ok

.y_center:
        sar     edx, 1

.y_ok:

        xor     eax, eax
;        stdcall BlendImage, edi, ecx, edx, esi, eax, eax, [esi+TImage.width], [esi+TImage.height]
        stdcall CopyImageRect, edi, ecx, edx, esi, eax, eax, [esi+TImage.width], [esi+TImage.height]

.finish:
        inherited
        popad
        return
endp







endmodule