cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

How to draw a point in TouchGFX view class?

sute
Associate III

I am having trouble figuring out this seemingly simple thing. Assuming I have the coordinates of a touch point in a touch screen, how do I draw pixel to that location?

1 ACCEPTED SOLUTION

Accepted Solutions
Romain DIELEMAN
ST Employee

Hi,

​

The "issue" here is that the easiest way would be to use a widget (like a line or box widget) to draw that pixel using TouchGFX Designer. I don't know what you are planning to do but I guess it is not just putting one pixel or 2, but you would need to know in advance how many times (and therefore how many widgets) you would need to write pixels . An "advanced/complex" way to do this, I'll share a project doing that, would be to draw that one pixel (using the line widget in my case) and save a screenshot of that area (using cacheable containers and bitmaps) so that you can do it multiple time using only one line widget instead of many. This was done in my project to draw curves based on the touch of a user, It might look complex at first but the code is actually quite "simple".

​

Otherwise what you could do I guess is save those coordinates, send them to your main.c through the model and set the pixel of the framebuffer there, a bit like what we do in this article to check if the display is working.

​

I'm sure there are other and better ways so if anyone has something that makes more sense or is cleaner please share 😁

/Romain

View solution in original post

4 REPLIES 4
Romain DIELEMAN
ST Employee

Hi,

​

The "issue" here is that the easiest way would be to use a widget (like a line or box widget) to draw that pixel using TouchGFX Designer. I don't know what you are planning to do but I guess it is not just putting one pixel or 2, but you would need to know in advance how many times (and therefore how many widgets) you would need to write pixels . An "advanced/complex" way to do this, I'll share a project doing that, would be to draw that one pixel (using the line widget in my case) and save a screenshot of that area (using cacheable containers and bitmaps) so that you can do it multiple time using only one line widget instead of many. This was done in my project to draw curves based on the touch of a user, It might look complex at first but the code is actually quite "simple".

​

Otherwise what you could do I guess is save those coordinates, send them to your main.c through the model and set the pixel of the framebuffer there, a bit like what we do in this article to check if the display is working.

​

I'm sure there are other and better ways so if anyone has something that makes more sense or is cleaner please share 😁

/Romain

In the project shared, the line/pixels are drawn when there is a "drag" and not when just on the click. In your case just put the code from the "handleDragEvent()" function into the "handleClickEvent()" I guess.

/Romain

ZTech.1
Associate

Thank you I was looking for this too. πŸ˜€

Thank you very much! I will follow your suggestions.