Page 1 of 1

Painting on different platforms

Posted: Sun Oct 25, 2009 11:24 am
by Little John
Hi all,

recently there was a small discussion on the German forum, which IMHO is of some general interest.

Let's for instance look at the example code of Circle() in the help (I always refer to PB 4.40 Beta 5 here):

Code: Select all

  Width=200
  Height=150 
  If OpenWindow(0, 0, 0, Width, Height, "Circles", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If StartDrawing(WindowOutput(0))
      x = Width/2
      y = Height/2
      For Radius = Height/2 To 10 Step -10
        Circle(x, y, radius ,RGB(Random(255),Random(255),Random(255)))
      Next
      StopDrawing()
    EndIf
    
    Repeat : Event = WaitWindowEvent() : Until  Event = #PB_Event_CloseWindow
  EndIf
On Windows (tested with XP x86), the code runs as expected, and paints some colored circles.

However, on Ubuntu 9.04 I only get an empty gray window, although this example code also is in the help of the PB Linux version.

On the German forum, user #Null suggested to change the code, so that the painting is done in the event loop on a #PB_Event_Repaint event. Indeed, the following code works as expected for me on Ubuntu 9.04:

Code: Select all

Define Width, Height, Event, x, y, Radius

Width = 200
Height = 150 
If OpenWindow(0, 0, 0, Width, Height, "Circles", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) = 0
   Debug "OpenWindow() failed."
EndIf    

Repeat
   Event = WaitWindowEvent()
   Select event
   Case #PB_Event_Repaint
      If StartDrawing(WindowOutput(0))
         x = Width/2
         y = Height/2
         For Radius = Height/2 To 10 Step -10
            Circle(x, y, radius, RGB(Random(255), Random(255), Random(255)))
         Next
         StopDrawing()
      EndIf
   EndSelect
Until Event = #PB_Event_CloseWindow
Is it officially recommended by the PB team to write the code this way on Linux? If so, the example code in the docs should be modified accordingly.

Regards, Little John

Re: Painting on different platforms

Posted: Sun Oct 25, 2009 11:27 am
by srod
In my opinion, the second version is the safer one to use on all platforms.

Re: Painting on different platforms

Posted: Sun Oct 25, 2009 10:39 pm
by Little John
Hi srod,

thanks for your reply. IMHO this is good news, since writing code the same way on all platforms makes cross-platform development easier.
Then probably several painting example codes should be changed in the docs for all platforms. :-)

Regards, Little John