Drawing on black background

Just starting out? Need help? Post your questions and find answers here.
urland
User
User
Posts: 13
Joined: Tue May 13, 2003 6:53 pm

Drawing on black background

Post by urland »

Drawing on an opened window with the default background color works but changing the window background color to black prevents things like Box() from showing. Is this a Windows thing? I'm using XP Pro SP3, PB 4.51

Code: Select all

If OpenWindow(0,0,0,400,300,"Test")
   SetWindowColor(0,RGB(0,0,0))
   StartDrawing(WindowOutput(0))
   DrawingMode(#PB_2DDrawing_Outlined)
   Box(20,20,350,250,RGB(255,255,255))
   StopDrawing()
   While WaitWindowEvent() <> #PB_Event_CloseWindow
   Wend
EndIf
Thank you.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Drawing on black background

Post by netmaestro »

Your difficulty is in event handling. SetWindowColor() causes an invalidation of the window DC, preventing the shortcut of drawing to the window before handling events. Here is the proper way to draw to WindowOutput() with persistence:

Code: Select all

If OpenWindow(0,0,0,400,300,"Test")
  SetWindowColor(0,RGB(0,0,0))
  Repeat
    ev = WaitWindowEvent() 
    If ev= #PB_Event_Repaint
      StartDrawing(WindowOutput(0))
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(20,20,350,250,RGB(255,255,255))
      StopDrawing()
    EndIf
  Until ev = #PB_Event_CloseWindow
EndIf
BERESHEIT
urland
User
User
Posts: 13
Joined: Tue May 13, 2003 6:53 pm

Re: Drawing on black background

Post by urland »

Thank you for your help. Much appreciated.
Post Reply