News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ModernUIText

Started by Adamanteus, July 17, 2020, 08:01:18 AM

Previous topic - Next topic

Adamanteus

That's small additions to ModernUI, for painting same as client rectangle text (with showdows not happened, yet) :
Code (asm) Select

MUITS_HAND EQU 2048
MUITS_TEXTFIT EQU 4096 ; Text to fit to client area


        ;-----------------------------------------------------------------------------------------------------
        ; Checkbox Examples:
        ;-----------------------------------------------------------------------------------------------------
        Invoke MUITextCreate, hWin, Addr szStaticText, 20, 150, 200, 44, NULL, MUITS_TEXTFIT or MUITS_FONT_DIALOG
        mov hText1, eax
        Invoke MUITextSetProperty, hText1, @TextColor, MUI_RGBCOLOR(45,45,45)
        Invoke MUITextSetProperty, hText1, @TextColorAlt, MUI_RGBCOLOR(55,55,55)
        Invoke MUITextSetProperty, hText1, @TextBackColor, MUI_RGBCOLOR(240,240,240)
        Invoke MUITextSetProperty, hText1, @TextBackColorAlt, MUI_RGBCOLOR(27,161,226)

TEXTSHADOW_METHOD equ 0

.CODE

;-------------------------------------------------------------------------------------
; _MUI_TextPaintText
;-------------------------------------------------------------------------------------
_MUI_TextPaintText PROC PUBLIC hWin : HWND, hdc : HDC, lpRect : POINTER, bEnabledState : BOOL, bMouseOver : BOOL
    LOCAL TextColor : COLORREF
IF TEXTSHADOW_METHOD
    LOCAL ShadowColor : COLORREF
if TEXTSHADOW_METHOD eq 2
LOCAL hBrush : HBRUSH
LOCAL hOldBrush : HBRUSH   
endif
ENDIF
    LOCAL BackColor : COLORREF
    LOCAL hFont : HFONT
    LOCAL hOldFont : HFONT
    LOCAL LenText : SIZE_T
    LOCAL dwTextStyle : INT_T
    LOCAL dwStyle : INT_T
    LOCAL rect : RECT
    LOCAL szText[4096] : CAP_T
   
    Invoke CopyRect, Addr rect, lpRect

    Invoke GetWindowLong, hWin, GWL_STYLE
    mov dwStyle, eax
   
    Invoke MUIGetExtProperty, hWin, @TextFont       
    mov hFont, eax

    .IF bEnabledState == TRUE
        .IF bMouseOver == FALSE
            Invoke MUIGetExtProperty, hWin, @TextBackColor        ; Normal back color
        .ELSE
            Invoke MUIGetExtProperty, hWin, @TextBackColorAlt     ; Mouse over back color
        .ENDIF
    .ELSE
        Invoke MUIGetExtProperty, hWin, @TextBackColorDisabled        ; Disabled back color
    .ENDIF
    .IF eax == 0 ; try to get default back color if others are set to 0
        Invoke MUIGetExtProperty, hWin, @TextBackColor                ; fallback to default Normal back color
    .ENDIF   
    mov BackColor, eax   

    .IF bEnabledState == TRUE
        .IF bMouseOver == FALSE
            Invoke MUIGetExtProperty, hWin, @TextColor        ; Normal text color
        .ELSE
            Invoke MUIGetExtProperty, hWin, @TextColorAlt     ; Mouse over text color
        .ENDIF
    .ELSE
        Invoke MUIGetExtProperty, hWin, @TextColorDisabled        ; Disabled text color
    .ENDIF
    .IF eax == 0 ; try to get default text color if others are set to 0
        Invoke MUIGetExtProperty, hWin, @TextColor                ; fallback to default Normal text color
    .ENDIF 
    mov TextColor, eax
   
IF TEXTSHADOW_METHOD
    .IF bEnabledState == TRUE
        .IF bMouseOver == FALSE
            Invoke MUIGetExtProperty, hWin, @TextShadowColor        ; Normal text color
        .ELSE
            Invoke MUIGetExtProperty, hWin, @TextShadowColorAlt     ; Mouse over text color
        .ENDIF
    .ELSE
        Invoke MUIGetExtProperty, hWin, @TextShadowColorDisabled        ; Disabled text color
    .ENDIF
    mov ShadowColor, eax
ENDIF

    Invoke GetWindowText, hWin, Addr szText, SIZEOF szText / SIZEOF CAP_T
   
    Invoke lstrlen, Addr szText
    mov LenText, eax

    Invoke SelectObject, hdc, hFont
    mov hOldFont, eax

    .IF BackColor != -1 ; transaprent
        Invoke SetBkMode, hdc, OPAQUE
        Invoke SetBkColor, hdc, BackColor
    .ELSE
        Invoke SetBkMode, hdc, TRANSPARENT
    .ENDIF

    mov eax, dwStyle
    and eax, MUITS_SINGLELINE
    .IF eax == MUITS_SINGLELINE
        mov dwTextStyle, DT_SINGLELINE
    .ELSE
        mov dwTextStyle, DT_WORDBREAK or DT_EDITCONTROL
    .ENDIF
    mov eax, dwStyle
    and eax, (MUITS_ALIGN_CENTER or MUITS_ALIGN_RIGHT)
    .IF eax == MUITS_ALIGN_CENTER
        or dwTextStyle, DT_CENTER
    .ELSEIF eax == MUITS_ALIGN_RIGHT
        or dwTextStyle, DT_RIGHT
    .ELSE
        or dwTextStyle, DT_LEFT
    .ENDIF

