Painting a component within a component


#1

this is probably just a quick and easy question. i have a sub class of component with its own overriden paint function drawing an image. this sub class also contains a label which i have called addAndMakeVisible, but it doesn’t show up. do I need to explicitly call its paint function in the paint function of the component sublcass that owns it?

some code in case i havent explained it well.

#ifndef _AUROROTARY_
#define _AUROROTARY_

#include "../JuceLibraryCode/JuceHeader.h"

class AuroRotary: public Component
{
public:
	AuroRotary(){}
	AuroRotary(String name);
	void mouseDown(const MouseEvent &event);
	void mouseDoubleClick (const MouseEvent& event);
	void paint(Graphics &g);
	void resized();
private:
	Label valuebox;
	Font testFont;
};

#endif
#include "AuroRotary.h"

AuroRotary::AuroRotary(String name):Component(name),valuebox("","slider")
{
	int i = 0;
	testFont.setTypefaceName("Arial");
	testFont.setHeight(12);
	valuebox.setFont(testFont);
	valuebox.setColour(Label::ColourIds::textColourId, Colours::white);
	valuebox.setEditable(true);
	addAndMakeVisible(&valuebox);
}

void AuroRotary::resized()
{
	valuebox.setBounds(20,20,50,50);
}

void AuroRotary::paint(Graphics &g)
{
	Image myStrip = ImageCache::getFromMemory (BinaryData::knob2w65horiz_png, BinaryData::knob2w65horiz_pngSize);	
	g.drawImage(myStrip, 0, 0, 64, 64, 0, 0, 64, 64);
}
class SlidersAudioProcessorEditor  : public AudioProcessorEditor
{
private:
	AuroRotary testRotary;
...
};
#include "PluginProcessor.h"
#include "PluginEditor.h"


//==============================================================================
SlidersAudioProcessorEditor::SlidersAudioProcessorEditor (SlidersAudioProcessor* ownerFilter)
    : AudioProcessorEditor (ownerFilter)//,valuebox("","sliders")
{
    setSize (400, 300);
	addAndMakeVisible(&testRotary);

}

void SlidersAudioProcessorEditor::resized()
{
	testRotary.setBounds(0,0,65,65);

}

//==============================================================================
void SlidersAudioProcessorEditor::paint (Graphics& g)
{
    g.fillAll (Colours::white);
    g.setColour (Colours::black);
    g.setFont (15.0f);

}

#2

Try calling setOpaque(false) inside your constructor.


#3

that didn’t work, ive also tried commenting out the draw of the image which didn’t do anything.i tried setting a breakpoint in labels paint method. and it didnt get called.


#4

Usually when a component doesn’t appear, it’ll be because you’ve not given it a size, or not added it to the parent, or not made it visible.


#5

i’ve done all that, i swapped the code word for word from AuroRotary to the main plugineditor class and the text box displayed. I need it in AuroRotary though.


#6

Well, if your paint method isn’t getting called, it’ll be because it’s off-screen or not visible, or something simple like that.


#7

if that were the case, wouldnt it be offscreen/not visible when i replace the code in the plugineditor class?


#8

i just changed AuroRotarys label and font from static memory to dynamic memory to see if that might help, now the dialog window is completely squashed (as though its height is set to 0) and i cant resize it.

edit: turns out I wasn’t using the correct constructor, doh.