Drawing on a Plain Window

Just starting out? Need help? Post your questions and find answers here.
Mike Yocum
New User
New User
Posts: 3
Joined: Sat Jan 04, 2025 3:42 am

Drawing on a Plain Window

Post 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
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Drawing on a Plain Window

Post 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
Mike Yocum
New User
New User
Posts: 3
Joined: Sat Jan 04, 2025 3:42 am

Re: Drawing on a Plain Win

Post 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?
Quin
Addict
Addict
Posts: 1135
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Drawing on a Plain Win

Post 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.
User avatar
mk-soft
Always Here
Always Here
Posts: 6320
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Drawing on a Plain Window

Post 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
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
Mike Yocum
New User
New User
Posts: 3
Joined: Sat Jan 04, 2025 3:42 am

Re: Drawing on a Plain Window

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