Customized Windows ?
- PedroMartins
- User
- Posts: 47
- Joined: Sat Sep 02, 2017 7:30 pm
Customized Windows ?
*** to Administrator: please delete this post reply ***
Last edited by PedroMartins on Fri Apr 06, 2018 2:30 pm, edited 4 times in total.
Re: Wishes for Window and Menu colors
I know it's a wish, but Fred has said in the past that only cross-platform wishes get considered:PedroMartins wrote:To Dude: It's just a wish. Don't kill the wish.
Fred in http://www.purebasic.fr/english/viewtopic.php?p=473254#p473254 wrote:We usually only add commands which can be used on all OS.
Re: Wishes for Window and Menu colors
Most applications with customised windows don't usually override the global system and theme settings, but rather, are custom drawn. Here is a quick and simple example to illustrate this:
The windows can be moved, minimised, and closed independently, and the functionalities could be expanded quite easily. It's not tested, but it should work across the three platforms.
Code: Select all
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)
ProcedureReturn window
EndProcedure
customWindow1 = OpenCustomWindow(100, 100, 300, 300, #Cyan, "My Custom Window 1", 70, #White, #Blue, 0)
customCanvas1 = GetWindowData(customWindow1)
windows + 1
customWindow2 = OpenCustomWindow(200, 200, 300, 300, #Yellow, "My Custom Window 2", 50, #Yellow, #Red, 0)
customCanvas2 = GetWindowData(customWindow2)
windows + 1
customWindow3 = OpenCustomWindow(300, 300, 300, 300, #White, "My Custom Window 3", 30, #White, #Black, 0)
customCanvas3 = GetWindowData(customWindow3)
windows + 1
Repeat
If dragOn
ResizeWindow(activeWindow, DesktopMouseX() - windowMouseXOffset,
DesktopMouseY() - windowMouseYOffset, #PB_Ignore, #PB_Ignore)
EndIf
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case customCanvas1, customCanvas2, customCanvas3
activeWindow = EventWindow()
activeCanvas = EventGadget()
activeWindowControlBoxWidth = GetGadgetData(activeCanvas)
Select EventType()
Case #PB_EventType_LeftClick
canvasDownX = GetGadgetAttribute(activeCanvas, #PB_Canvas_MouseX)
If canvasDownX > WindowWidth(activeWindow) - activeWindowControlBoxWidth
CloseWindow(activeWindow)
windows - 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
EndSelect
EndSelect
Until windows = 0
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
- PedroMartins
- User
- Posts: 47
- Joined: Sat Sep 02, 2017 7:30 pm
Re: Wishes for Window and Menu colors
*** to Administrator: please delete this post reply ***
Last edited by PedroMartins on Fri Apr 06, 2018 2:29 pm, edited 1 time in total.
- the.weavster
- Addict
- Posts: 1537
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
Re: Wishes for Window and Menu colors
If you try to drag one of those windows by its titlebar on Ubuntu you can't let go of it againTI-994A wrote:Most applications with customised windows don't usually override the global system and theme settings, but rather, are custom drawn. Here is a quick and simple example to illustrate this:
- PedroMartins
- User
- Posts: 47
- Joined: Sat Sep 02, 2017 7:30 pm
Re: Wishes for Window and Menu colors
*** to Administrator: please delete this post reply ***
Last edited by PedroMartins on Fri Apr 06, 2018 2:29 pm, edited 1 time in total.
Re: Wishes for Window and Menu colors
Hi weavster; been quite a while. Thanks for the feedback. The example utilises native cross-platform functions, so that's quite puzzling. Perhaps a sequencing issue, or a clash between the mouse down and mouse click events.the.weavster wrote:If you try to drag one of those windows by its titlebar on Ubuntu you can't let go of it again
Nonetheless, it's simply a contributory proof of concept; killing time.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
- the.weavster
- Addict
- Posts: 1537
- Joined: Thu Jul 03, 2003 6:53 pm
- Location: England
Re: Wishes for Window and Menu colors
Sure:PedroMartins wrote:to the.weavster: Can you change TI-994A code and make it work on ubuntu ?
Code: Select all
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)
ProcedureReturn window
EndProcedure
customWindow1 = OpenCustomWindow(100, 100, 300, 300, #Cyan, "My Custom Window 1", 70, #White, #Blue, 0)
customCanvas1 = GetWindowData(customWindow1)
windows + 1
customWindow2 = OpenCustomWindow(200, 200, 300, 300, #Yellow, "My Custom Window 2", 50, #Yellow, #Red, 0)
customCanvas2 = GetWindowData(customWindow2)
windows + 1
customWindow3 = OpenCustomWindow(300, 300, 300, 300, #White, "My Custom Window 3", 30, #White, #Black, 0)
customCanvas3 = GetWindowData(customWindow3)
windows + 1
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case customCanvas1, customCanvas2, customCanvas3
activeWindow = EventWindow()
activeCanvas = EventGadget()
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)
windows - 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
EndSelect
EndSelect
Until windows = 0
Hi TI-994ATI-994A wrote:The example utilises native cross-platform functions, so that's quite puzzling.
Having ResizeWindow() outside of WaitWindowEvent() seems to prevent the #PB_EventType_LeftButtonUp ever getting triggered.
Re: Wishes for Window and Menu colors
Nice! OSX has such quirks too, IIRC. Thanks for the debug.the.weavster wrote:Hi TI-994A
Having ResizeWindow() outside of WaitWindowEvent() seems to prevent the #PB_EventType_LeftButtonUp ever getting triggered.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel
Re: Wishes for Window and Menu colors
Very nice
small update with BindGadgetEvent
small update with BindGadgetEvent
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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive