ButtonImageGadget and CanvasGadget Container

Just starting out? Need help? Post your questions and find answers here.
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

ButtonImageGadget and CanvasGadget Container

Post by wombats »

Hi,

I use ButtonImageGadgets inside a CanvasGadget container that itself sits within a ContainerGadget.

When the window is resized or the splitter moved, the ButtonImageGadget sometimes loses its image. Moving the mouse over the gadget restores the image. RedrawWindow_() makes it a little better, but it still happens.

Does anyone have any ideas? This only happens on Windows.

Code: Select all

Enumeration
  #Container
  #Canvas
  #String
  #Button
  #Splitter
EndEnumeration

Procedure DrawCanvas()
  If StartDrawing(CanvasOutput(#Canvas))
    Box(0, 0, OutputWidth(), OutputHeight(), RGB(220, 220, 220))
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(10, 60, "Hello World")
    StopDrawing()
  EndIf
EndProcedure

Procedure OnWindowSized()
  ResizeGadget(#Splitter, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0))
EndProcedure

Procedure OnContainerResized()
  ResizeGadget(#Canvas, #PB_Ignore, #PB_Ignore, GadgetWidth(#Container), GadgetHeight(#Container))
  RedrawWindow_(GadgetID(#Button), 0, 0, #RDW_INVALIDATE)
  DrawCanvas()
EndProcedure

CreateImage(0, 16, 16, 24, #Blue)

If OpenWindow(0, 0, 0, 640, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  
  BindEvent(#PB_Event_SizeWindow, @OnWindowSized(), 0)
  
  StringGadget(#String, 0, 0, 10, 10, "...")
  
  ContainerGadget(#Container, 0, 0, 100, 100)
  CanvasGadget(#Canvas, 0, 0, GadgetWidth(#Container), GadgetHeight(#Container), #PB_Canvas_Container)
  ButtonImageGadget(#Button, 10, 10, 25, 25, ImageID(0))
  CloseGadgetList()
  CloseGadgetList()
  
  SplitterGadget(#Splitter, 0, 0, 640, 480, #String, #Container, #PB_Splitter_Vertical)
  
  BindGadgetEvent(#Container, @OnContainerResized(), #PB_EventType_Resize)
  
  PostEvent(#PB_Event_Gadget, 0, #Container, #PB_EventType_Resize)
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: ButtonImageGadget and CanvasGadget Container

Post by RASHAD »

Hi

Code: Select all

  AddWindowTimer(0,125,100)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_Timer
        SetGadgetState(#Button, ImageID(0))
;  
    EndSelect
  Until Quit = 1
Egypt my love
wombats
Enthusiast
Enthusiast
Posts: 664
Joined: Thu Dec 29, 2011 5:03 pm

Re: ButtonImageGadget and CanvasGadget Container

Post by wombats »

Thanks for the idea. I think this is a bug, however, as it happens with other gadgets too. I have reported it.
Post Reply