PanelGadget background image

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

PanelGadget background image

Post by Dude »

Is it possible to put an image on a PanelGadget background? I want to put a grid of dots on mine, that appear everywhere on the PanelGadget except its tabs. Thanks for any ideas!

Sort of like this, but on the PanelGadget, not the window:

Code: Select all

Procedure DrawGrid()
  StartDrawing(WindowOutput(0))  
    For x=5 To WindowWidth(0)-1 Step 5
      For y=5 To WindowHeight(0)-1 Step 5
        Plot(x,y,0)
      Next
    Next  
  StopDrawing()
EndProcedure

Procedure Callback(WindowID,Message,wParam,lParam)
  result=#PB_ProcessPureBasicEvents
  If message=#WM_PAINT
    DrawGrid()
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,200,200,640,480,"",#PB_Window_SystemMenu)

SetWindowCallback(@Callback())

Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: PanelGadget background image

Post by wombats »

ProGUI supports this, but it isn't free.

There are some examples in the CodeArchiv that look promising, like this one.

Have you considered using a CanvasGadget with the container flag?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: PanelGadget background image

Post by RASHAD »

Hi

Code: Select all

w = 300
h = 200
      
CreateImage(0,w,h,24,$FFFFFF)

StartDrawing(ImageOutput(0)) 
  For x=5 To w-11 Step 5
    For y=5 To h-11 Step 5
      Plot(x,y,0)
    Next
  Next 
StopDrawing()
  
