Page 1 of 1

2D Drawing ... mysterious things happen

Posted: Sat Apr 14, 2007 8:06 pm
by walker
I'd copied the 3 examples (elipses, lines and fillarea) in one source... and only the first one is working... though all three are if you run them standalone... :roll: :roll:

Only the first window is shown with contents... 2nd and 3rd are empty
Comment out the first example and the fillarea is working....

Code: Select all


  ; Several ellipses with random colors
  Width  = 220
  Height = 150
  If OpenWindow(0, 0, 0, Width, Height, "Ellipses", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If StartDrawing(WindowOutput(0))
      x = Width/2
      y = Height/2
      For radius=Height/2 To 10 Step -10
        Ellipse(x, y, radius*Width/Height, radius, RGB(Random(255),Random(255),Random(255)))
      Next radius
      StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
    EndIf
    
    Repeat : Event = WaitWindowEvent(1) : Until  Event = #PB_Event_CloseWindow
    CloseWindow(0)
  EndIf
  
 ;fillarea 
    Width = 270
  Height = 270
  If OpenWindow(0, 0, 0, Width, Height, "FillArea", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If StartDrawing(WindowOutput(0))
      x = Width/2
      y = Height/2
      Circle(x, y, 125 ,$00FF00)
      Circle(x, y, 120 ,$FF0000)
      LineXY(x-120, y, x+120, y, $FFFFFF)
      FillArea(x, y+5, -1, $0000FF) ; Replace -1 by $00FF00, and compare the result
      StopDrawing() ; It is absolutely essential when the drawing operations are finished!!! Never forget it! 
    EndIf
   
    Repeat : Event = WaitWindowEvent(1) : Until  Event = #PB_Event_CloseWindow
    CloseWindow(0)
  EndIf
  
;   Several lines in random colors
  Width  = 220
  Height = 150
  If OpenWindow(0, 0, 0, Width, Height, "Lines", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    If StartDrawing(WindowOutput(0))
      yStart = 0
      yEnd   = Height-yStart
      xStart = 10
      For xEnd=xStart To Width-xStart Step 1
        Line(xStart, yStart, xEnd, yEnd ,RGB(Random(255),Random(255),Random(255))) 
      Next
      StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !
    EndIf
    
    Repeat : Event = WaitWindowEvent(1) : Until  Event = #PB_Event_CloseWindow
  EndIf

Posted: Sat Apr 14, 2007 9:31 pm
by freak
It is actually a problem of the gtk2 double-buffering.

Basically you cannot simply draw once on the window and expect it to stay.
If i add a redrawing for the #PB_Event_Repaint event, all is displayed here.

We will have to change the drawing examples to draw on an image instead (which is better anyway)