Page 1 of 1

Drawing on a Plain Window

Posted: Sat Jan 04, 2025 3:58 am
by Mike Yocum
Hi, thanks for having me. My background is Visual Basic prior to .NET. I have purchased PureBasic, and am currently teaching myself on a Mac Mini M4. This is a very small program, which is supposed to draw on a window itself (i.e., no ImageGadget). It is a variant on a program from page 1671 of the book, "PureBasic Reference Manual 6.00." On pressing the button, the program is supposed to draw a red box on the window. It doesn’t work, and I don’t know why. All help is appreciated!

Thanks,
Mike

Code: Select all

If OpenWindow(0, 0, 0, 640, 480, "WindowOutput Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(1, (640 - 200) / 2, (480 - 30) - 10, 200, 30, "Draw on Window")
  
  Repeat
    E = WaitWindowEvent()
    
    Select E
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            If StartDrawing(WindowOutput(0))
              Box(100, 100, 100, 100, RGB(255, 0, 0))
              StopDrawing()
            EndIf
        EndSelect
    EndSelect
  Until E = #PB_Event3D_CloseWindow
EndIf

Re: Drawing on a Plain Window

Posted: Sat Jan 04, 2025 4:46 am
by idle
Apart from the wrong close window event it works on windows, so maybe an issue with mac

Code: Select all

If OpenWindow(0, 0, 0, 640, 480, "WindowOutput Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, (640 - 200) / 2, (480 - 30) - 10, 200, 30, "Draw on Window")
  
  Repeat
    E = WaitWindowEvent()
    
    Select E
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            If StartDrawing(WindowOutput(0))
              Box(100, 100, 100, 100, RGB(255, 0, 0))
              StopDrawing()
            EndIf
        EndSelect
    EndSelect
  Until E = #PB_Event_CloseWindow
EndIf

Re: Drawing on a Plain Win

Posted: Sat Jan 04, 2025 5:09 am
by Mike Yocum
idle,

Thanks for pointing that out! I’m still getting used to auto complete. ;’)

Maybe it IS a Mac issue. When I use an ImageGadget, it works fine.

By the way, how did you format that code so nicely?

Thanks,
Mike

PS Any PureBasic Mac users out there?

Re: Drawing on a Plain Win

Posted: Sat Jan 04, 2025 6:43 am
by Quin
Mike Yocum wrote: Sat Jan 04, 2025 5:09 am By the way, how did you format that code so nicely?
PS Any PureBasic Mac users out there?
He probably used the [ code-pb ] and [ /code-pb ] tags to wrap the code.
There are plenty of Mac users around here, don't worry, there are entire forums deticated to it :) I'm sure one of the insanely intelligent people around here will be able to figure something out.

Re: Drawing on a Plain Window

Posted: Sat Jan 04, 2025 3:09 pm
by mk-soft
Something was changed in the macOS that you could no longer draw on it since DarkMode was introduced.
Maybe Fred can fix that.

You can draw with the CanvasGadget as a container. But the problem here is that in DarkMode the background is used for gadgets.

Here is a solution with CanvasGadget ...

Link: Workaround DarkMode CanvasGadget

Re: Drawing on a Plain Window

Posted: Sat Jan 04, 2025 4:39 pm
by Mike Yocum
Quin,

Thank you for that tip, I will use that next time!

mk-soft,

Thank you for the explanation and workaround!

Mike