Page 1 of 1

Transparency for TextGadget and overlaping...???

Posted: Mon Oct 27, 2008 3:14 pm
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.

Posted: Mon Oct 27, 2008 6:47 pm
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

Posted: Mon Oct 27, 2008 9:56 pm
by Sparkie
Try #WS_CLIPSIBLINGS

Code: Select all

ButtonImageGadget(1, 10, 25, 50, 50, icoid, #WS_CLIPSIBLINGS) 

Posted: Tue Oct 28, 2008 12:16 am
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) 

Posted: Tue Oct 28, 2008 6:40 am
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.

Posted: Tue Oct 28, 2008 7:37 pm
by +18
maybe can use this Constant #HWND_TOPMOST, but i dont know how can do it yet.

Posted: Tue Oct 28, 2008 8:44 pm
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)

Posted: Wed Oct 29, 2008 7:16 am
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)

Posted: Thu Dec 25, 2008 10:56 am
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.

Posted: Thu Dec 25, 2008 4:59 pm
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.

Posted: Thu Dec 25, 2008 6:42 pm
by Andi
Perfect! That's what I was looking for. Thanks, Sparkie!