"You are my master and i have your slave"


Code: Select all
; Window Z-Order for Screen GUI (V3)
; Fluid Byte
; August 05, 2008
InitSprite() : InitKeyboard() : InitMouse()
; Screen-GUI Stuff
Structure GUI_WINDOW
X.w
Y.w
Width.w
Height.w
Title.s
Active.b
Dragging.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()
MX = MouseX() : MY = MouseY()
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
ForEach gwin()
WX = gwin()\X : WY = gwin()\Y : WW = gwin()\Width : WH = gwin()\Height
; // Drag Windows //
If gwin()\Dragging
gwin()\X = MouseX() + MTX
gwin()\Y = MouseY() + MTY
EndIf
If MouseButton(1) = 0 : gwin()\Dragging = #False : EndIf
; // Draw Windows //
; * 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)
; * Detect Titlebar click
If MY < (WY + 30)
MTX = gwin()\X - MX
MTY = gwin()\Y - MY
gwin()\Dragging = #True
EndIf
; * 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
EndIf
If 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
Code: Select all
ForEach PanelLinkedList()
Draw panel
Draw all child gadgets
Next
Heh, I got about 200 PB projects lying here and like 5 of them are finished. So I think we share the same kind of disease.untune wrote:My problem is my attention span is too short to stick with a project usually but this one is coming on in leaps and bounds which is a great motivator.
Buttons? Check. Scrollbars? Check. Progressbars? Check. Windows without Z-Order? Check indeed. I also got some statusbar and menubar code but this is in early beta stage like some other controls.untune wrote:How far did you get with yours then?
Code: Select all
; // Get the info from the structure, create temporary structure to store it
GUI_PANEL_TEMPHEADER = GUI_LIST_PANEL()\Header
GUI_PANEL_TEMPBUFFER = AllocateMemory(SizeOf(_GUI_PANEL))
CopyMemory(GUI_LIST_PANEL(), GUI_PANEL_TEMPBUFFER, SizeOf(_GUI_PANEL))
; // Remove the element from the list
DeleteElement(GUI_LIST_PANEL())
; // Go to the front (end) of the list and add a new element
LastElement(GUI_LIST_PANEL())
AddElement(GUI_LIST_PANEL())
; // Copy data from buffer to new element
GUI_LIST_PANEL()\Header = GUI_PANEL_TEMPHEADER
CopyMemory(GUI_PANEL_TEMPBUFFER, GUI_LIST_PANEL(), SizeOf(_GUI_PANEL))
FreeMemory(GUI_PANEL_TEMPBUFFER)
; // Deactivate old panel, activate new panel
ChangeCurrentElement(GUI_LIST_PANEL(), GUI_PANEL_CURRENT)
GUI_LIST_PANEL()\Active = #False
LastElement(GUI_LIST_PANEL())
GUI_LIST_PANEL()\Active = #True
Code: Select all
; // Copy data from buffer to new element
*** GUI_LIST_PANEL()\Header = GUI_PANEL_TEMPHEADER
CopyMemory(GUI_PANEL_TEMPBUFFER, GUI_LIST_PANEL(), SizeOf(_GUI_PANEL))
FreeMemory(GUI_PANEL_TEMPBUFFER)