2024-06-04 05:08 AM - edited 2024-06-04 05:08 AM
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?
Solved! Go to Solution.
2024-06-04 09:10 AM
Hello @nico23 ,
"getCenterX() returns the same value of.getCenterX()" you typed the same function twice here.
I have tested and subDemoIcon.getWidth() returns 92 :
"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,
2024-06-04 06:25 AM - edited 2024-06-04 06:41 AM
Hello @nico23 ,
There is indeed no way to get the center of the image.
The proper way is what you suggest: getX() + getWidth()/2
2024-06-04 07:34 AM - edited 2024-06-04 11:45 PM
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
2024-06-04 09:10 AM
Hello @nico23 ,
"getCenterX() returns the same value of.getCenterX()" you typed the same function twice here.
I have tested and subDemoIcon.getWidth() returns 92 :
"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,
2024-06-20 01:17 AM
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,