I’m new to Juce. I want to draw a cursor synchronized with a Metronome. I tried to create the cursor as a child from AnimatedAppComponent, at the moment the cursor is a triangle.
The Metronome was done with libpd. The whole score coordinates are scored in a std::vector. I’m actualizing the coordinates inside the PdObject class. Always when I receive a bang I’m reading the next coordinates and I store it inside a struct. This struct is a std::shared_ptr , the Cursor class receive this shared_ptr and set the cursor coordinates. My problem here is that after the first time, the cursor doesn’t moves, the coordinates are actualized but it doesn’t have any effect in the cursor’s position, I’m calling addTriangle within the Cursor’s update method. I don’t know exactly how I have to refresh the draw, I called repaint() inside the update method too, but again it doesn’t have any effect.
The Cursor class is the following:
Cursor : public AnimatedAppComponent {
public:
Cursor(std::shared_ptr<coord> _coords) {
coords = _coords;
setSize (600, 300);
setFramesPerSecond (60);
toFront(true);
}
void update() override {
tri.addTriangle(coords->x3, coords->y3, coords->x1, coords->y1, coords->x2, coords->y2);
//if(fGraphics)
//fGraphics->fillPath(tri);
repaint();
}
void paint (Graphics& g) override {
fGraphics = &g;
fGraphics->setColour(Colours::red);
tri.addTriangle(coords->x3, coords->y3, coords->x1, coords->y1, coords->x2, coords->y2);
fGraphics->fillPath(tri);
}
void resized() override {
//this->setBounds(0, 0, getWidth(), getHeight());
}
private:
Path tri;
std::shared_ptr<coord> coords;
juce::Graphics * fGraphics;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Cursor)
};
The coordinates are right, Libpd is working fine without problems. I think the update() method is wrong, but I don’t know exactly how should I have to use it. Maybe is possible to do the same in another way. I’d be glad to become some help.
Regards.