Jump to content

Redrawing transparent label with background image


Asaliii

Recommended Posts

Hello,

I am passing an image to my container in each screen then I start drawing my labels (which have transparent custom draw function ) on this background image.

I need to change and update my labels on the screen and I use gwinSetText in order to update my widgets' texts but it seems that it keeps the last text and draw the second text on top of the last text.

does this have anything to do with the transparency function I'm using? Is there a way to fix this? 

Link to comment
Share on other sites

Hi,

Yes, this is definitely due to the transparent custom rendering function. There is no concept of transparency in µGFX (that will follow with µGFX v3). The GWIN window manager excepts that the widget always clears it's own area. You have the following options:

  • Modify your label's custom rendering function so that it receives an image chunk that it will use to clear the widget area prior to rendering the new text. The image chunk you give it should be exactly the container's background image below the label area.
  • Redraw the entire container
  • Redraw the entire container but render it into a pixmap and then just blit it to the display to ensure flicker-free and fast updating
  • Write your own GWIN window manager that can handle transparency: https://www.youtube.com/watch?v=xZKgp5XaxVE

Which option you're choosing is mainly depending on your platform and the available resources.

Link to comment
Share on other sites

What I understood is that I have to draw that portion on my background image again then try to redraw the label in my label's custom drawing function.

my custom drawing function is very simple, it first checks for an image, then draw the string, So what you are saying is that I should first draw the background and then string on top of it?in the same custom drawing unction?

correct me if I'm wrong. 

Link to comment
Share on other sites

Something like this (untested):

void myRendering(GWidgetObject* wo, void* param)
{
	coord_t sx, sy;
	
	// Cast parameters
	img = (gdispImage*)param;
	if (!img) {
		return;
	}
	
	// Render background (use the specified portion of the specified image)
	if (img) {
		// Determine the coordinates relative to the parent
		if (wo->g.parent) {
			sx = ...
			sy = ...
		} else {
			sx = 0;
			sy = 0;
		}
		
		// Render the image
		gdispGImageDraw(wo->g.display, img, wo->g.x, wo->g.y, sx, sy, wo->g.width, wo->g.height);
	}
	
	// Render the label
	gdispGDrawStringBox(...);
}

When creating the label you assign that rendering function to it and you pass a pointer to the containers background image as the parameter.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...