cancel
Showing results for 
Search instead for 
Did you mean: 

why can't we draw more than 45 lines in touchgfx?

Lviet.1
Associate II
 
7 REPLIES 7
Martin KJELDSEN
Chief III

I need way more information than that :) thanks

Martin KJELDSEN
Chief III

What are you trying to achieve? Generally, adding as many widgets as possible to a root container of a view is not always the best option. Try bundling some lines together in a container. Maybe you really don't need a canvas line with antialiasing but can create a custom widget that implements ::draw() and writes pixels directly into the farmebuffer.

/Martin

thank you for replying. I like your idea "create a custom widget that implements ::draw() and writes pixels directly into the farmebuffer", but I don't know how to do that. Can you help me ?

Sure! The best thing you can do is maybe take a look at the "Custom Widget Example" UI template from the designer.

There's nothing noteworthy on the canvas because the example is based around the Lens widget (Lens.cpp under gui/src/common/) which has no elements and draws directly into the framebuffer through draw().

  

/Martin

Generally, you would declare your widget like:

#include <touchgfx/widgets/Widget.hpp>
 
class MyWidget : public touchgfx::Widget
{

And implement a custom draw-function to become part of the TouchGFX render chain.

void MyWidget::draw(const touchgfx::Rect& invalidatedArea) const
{
    //lock FB - Get pointer to start of framebuffer
    uint16_t* fb = touchgfx::HAL::getInstance()->lockFrameBuffer();
 
    //Start writing something!
 
    //Unlock FB
    touchgfx::HAL::getInstance()->unlockFrameBuffer();
}

thank you so much! I'll try

Lviet.1
Associate II

For example, I want to draw a rectangle with 5x5 pixels, how do I do it?

  1. void MyWidget::draw(const touchgfx::Rect& invalidatedArea) const
  2. {
  3. //lock FB - Get pointer to start of framebuffer
  4. uint16_t* fb = touchgfx::HAL::getInstance()->lockFrameBuffer();
  5. for(int x = 0; x < 5; x++)
  6. {
  7. for(int y = 0; y < 5; y++)
  8. {
  9. // what do I need write here
  10. }
  11. }
  12. //Unlock FB
  13. touchgfx::HAL::getInstance()->unlockFrameBuffer();
  14. }