cancel
Showing results for 
Search instead for 
Did you mean: 

getXY/setXY relative to the center of an image/TextureMapper

nico23
Associate III

Is there a way to get/set the coordinate of an image or a Texture Mapper realtive to its center?

I think one suitable idea I have is to overload the class with new methods called like getXYcenter where I get the X coordinate and add half of the width (the same with Y and heigh)

On the other hand, setXYcenter would take the X coordinate and use setX minus half of the width (the same with Y and heigh)

Does it make sense? Or are there something already implemented?

1 ACCEPTED SOLUTION

Accepted Solutions
GaetanGodart
ST Employee

Hello @nico23 ,

 

"getCenterX() returns the same value of.getCenterX()" you typed the same function twice here.

 

I have tested and subDemoIcon.getWidth() returns 92 :

GaetanGodart_0-1717517109888.png

GaetanGodart_1-1717517154501.png

 

"It seem that setCenterXY doesn't actually draw the image" indeed, you do not invalidate the widget and I don't think setX and setY redraw the widget by default.
Try adding subDemoIcon.invalidate();.

 

Overall, you seems to make things more complicated than they have to be.
You take an example of a demo using a custom container inside a custom container inside a scrollWheel.
The logic works for sure.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

View solution in original post

4 REPLIES 4
hellohello
ST Employee

Hello @nico23 ,

 

There is indeed no way to get the center of the image.
The proper way is what you suggest: getX() + getWidth()/2

nico23
Associate III

I've tried using the Wheel menù demo you provide with the circular display.

I've set the new functions in the hpp file

 

 

#include <gui_generated/containers/MainWheelIconBase.hpp>

class MainWheelIcon : public MainWheelIconBase
{
public:
...
    void setCenterXY(int16_t x, int16_t y);
    int16_t getCenterX() const;
    int16_t getCenterY() const;
...
protected:
};

 

 

and in the cpp

 

 

void MainWheelIcon::setCenterXY(int16_t x, int16_t y)
{
    subDemoIcon.setX(x - static_cast<int16_t>(subDemoIcon.getWidth() / 2));
    subDemoIcon.setY(y - static_cast<int16_t>(subDemoIcon.getHeight() / 2));
}

int16_t MainWheelIcon::getCenterX() const
{
    return (subDemoIcon.getX() + static_cast<int16_t>(subDemoIcon.getWidth() / 2));
}

int16_t MainWheelIcon::getCenterY() const
{
    return (subDemoIcon.getY() + static_cast<int16_t>(subDemoIcon.getHeight() / 2));
}

 

 

Now if I set the position with .setXY().getCenterX() returns the same value of.getX(). I'm sure getWidth() is not 0

It seem that setCenterXY doesn't actually draw the image

GaetanGodart
ST Employee

Hello @nico23 ,

 

"getCenterX() returns the same value of.getCenterX()" you typed the same function twice here.

 

I have tested and subDemoIcon.getWidth() returns 92 :

GaetanGodart_0-1717517109888.png

GaetanGodart_1-1717517154501.png

 

"It seem that setCenterXY doesn't actually draw the image" indeed, you do not invalidate the widget and I don't think setX and setY redraw the widget by default.
Try adding subDemoIcon.invalidate();.

 

Overall, you seems to make things more complicated than they have to be.
You take an example of a demo using a custom container inside a custom container inside a scrollWheel.
The logic works for sure.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)
GaetanGodart
ST Employee

Hello @nico23 ,

 

Have you been able to move forward with your project?

If my last comment helped you solve your issue, I invite you to select it as "best answer".

If you are still encountering problems, I invite you to give me more information so I can help you.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)