Code: Select all
Global CountCustomWindow
Procedure EventCustomWindow()
Static dragOn, windowMouseXOffset, windowMouseYOffset
Protected canvasDownX
Protected activeWindow = EventWindow()
Protected activeCanvas = EventGadget()
Protected activeWindowControlBoxWidth = GetGadgetData(activeCanvas)
Select EventType()
Case #PB_EventType_MouseMove
If dragOn
ResizeWindow(activeWindow, DesktopMouseX() - windowMouseXOffset,DesktopMouseY() - windowMouseYOffset, #PB_Ignore, #PB_Ignore)
EndIf
Case #PB_EventType_LeftClick
canvasDownX = GetGadgetAttribute(activeCanvas, #PB_Canvas_MouseX)
If canvasDownX > WindowWidth(activeWindow) - activeWindowControlBoxWidth
CloseWindow(activeWindow)
CountCustomWindow - 1
ElseIf canvasDownX > WindowWidth(activeWindow) - (activeWindowControlBoxWidth * 2)
SetWindowState(activeWindow, #PB_Window_Minimize)
EndIf
Case #PB_EventType_LeftButtonDown
windowMouseXOffset = DesktopMouseX() - WindowX(activeWindow)
windowMouseYOffset = DesktopMouseY() - WindowY(activeWindow)
dragOn = 1
Case #PB_EventType_LeftButtonUp
dragOn = 0
EndSelect
EndProcedure
Procedure OpenCustomWindow(x, y, width, height, windowColor, titleText.s,
titleHeight, titleFontColor, titleBackColor, centred)
If centred
windowFlags = #PB_Window_BorderLess | #PB_Window_ScreenCentered
Else
windowFlags = #PB_Window_BorderLess
EndIf
window = OpenWindow(#PB_Any, x, y, width, height, "", windowFlags)
SetWindowColor(window, windowColor)
canvas = CanvasGadget(#PB_Any, 0, 0, width, titleHeight, #PB_Canvas_Keyboard)
StartDrawing(CanvasOutput(canvas))
Box(0, 0, width, titleHeight, titleBackColor)
titleOffset = (titleHeight - TextHeight("A")) / 2
controlBoxWidth = TextWidth("X") * 2
DrawText(titleOffset, titleOffset, titleText, titleFontColor, titleBackColor)
DrawText(width - controlBoxWidth, titleOffset, "X", titleFontColor, titleBackColor)
DrawText(width - controlBoxWidth * 2, titleOffset, "_", titleFontColor, titleBackColor)
StopDrawing()
SetWindowData(window, canvas)
SetGadgetData(canvas, controlBoxWidth)
CountCustomWindow + 1
BindGadgetEvent(canvas, @EventCustomWindow())
ProcedureReturn window
EndProcedure
customWindow1 = OpenCustomWindow(100, 100, 300, 300, #Cyan, "My Custom Window 1", 70, #White, #Blue, 0)
customWindow2 = OpenCustomWindow(200, 200, 300, 300, #Yellow, "My Custom Window 2", 50, #Yellow, #Red, 0)
customWindow3 = OpenCustomWindow(300, 300, 300, 300, #White, "My Custom Window 3", 30, #White, #Black, 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
EndSelect
Until CountCustomWindow = 0