Page 2 of 2

Customized Windows ?

Posted: Tue Apr 03, 2018 11:59 am
by PedroMartins
*** to Administrator: please delete this post reply ***

Re: Wishes for Window and Menu colors

Posted: Tue Apr 03, 2018 12:01 pm
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.

Re: Wishes for Window and Menu colors

Posted: Tue Apr 03, 2018 6:24 pm
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.

Re: Wishes for Window and Menu colors

Posted: Tue Apr 03, 2018 6:32 pm
by PedroMartins
*** to Administrator: please delete this post reply ***

Re: Wishes for Window and Menu colors

Posted: Tue Apr 03, 2018 6:53 pm
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 :)

Re: Wishes for Window and Menu colors

Posted: Tue Apr 03, 2018 7:35 pm
by PedroMartins
*** to Administrator: please delete this post reply ***

Re: Wishes for Window and Menu colors

Posted: Wed Apr 04, 2018 9:32 am
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

Re: Wishes for Window and Menu colors

Posted: Wed Apr 04, 2018 11:11 am
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.

Re: Wishes for Window and Menu colors

Posted: Wed Apr 04, 2018 12:24 pm
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.

Re: Wishes for Window and Menu colors

Posted: Wed Apr 04, 2018 1:54 pm
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