Untune, forget the code I posted and use this one instead. I made some necessary changes:
- theres no more Z-Order to change because it can be removed completely with this technique. You just deactivate the old window and activate the new one by a flag.
Code: Select all
; Window Z-Order for Screen GUI (v2)
; Fluid Byte
; July 30, 2008
InitSprite() : InitKeyboard() : InitMouse()
; Screen-GUI Stuff
Structure GUI_WINDOW
X.w
Y.w
Width.w
Height.w
Title.s
Active.b
EndStructure
Global NewList gwin.GUI_WINDOW()
Global GUI_LASTID
Procedure GUI_OpenWindow(X,Y,Width,Height,Title.s)
If GUI_LASTID
ChangeCurrentElement(gwin(),GUI_LASTID) : gwin()\Active = #False
EndIf
AddElement(gwin())
gwin()\X = X
gwin()\Y = Y
gwin()\Width = Width
gwin()\Height = Height
gwin()\Title = Title
gwin()\Active = #True
GUI_LASTID = gwin()
ProcedureReturn GUI_LASTID
EndProcedure
; Open Screen
OpenWindow(0,0,0,640,480,"Z-Order",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
; GUI Windows
guiWindow1 = GUI_OpenWindow(10,10,320,220,"GUI Window #1")
guiWindow2 = GUI_OpenWindow(150,70,310,220,"GUI Window #2")
guiWindow3 = GUI_OpenWindow(100,150,320,220,"GUI Window #3")
guiWindow4 = GUI_OpenWindow(240,220,320,220,"GUI Window #4")
; Mouse Pointer
lpBuffer = AllocateMemory(630)
UnpackMemory(?Cursor,lpBuffer)
CatchSprite(0,lpBuffer)
TransparentSpriteColor(0,RGB(0,128,128))
FreeMemory(lpBuffer)
; -------------------------------------------------------------------
; MAIN LOOP
; -------------------------------------------------------------------
Repeat
EventID = WindowEvent()
ClearScreen(RGB(150,120,50))
ExamineKeyboard() : ExamineMouse()
; // Draw Windows //
StartDrawing(ScreenOutput())
DrawingMode(1)
ForEach gwin()
WX = gwin()\X : WY = gwin()\Y : WW = gwin()\Width : WH = gwin()\Height
; * Active Window
If gwin()\Active = #True
Box(WX,WY,WW,WH,0)
Box(WX + 1,WY + 1,WW - 2,WH - 2,RGB(255,220,0))
Box(WX + 1,WY + 1,WW - 2,30,RGB(255,170,0))
Line(WX,WY + 30,WW,0)
DrawText(WX + 10,WY + 8,gwin()\Title,RGB(100,30,0))
Else
; * Inactive Window
Box(WX,WY,WW,WH,0)
Box(WX + 1,WY + 1,WW - 2,WH - 2,RGB(200,170,50))
Box(WX + 1,WY + 1,WW - 2,30,RGB(180,140,0))
Line(WX,WY + 30,WW,0)
DrawText(WX + 10,WY + 8,gwin()\Title,$44aacc)
EndIf
Next
StopDrawing()
; // Check Mouseclick //
If CountList(gwin()) ! 0 And MouseButton(1) And GUI_MOUSEBLOCK = #False
GUI_MOUSEBLOCK = #True
MX = MouseX() : MY = MouseY()
; * Cycle through items from back to front
LastElement(gwin())
hMemCurrent = gwin() ; address of last element / first window
Repeat
WX = gwin()\X : WY = gwin()\Y : WW = gwin()\Width : WH = gwin()\Height
If MX >= WX And MX < (WX + WW) And MY >= WY And MY < (WY + WH)
; * Exit loop and don't do anything if clicked window is the active one
If gwin() = hMemCurrent : Break : EndIf
; * Retrieve Window title and data from element address in memory
tmpString$ = gwin()\Title
hMemBuffer = AllocateMemory(SizeOf(GUI_WINDOW))
CopyMemory(gwin(),hMemBuffer,SizeOf(GUI_WINDOW))
; * Remove selected element (data has been temporarily saved)
DeleteElement(gwin())
; * Goto end of list and add a new item so it's last and the new topmost window
LastElement(gwin())
AddElement(gwin())
gwin()\Title = tmpString$
; * Copy window data to address of new element
CopyMemory(hMemBuffer,gwin(),SizeOf(GUI_WINDOW))
FreeMemory(hMemBuffer)
; * Activte new window, deactivte old window
gwin()\Active = #True
ChangeCurrentElement(gwin(),hMemCurrent)
gwin()\Active = #False
Break ; we found our window, get outta here
EndIf
Until PreviousElement(gwin()) = 0
ElseIf MouseButton(1) = 0
GUI_MOUSEBLOCK = #False
EndIf
DisplayTransparentSprite(0,MouseX(),MouseY())
FlipBuffers()
Until KeyboardPushed(1) Or EventID = #PB_Event_CloseWindow
; -------------------------------------------------------------------
; DATA SECTION
; -------------------------------------------------------------------
DataSection
Cursor:
Data.l $0276434A,$4A720000,$A9B7AACC,$146320D0,$284A6811,$01232023,$9188409D,$F3000461,$20492601,$0A0401E0
Data.l $E00081C0,$FFC0E015,$09302024,$409C3C04,$66013801,$FE4D02B6,$91FB77FB,$B7C236B7,$BDF63086,$BFEC1EC1
Data.l $C0F36107,$0F625EF7,$008A083D,$87FFF581,$C4592A11,$4287C926,$3EC90540,$69F6974F,$21E5E328,$DDDE6107
Data.l $50B353C6,$0FB86C06,$0000D893
Data.b $90,$48
EndDataSection