How to place text on image
Posted: Fri Apr 29, 2005 12:50 am
Hi,
how can i place a TextGadget on top of an ImageGadget ?
Cheers
how can i place a TextGadget on top of an ImageGadget ?
Cheers
http://www.purebasic.com
https://www.purebasic.fr/english/
pickelrobert wrote:how can i place a TextGadget on top of an ImageGadget ?
Code: Select all
; --> Create a brush for our TextGadget. This is needed in #WM_CTLCOLORSTATIC
textBGcolor = RGB(155, 200, 155)
textBGbrush = CreateSolidBrush_(textBGcolor)
; --> Set our text color
textFGcolor = RGB(0, 100, 0)
Global textBGbrush, textFGcolor
; --> Create image
CreateImage(0, 300, 200)
StartDrawing(ImageOutput())
Box(0, 0, 300, 200, textBGcolor)
StopDrawing()
; --> Window Callback
Procedure myWindowCallback(hwnd, msg, wparam, lParam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CTLCOLORSTATIC
; --> Is this our TextGadget
If IsGadget(0) And lParam = GadgetID(0)
; --> If so, then color the text and background
SetTextColor_(wparam, textFGcolor)
SetBkMode_(wparam, #TRANSPARENT)
result = textBGbrush
EndIf
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Test") And CreateGadgetList(WindowID(0))
SetWindowCallback(@myWindowCallback())
; --> TextGadget z-order is on top of ImageGaget
TextGadget(0, 50, 140, 300, 20, "TextGadget on top of ImageGadget", #PB_Text_Center)
ImageGadget(1, 50, 50, 300, 200, UseImage(0))
; --> Let gadgets redraw on top of ImageGadget by setting #WS_CLIPSIBLINGS for ImageGadget
SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE) | #WS_CLIPSIBLINGS)
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
DeleteObject_(textBGbrush)
EndIf