Skip to main content
sute
Associate III
March 15, 2023
Solved

How to draw a point in TouchGFX view class?

  • March 15, 2023
  • 4 replies
  • 2172 views

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?

This topic has been closed for replies.
Best answer by Romain DIELEMAN

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 :beaming_face_with_smiling_eyes:

/Romain

4 replies

Romain DIELEMAN
Romain DIELEMANBest answer
ST Employee
March 17, 2023

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 :beaming_face_with_smiling_eyes:

/Romain

Romain DIELEMAN
ST Employee
March 17, 2023

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
Visitor II
March 17, 2023

Thank you I was looking for this too. :grinning_face: