Gadget z-depth reversed?

Just starting out? Need help? Post your questions and find answers here.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Gadget z-depth reversed?

Post by Mistrel »

When I add new gadgets to a window the new gadgets will overlap the old ones. Ok, I get that. But why do the gadgets behind the overlapping gadgets have a higher priority?

Is there any way to force priority for foreground gadgets?

In this example button "two" is drawn on top of button "one". But if you click on the overlapping area the button in the back is activated instead of the one on top.

Code: Select all

OpenWindow(0,640,480,120,100,"")
CreateGadgetList(WindowID(0))
ButtonGadget(0, 10, 10, 70, 50, "One")
ButtonGadget(1, 40, 40, 70, 50, "Two")

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
End
Here is another example with a scroll area

Code: Select all

OpenWindow(0,640,480,120,100,"")
CreateGadgetList(WindowID(0))

ScrollAreaGadget(0,10,10,70,50,140,100,30,#PB_ScrollArea_BorderLess)
CloseGadgetList()

ButtonGadget(2, 40, 40, 70, 50, "Two")

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
End
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Gadgets doesn't have Z-depth.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Gadget z-depth reversed?

Post by PB »

Thanks to Sparkie:

Code: Select all

OpenWindow(0,640,480,120,100,"")
CreateGadgetList(WindowID(0))
ButtonGadget(1, 10, 10, 70, 50, "Bottom")
ButtonGadget(2, 40, 40, 70, 50, "Top")
SetWindowLong_(GadgetID(1), #GWL_STYLE, GetWindowLong_(GadgetID(1), #GWL_STYLE) | #WS_CLIPSIBLINGS)
SetWindowPos_(GadgetID(1), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
Sparkie's original code was from my question here:
http://www.purebasic.fr/english/viewtopic.php?t=17952
.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

That's perfect! I've modified it a bit to force gadgets to be drawn on-top instead of forcing a particular gadget to the bottom.

Thank you. :)

I couldn't find a way to push a single gadget to the top so this procedure will have to be used on gadgets that overlap and the gadgets they obscure.

Code: Select all

Procedure ForceGadgetZOrder(gadget)
	;/ Flip the gadget draw order and force
	;/ the topmost gadget to recieve focus
	;/ first for overlapping gadgets

	SetWindowLong_(GadgetID(gadget),#GWL_STYLE,GetWindowLong_(GadgetID(gadget),#GWL_STYLE)|#WS_CLIPSIBLINGS)
	SetWindowPos_(GadgetID(gadget),#HWND_TOP,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
EndProcedure

OpenWindow(0,640,480,120,100,"")
CreateGadgetList(WindowID(0))
ForceGadgetZOrder(ButtonGadget(#PB_Any,10,10,70,50,"Bottom"))
ForceGadgetZOrder(ButtonGadget(#PB_Any,40,40,70,50,"Top"))

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

This is the routine I've used successfully in a number of programs:

Code: Select all

Procedure SetGadgetZOrder(gadget, zorder=0)
; Correct the z-order and draw order for [potentially] overlapping gadgets
; Call with zorder=0 just after creating each gadget
; Call with zorder=1 to later bring a gadget to the top of the z-order
; Call with zorder=-1 to later bring a gadget to the bottom of the z-order
; www.purebasic.fr/english/viewtopic.php?t=28802
If zorder=0
  SetWindowLong_(GadgetID(gadget),#GWL_STYLE,GetWindowLong_(GadgetID(gadget),#GWL_STYLE)|#WS_CLIPSIBLINGS)
EndIf
If zorder>=0
  SetWindowPos_(GadgetID(gadget),#HWND_TOP,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
Else
  SetWindowPos_(GadgetID(gadget),#HWND_BOTTOM,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
EndIf
EndProcedure
Anthony Jordan
Post Reply