- Linux Mint 17.3 x86 "Rosa"
- Lubuntu 14.04 x86 with LXDE
- Ubuntu 14.04 x64 with Enlightenment E17
- Ubuntu 14.04 x64 with KDE
- Ubuntu 14.04 x64 with Unity
- Xubuntu 14.04 x86 with Xfce
Code: Select all
EnableExplicit
#CAIRO_EXTEND_REPEAT = 1
ImportC ""
gdk_cairo_create(*Drawable.GdkDrawable)
EndImport
ImportC "-lcairo"
cairo_destroy(*CairoContext)
cairo_fill(*CairoContext)
cairo_get_source(*CairoContext)
cairo_image_surface_create_from_png(Filename.P-UTF8)
cairo_pattern_create_for_surface(*CairoSurface)
cairo_pattern_destroy(*CairoPattern)
cairo_pattern_set_extend(*CairoPattern, Extend.I)
cairo_rectangle(*CairoContext, x.D, y.D, Width.D, Height.D)
cairo_set_source(*CairoContext, *CairoPattern)
cairo_surface_destroy(*CairoSurface)
EndImport
Define Pattern.I
Define Surface.I
CompilerIf Subsystem("gtk2")
ProcedureC WidgetExposeHandler(*Widget.GtkWidget, *Event.GdkEventExpose)
Protected CairoContext.I
CairoContext = gdk_cairo_create(*Widget\window)
CompilerElse
ProcedureC WidgetDrawHandler(*Widget.GtkWidget, CairoContext.I, *UserData)
CompilerEndIf
Shared Pattern.I
Shared Surface.I
cairo_set_source(CairoContext, Pattern)
cairo_pattern_set_extend(cairo_get_source(CairoContext),
#CAIRO_EXTEND_REPEAT)
cairo_rectangle(CairoContext, 10, 10, WindowWidth(0) - 20,
WindowHeight(0) - 20)
cairo_fill(CairoContext)
CompilerIf Subsystem("gtk2") = #True
cairo_destroy(CairoContext)
CompilerEndIf
EndProcedure ;}
Procedure.I GetContainer(WindowID.I, ContainerName.S)
Protected Child.I
Protected ChildrenList.I
Protected *Name
Protected Widget.I = WindowID(WindowID)
Child = gtk_bin_get_child_(Widget)
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) = ContainerName
ProcedureReturn Child
EndProcedure
OpenWindow(0, 140, 100, 550, 530,
"Window with transparent PNG background image", #PB_Window_SizeGadget)
SetWindowColor(0, $CDFAFF)
ButtonGadget(0, 220, 400, 100, 25, "Click me!")
Surface = cairo_image_surface_create_from_png(#PB_Compiler_Home +
"examples/3d/Data/Textures/grass1.png")
Pattern = cairo_pattern_create_for_surface(Surface)
CompilerIf Subsystem("gtk2")
g_signal_connect_(GetContainer(0, "GtkFixed"), "expose-event",
@WidgetExposeHandler(), 0)
CompilerElse
g_signal_connect_(GetContainer(0, "GtkFixed"), "draw",
@WidgetDrawHandler(), 0)
CompilerEndIf
; ----- Force initial drawing of window
gtk_widget_queue_draw_(WindowID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
cairo_pattern_destroy(Pattern)
cairo_surface_destroy(Surface)
Break
Case #PB_Event_Gadget
If EventGadget() = 0
Debug "Button was clicked!"
EndIf
EndSelect
ForEver
- I have changed
Code: Select all
cairo_image_surface_create_from_png(Filename.S)
Code: Select all
cairo_image_surface_create_from_png(Filename.P-UTF8)
- I added
Code: Select all
SetWindowColor(0, $CDFAFF)
- I removed the creation of the surface and the pattern from the callback and moved it to the main program because it's bad practice to put resource-hungry operations in a callback which has to be optimized for speed because it is called very often.
- I added the line
Code: Select all
gtk_widget_queue_draw_(WindowID(0))