How to re-draw background png image with mouseEvent function?

I’m currently using the binary png method to implement my GUI background. now I am trying to achieve animating the background by making the background png change when hover over different dials

void TokyoRe_verbAudioProcessorEditor::paint (Graphics& g)
{
    Image background = ImageCache::getFromMemory(BinaryData::Animation1_png, BinaryData::Animation1_pngSize);
    g.drawImageAt(background, 0, 0);
 
}

I have swapped to using a struct class in my Editor.h to be able to implement the mouseEvent function along side the GUI png (paint::Graphics &g) draw function

struct AnimatedComponent : public Component
{
	void paint(Graphics&) override;

	Image AnimationOne = ImageCache::getFromMemory(BinaryData::Animation1_png, BinaryData::Animation1_pngSize);
	Image AnimationTwo = ImageCache::getFromMemory(BinaryData::Animation2_png, BinaryData::Animation2_pngSize);
	Image AnimationThree = ImageCache::getFromMemory(BinaryData::Animation3_png, BinaryData::Animation3_pngSize);
	Image AnimationFour = ImageCache::getFromMemory(BinaryData::Animation4_png, BinaryData::Animation4_pngSize);

	
	void mouseEnter(const MouseEvent& e) override;
	void mouseExit(const MouseEvent& e) override;

};

Below is the part in the Editor.cpp that calls the struct class and draws the Background Image with the mouseEvent

void AnimatedComponent::paint(juce::Graphics &g)
{
	/g.setColour(Colours::blue);
	g.drawEllipse(getWidth() - 113, 80, 80, 80, 3);	
	Draws the image at set bounds 	
	g.drawImageAt(AnimationOne, 0, 0);
}

void AnimatedComponent::mouseExit(const juce::MouseEvent &e)  
{
	
	-> undefined g gdrawImageAt(AnimationOne, 0, 0);
	Image Comp = AnimationOne;
	repaint();
	DBG("blaExit");
}

void AnimatedComponent::mouseEnter(const juce::MouseEvent &e) 
{
	/g.drawImageAt(AnimationTwo, 0, 0);
	Image Comp = AnimationTwo;
	repaint();
	DBG("blaEnter");
}

is there anyway for me to add (paint::Graphics &g) to the void AnimatedComponent::MouseEvent?

I’m really new to coding and would appreciate some help cracking this :slight_smile: Thanks!

I could help, but I can’t read your code as you posted it. Please reformat your code by putting a triple tick, three of these ` right next to each other, at the start and end of each section

my code

Hey, thanks for replying, I hope this helps

First off, there was no need to change from a class to a struct.

I haven’t tested this code, but this is the direction I would take.
Add this to your class declaration:

    Image currentImage;

in paint(), draw currentImage

    g.drawImageAt(currentImage, 0, 0);

Set currentImage accordingly in mouseEnter/mouseExit, and possibly in your constructor (so it is initialized before mouseEnter/Exit is called)

void AnimatedComponent::mouseExit(const juce::MouseEvent &e)
{
    currentImage = AnitmationOne;
    repaint();
}

void AnimatedComponent::mouseEnter(const juce::MouseEvent &e)
{
    currentImage = AnimationTwo;
    repaint();
}

Thanks, We will look into it and get back to you