So this is the code in question. I've posted whichever function i thought was essential.
Class of parent_component:
Parent_component::Parent_component ()
{
cachedImage_Parent_back_png = ImageCache::getFromMemory (Parent_back_png, Parent_back_pngSize);
//[UserPreSize]
//[/UserPreSize]
setSize (885, 640);
//[Constructor] You can add your own custom stuff here..
bool_flag= true;
addAndMakeVisible(btn1, ++id_components);
btn1.setTopLeftPosition(610, 65);
btn1.addMouseListener(this, true);
btn1.addListener(this);
addAndMakeVisible(child_component, ++id_components);
child_component.setTopLeftPosition(313, 226 );
child_component.addMouseListener(this, true);
//[/Constructor]
}
void Parent_component::buttonClicked( Button* btn_clicked )
{
if ( btn_clicked== &btn1 )
{
bool_flag= !bool_flag;
child_component.setVisible(bool_flag);
this->repaint();
}
}
Next is the switch's code. btn1 is of class Simple_switch which in turn inherits ImageButton.
Could the inheritance from ImageButton be the problem?
Simple_switch::Simple_switch ()
{
image_painted= cachedImage_simple_switch_st1_png = ImageCache::getFromMemory (simple_switch_st1_png, simple_switch_st1_pngSize);
image_painted_Size= simple_switch_st1_pngSize;
cachedImage_simple_switch_st2_png= ImageCache::getFromMemory (simple_switch_st2_png, simple_switch_st2_pngSize);
//[UserPreSize]
btn_state= true;
//[/UserPreSize]
setSize (116, 28);
//[Constructor] You can add your own custom stuff here..
//[/Constructor]
}
void Simple_switch::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here..
//[/UserPrePaint]
g.drawImage (image_painted,
0, 0, 116, 28,
0, 0, image_painted.getWidth(), image_painted.getHeight());
//[UserPaint] Add your own custom painting code here..
//[/UserPaint]
}
void Simple_switch::mouseDown( const MouseEvent& e )
{
if ( btn_state )
{
image_painted= cachedImage_simple_switch_st2_png;
}
else
{
image_painted= cachedImage_simple_switch_st1_png;
}
btn_state= !btn_state;
this->repaint();
}
And finally the Child_component class:
Child_component::Child_component ()
{
cachedImage_child_component_bg_png = ImageCache::getFromMemory (child_component_bg_png, child_component_bg_pngSize);
//[UserPreSize]
//[/UserPreSize]
setSize (500, 111);
//[Constructor] You can add your own custom stuff here..
//[/Constructor]
}
void Child_component::paint (Graphics& g)
{
//[UserPrePaint] Add your own custom painting code here..
//[/UserPrePaint]
g.drawImageWithin (cachedImage_child_component_bg_png,
0, 0, 500, 111,
RectanglePlacement::centred,
false);
//[UserPaint] Add your own custom painting code here..
//[/UserPaint]
}
Thank you all for the suggestions on the bool flag.