Strange Z-Ordering and Parenting effects

BlitzMax Forums/MaxGUI Module/Strange Z-Ordering and Parenting effects

- -(Posted 2011) [#1]
I am trying to create some panels that act as the parent gadgets for a textfield contained within them. I was successful in getting the first panel and its textfield to do this. Subsequent panels and their textfields either won't accept this same arrangement, or seem to have z-ordering issues unlike the first panel and textfield created.

[code]
SuperStrict
Import MaxGui.Drivers

Extern "win32"
Function DrawFocusRect% (hdc%, lpRect:Byte Ptr)
Function GetDC%(hwnd%)
Function GetWindowRect%(hwnd%,lpRect:Byte Ptr)
Function GetCursorPos%(point: Byte Ptr)
Function SetParent(Child:Int,Parent:Int)
End Extern
Global list:TList=CreateList()
Global mx:Int, my:Int, Drag:Int
Global wndMain:TGadget = CreateWindow("Test Window",100,100,400,300,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_STATUS|WINDOW_CLIENTCOORDS)
list.addlast wndMain
'MaximizeWindow wndMain
Global gadWindowPanel:TGadget = CreatePanel(0,0,ClientWidth(wndMain),ClientHeight(wndMain),wndMain,PANEL_ACTIVE,"WindowPanel")
list.addlast gadWindowPanel
Global p1:TGadget = CreatePanel(5,5,110,30,gadWindowPanel,PANEL_ACTIVE,"p1")
list.addlast p1
Global t1:Tgadget=CreateTextField(5,5,100,20,p1)
SetGadgetColor p1, 100,100,100
list.addlast t1
Global p2:TGadget = CreatePanel(130,5,110,30,gadWindowPanel,PANEL_ACTIVE,"p2")
list.addlast p2
Global t2:Tgadget=CreateTextField(130,5,100,20,gadwindowPanel)
SetGadgetColor p2, 0,0,200
list.addlast t2

Global p3:TGadget = CreatePanel(255,5,110,30,gadWindowPanel,PANEL_ACTIVE,"p3")
list.addlast p3
Global t3:Tgadget=CreateTextField(255,5,100,20,gadWindowPanel)
'Global t3:Tgadget=CreateTextField(275,5,100,20,p3)
SetPanelColor p3, 200,0,0
list.addlast t3

'Setgadgetsensitivity allows the textfield to emit selected events.
SetGadgetSensitivity(t1,EVENT_MOUSEDOWN|EVENT_MOUSEUP|EVENT_MOUSEENTER|EVENT_MOUSELEAVE)
SetGadgetSensitivity(t2,EVENT_MOUSEDOWN|EVENT_MOUSEUP|EVENT_MOUSEENTER|EVENT_MOUSELEAVE)
SetGadgetSensitivity(t3,EVENT_MOUSEDOWN|EVENT_MOUSEUP|EVENT_MOUSEENTER|EVENT_MOUSELEAVE)

Local r:lpRECT = New lpRECT
Repeat
'Print CurrentEvent.ToString()
Select WaitEvent()
Case EVENT_GADGETACTION
Case EVENT_GADGETPAINT
Case EVENT_WINDOWCLOSE;End
Case EVENT_MOUSEENTER
Case EVENT_MOUSEDOWN
Select EventSource()
Case p1,p2,p3
mx = EventX()
my = EventY()
Drag = 1
SetPointer(POINTER_HAND)
SetGadgetAlpha(ActiveGadget(),0.3)
Case t2,t3
mx = EventX()
my = EventY()
Drag = 1
SetPointer(POINTER_HAND)
SetGadgetAlpha(ActiveGadget(),0.3)
End Select
Case EVENT_MOUSEUP
Select EventSource()
Case p1,p2,p3
Drag = 0
SetPointer(POINTER_DEFAULT)
SetGadgetAlpha(ActiveGadget(),1)
Case t2,t3
Drag = 0
SetPointer(POINTER_DEFAULT)
SetGadgetAlpha(ActiveGadget(),1)
End Select
Case EVENT_MOUSEMOVE
'SetStatusText(wndMain,EventX()+":"+EventY())
SetStatusText( wndMain, EventX()+":"+EventY() + "~t~t" + CurrentEvent.ToString() + " " )

Select EventSource()
Case p1,p2,p3
If Drag
Local x:Int, y:Int
'Get top left coords of dragging object
x = EventX() + GadgetX(ActiveGadget()) - mx
y = EventY() + GadgetY(ActiveGadget()) - my
DebugLog x +" "+ y
'DebugLog EventX() +" "+ EventY()
'DebugLog ClientWidth(gadWindowpanel) + " " + ClientHeight(gadWindowpanel)
'Only move within the gadWindowpanel coords
If x=> 0 And x=<ClientWidth(wndMain)- ClientWidth(ActiveGadget()) And y=>0 And y=<ClientHeight(wndMain) - ClientHeight(ActiveGadget()) Then
SetGadgetShape (ActiveGadget(), x,y,GadgetWidth(ActiveGadget()),GadgetHeight(ActiveGadget()))

End If

End If
Case t2,t3
If Drag
Local x:Int, y:Int
x = EventX() + GadgetX(ActiveGadget()) - mx
y = EventY() + GadgetY(ActiveGadget()) - my
DebugLog x +" "+ y
'DebugLog ClientWidth(gadWindowpanel) + " " + ClientHeight(gadWindowpanel)
'Only move within the gadWindowpanel coords
If x=> 0 And x=<ClientWidth(wndMain)- ClientWidth(ActiveGadget()) And y=>0 And y=<ClientHeight(wndMain) - ClientHeight(ActiveGadget()) Then
SetGadgetShape (ActiveGadget(), x,y,GadgetWidth(ActiveGadget()),GadgetHeight(ActiveGadget()))

End If

End If

End Select
EndSelect

Forever

Type lpRECT
Field l%, t%, r%, b%
End Type
'Type for a point
Type TPoint
Field X:Int
Field Y:Int

Method Set(tx%,ty%)
X = tx
Y = ty
End Method
End Type
[\code]

This code attempts to set up 3 panels each containing a child textfield. There is a fourth panel, gadWindowPanel, that plays host to all 3 gadget sets and consists of the window client area between the menubar and statusbar. I know the code currently has t2 and t3 being parented by gadWindowPanel. I did this deliberately to show you that they were being created. You won't see them immediately, until you drag p2 and p3 off of them using the left mouse button. (When t2 and t3 are parented by their respective panels, you can't see them as apparently they are still masked by their panel. In other words, rendered underneath their panel. I even tried "oversizing" the textfields, but apparently Maxgui clips them to the panel borders when the textfields are created.)