OpenWindow(0,0,0,400,220,"Color Pan", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  PanelGadget(0, 10, 10, w,h)
    AddGadgetItem(0, -1, "Pan #1")
      ImageGadget(3,0,0, w,h, ImageID(0))
      DisableGadget(3,1)
      ListIconGadget(4, 15, 15,260,140,"TEST",50 ,#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
      Header = SendMessage_(GadgetID(4), #LVM_GETHEADER, 0, 0)
      AddGadgetColumn(4,1,"Name",150)
      AddGadgetColumn(4,2,"",55)
      AddGadgetItem(4,0,"Test"+Chr(10)+"Name")
    AddGadgetItem(0, -1, "Pan #2")
      ImageGadget(5, 0,0,w,h, ImageID(0))
      DisableGadget(5,1)
      ButtonGadget(6, 10, 15, 80, 24,"Button 1") 
      ButtonGadget(7, 95, 15, 80, 24,"Button 2")
  CloseGadgetList()
Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1
        
      Case #PB_Event_Gadget
        Select EventGadget()
  
          Case 6
            MessageRequester("This is a window title","Hello World!"+Chr(10)+"What Now??",#MB_ICONWARNING)         
        EndSelect
      
  EndSelect     

Until Quit = 1
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: PanelGadget background image

Post by Dude »

Hi Rashad,

Thanks for your tip, but today I noticed a problem when using EditorGadgets with it.

The EditorGadget gets corrupted when scrolling. I tried to fix it (see below) but no luck.

Code: Select all

w = 300
h = 200
     
CreateImage(0,w,h,24,$FFFFFF)

StartDrawing(ImageOutput(0))
  For x=5 To w-11 Step 5
    For y=5 To h-11 Step 5
      Plot(x,y,0)
    Next
  Next
StopDrawing()
 
OpenWindow(0,0,0,400,220,"Color Pan", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  PanelGadget(0, 10, 10, w,h)
    AddGadgetItem(0, -1, "Pan #1")
      ImageGadget(3,0,0, w,h, ImageID(0))
      DisableGadget(3,1)
      ListIconGadget(4, 15, 15,260,140,"TEST",50 ,#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
      AddGadgetColumn(4,1,"Name",150)
      AddGadgetColumn(4,2,"",55)
      AddGadgetItem(4,0,"Test"+Chr(10)+"Name")
    AddGadgetItem(0, -1, "Pan #2")
      ImageGadget(5, 0,0,w,h, ImageID(0))
      DisableGadget(5,1)
      ButtonGadget(6, 10, 15, 80, 24,"Button 1")
      ButtonGadget(7, 95, 15, 80, 24,"Button 2")
      EditorGadget(8, 10, 100, 150, 50)
      SetGadgetText(8, "Hit Enter a few times...")
      BringWindowToTop_(GadgetID(8)) ; Doesn't help.
  CloseGadgetList()
Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1      
      Case #PB_Event_Gadget
        If EventGadget()=8 And EventType()=#PB_EventType_Change
          InvalidateRect_(GadgetID(8),0,1) ; Also doesn't help.
        EndIf
     
  EndSelect     

Until Quit = 1
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: PanelGadget background image

Post by RASHAD »

Hi Dude

Code: Select all

w = 300
h = 200
     
CreateImage(0,w,h,24,$FFFFFF)

StartDrawing(ImageOutput(0))
  For x=5 To w-11 Step 5
    For y=5 To h-11 Step 5
      Plot(x,y,0)
    Next
  Next
StopDrawing()
 
OpenWindow(0,0,0,400,220,"Color Pan", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  PanelGadget(0, 10, 10, w,h)
    AddGadgetItem(0, -1, "Pan #1")
      ImageGadget(3,0,0, w,h, ImageID(0))
      DisableGadget(3,1)
      ListIconGadget(4, 15, 15,260,140,"TEST",50 ,#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
      AddGadgetColumn(4,1,"Name",150)
      AddGadgetColumn(4,2,"",55)
      AddGadgetItem(4,0,"Test"+Chr(10)+"Name")
      SetWindowLongPtr_(GadgetID(3), #GWL_STYLE, GetWindowLongPtr_(GadgetID(3), #GWL_STYLE) | #WS_CLIPSIBLINGS)
      SetWindowPos_(GadgetID(3), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
    AddGadgetItem(0, -1, "Pan #2")
      ImageGadget(5, 0,0,w,h, ImageID(0))
      DisableGadget(5,1)
      ButtonGadget(6, 10, 15, 80, 24,"Button 1")
      ButtonGadget(7, 95, 15, 80, 24,"Button 2")
      EditorGadget(8, 10, 100, 150, 50)
      SetGadgetText(8, "Hit Enter a few times...")
      SetWindowLongPtr_(GadgetID(5), #GWL_STYLE, GetWindowLongPtr_(GadgetID(5), #GWL_STYLE) | #WS_CLIPSIBLINGS)
      SetWindowPos_(GadgetID(5), #HWND_BOTTOM, -1, -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE)
  CloseGadgetList()
Repeat
  Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Quit = 1     
      Case #PB_Event_Gadget
        If EventGadget()=8 And EventType()=#PB_EventType_Change
          InvalidateRect_(GadgetID(8),0,1) ; Also doesn't help.
        EndIf
     
  EndSelect     

Until Quit = 1
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: PanelGadget background image

Post by Dude »

Damn, you're good. Really good. Thanks again! :D
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PanelGadget background image

Post by Kwai chang caine »

Very nice :shock:
Thanks RASHAD 8)
ImageThe happiness is a road...
Not a destination
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: PanelGadget background image

Post by Dude »

Just a follow-up question: is there a way to do this with a repeated patten (brush?) instead of creating the image to a set size? My window size will vary and I don't want to create the image with each resize.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: PanelGadget background image

Post by RASHAD »

Hi

Code: Select all

LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)
If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  PanelGadget     (0, 8, 8, 306, 203)
    AddGadgetItem (0, -1, "Panel 1")
      pan1 = PanelGadget (1, 5, 5, 290, 166)
        AddGadgetItem(1, -1, "Sub-Panel 1")
        AddGadgetItem(1, -1, "Sub-Panel 2")
        AddGadgetItem(1, -1, "Sub-Panel 3")
      CloseGadgetList()
      SetWindowTheme_(pan1, @null.w, @null.w)
      SetClassLongPtr_(pan1, #GCL_HBRBACKGROUND, brush)
    AddGadgetItem (0, -1,"Panel 2")
      ButtonGadget(2, 10, 15, 80, 24,"Button 1")
      ButtonGadget(3, 95, 15, 80, 24,"Button 2")
  CloseGadgetList()
  SetWindowTheme_(GadgetID(0), @null.w, @null.w)
  SetClassLongPtr_(GadgetID(0), #GCL_HBRBACKGROUND, brush)

  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: PanelGadget background image

Post by Dude »

Damn, Rashad, that's the fastest you've responded! :shock: :lol:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: PanelGadget background image

Post by RASHAD »

Hi Dude :)
For your removed request

Code: Select all


CreateImage(0,10,10,24,$FFFFFF)
StartDrawing(ImageOutput(0))
  For x=0 To 9 Step 5
    For y=0 To 9 Step 5
      Plot(x,y,0)
    Next
  Next
StopDrawing()
brush = CreatePatternBrush_(ImageID(0))
FreeImage(0)

If OpenWindow(0, 0, 0, 322, 220, "PanelGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  PanelGadget     (0, 8, 8, 306, 203)
    AddGadgetItem (0, -1, "Panel 1")
      pan1 = PanelGadget (1,0, 0, 306, 203)
      cont = ContainerGadget(#PB_Any, 0, 20, 306, 203)
      CloseGadgetList()
      DisableGadget(cont,1)
      SetClassLongPtr_(GadgetID(cont), #GCL_HBRBACKGROUND, brush)
      InvalidateRect_(GadgetID(cont),0,1)
        AddGadgetItem(1, -1, "Sub-Panel 1")
        AddGadgetItem(1, -1, "Sub-Panel 2")
        AddGadgetItem(1, -1, "Sub-Panel 3")
      CloseGadgetList()
    AddGadgetItem (0, -1,"Panel 2")
      cont2 = ContainerGadget(#PB_Any, 0, 0, 306, 203)
      CloseGadgetList()
      DisableGadget(cont2,1)
      SetClassLongPtr_(GadgetID(cont2), #GCL_HBRBACKGROUND, brush)
      InvalidateRect_(GadgetID(cont2),0,1)
      ButtonGadget(2, 10, 15, 80, 24,"Button 1")
      ButtonGadget(3, 95, 15, 80, 24,"Button 2")
  CloseGadgetList()
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Egypt my love
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: PanelGadget background image

Post by Dude »

I didn't think you saw it. :oops: I thought I had it worked out, so I quickly deleted my request.

However, I will work with your new example, because mine was flickering badly (and I abandoned my code). Your example doesn't flicker and thus gives me a solid base to work on. Thanks! :wink:
Post Reply