Page 1 of 1

Transparent text

Posted: Sun Sep 13, 2015 11:34 am
by Joubarbe
Hello,

I'm trying to "simulate" a desktop in order to have movable icons. An icon is composed of an image and a text. Problem is, canvas cannot be transparent, so I figured I use a canvas for the image only, and a text gadget for the icon's title. But second problem, text gadgets cannot be colorized :

Code: Select all

OpenWindow(0, 0, 0, 200, 200, "Text color test", #PB_Window_ScreenCentered)

TextGadget(0, 0, 0, 200, 200, "this is a text")
SetGadgetColor(0, #PB_Gadget_FrontColor, RGB(255,0,0))

Repeat
  
  event = WaitWindowEvent()
  
Until event = #PB_Event_CloseWindow
The text should be red. It remains black (at least on PB 5.40b3).
The point of using a text gadget is that the text is drawn on an alpha background, so it's fully transparent.
And I need a canvas to interact with mouse input (pressed, released, clicked, hovered, double clicked).

If only canvases could be transparent !

EDIT : hmm maybe I should have posted that in the Code section. Upon reflection, it has nothing related to Linux specifically...

Re: Transparent text

Posted: Sun Sep 13, 2015 2:46 pm
by HanPBF
Hello Joubarbe,

transparency seems to be the running "gag" in the forum...

http://forum.purebasic.com/english/view ... 13&t=62819
Loook around in the forum; there are some solutions.

Concerning CanvasGadget, a way to emulate transparency is to get the background and put it at z-index=0 or in another words, draw it first. It's way fast enough!

As far as I know, real transparency is not possible with CanvasGadget; that problem shall be OS specific not a real PB problem.

Maybe we should start voting about transparency :wink:

Better would be a user drawn GUI library (like ZebKit for the web http://www.zebkit.com).
I hate those "keep it native to OS GUI"...

Re: Transparent text

Posted: Sun Sep 13, 2015 2:49 pm
by Oma
Hi Joubarbe,

ain't broken too as background color at 5.40-beta with gtk3.

A quick fix:

Code: Select all

ImportC ""
	gdk_rgba_parse(*rgba, spec.p-utf8)
	gtk_widget_override_color(*widget.GtkWidget, state, color)
EndImport

Structure GdkRGBA
	red.d
	green.d
	blue.d
	alpha.d
EndStructure

Enumeration GtkStateFlags
	#GTK_STATE_FLAG_NORMAL
	#GTK_STATE_FLAG_ACTIVE
	#GTK_STATE_FLAG_PRELIGHT
	#GTK_STATE_FLAG_SELECTED
	#GTK_STATE_FLAG_INSENSITIVE
	#GTK_STATE_FLAG_INCONSISTENT
	#GTK_STATE_FLAG_FOCUSED
	#GTK_STATE_FLAG_BACKDROP
	#GTK_STATE_FLAG_DIR_LTR
	#GTK_STATE_FLAG_DIR_RTL
EndEnumeration

Global   ftcolor.GdkRGBA

OpenWindow(0, 0, 0, 200, 200, "Text color test", #PB_Window_ScreenCentered)

TextGadget(0, 5, 5, 200, 200, "this is a text")
; SetGadgetColor(0, #PB_Gadget_FrontColor, $0000FF)

	gdk_rgba_parse(@ftcolor, "#FF0000")
	gtk_widget_override_color(GadgetID(0), #GTK_STATE_FLAG_NORMAL, ftcolor)

Repeat
 
  event = WaitWindowEvent()
 
Until event = #PB_Event_CloseWindow
But we should wait. I'm shure Fred will fix it (if he knows about :wink: )

Regards, Charly

Re: Transparent text

Posted: Sun Sep 13, 2015 3:51 pm
by Joubarbe
HanPBF wrote:Concerning CanvasGadget, a way to emulate transparency is to get the background and put it at z-index=0 or in another words, draw it first. It's way fast enough!
"First" ? To what ?
If you mean draw the canvas background the same color as the background of the window, yeah, but no :) I need real transparency, because my icons/canvas are movable.

I'll wait a fix for the text gadget. In the meantime, I think I found a solution : instead of using text gadgets, I use image gadgets. Those can be fully transparent.

(Zebkit seems cool indeed !)

Re: Transparent text

Posted: Sun Sep 13, 2015 5:24 pm
by HanPBF
I am not really sure if transparency is at its lowest level not something like drawing (any) background first...

Maybe someone can clarify this?


Thanks!

Re: Transparent text

Posted: Sun Sep 13, 2015 5:40 pm
by Joubarbe
No it's not. If you draw a background, then moving a canvas over another one will give bad results. There's no alpha channel in canvases.