since I included shardik's useful example in the Linux API library, I took the liberty of modifying it to change the output text via a timer event. I hope he forgives me .
I packed the necessary data into a structure, which is passed to the WidgetDrawHandler(*Widget.GtkWidget, CairoContext.I, *UserData.HUDWIN) as parameter *UserData, -> @HUD_Data.
By the structure field HUD_Data\Window with the PB-WindowNo the WidgetDrawHandler() can work window independent.
With the timer event only the structure content must be updated and WidgetDrawHandler(Window, 0, @HUD_Data) must be called manually. (Tested with PB 5.62 + PB5.70B3 for gtk3)
Code: Select all
;from shardiks example
EnableExplicit
#CAIRO_OPERATOR_SOURCE = 1
ImportC ""
gdk_cairo_create(*Drawable.GdkDrawable)
gtk_widget_get_window(*Widget.GtkWidget)
gtk_widget_is_composited(*Widget.GtkWidget)
EndImport
ImportC "-lcairo"
cairo_paint(*CairoContext)
cairo_set_operator(*CairoContext, CairoOperator.I)
cairo_set_source_rgba(*CairoContext, Red.D, Green.D, Blue.D, Alpha.D)
EndImport
ImportC ""
gdk_screen_get_rgba_visual(*Screen.GdkScreen)
gdk_screen_get_system_visual(*Screen.GdkScreen)
gtk_widget_set_visual(*Vidget.GtkWidget, *Visual.GdkVisual)
EndImport
; Object constants
;Window ...
#Win_Main = 0
;Gadgets ...
#ImgGdgt = 0
Define Container.I
Define Screen.I
Define Visual.I
Define Window.I
Structure HUDWIN
Window.i
Counter.i
RumourBasic.s
Rumour.s
Exit.s
EndStructure
Global HUD_Data.HUDWIN
With HUD_Data
\Counter = 0
\RumourBasic= "Text in HUD window"
\Rumour = \RumourBasic
\Exit = "<Esc> to close"
EndWith
ProcedureC WidgetDrawHandler(*Widget.GtkWidget, CairoContext.I, *UserData.HUDWIN)
CairoContext = gdk_cairo_create(gtk_widget_get_window(*Widget))
cairo_set_source_rgba(CairoContext, 1, 1, 1, 0)
cairo_set_operator(CairoContext, #CAIRO_OPERATOR_SOURCE)
cairo_paint(CairoContext)
If StartDrawing(WindowOutput(HUD_Data\Window))
; ----- Draw frame of HUD
DrawingMode(#PB_2DDrawing_Default)
Line(1, 1, WindowWidth(HUD_Data\Window), 1, $FF)
Line(1, 2, WindowWidth(HUD_Data\Window), 1, $FF)
Line(1, WindowHeight(HUD_Data\Window), WindowWidth(HUD_Data\Window), 1, $FF)
Line(1, WindowHeight(HUD_Data\Window) - 1, WindowWidth(HUD_Data\Window), 1, $FF)
Line(1, 1, 1, WindowHeight(HUD_Data\Window), $FF)
Line(2, 1, 1, WindowHeight(HUD_Data\Window), $FF)
Line(WindowWidth(HUD_Data\Window), 1, 1, WindowHeight(HUD_Data\Window) - 1, $FF)
Line(WindowWidth(HUD_Data\Window) - 1, 1, 1, WindowHeight(HUD_Data\Window) - 2, $FF)
; ----- Draw text into HUD window
DrawingMode(#PB_2DDrawing_Transparent)
DrawText((WindowWidth(HUD_Data\Window) - TextWidth(*UserData\Rumour)) / 2, 26, *UserData\Rumour, $FF0000)
DrawText(48, 53, *UserData\Exit, $FF)
StopDrawing()
EndIf
EndProcedure
CreateImage(#ImgGdgt, 220, 100, 32, #PB_Image_Transparent)
Window = OpenWindow(#Win_Main, 200, 150, ImageWidth(#ImgGdgt), ImageHeight(#ImgGdgt), "HUD window", #PB_Window_Invisible)
HUD_Data\Window= #Win_Main
If gtk_widget_is_composited(WindowID(#Win_Main)) = #False
MessageRequester("Error", "Sorry, but transparency is not supported on this system!")
End
EndIf
; ----- Disable visibility of window frame
; gtk_window_set_decorated_(Window, #False)
; ----- Enable modification of window colors
gtk_widget_set_app_paintable_(Window, #True)
ImageGadget(#ImgGdgt, 0, 0, ImageWidth(#ImgGdgt), ImageHeight(#ImgGdgt), ImageID(#ImgGdgt))
; ----- Delete GdkWindow resources to be able to change colormap
gtk_widget_unrealize_(Window)
; ----- Get window's child container
Container = g_list_nth_data_(gtk_container_get_children_(gtk_bin_get_child_(WindowID(#Win_Main))), 0)
g_signal_connect_(GadgetID(#ImgGdgt), "draw", @WidgetDrawHandler(), @HUD_Data)
Screen = gtk_widget_get_screen_(Window)
Visual = gdk_screen_get_rgba_visual(Screen)
If Visual = 0
Visual = gdk_screen_get_system_visual(Screen)
EndIf
gtk_widget_set_visual(Window, Visual)
; ----- Realize window and rebuild new GdkWindow
HideWindow(#Win_Main, #False)
; ----- Define <Esc> key to close splash window
AddKeyboardShortcut(#Win_Main, #PB_Shortcut_Escape, 0)
AddWindowTimer(#Win_Main, 999, 1000)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Menu
If EventMenu() = 0
Break
EndIf
Case #PB_Event_Timer
HUD_Data\Counter+ 1
HUD_Data\Rumour= HUD_Data\RumourBasic + " " + Str(HUD_Data\Counter)
WidgetDrawHandler(Window, #Null, @HUD_Data)
EndSelect
ForEver