cancel
Showing results for 
Search instead for 
Did you mean: 

How to draw a rounded rectangle?

SKILA
Associate II

Hello all,

Is there a way to draw a rounded filled rectangle dynamically and assign it to a button?

Thanks!

Samer

7 REPLIES 7
Martin KJELDSEN
Chief III

Can i ask why you'd want to do that dynamically? Because the size of your buttons change dynamically? Otherwise i'd simply draw them in paint.exe as an asset and use those. There's no direct support for drawing filled, rounded rectangles, no. You could create a custom widget that took a width and height and color, then you would have 4 images of rounded edges with full alpha that you place in each corner to indicate a rounded rectangle. You'd use the DMA to draw a color for the body and only a small piece of flash for the 4 images, which are reusable for all colors and perhaps sizes.

/Martin

Perhaps I shouldn't have said dynamic​ because none of the shapes change during runtime. What I would really want to do is reduce the overall size of my firmware. I have many rounded rectangles in my design with a single filled colour. I can see that for some of the large rectangles the size of the generated file exceeds 1Mb which I just feel to be a waste.

Samer​

Ok. Did my suggestion make sense? You save some flash, pay some RAM instead.

There is more than enough RAM and Flash on my board. The problem is with the size of the firmware. The board is part of a larger system and will be programmed and updated using another board via a slow control link. Hence, why I need the firmware to be as small as possible.

The whole idea here is that I was hoping there is a way to draw a rounded rectangle just like I can draw a filled box in Touchgfx.

I hope that makes sense.

Samer​

Sure. There isn't, unfortunately. It violates the TouchGFX philosophy that we want do things and efficient as fast as possible, and try not to offer up too many inefficient alternatives, like using the CPU to render (we would have to use the CPU in this case).

You could do a crazy workaround where you draw yourself into some memory and use that as input to a dynamic bitmap which you could then use for a button. It's pretty convoluted, but if that's your only option.

No problem. Thanks for the input. Appreciate it.​

No problem. Let me know if you want to explore some of this further.