why would a gouped window close the app
BlitzMax Forums/MaxGUI Module/why would a gouped window close the app
| ||
| i want to create sub windows for things like item propertes. Weird thing is even though the new window is grouped to the main window: 1) execution still continues in the main window (i dont want this) 2) clicking X on the sub-window closes the main window as well. Any ideas? |
| ||
| 1) Disable the main menu and all active gadgets. 2) You need to check if the subwindow is existant or not: Case EVENT_WINDOWCLOSE If Mysubwindow:TGadget <> Null then hidegadget( Mysubwindow ) else end endif P.S.: A bit sourcecode is mostly helpful when asking questions. |
| ||
| Check EVENT_WINDOWCLOSE against EventSource() - which will tell you *which* window raised the close event. Then you can act on it. Tricky with 1) ... On Mac I was able to move the "current" loop to the child-window by making the child-window modal, but on Windows/Linux opening the child-window didn't seem to have this effect... But I think if you use event hooks to handle your UI you might be able to get around this issue... |
| ||
| @D-Grafix Here's some simple code that might help:
SuperStrict
Local window:TGadget = CreateWindow("Main Window",50, 50, 240, 240)
Local button:TGadget = CreateButton("Click Me", 5, 5, 100, 50, window)
Local modal:TGadget = CreateWindow("Modal Window",50, 50, 200, 200, window, WINDOW_TITLEBAR | WINDOW_HIDDEN)
While WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
If EventSource() = window Then End
If EventSource() = modal
EnableGadget button
EnableGadget window
HideGadget modal
EndIf
Case EVENT_GADGETACTION
DisableGadget button
DisableGadget window
ShowGadget modal
End Select
Wend
EDIT: If you want the main window's gadgets to have a 'greyed-out' appearance when the subwindow is displayed you will need to disable each one accordingly. Updated the code sample to reflect this. |
| ||
And if you want to actually suspend main window-related execution you'll need to structure your primary loop appropriately. Example:
SuperStrict
Local window:TGadget = CreateWindow("Main Window",50, 50, 240, 240)
Local button:TGadget = CreateButton("Click Me", 5, 5, 100, 50, window)
Local label:TGadget = CreateLabel("0", 5, 60, 100, 50, window)
Local modal:TGadget = CreateWindow("Modal Window",50, 50, 200, 200, window, WINDOW_TITLEBAR | WINDOW_HIDDEN)
Local timer:TTimer = CreateTimer(1)
Local oldtime:Int = 0
Local value:Int = 0
Local DoMainWindowStuff:Int = True
Repeat
PollEvent
Select EventID()
Case EVENT_WINDOWCLOSE
If EventSource() = window Then End
If EventSource() = modal
EnableGadget button
EnableGadget window
DoMainWindowStuff = True
HideGadget modal
EndIf
Case EVENT_GADGETACTION
DoMainWindowStuff = False
DisableGadget button
DisableGadget window
ShowGadget modal
End Select
If DoMainWindowStuff
Local t:Int = TimerTicks(timer)
If t > oldtime
oldtime = t
value :+ 1
If value > 1000 Then value = 0
SetGadgetText(label, value)
EndIf
EndIf
Forever
|
| ||
| great, thanks guys! |