Customized Windows ?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Customized Windows ?

Post by PedroMartins »

*** to Administrator: please delete this post reply ***
Last edited by PedroMartins on Fri Apr 06, 2018 2:30 pm, edited 4 times in total.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Wishes for Window and Menu colors

Post by Dude »

PedroMartins wrote:To Dude: It's just a wish. Don't kill the wish.
I know it's a wish, but Fred has said in the past that only cross-platform wishes get considered:
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.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Wishes for Window and Menu colors

Post by TI-994A »

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:

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
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.
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 :D
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Wishes for Window and Menu colors

Post by PedroMartins »

*** to Administrator: please delete this post reply ***
Last edited by PedroMartins on Fri Apr 06, 2018 2:29 pm, edited 1 time in total.
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Wishes for Window and Menu colors

Post by the.weavster »

TI-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:
If you try to drag one of those windows by its titlebar on Ubuntu you can't let go of it again :)
User avatar
PedroMartins
User
User
Posts: 47
Joined: Sat Sep 02, 2017 7:30 pm

Re: Wishes for Window and Menu colors

Post by PedroMartins »

*** to Administrator: please delete this post reply ***
Last edited by PedroMartins on Fri Apr 06, 2018 2:29 pm, edited 1 time in total.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Wishes for Window and Menu colors

Post by TI-994A »

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 :)
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.

Nonetheless, it's simply a contributory proof of concept; killing time. :D
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 :D
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Wishes for Window and Menu colors

Post by the.weavster »

PedroMartins wrote:to the.weavster: Can you change TI-994A code and make it work on ubuntu ?
Sure:

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
TI-994A wrote:The example utilises native cross-platform functions, so that's quite puzzling.
Hi TI-994A :)
Having ResizeWindow() outside of WaitWindowEvent() seems to prevent the #PB_EventType_LeftButtonUp ever getting triggered.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Wishes for Window and Menu colors

Post by TI-994A »

the.weavster wrote:Hi TI-994A :)
Having ResizeWindow() outside of WaitWindowEvent() seems to prevent the #PB_EventType_LeftButtonUp ever getting triggered.
Nice! OSX has such quirks too, IIRC. Thanks for the debug.
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 :D
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Wishes for Window and Menu colors

Post by mk-soft »

Very nice :D

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
Post Reply