p1,p2,p3, t2, and t3 are all draggable. One thing to notice as you are dragging them around is that they seem to be in a z-order that mimics their order of creation in reverse. For example, p2 is just under/behind p1 even though p2 was created after p1. p2,p3,t2,t3 all seem to share the same z-order behavior.

What is up with t1? Why did it appear on top of p1, just like I wanted, yet different than all the rest? I would like to have each panel with its child textfield just like the p1/t1 pairing. I am assuming that "parenting" is simply a case where I simply tell the child gadget which gadget to render to on its creation. Or do I have that wrong?


jsp(Posted 2011) [#2]
Not sure if I understand your problem, does the below what you where asking?



If yes your problem is may the relative coordinates you have to use when using a parent container.


- -(Posted 2011) [#3]
Thanks JSP. That did the trick exactly. Btw, my apologies for the lack of code indentation. When I copied it to the screen, it was indented. When I saw the post, my first one, I gagged.

How do you get the nice little code window with scrollbars to present?


jsp(Posted 2011) [#4]
How do you get the nice little code window with scrollbars to present?

Use codebox instead of code, see forum code here:
http://www.blitzbasic.com/faq/faq_entry.php?id=2


- -(Posted 2011) [#5]
Here's the indented and corrected code:




jsp(Posted 2011) [#6]
What is it used for?


- -(Posted 2011) [#7]
Ultimately, I'd like to create a cause mapping tool to facilitate root cause analysis and determine a solutions map. Most companies do not do root cause analysis well and one of the reasons is that the tools supporting such activity are woefully lacking. So I'm fiddling around with BMax to see if it is industrial strength enough to get there. From my meager skill set now, I'm not sure I'll get there. Too much hardcoded stuff. Too much reliance on named gadgets. I need to be able to create gadgets dynamically for things such as adding/deleting nodes to a network diagram, etc...


jsp(Posted 2011) [#8]
Nice task and although it could be done with MaxGui I would prefer to do it within a canvas with standard BlitzMax drawing commands. That should be a magnitude simpler to manage and would give more flexibility.
Creating dynamic gadgets should be no problem, I do it often reading a xml file and create gadgets as mentioned, but I don't see the advantage one would get in this scenario (but I don't know your full plan).
MaxGui is easy for the application surrounding buttons, menu, toolbar and such.