Page 1 of 1

Draw on Window. Strange behavior, or..?

Posted: Fri Aug 24, 2012 10:30 am
by FlixFlax
I probably miss something simple :

Code: Select all

If OpenWindow(0, 0, 0, 200, 200, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  
  ;Please try to comment the following 2 lines in and out :
  
  
  SetWindowColor(0, $368390) ;                                      This command makes "Hello" disappear!? Why?
  ;ButtonGadget  (1, 10, 10, 100, 20, "I will make i work!");       The gadget makes it appear again! But why? 
  
  StartDrawing(WindowOutput(0))
    DrawText(20,50,"Hello!")
  StopDrawing()
  
  Repeat
 
    Event = WaitWindowEvent()
    
    Select Event
        
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            ;Do nothing
        EndSelect
        
    EndSelect
  Until Event = #PB_Event_CloseWindow
EndIf

Re: Draw on Window. Strange behavior, or..?

Posted: Fri Aug 24, 2012 11:54 am
by IdeasVacuum
Window backgrounds are not persistent, they get "repainted" either by the system or another app that is running.

If you are going to fill the whole window with graphics, the CanvasGadget is good. Or something like this:

Code: Select all

Enumeration
#Win
#Img
#ImgGdt
EndEnumeration

If OpenWindow(#Win, 0, 0, 200, 200, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

       SetWindowColor(#Win, $368390)

          ImageGadget(#ImgGdt,0,0,200,200,0)

       If CreateImage(#Img,200,200,24)

             If StartDrawing(ImageOutput(#Img))

                      DrawingMode(#PB_2DDrawing_Default)
                              Box(0,0,200,200,$368390)
                        BackColor($368390)
                         DrawText(20,50,"Hello!")
                      StopDrawing()
                   SetGadgetState(#ImgGdt,ImageID(#Img))
                    DisableGadget(#ImgGdt,#True)
             EndIf
       EndIf

       Repeat

              Event = WaitWindowEvent()
        Until Event = #PB_Event_CloseWindow

EndIf

End

Re: Draw on Window. Strange behavior, or..?

Posted: Sat Aug 25, 2012 7:45 am
by FlixFlax
Thank you IdeasV.
I guess I have to stop beeing lazy, and do it the right way :)
(I actually knew about the image gadget, but thought other things were at play in my example code)