Draw on Window. Strange behavior, or..?

Just starting out? Need help? Post your questions and find answers here.
FlixFlax
User
User
Posts: 18
Joined: Sat Apr 26, 2003 10:35 pm
Location: Denmark

Draw on Window. Strange behavior, or..?

Post 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
Win10 , PB5.72
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
FlixFlax
User
User
Posts: 18
Joined: Sat Apr 26, 2003 10:35 pm
Location: Denmark

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

Post 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)
Win10 , PB5.72
Post Reply