Drawing to WindowOutput

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Drawing to WindowOutput

Post by WilliamL »

Should this code work? I get a gray window.

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If StartDrawing(WindowOutput(0))
      y = 0
      For x = 0 To 95 Step 10
        Box(x, y, 200-2*x, 200-2*y, RGB(Random(255), Random(255), Random(255)))
        y + 10        ; the same as y = y + 10
      Next x
      StopDrawing() 
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Drawing to WindowOutput

Post by fsw »

Confirmed.

In the documentation all the examples for WindowOutput() do not work.
Drawing on an Image or on a Screen work...

:arrow: Sierra, Xcode 8, PB 5.5

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Drawing to WindowOutput

Post by Keya »

confirmed also on El Capitan, so its seemingly not just a Sierra thing
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: Drawing to WindowOutput

Post by Wolfram »

Workaround:

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  Repeat
  Until WaitWindowEvent() = 4
  
    
    If StartDrawing(WindowOutput(0))
      y = 0
      For x = 0 To 95 Step 10
        Box(x, y, 200-2*x, 200-2*y, RGB(Random(255), Random(255), Random(255)))
        y + 10        ; the same as y = y + 10
      Next x
      StopDrawing() 
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
macOS Catalina 10.15.7
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Drawing to WindowOutput

Post by fsw »

Wolfram wrote:Workaround:
Confirmed 8)

So is event "4" the Cocoa "drawing event" or the "view did load" event?
Last edited by fsw on Wed Nov 16, 2016 6:47 pm, edited 1 time in total.

I am to provide the public with beneficial shocks.
Alfred Hitshock
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Drawing to WindowOutput

Post by WilliamL »

Good one Wolfram. That works but I have no idea why. :?

Maybe this should be moved to the 'Bugs - Mac OSX' forum...
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Drawing to WindowOutput

Post by fsw »

Really hope the next PureBasic version comes with updated macOS functionality 8)
Fred, let me know when you need macOS alpha testers :mrgreen:

I am to provide the public with beneficial shocks.
Alfred Hitshock
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Drawing to WindowOutput

Post by freak »

You can't just draw to a window once and expect it to stay there. You have to watch for the #PB_Event_Repaint and redraw every time. This is the same on all OS.
quidquid Latine dictum sit altum videtur
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Drawing to WindowOutput

Post by WilliamL »

Well, there's the answer. I don't know why I didn't think of that?! (not serious) I guess if the drawing had appeared even once I might have gotten the re-draw idea.

So, in Wolfram's example, WaitWindowEvent() = 4 must the the #PB_Event_Repaint.

...not a bug and thanks to freak for an answer.

[later]
ok, I found the info in the Help file under 'WindowOutput' and it is pretty clear how it works (never saw it before-thanks fsw)
Last edited by WilliamL on Wed Nov 16, 2016 10:18 pm, edited 2 times in total.
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Drawing to WindowOutput

Post by fsw »

freak wrote:You can't just draw to a window once and expect it to stay there. You have to watch for the #PB_Event_Repaint and redraw every time. This is the same on all OS.
OK.

The documentation of WindowOutput() needs to be fixed.
In the example the "#" of "#PB_Event_Repaint" is missing...

I am to provide the public with beneficial shocks.
Alfred Hitshock
Post Reply