A simple resizable image as window bg
A simple resizable image as window bg
Is there a simple easy to use an image as the window or dialogs background. I'm sure using win api it's possible. But feel like I'm missing something, surely there's an easy way in pb.
Thanks just started out with pb.
Aaron
Thanks just started out with pb.
Aaron
-
- Enthusiast
- Posts: 237
- Joined: Tue Feb 14, 2017 12:07 pm
Re: A simple resizable image as window bg
ImageGadget !
I am French, I do not speak English.
My apologies for the mistakes.
I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
My apologies for the mistakes.
I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
Re: A simple resizable image as window bg
I tired that but it does not draw on the window, only frames with in it. am I missing a flag.ShadowStorm wrote:ImageGadget !
Thanks,
Aaron
Re: A simple resizable image as window bg
He means like this :
Code: Select all
LoadImage(1, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp")
OpenWindow(0, 0, 0, 255, 255, "Test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ImageGadget(1, 0, 0, 255, 255, ImageID(1))
DisableGadget(1, #True)
ButtonGadget(2, 20, 20, 100, 25, "Button")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Re: A simple resizable image as window bg
Thanks, I''l try it out.. I've been having the weird "cannot load compiler error on this computer. Everty thing was working great, I'm sure it was windows updates about 3 weeks ago my main computer can't compile PB code. I've reinstalled several time. I did noticed a thread on this but the link I found was old.Bisonte wrote:He means like this :Code: Select all
LoadImage(1, #PB_Compiler_Home + "Examples\Sources\Data\Background.bmp") OpenWindow(0, 0, 0, 255, 255, "Test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) ImageGadget(1, 0, 0, 255, 255, ImageID(1)) DisableGadget(1, #True) ButtonGadget(2, 20, 20, 100, 25, "Button") Repeat Event = WaitWindowEvent() Select Event Case #PB_Event_CloseWindow Break EndSelect ForEver
https://drive.google.com/file/d/11wiLNm ... AblWLQIHC/
I don't think I can embed the problems. but a screeny is on my drive above.
Re: A simple resizable image as window bg
Thanks Shardik
Update
Update
Code: Select all
;-TOP
; Comment: SetWindowBackgroundImage
; Authors: ts-soft (Windows), Shardik (Linux , masOS)
; Create : ??.??.2014
; Update : 30.05.2019
; Link : https://www.purebasic.fr/german/viewtopic.php?f=16&t=28467&start=10#p352932
; OS : All
EnableExplicit
InitNetwork()
UsePNGImageDecoder()
Procedure SetWindowBackgroundImage(hWnd.i, hImage.i)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected Container.I
Protected *Name
Protected Widget.I = gtk_bin_get_child_(hWnd)
Container = g_list_nth_data_(gtk_container_get_children_(0 +
gtk_bin_get_child_(WindowID(0))), 0)
If Container
If PeekS(gtk_widget_get_name_(Container), -1, #PB_UTF8) = "GtkFixed"
gtk_fixed_put_(Container, gtk_image_new_from_pixbuf_(hImage), 0, 0)
Else
gtk_layout_put_(Container, gtk_image_new_from_pixbuf_(hImage), 0, 0)
EndIf
gtk_widget_show_all_(hWnd)
EndIf
CompilerCase #PB_OS_Windows
Protected hBrush = CreatePatternBrush_(hImage)
If hBrush
SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush)
InvalidateRect_(hWnd, 0, #True)
UpdateWindow_(hWnd)
EndIf
CompilerCase #PB_OS_MacOS
CocoaMessage(0, hWnd, "setBackgroundColor:",
CocoaMessage(0, 0, "NSColor colorWithPatternImage:", hImage))
CompilerEndSelect
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")
SetWindowBackgroundImage(WindowID(0), ImageID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Last edited by mk-soft on Thu May 30, 2019 9:26 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: A simple resizable image as window bg
This mostly is the result of an av system. Put Purebasic and his compiler to the whitelist.scanfff wrote:I've been having the weird "cannot load compiler error on this computer. Everty thing was working great, I'm sure it was windows updates about 3 weeks ago my main computer can't compile PB code. I've reinstalled several time. I did noticed a thread on this but the link I found was old.
https://drive.google.com/file/d/11wiLNm ... AblWLQIHC/
I don't think I can embed the problems. but a screeny is on my drive above.
Re: A simple resizable image as window bg
The Windows part is from ts-soft, the Linux and Mac parts are from me. Your posted example is from the German forum. In PB 5.31 and 5.40 that example worked in Linux with GTK2 and GTK3. But because of internal changes in PureBasic the GTK3 subsystem now utilizes GtkLayout instead of GtkFixed and I therefore have modified my example to support both GTK2 and GTK3 again...mk-soft wrote:Windows, macOS, Linux GTK2
Author Unknown
Re: A simple resizable image as window bg
I've always had AVG, it only freaks about the compiled binary. Never before about the environment. I whitelisted it, no change so I turned off AVG still the same. The only difference I can think of is I did upgrade ( well just changed the product key ) win10 from pro to win10 enterprise. but meh I also did that on my laptop and pb works fine.Bisonte wrote:This mostly is the result of an av system. Put Purebasic and his compiler to the whitelist.scanfff wrote:I've been having the weird "cannot load compiler error on this computer. Everty thing was working great, I'm sure it was windows updates about 3 weeks ago my main computer can't compile PB code. I've reinstalled several time. I did noticed a thread on this but the link I found was old.
https://drive.google.com/file/d/11wiLNm ... AblWLQIHC/
I don't think I can embed the problems. but a screeny is on my drive above.
Re: A simple resizable image as window bg
mk-soft wrote:Thanks Shardik
UpdateCode: Select all
;-TOP ; Comment: SetWindowBackgroundImage ; Authors: ts-soft (Windows), Shardik (Linux , masOS) ; Create : ??.??.2014 ; Update : 30.05.2019 ; Link : https://www.purebasic.fr/german/viewtopic.php?f=16&t=28467&start=10#p352932 ; OS : All EnableExplicit InitNetwork() UsePNGImageDecoder() Procedure SetWindowBackgroundImage(hWnd.i, hImage.i) CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux Protected Container.I Protected *Name Protected Widget.I = gtk_bin_get_child_(hWnd) Container = g_list_nth_data_(gtk_container_get_children_(0 + gtk_bin_get_child_(WindowID(0))), 0) If Container If PeekS(gtk_widget_get_name_(Container), -1, #PB_UTF8) = "GtkFixed" gtk_fixed_put_(Container, gtk_image_new_from_pixbuf_(hImage), 0, 0) Else gtk_layout_put_(Container, gtk_image_new_from_pixbuf_(hImage), 0, 0) EndIf gtk_widget_show_all_(hWnd) EndIf CompilerCase #PB_OS_Windows Protected hBrush = CreatePatternBrush_(hImage) If hBrush SetClassLongPtr_(hWnd, #GCL_HBRBACKGROUND, hBrush) InvalidateRect_(hWnd, 0, #True) UpdateWindow_(hWnd) EndIf CompilerCase #PB_OS_MacOS CocoaMessage(0, hWnd, "setBackgroundColor:", CocoaMessage(0, 0, "NSColor colorWithPatternImage:", hImage)) CompilerEndSelect 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") SetWindowBackgroundImage(WindowID(0), ImageID(0)) Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow EndIf
Thanks I got it working, I installed the 5.71 Beta and compiler loading error is no more. Funny the release 5.70 seems glitcher to me
Thanks for all the help
Re: A simple resizable image as window bg
You can also use a canvas container as the window background and use DrawImage(), without api.
Re: A simple resizable image as window bg
nice to know, can you point me to an example. ThanksJustin wrote:You can also use a canvas container as the window background and use DrawImage(), without api.
Re: A simple resizable image as window bg
Justin is right. The flag #PB_Canvas_Container is relatively new and was implemented in PureBASIC 5.60 in March 2017.scanfff wrote:nice to know, can you point me to an example. ThanksJustin wrote:You can also use a canvas container as the window background and use DrawImage(), without api.
Code: Select all
UsePNGImageDecoder()
Procedure SetWindowBackgroundImage(CanvasID.I, ImageID.I)
If StartDrawing(CanvasOutput(CanvasID))
DrawImage(ImageID(ImageID), 0, 0, ImageWidth(ImageID),
ImageHeight(ImageID))
StopDrawing()
EndIf
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")
CanvasGadget(0, 0, 0, ImageWidth(0), ImageHeight(0), #PB_Canvas_Container)
SetWindowBackgroundImage(0, 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: A simple resizable image as window bg
To expand on Shardik's example, if you want a resizable window, bind the CanvasGadget's #PB_EventType_Resize event to a procedure and do the drawing there instead of when you resize the CanvasGadget. I have experienced issues (mostly with the Dialog library, admittedly), that were resolved by doing this.
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))
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
Re: A simple resizable image as window bg
This does not work for me:wombats wrote:To expand on Shardik's example, if you want a resizable window, bind the CanvasGadget's #PB_EventType_Resize event to a procedure and do the drawing there instead of when you resize the CanvasGadget. I have experienced issues (mostly with the Dialog library, admittedly), that were resolved by doing this.Code: Select all
...