Transparency for TextGadget and overlaping...???

Just starting out? Need help? Post your questions and find answers here.
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Transparency for TextGadget and overlaping...???

Post by +18 »

If there is a movable TextGadget under mouse position same as :

Code: Select all

#Wsize = 50
#Hsize = 25

imgid = LoadImage(0, #PB_Compiler_Home + "\Examples\Sources\Data\Background.bmp")
fonid = LoadFont(0, "Arial", 8, #PB_Font_Bold)
icoid = LoadIcon_(0, #IDI_ASTERISK)

Procedure MoveGadjet(Gadget)
  MoveWindow_(GadgetID(Gadget), WindowMouseX(0)-40, WindowMouseY(0)-20, #Wsize, #Hsize, 1);
EndProcedure

OpenWindow(0, 100, 100, 300, 240, "Test", #PB_Window_SystemMenu | #SS_CENTER)
SetWindowColor(0, #Blue)

CreateGadgetList(WindowID(0))
ButtonImageGadget(1, 10, 25, 50, 50, icoid)
TextGadget(2, 10, 10, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE) : SetGadgetFont(2, fonid)

Repeat
  ev = WaitWindowEvent()
  tp = EventType()
  gt = EventGadget()
  Select ev
    Case #WM_MOUSEMOVE ;And tp = #PB_EventType_LeftClick
      MoveGadjet(2)
      ;     Case #PB_Event_Repaint
      ;       TextGadget(100, WindowMouseX(0)-40, WindowMouseY(0)-20, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE)
  EndSelect
  
Until ev = #PB_Event_CloseWindow


; need Transparency TextGadget and overlaping...

then is some askings:
1) Your t'n't for Solving\improvement in overlaping with other gadgets???
2) Your t'n't for Transparency on TextGadget???

i think the above cases are without proceed about These in forum.
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post by +18 »

I'm finding an improvement for overlaping problem:

Code: Select all

#Wsize = 50
#Hsize = 25

imgid = LoadImage(0, #PB_Compiler_Home + "\Examples\Sources\Data\Background.bmp")
fonid = LoadFont(0, "Arial", 8, #PB_Font_Bold)
icoid = LoadIcon_(0, #IDI_ASTERISK)

; Debug
Procedure MoveGadjet(Gadget)
  
  MoveWindow_(GadgetID(Gadget), WindowMouseX(0)-40, WindowMouseY(0)-20, #Wsize, #Hsize, 1);
  
EndProcedure

OpenWindow(0, 100, 100, 300, 240, "Test", #PB_Window_SystemMenu | #SS_CENTER)
SetWindowColor(0, #Blue)

CreateGadgetList(WindowID(0))
ButtonImageGadget(1, 10, 25, 50, 50, icoid)
TextGadget(2, 10, 10, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE) : SetGadgetFont(2, fonid)

Repeat
  ev = WaitWindowEvent()
  tp = EventType()
  gt = EventGadget()
  Select ev
    Case #WM_MOUSEMOVE ;And tp = #PB_EventType_LeftClick
      MoveGadjet(2)
    Case #PB_Event_Repaint
      SetWindowText_(GadgetID(2), "Hello")
      
  EndSelect
  
Until ev = #PB_Event_CloseWindow

; need Transparency
I'm waiting for your help, PLZ
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Try #WS_CLIPSIBLINGS

Code: Select all

ButtonImageGadget(1, 10, 25, 50, 50, icoid, #WS_CLIPSIBLINGS) 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

This seems to have most of it. If you want the text gadget to show above any other gadgets then we have more work to do. For now, see how you like this:

Code: Select all

#Wsize = 50 
#Hsize = 25 

fonid = LoadFont(0, "Arial", 8, #PB_Font_Bold) 
icoid = LoadIcon_(0, #IDI_ASTERISK) 

OpenLibrary(0,"Msimg32.dll") 
Prototype GradientFill(hdc,*Vert,Int1,*Rect,Int2,Flags) 
GradientFill.GradientFill=GetFunction(0,"GradientFill") 

Dim vert.TRIVERTEX(1) 
gRect.GRADIENT_RECT 
vert (0) \x      = 0 
vert (0) \y      = 0 
vert (0) \Red    = $0000 
vert (0) \Green  = $ffff 
vert (0) \Blue   = $ffff 
vert (0) \Alpha  = $0000 

vert (1) \x      = 300 
vert (1) \y      = 240 
vert (1) \Red    = $ffff 
vert (1) \Green  = $0ff0 
vert (1) \Blue   = $ffff 
vert (1) \Alpha  = $0000 

gRect\UpperLeft  = 0 
gRect\LowerRight = 1 

CreateImage(0,300,240,32) 
hDC = StartDrawing(ImageOutput(0)) 
  GradientFill(hdc, @vert(), 2, @gRect, 1, #GRADIENT_FILL_RECT_H) 
StopDrawing() 

CloseLibrary(0) 

Procedure WindowProc(hWnd, Msg, wParam, lParam) 
  result = #PB_ProcessPureBasicEvents 
  If Msg=#WM_CTLCOLORSTATIC 
    Select GetDlgCtrlID_(lparam) 
      Case 2 
        SetBkMode_(wParam,#TRANSPARENT) 
        SetTextColor_(wParam,#Black) 
        result = GetStockObject_(#HOLLOW_BRUSH) 
    EndSelect 
  EndIf 
  ProcedureReturn result 
EndProcedure 

Procedure MoveGadjet(Gadget) 
  MoveWindow_(GadgetID(Gadget), WindowMouseX(0)-40, WindowMouseY(0)-20, #Wsize, #Hsize, 1); 
  GetWindowRect_(GadgetID(2),gr.RECT) 
  MapWindowPoints_(0,WindowID(0),gr,2) 
  InvalidateRect_(WindowID(0),gr,1) 
EndProcedure 

OpenWindow(0, 100, 100, 300, 240, "Test", #PB_Window_SystemMenu | #SS_CENTER) 
SetWindowCallback(@WindowProc()) 

CreateGadgetList(WindowID(0)) 
ButtonImageGadget(1, 10, 25, 50, 50, icoid) 
TextGadget(2, 10, 10, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE | #WS_CLIPSIBLINGS ) : SetGadgetFont(2, fonid) 
hBrush = CreatePatternBrush_(ImageID(0)) 
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)  
InvalidateRect_(WindowID(0), 0, #True)  

Repeat 
  ev = WaitWindowEvent() 
  tp = EventType() 
  gt = EventGadget() 
  Select ev 
    Case #WM_MOUSEMOVE ;And tp = #PB_EventType_LeftClick 
      MoveGadjet(2) 
   EndSelect 
  
Until ev = #PB_Event_CloseWindow 
DeleteObject_(hBrush) 
BERESHEIT
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post by +18 »

very well, your technique are very useful, thank you very much to dear both .
just there is a small problem, can be TextGadget on top level of all gadget? :?:


Added:

ok, i make test it Lot, the results:
#1
In this example if we change :

Code: Select all

TextGadget(2, 10, 10, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE | #WS_CLIPSIBLINGS)
to:

Code: Select all

TextGadget(2, 10, 10, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE | #MA_ACTIVATE)
That's great

#2
but if adding numbers of gadget, like this :

Code: Select all

#Wsize = 50
#Hsize = 25
imgid = LoadImage(0, #PB_Compiler_Home + "\Examples\Sources\Data\Background.bmp")
fonid = LoadFont(0, "Arial", 8, #PB_Font_Bold)
icoid = LoadIcon_(0, #IDI_ASTERISK)

OpenLibrary(0, "Msimg32.dll")
Prototype GradientFill(hdc, *Vert, Int1, *Rect, Int2, Flags)
GradientFill.GradientFill = GetFunction(0, "GradientFill")

Dim vert.TRIVERTEX(1)
gRect.GRADIENT_RECT
vert(0) \x = 0
vert(0) \y = 0
vert(0) \Red = $0000
vert(0) \Green = $ffff
vert(0) \Blue = $ffff
vert(0) \Alpha = $0000

vert(1) \x = 300
vert(1) \y = 240
vert(1) \Red = $ffff
vert(1) \Green = $0ff0
vert(1) \Blue = $ffff
vert(1) \Alpha = $0000

gRect\UpperLeft = 0
gRect\LowerRight = 1

; CreateImage(0, 300, 240, 32)
; hDC = StartDrawing(ImageOutput(0))
;   GradientFill(hdc, @vert(), 2, @gRect, 1, #GRADIENT_FILL_RECT_H)
; StopDrawing()

CloseLibrary(0)

Procedure WindowProc(hWnd, Msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  If Msg = #WM_CTLCOLORSTATIC
    Select GetDlgCtrlID_(lparam)
      Case 2
        
        SetBkMode_(wParam, #TRANSPARENT)
        SetTextColor_(wParam, #Black)
        result = GetStockObject_(#HOLLOW_BRUSH)
        
    EndSelect
  EndIf
  ProcedureReturn result
EndProcedure

Procedure MoveGadjet(Gadget)
  MoveWindow_(GadgetID(Gadget), WindowMouseX(0)-40, WindowMouseY(0)-20, #Wsize, #Hsize, 1);
  GetWindowRect_(GadgetID(2), gr.RECT)
  MapWindowPoints_(0, WindowID(0), gr, 2)
  InvalidateRect_(WindowID(0), gr, 1)
EndProcedure

OpenWindow(0, 100, 100, 300, 240, "Test", #PB_Window_SystemMenu | #SS_CENTER)
SetWindowCallback(@WindowProc())

CreateGadgetList(WindowID(0))
PanelGadget(0,0,0,WindowX(0),WindowY(0))
AddGadgetItem(0,-1,"Test on Gadgets")
ButtonImageGadget(1, 10, 25, 50, 50, icoid)
TextGadget(2, 10, 10, #Wsize, #Hsize, "Hello", #PB_Text_Center | #SS_CENTERIMAGE | #WS_CLIPSIBLINGS) : SetGadgetFont(2, fonid)


OptionGadget(3, 100, 50, 50, 20, "test gt")
ImageGadget(4, 100, 175, 0, 0, imgid)


hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, #True)

Repeat
  ev = WaitWindowEvent()
  tp = EventType()
  gt = EventGadget()
  Select ev
    Case #WM_MOUSEMOVE ;And tp = #PB_EventType_LeftClick
      MoveGadjet(2)
      
  EndSelect
  
Until ev = #PB_Event_CloseWindow
DeleteObject_(hBrush)
I'm looking for a respons to top level in TextGadget.
I think your technique is very useful in Transparency and will completed if
can be add to it a overloping.

btw , i'm thanksful to you too.
please help me if have a little time.
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post by +18 »

maybe can use this Constant #HWND_TOPMOST, but i dont know how can do it yet.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Although this code seems to work it still flickers pretty bad.

Code: Select all

Enumeration
	#BTI_Icon
	#TXT_Label
EndEnumeration

#TXTWIDTH = 50
#TXTHEIGHT = 25

CreateImage(0,300,240)
StartDrawing(ImageOutput(0))
For i=0 To 239 : Box(0,i,300,1,RGB(255,100 + 155 * i / 239,0)) : Next
StopDrawing()

Procedure WindowProc(hWnd,uMsg,wParam,lParam)
	Select uMsg
		Case #WM_CTLCOLORSTATIC
		If lParam = GadgetID(#TXT_Label)
			SetBkMode_(wParam,#TRANSPARENT)
			SetBkColor_(wParam,0)
			ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
		EndIf
	EndSelect
	
	ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

Procedure MoveGadget(Gadget)
	ResizeGadget(#TXT_Label,WindowMouseX(0) - 40, WindowMouseY(0) - 20,#PB_Ignore,#PB_Ignore)	
	GetWindowRect_(GadgetID(#TXT_Label),crc.RECT)
	MapWindowPoints_(0,WindowID(0),crc,2)
	InvalidateRect_(WindowID(0),crc,1)	
	InvalidateRect_(GadgetID(#BTI_Icon),0,0)
EndProcedure

OpenWindow(0,0,0,300,240,"Test",#PB_Window_SystemMenu | 1)
CreateGadgetList(WindowID(0))
ButtonImageGadget(#BTI_Icon,25,25,50,50,LoadIcon_(0,#IDI_ASTERISK),#WS_CLIPSIBLINGS)
TextGadget(#TXT_Label,10,10,#TXTWIDTH,#TXTHEIGHT,"Hello",#PB_Text_Center | #SS_CENTERIMAGE)

SetGadgetFont(#TXT_Label,LoadFont(0,"Arial",8,#PB_Font_Bold))

SetWindowCallback(@WindowProc())

hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0),#GCL_HBRBACKGROUND,hBrush) 
InvalidateRect_(WindowID(0),0,1) 

SetWindowLong_(GadgetID(#TXT_Label),#GWL_EXSTYLE,#WS_EX_TRANSPARENT)

Repeat
	EventID = WaitWindowEvent()
	
	Select EventID
		Case #WM_MOUSEMOVE
		MoveGadget(#TXT_Label)
	EndSelect
Until EventID = #PB_Event_CloseWindow

DeleteObject_(hBrush)
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
+18
Enthusiast
Enthusiast
Posts: 228
Joined: Fri Oct 24, 2008 2:07 pm

Post by +18 »

Really nice.
ok, that has a little of filkering ,i think it is tolerable.just there is a small problem, i need when push a button ,movement must be stop and Textgadget can placed in same point. i'm try to finding it self, if you have a quick code, geive me PLZ.
Thank you

i test it on numbers of gadget, yes

Code: Select all

Enumeration
  #BTI_Icon
  #TXT_Label
  #Str
  #Trk
  #BTN
  #Chk
  #Pnl
EndEnumeration

#TXTWIDTH = 50
#TXTHEIGHT = 25

CreateImage(0, 300, 240)
StartDrawing(ImageOutput(0))
  For i = 0 To 239 : Box(0, i, 300, 1, RGB(255, 100 + 155*i/239, 0)) : Next
StopDrawing()

Procedure WindowProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_CTLCOLORSTATIC
      If lParam = GadgetID(#TXT_Label)
        SetBkMode_(wParam, #TRANSPARENT)
        SetBkColor_(wParam, 0)
        ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
      EndIf
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

Procedure MoveGadget(Gadget)
  ResizeGadget(#TXT_Label, WindowMouseX(0)-40, WindowMouseY(0)-20, #PB_Ignore, #PB_Ignore)
  GetWindowRect_(GadgetID(#TXT_Label), crc.RECT)
  MapWindowPoints_(0, WindowID(0), crc, 2)
  InvalidateRect_(WindowID(0), crc, 1)
  InvalidateRect_(GadgetID(#BTI_Icon), 0, 0)
EndProcedure

OpenWindow(0, 0, 0, 300, 240, "Test", #PB_Window_SystemMenu | 1)
CreateGadgetList(WindowID(0))
ButtonImageGadget(#BTI_Icon, 25, 25, 50, 50, LoadIcon_(0, #IDI_ASTERISK), #WS_CLIPSIBLINGS)
TextGadget(#TXT_Label, 10, 10, #TXTWIDTH, #TXTHEIGHT, "Hello", #PB_Text_Center | #SS_CENTERIMAGE) : SetGadgetFont(#TXT_Label, LoadFont(0, "Arial", 8, #PB_Font_Bold))
StringGadget(#Str, 100, 100, 50, 30, "test")
TrackBarGadget(#Trk, 150, 20, 50, 23, 0, 100)

PanelGadget(#Pnl, 0, 140, 300, 100)
AddGadgetItem(#Pnl, -1, "test")
ButtonGadget(#BTN, 100, 0, 50, 25, "test")
CheckBoxGadget(#Chk, 0, 0, 40, 20, "test")
CloseGadgetList()

SetWindowCallback(@WindowProc())

hBrush = CreatePatternBrush_(ImageID(0))
SetClassLong_(WindowID(0), #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(WindowID(0), 0, 1)

SetWindowLong_(GadgetID(#TXT_Label), #GWL_EXSTYLE, #WS_EX_TRANSPARENT)

Repeat
  EventID = WaitWindowEvent()
  
  Select EventID
    Case #WM_MOUSEMOVE
      MoveGadget(#TXT_Label)
  EndSelect
Until EventID = #PB_Event_CloseWindow

DeleteObject_(hBrush)
Andi
User
User
Posts: 21
Joined: Fri Sep 12, 2008 2:43 pm
Location: Berlin

Post by Andi »

For me it is a nice example 'cause it shows how to make a TextGadget transparent. Does anyone know, how to get other gadgets (e.g. a trackbar-gadget, string-gadget) transparent? Although using #WM_CTLCOLOREDIT to catch the window-message, I had no success.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

For a transparent StringGadget, look here...
http://www.purebasic.fr/english/viewtop ... 328#221328

For a transparent TrackBarGadget, use the same code as in the link but use #WM_CTLCOLORSTATIC in place of #WM_CTLCOLOREDIT.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Andi
User
User
Posts: 21
Joined: Fri Sep 12, 2008 2:43 pm
Location: Berlin

Post by Andi »

Perfect! That's what I was looking for. Thanks, Sparkie!
Post Reply