Page 1 of 1

How to place text on image

Posted: Fri Apr 29, 2005 12:50 am
by pickelrobert
Hi,

how can i place a TextGadget on top of an ImageGadget ?

Cheers

Posted: Fri Apr 29, 2005 12:59 am
by Shannara
mm, first I want to apologize for any assumptions I make in this reply :)

Before you set the image in the imagegadget and after you load the image, you should be able to do something like UseImage(ImageVar), then call StartDrawing(ImageOutput()). Then call ... Locate(x,y,) where you want your text to be, then DrawTexT(TextToDraw).

:)

Posted: Fri Apr 29, 2005 3:21 pm
by pickelrobert
Thank you, but this is not really that what i want. I mean more something the using of imagegadget as container (like the Picturecontrol in Visual Basic), because i'd not found an ability the set an image as background for the main window.

Posted: Sat Apr 30, 2005 1:08 am
by Sparkie
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