Page 1 of 1

Drawing to WindowOutput

Posted: Tue Nov 15, 2016 7:50 pm
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

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 1:54 am
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

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 3:10 am
by Keya
confirmed also on El Capitan, so its seemingly not just a Sierra thing

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 1:03 pm
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

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 6:45 pm
by fsw
Wolfram wrote:Workaround:
Confirmed 8)

So is event "4" the Cocoa "drawing event" or the "view did load" event?

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 6:47 pm
by WilliamL
Good one Wolfram. That works but I have no idea why. :?

Maybe this should be moved to the 'Bugs - Mac OSX' forum...

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 6:48 pm
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:

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 9:10 pm
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.

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 10:05 pm
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)

Re: Drawing to WindowOutput

Posted: Wed Nov 16, 2016 10:11 pm
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...