Transparent text

Linux specific forum
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Transparent text

Post 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...
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: Transparent text

Post 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"...
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: Transparent text

Post 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
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Transparent text

Post 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 !)
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: Transparent text

Post 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!
Joubarbe
Enthusiast
Enthusiast
Posts: 714
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Transparent text

Post 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.
Post Reply