Seite 2 von 2
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 24.10.2015 13:44
von Shardik
Ich habe den Linux-spezifischen Teil so angepaßt, dass er sowohl mit Gtk2 und Gtk3 funktioniert und in PB 5.31 und 5.40 im ASCII- und Unicode-Modus problemlos läuft (getestet unter Ubuntu 14.04 x64 mit KDE):
Code: Alles auswählen
EnableExplicit
InitNetwork()
UseJPEGImageDecoder()
Procedure SetWindowBackgroundImage(hWnd.i, hImage.i)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected Child.I
Protected ChildrenList.I
Protected *Name
Protected Widget.I = gtk_bin_get_child_(hWnd)
Repeat
ChildrenList = gtk_container_get_children_(Widget)
Child = g_list_nth_data_(ChildrenList, 0)
If Child = 0
Break
Else
*Name = gtk_widget_get_name_(Child)
Widget = Child
EndIf
Until PeekS(*Name, -1, #PB_UTF8) = "GtkFixed"
If Child
gtk_fixed_put_(Child, gtk_image_new_from_pixbuf_(hImage), 0, 0)
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 ReceiveHTTPFile("http://realsource.de/images/stargate_atlantis.jpg", GetTemporaryDirectory() + "stargate_atlantis.jpg")
LoadImage(0, GetTemporaryDirectory() + "stargate_atlantis.jpg")
OpenWindow(0, 100, 100, 800, 450, "Window with background image")
SetWindowBackgroundImage(WindowID(0), ImageID(0))
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 24.10.2015 14:36
von ts-soft
Kannst Du das in dem Tipps & Tricks Forum posten, danke!
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 24.10.2015 14:40
von mk-soft
Vielen Dank

Re: Fensterhintergrund ein Bild (Image)
Verfasst: 24.10.2015 14:42
von Omi
Hallo Shardik,
ich hab mich heut Früh rangemacht rauszufinden, was denn das PB unter Linux gtk2 und gtk3 denn nun wirklich einfärbt bei den Fensterfarben und Bildern, da API-Funktionen ja nicht durchkommen.
Ich hab mich vom einem Gadget zum 1. GtkFixed runtergehangelt und gemerkt dass man dies umfärben und auch durchsichtig machen kann. Darunter kam die alte original API-Fensterfarbe zum Vorschein die dann auch unter gtk3 sichtbar zu manipulieren ist.
Morgen wollte ich mich mal von der Fensterseite zum 1. GtkFixed durchhangeln und für die ganzen PB- u. API-Färbereien und Image-Einpflanzung exemplarische gtk2- und gtk3-Codes zu erstellen.
Danke, dass Du immer schneller bist und schon vorgehangelt hast!
Charly
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 03.01.2017 15:32
von schleicher
Das mit dem Windowshintergrund geht ja gut, doch wie bekomme ich den texthintergrund(textgadget) transparent ? Habe mal beide winapi kombiniert, aber das geht nicht.
Eine Idee warum und wie könnte man das richtig machen ? Fordergrundfarbe textgadget wählbar/ Hintergrundfarbe transparent. (windos, linux, mac)
Code: Alles auswählen
EnableExplicit
UseJPEGImageDecoder()
Procedure SetWindowBackgroundImage(hWnd.i, hImage.i)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected Child.I
Protected ChildrenList.I
Protected *Name
Protected Widget.I = gtk_bin_get_child_(hWnd)
Repeat
ChildrenList = gtk_container_get_children_(Widget)
Child = g_list_nth_data_(ChildrenList, 0)
If Child = 0
Break
Else
*Name = gtk_widget_get_name_(Child)
Widget = Child
EndIf
Until PeekS(*Name, -1, #PB_UTF8) = "GtkFixed"
If Child
gtk_fixed_put_(Child, gtk_image_new_from_pixbuf_(hImage), 0, 0)
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
Procedure WCB(WindowID, Message, wParam, lParam)
Protected Result
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_CTLCOLORSTATIC
Select lparam
Case GadgetID(1)
SetBkMode_(wparam,#TRANSPARENT)
ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
LoadImage(0, GetCurrentDirectory()+"Image\black-background.jpg");-Pfad anpassen
OpenWindow(0, 100, 100, 800, 450, "Window with background image")
TextGadget(1, 20, 20, 100, 20, "Text transparent")
SetWindowBackgroundImage(WindowID(0), ImageID(0))
SetWindowCallback(@WCB(), 0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 03.01.2017 15:39
von RSBasic
Code: Alles auswählen
SetWindowBackgroundImage(WindowID(0), ImageID(0))
SetWindowCallback(@WCB(), 0)
Code: Alles auswählen
SetWindowCallback(@WCB(), 0)
SetWindowBackgroundImage(WindowID(0), ImageID(0))
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 03.01.2017 16:03
von schleicher
ah ja. das funktioniert . Jedoch die Textfarbe setzen mit SetGadgetColor(1, #PB_Gadget_FrontColor, textcolor) geht dann nicht mehr. Habe das mit winapi gelöst bekommen.
Muss das ganze nun noch für linux und mac rausfinden.
Code: Alles auswählen
EnableExplicit
Global textcolor=RGB(253, 255, 0)
InitNetwork()
UseJPEGImageDecoder()
Procedure SetWindowBackgroundImage(hWnd.i, hImage.i)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected Child.I
Protected ChildrenList.I
Protected *Name
Protected Widget.I = gtk_bin_get_child_(hWnd)
Repeat
ChildrenList = gtk_container_get_children_(Widget)
Child = g_list_nth_data_(ChildrenList, 0)
If Child = 0
Break
Else
*Name = gtk_widget_get_name_(Child)
Widget = Child
EndIf
Until PeekS(*Name, -1, #PB_UTF8) = "GtkFixed"
If Child
gtk_fixed_put_(Child, gtk_image_new_from_pixbuf_(hImage), 0, 0)
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
Procedure WCB(WindowID, Message, wParam, lParam)
Protected Result
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_CTLCOLORSTATIC
Select lparam
Case GadgetID(1)
SetBkMode_(wparam,#TRANSPARENT)
SetTextColor_(wParam, textcolor)
ProcedureReturn GetStockObject_(#HOLLOW_BRUSH)
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
LoadImage(0, GetCurrentDirectory()+"Image\black-background.jpg");-Pfad anpassen
OpenWindow(0, 100, 100, 800, 450, "Window with background image")
TextGadget(1, 20, 20, 100, 20, "Text transparent")
SetWindowCallback(@WCB(), 0)
SetWindowBackgroundImage(WindowID(0), ImageID(0))
;SetGadgetColor(1, #PB_Gadget_FrontColor, textcolor)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 30.05.2019 21:15
von Shardik
Mein obiges Multiplattform-Beispiel funktioniert nicht mehr, weil die zum Download des Testbildes verwendete Website realsource.de von ts-soft und edel wohl aufgegeben wurde. Außerdem musste der Linux-Teil angepasst werden, weil auf Grund von internen Änderungen in der Linux-Version von PureBasic in GTK3 kein GtkFixed mehr als Container verwendet wird sondern GtkLayout. Das folgende Beispiel funktioniert wieder auf allen Plattformen und in Linux mit GTK2 und GTK3:
Code: Alles auswählen
EnableExplicit
InitNetwork()
UsePNGImageDecoder()
Procedure SetWindowBackgroundImage(hWnd.i, hImage.i)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected Container.I
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
Re: Fensterhintergrund ein Bild (Image)
Verfasst: 22.06.2019 09:50
von mk-soft
Kleines Update...
Nach Verwendung von "gtk_container_get_children" muss noch die "g_list" wieder freigegeben werden.
Kleine Bugs entfernt
Update v1.02
Code: Alles auswählen
;-TOP
; Comment: SetWindowBackgroundImage
; Authors: ts-soft (Windows), Shardik (Linux , masOS), mk-soft
; Version: v1.02
; Create : ??.??.2014
; Update : 22.06.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 Widget.I, Container.I, Layer.I
Widget.I = gtk_bin_get_child_(hWnd)
Container = gtk_container_get_children_(Widget)
Layer = g_list_nth_data_(Container, 0)
g_list_free_(Container)
If Layer
If PeekS(gtk_widget_get_name_(Layer), -1, #PB_UTF8) = "GtkFixed"
gtk_fixed_put_(Layer, gtk_image_new_from_pixbuf_(hImage), 0, 0)
Else
gtk_layout_put_(Layer, 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
; ----
;- Example
CompilerIf #PB_Compiler_IsMainFile
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
CompilerEndIf