A simple resizable image as window bg

Windows specific forum
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: A simple resizable image as window bg

Post by wombats »

That is odd. I tested it on Windows and macOS. Does it work if you clear the CanvasGadget on each redraw?

Code: Select all

Procedure SetWindowBackgroundImage(CanvasID.I, ImageID.I)
  If StartDrawing(CanvasOutput(CanvasID))
    Box(0, 0, OutputWidth(), OutputHeight(), RGB(255, 255, 255))
    DrawImage(ImageID(ImageID), 0, 0, GadgetWidth(CanvasID),
      GadgetHeight(CanvasID))
    StopDrawing()
  EndIf
EndProcedure
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: A simple resizable image as window bg

Post by Mijikai »

Still get the same result.

Edit:

If i change your code like that it works

Code: Select all

UsePNGImageDecoder()

Procedure SetWindowBackgroundImage(CanvasID.I, ImageID.I)
  If StartDrawing(CanvasOutput(CanvasID))
    DrawImage(ImageID(ImageID), 0, 0, GadgetWidth(CanvasID),
      GadgetHeight(CanvasID))
    StopDrawing()
  EndIf
EndProcedure


Procedure OnWindowResize()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0))
  SetWindowBackgroundImage(0, 0)
EndProcedure

; Procedure OnCanvasResize()
;   SetWindowBackgroundImage(0, 0)
; EndProcedure

If LoadImage(0, #PB_Compiler_Home + "examples/3d/Data/Textures/spheremap.png")
  OpenWindow(0, 100, 100, ImageWidth(0), ImageHeight(0),
    "Window with background image", #PB_Window_SizeGadget)
  CanvasGadget(0, 0, 0, ImageWidth(0), ImageHeight(0), #PB_Canvas_Container)
  BindEvent(#PB_Event_SizeWindow, @OnWindowResize(), 0)
  ;BindGadgetEvent(0, @OnCanvasResize(), #PB_EventType_Resize)
  SetWindowBackgroundImage(0, 0)
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: A simple resizable image as window bg

Post by wombats »

Interesting. I wonder why my code works for me on Windows and macOS and not for you.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: A simple resizable image as window bg

Post by Mijikai »

Im currently on Windows 7 x64 using PureBasic is 5.62
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: A simple resizable image as window bg

Post by wombats »

That would be why. I just tested it in 5.61 and it didn't work properly. I believe some bugs with the CanvasGadget were fixed in recent versions.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: A simple resizable image as window bg

Post by Mijikai »

wombats wrote:That would be why. I just tested it in 5.61 and it didn't work properly. I believe some bugs with the CanvasGadget were fixed in recent versions.
Does the code i posted run for you ?
Newer PB versions are unusable for me (unresolved #Null$ memory bug and i use strings always somewhere).
wombats
Enthusiast
Enthusiast
Posts: 663
Joined: Thu Dec 29, 2011 5:03 pm

Re: A simple resizable image as window bg

Post by wombats »

Mijikai wrote:
wombats wrote:That would be why. I just tested it in 5.61 and it didn't work properly. I believe some bugs with the CanvasGadget were fixed in recent versions.
Does the code i posted run for you ?
Newer PB versions are unusable for me (unresolved #Null$ memory bug and i use strings always somewhere).
Yes, it does. I don't know anything about #Null$.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: A simple resizable image as window bg

Post by Mijikai »

wombats wrote:I don't know anything about #Null$.
The Bug: viewtopic.php?p=531591#p531591
Post Reply