ChrisR wrote:Let us know for the other method.
I wrote a few lines of code to illustrate what I mean.Of course the codes are dirty and not optimized.
In these codes, instead of using a dedicated canvas for each gadget, I only use one canvas that sits on the main canvas.
Of course requires more work but the result seems to me desirable because :
1-Prevents the creation of additional canvas.
2-The controls are moved without flickering
I do not know maybe not good.
Code: Select all
Procedure SetGadgetZOrder(gadget, zorder=0)
If IsGadget(gadget)
If zorder = 0 ;Call with zorder=0 just after creating each gadget
SetWindowLong_(GadgetID(gadget), #GWL_STYLE, GetWindowLong_(GadgetID(gadget), #GWL_STYLE) | #WS_CLIPSIBLINGS)
ElseIf zorder = 1 ;Call with zorder=1 to later bring a gadget to the top of the z-order
SetWindowPos_(GadgetID (gadget), #HWND_BOTTOM, 0,0,0,0, #SWP_NOSIZE | #SWP_NOMOVE)
Else ;Call with zorder=-1 to later bring a gadget to the bottom of the z-order
SetWindowPos_(GadgetID(gadget), #HWND_TOP, 0, 0, 0, 0, #SWP_NOSIZE | #SWP_NOMOVE)
EndIf
EndIf
EndProcedure
Structure VDG_Data
Btn.i
IsSelected.b
EndStructure
Global NewList GList.VDG_Data()
Enumeration
#UnderForm
#OverForm
#AddGadget
EndEnumeration
Procedure CreateGadget(X,Y,W,H)
OpenGadgetList(#UnderForm)
AddElement(GList())
GList()\Btn = ExplorerComboGadget(#PB_Any,X,Y,W,H,"")
CloseGadgetList()
EndProcedure
Procedure IsMouseOverGadget(dummyX,dummyY,GX,GW,GY,GH)
If (dummyX > GX) And ( dummyX < (GX + GW) ) And
(dummyY > GY) And ( dummyY < (GY + GH) )
ProcedureReturn 1
EndIf
EndProcedure
Procedure Canvas_Events_Handler()
Protected eg,et,MMX,MMY,_Gadget
Static g_Drag,LBD_X,LBD_Y
eg = EventGadget()
et = EventType()
Select et
Case #PB_EventType_LeftButtonDown
LBD_X = GetGadgetAttribute(eg,#PB_Canvas_MouseX)
LBD_Y = GetGadgetAttribute(eg,#PB_Canvas_MouseY)
ResetList(GList())
ForEach GList()
_Gadget = GList()\Btn
If IsMouseOverGadget(LBD_X,LBD_Y,GadgetX(_Gadget),GadgetWidth(_Gadget),GadgetY(_Gadget),GadgetHeight(_Gadget))
g_Drag = #True
GList()\IsSelected = #True
EndIf
Next
Case #PB_EventType_MouseMove
If g_Drag
MMX = GetGadgetAttribute(eg,#PB_Canvas_MouseX) ;- LBD_X
MMY = GetGadgetAttribute(eg,#PB_Canvas_MouseY) ;- LBD_Y
ResetList(GList())
ForEach GList()
If GList()\IsSelected
ResizeGadget(GList()\Btn,MMX,MMY,#PB_Ignore,#PB_Ignore)
EndIf
Next
EndIf
Case #PB_EventType_LeftButtonUp
If g_Drag
g_Drag = #False
ResetList(GList())
ForEach GList()
If GList()\IsSelected
GList()\IsSelected = #False
EndIf
Next
EndIf
EndSelect
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
ButtonGadget(#AddGadget,650,20,100,30,"Add Gadget")
CanvasGadget(#OverForm,0,0,600,600)
SetGadgetZOrder(#OverForm)
SetGadgetZOrder(#OverForm,1)
BindGadgetEvent(#OverForm,@Canvas_Events_Handler())
CanvasGadget(#UnderForm,0,0,600,600,#PB_Canvas_Container)
CloseGadgetList()
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #AddGadget : CreateGadget(20,20,100,30)
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf