Page 1 of 2

Transparent Labels?

Posted: Mon Jun 28, 2004 3:51 pm
by Kazmirzak
I know that you are able to change the background-color with some callback-commands.

Is it possible to create Labels with real transparent background?

Posted: Mon Jun 28, 2004 4:05 pm
by thefool
I would also like to know how to do that.
I would also like pb to have commands for changing the colors of a label
and other gadgets implemented in pb. Does anyone know a userlib for doing that stuff?

Re: Transparent Labels?

Posted: Tue Jun 29, 2004 1:38 am
by PB
> Is it possible to create Labels with real transparent background?

Do you mean something like this:
viewtopic.php?t=9202

Posted: Tue Jun 29, 2004 8:26 am
by thefool
No, thats just coloring.
I know how to color. If you look at VB, it has real transperrent labels.

as num3 says in the code:
;My contribution is getting the background color
;so the text background always "looks" transparent!

Posted: Tue Jun 29, 2004 12:45 pm
by PB
> If you look at VB, it has real transperrent labels.

I don't know what you mean by "transparent labels" sorry.

Posted: Tue Jun 29, 2004 12:53 pm
by thefool
Transparrent means you can look through them.-
If you place an image then places a label on top:

If the label(textgadget) is transparrent (opacity) then you cant see the box sorrouning the text. If it is solid, you see the box.

What i mean is the background of a textgadget would be nice to have transperrent.

Posted: Tue Jun 29, 2004 1:07 pm
by Sparkie
I think they're looking for something like this, only using TextGadget rather than the DrawText as shown in image.pb example.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Image example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;

Procedure WindowCallback(WindowID, Message, lParam, wParam)
  If Message = #WM_PAINT
    StartDrawing(WindowOutput())
      DrawImage(UseImage(0), 20, 10)
      DrawImage(UseImage(1), 320, 80)
      DrawImage(UseImage(2), 320, 200)
    StopDrawing()
  EndIf
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


If OpenWindow(0, 100, 100, 500, 300, #PB_Window_SystemMenu, "PureBasic - Image")

  Gosub CreateImage
      
  SetWindowCallback(@WindowCallback())

  Repeat
    EventID = WaitWindowEvent()
  Until EventID = #PB_EventCloseWindow  ; If the user has pressed on the close button
  
EndIf

End   ; All the opened windows are closed automatically by PureBasic


;
; Some 2D graphics functions...
;

CreateImage:

  If CreateImage(0, 255, 255)

    StartDrawing(ImageOutput())
    
    For k=0 To 255
      FrontColor(k,0, k)  ; a rainbow, from black to pink
      Line(0, k, 255, 0)
    Next

    DrawingMode(1)
    Locate(40, 50)
    FrontColor(255,255,255) ; print the text to white !
    DrawText("An image created easely...")

    StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
    
  EndIf
  
  CopyImage(0, 1)
  ResizeImage(1, 100, 100)
  
  GrabImage(0, 2, 100, 60, 150, 40)

Return   

Posted: Tue Jun 29, 2004 1:13 pm
by thefool
@sparkie is right.
In VB you can just turn label transperrency on and then the labels are transperrent.
Can you use drawtext on a normal window with buttongadgets and that stuff? This is most for use when drawing on images, thats why drawtext() can be used, but if you could just make the textgadgets transperrent, it would be easier.

Posted: Tue Jun 29, 2004 2:12 pm
by Num3
I'll post some code that does this later on today...

This problems comes when you use a background image in your window...

Posted: Tue Jun 29, 2004 2:15 pm
by PB
> I'll post some code that does this later on today...

Too late, I just modified your (and Danilo's) code to do it :)

Code: Select all

; Original code by Danilo and Num3 (thanks, guys).
; Modified by PB to get a transparent TextGadget.

Global TextGadgetBackground,TextGadgetForeground

TextGadgetBackground=GetStockObject_(#HOLLOW_BRUSH)
TextGadgetForeground=RGB($FF,$00,$00)

Procedure WinProc(hWnd,Msg,wParam,lParam)
  If Msg=#WM_CTLCOLORSTATIC And lParam=GadgetID(0)
    SetBkMode_(wParam,#TRANSPARENT)
    SetTextColor_(wParam,TextGadgetForeground)
    ProcedureReturn TextGadgetBackground
  Else
    ProcedureReturn #PB_ProcessPureBasicEvents
  EndIf
EndProcedure

OpenWindow(0,0,0,250,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"test")
SetWindowCallback(@WinProc()) : CreateGadgetList(WindowID())
TextGadget(0,0,0,225,13,"This TextGadget has a transparent background")
r=LoadImage(1,"Babe.bmp") : ImageGadget(1,0,0,0,0,r)
Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow

DeleteObject_(TextGadgetBackground)

Posted: Tue Jun 29, 2004 5:18 pm
by thefool
thanks :D

that should go to the codearcive..

Posted: Fri Jun 30, 2006 5:59 pm
by Straker
HELP! - this only works on the first drawing of the window.

If you minimize or the window gets hidden behind another window, then the text either disappears or the Window background show thru as the TextGadget background instead of the Image.

I have searched these forums and tried all of the code examples, but cannot find a solution when you load a bitmap from a file. I need to load a bitmap from a file, not draw one on the fly or draw a gradient. I really need a solution to draw (and re-draw if necessary) a transparent text gadget ontop of a real bitmap.

please help.

Thanks in advance

Posted: Fri Jun 30, 2006 6:11 pm
by netmaestro

Code: Select all

; Original code by Danilo and Num3 (thanks, guys). 
; Modified by PB to get a transparent TextGadget. 

Global TextGadgetBackground,TextGadgetForeground 

TextGadgetBackground=GetStockObject_(#HOLLOW_BRUSH) 
TextGadgetForeground=RGB($FF,$00,$00) 

Procedure WinProc(hWnd,Msg,wParam,lParam) 
  If Msg=#WM_CTLCOLORSTATIC And lParam=GadgetID(0) 
    SetBkMode_(wParam,#TRANSPARENT) 
    SetTextColor_(wParam,TextGadgetForeground) 
    ProcedureReturn TextGadgetBackground 
  Else 
    ProcedureReturn #PB_ProcessPureBasicEvents 
  EndIf 
EndProcedure 

OpenWindow(0,0,0,250,100,"test",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
SetWindowCallback(@WinProc()) : CreateGadgetList(WindowID(0)) 
TextGadget(0,0,0,225,13,"This TextGadget has a transparent background")

hBrush = CreatePatternBrush_(LoadImage(1,"c:\purebasiclogo.bmp")) 
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)  
InvalidateRect_(WindowID(0), 0, #True) 
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow 

DeleteObject_(TextGadgetBackground) 
 

Posted: Fri Jun 30, 2006 6:42 pm
by Straker
ROCK & ROLL! That works. Thanks netmaestro, you're awesome. I don't care WHAT Num3 says about you.

Why isn't this in the CodeArchiv? hey Andre....

For others who run into the same thing, the operative code here is to use the following instead of an ImageGadget:

Code: Select all

hBrush = CreatePatternBrush_(LoadImage(1,"c:\purebasiclogo.bmp"))
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush) 
InvalidateRect_(WindowID(0), 0, #True)
Cheers and thanks for saving my day.

Posted: Fri Jun 30, 2006 6:47 pm
by Edwin Knoppert
Extended style WS_EX_TRANSPARENT
but wonders me, afaik it should be set by default (by label controls/STATIC class).

Another way *might* abort the WM_ERASEBKGND message ?