; draw the shadow first
IF TEXTSHADOW_METHOD
.if ShadowColor
if TEXTSHADOW_METHOD eq 1
Invoke SetTextColor, hdc, ShadowColor
add rect.left, 2
add rect.top, 2
add rect.right, 2
add rect.bottom, 2
Invoke DrawText, hdc, Addr szText, LenText, Addr rect, dwTextStyle
Invoke CopyRect, Addr rect, lpRect
elseif TEXTSHADOW_METHOD eq 2
Invoke BeginPath, hdc
endif
.endif
ENDIF

; draw the text color next
    Invoke SetTextColor, hdc, TextColor
Invoke DrawText, hdc, Addr szText, LenText, Addr rect, dwTextStyle

IFNDEF NO_TEXTFIT
    mov eax, dwStyle
    and eax, MUITS_TEXTFIT
    .IF eax == MUITS_TEXTFIT
OR dwTextStyle, DT_CALCRECT
Invoke DrawText, hdc, Addr szText, LenText, lpRect, dwTextStyle
    .ENDIF
ENDIF
   
IF TEXTSHADOW_METHOD eq 2
.if ShadowColor
Invoke EndPath, hdc
Invoke  CreateHatchBrush, HS_DIAGCROSS, ShadowColor
MOV hBrush, EAX
Invoke  SelectObject, hdc, hBrush
MOV hOldBrush, EAX
;Invoke SetBkColor, hdc, ShadowColor
Invoke StrokeAndFillPath, hdc
.endif
    .IF hOldBrush != 0
        Invoke SelectObject, hdc, hOldBrush
        Invoke DeleteObject, hOldBrush
    .ENDIF     
    .IF hBrush != 0
        Invoke DeleteObject, hBrush
    .ENDIF
ENDIF

.IF hOldFont != 0
Invoke SelectObject, hdc, hOldFont
Invoke DeleteObject, hOldFont
.ENDIF
   
    ret
_MUI_TextPaintText ENDP

;-------------------------------------------------------------------------------------
; _MUI_TextPaint
;-------------------------------------------------------------------------------------
_MUI_TextPaint PROC PUBLIC hWin : HWND
    LOCAL ps : PAINTSTRUCT
    LOCAL rect : RECT, rct : RECT
    LOCAL hdc : HDC
    LOCAL hdcMem : HDC
    LOCAL hbmMem : HBITMAP
    LOCAL hBitmap : HBITMAP
    LOCAL hOldBitmap : HBITMAP
    LOCAL EnabledState : BOOL
    LOCAL MouseOver : INT_T
    LOCAL BackColor : COLORREF

    Invoke BeginPaint, hWin, Addr ps
    mov hdc, eax

    ;----------------------------------------------------------
    ; Get some property values
    ;----------------------------------------------------------
    Invoke GetClientRect, hWin, Addr rect
    Invoke MUIGetIntProperty, hWin, @TextEnabledState
    mov EnabledState, eax
    Invoke MUIGetIntProperty, hWin, @TextMouseOver
    mov MouseOver, eax
    Invoke MUIGetExtProperty, hWin, @TextBackColor
    mov BackColor, eax

    .IF BackColor != -1 ; Not Transparent, background color is specified

Invoke CopyRect, Addr rct, Addr rect

        ;----------------------------------------------------------
        ; Setup Double Buffering
        ;----------------------------------------------------------
        Invoke CreateCompatibleDC, hdc
        mov hdcMem, eax
        Invoke CreateCompatibleBitmap, hdc, rect.right, rect.bottom
        mov hbmMem, eax
        Invoke SelectObject, hdcMem, hbmMem
        mov hOldBitmap, eax
   
        ;----------------------------------------------------------
        ; Background
        ;----------------------------------------------------------
        Invoke _MUI_TextPaintBackground, hWin, hdcMem, Addr rect, EnabledState, MouseOver
   
        ;----------------------------------------------------------
        ; Text
        ;----------------------------------------------------------
        Invoke _MUI_TextPaintText, hWin, hdcMem, Addr rect, EnabledState, MouseOver
   
        ;----------------------------------------------------------
        ; BitBlt from hdcMem back to hdc
        ;----------------------------------------------------------
        ;Invoke BitBlt, hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY
        Invoke StretchBlt, hdc, 0, 0, rct.right, rct.bottom, hdcMem, 0, 0, rect.right, rect.bottom, SRCCOPY
   
        ;----------------------------------------------------------
        ; Cleanup
        ;----------------------------------------------------------
        Invoke SelectObject, hdcMem, hOldBitmap
        Invoke DeleteDC, hdcMem
        Invoke DeleteObject, hbmMem
        .IF hOldBitmap != 0
            Invoke DeleteObject, hOldBitmap
        .ENDIF
   
    .ELSE ; Text on Transparent Background
   
        ;----------------------------------------------------------
        ; Text
        ;----------------------------------------------------------   
        Invoke _MUI_TextPaintText, hWin, hdc, Addr rect, EnabledState, MouseOver
   
    .ENDIF
     
    Invoke EndPaint, hWin, Addr ps

    ret
_MUI_TextPaint ENDP


fearless

Cool, nice idea for the shadow text effect.