It is currently Thu Dec 12, 2019 12:12 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 10:12 am 
Offline
User
User
User avatar

Joined: Thu May 30, 2019 10:02 am
Posts: 10
Location: Seattle
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


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 10:49 am 
Offline
User
User

Joined: Tue Feb 14, 2017 12:07 pm
Posts: 42
ImageGadget !

_________________
I am French, I do not speak English.
My apologies for the mistakes.


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 10:56 am 
Offline
User
User
User avatar

Joined: Thu May 30, 2019 10:02 am
Posts: 10
Location: Seattle
ShadowStorm wrote:
ImageGadget !


I tired that but it does not draw on the window, only frames with in it. am I missing a flag.

Thanks,
Aaron


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 11:08 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1093
He means like this :
Code:
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

_________________
PureBasic 5.71 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 11:37 am 
Offline
User
User
User avatar

Joined: Thu May 30, 2019 10:02 am
Posts: 10
Location: Seattle
Bisonte wrote:
He means like this :
Code:
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


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.

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.


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 2:34 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2057
Location: Germany
Thanks Shardik

Update
Code:
;-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

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Thu May 30, 2019 9:26 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 6:42 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1093
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.


This mostly is the result of an av system. Put Purebasic and his compiler to the whitelist.

_________________
PureBasic 5.71 LTS (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Thu May 30, 2019 7:34 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1657
Location: Germany
mk-soft wrote:
Windows, macOS, Linux GTK2
Author Unknown

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...:wink:


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Fri May 31, 2019 5:50 am 
Offline
User
User
User avatar

Joined: Thu May 30, 2019 10:02 am
Posts: 10
Location: Seattle
Bisonte wrote:
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.


This mostly is the result of an av system. Put Purebasic and his compiler to the whitelist.


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.


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Fri May 31, 2019 4:09 pm 
Offline
User
User
User avatar

Joined: Thu May 30, 2019 10:02 am
Posts: 10
Location: Seattle
mk-soft wrote:
Thanks Shardik

Update
Code:
;-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 :P

Thanks for all the help :)


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Fri May 31, 2019 10:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 2:49 pm
Posts: 634
You can also use a canvas container as the window background and use DrawImage(), without api.


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Fri May 31, 2019 11:24 pm 
Offline
User
User
User avatar

Joined: Thu May 30, 2019 10:02 am
Posts: 10
Location: Seattle
Justin wrote:
You can also use a canvas container as the window background and use DrawImage(), without api.


nice to know, can you point me to an example. Thanks :)


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Sat Jun 01, 2019 1:31 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1657
Location: Germany
scanfff wrote:
Justin wrote:
You can also use a canvas container as the window background and use DrawImage(), without api.


nice to know, can you point me to an example. Thanks :)

Justin is right. The flag #PB_Canvas_Container is relatively new and was implemented in PureBASIC 5.60 in March 2017.
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Sun Jun 02, 2019 6:57 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Dec 29, 2011 5:03 pm
Posts: 508
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: A simple resizable image as window bg
PostPosted: Sun Jun 02, 2019 7:11 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 577
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:
...


This does not work for me:
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye