Here’s some code I’m using for my NewLookAndFeel class and also UserSettings class. This is very handy, as its created only once, taking less memory compared to a multi-memory-variable code. All my PNG files get added to the NewLookAndFeel class. So, when the Plugin loads, I just check if it was loaded already, otherwise, I fill up the Image* variables. (Background = new Image(…)
Header:
[code]//-----------------------------------------------------------------------------------------------------------
class JUCE_API NewLookAndFeel : public LookAndFeel, DeletedAtShutdown
{
public:
NewLookAndFeel();
~NewLookAndFeel();
juce_DeclareSingleton (NewLookAndFeel,false)
(…)
static void drawImageSquare(Graphics& g,Image** images,int x,int y,int width,int height,float opacity);
// Extra Variables //
Image* Background[9];
//
bool didLoadSkin;
};[/code]
CPP:
[code]//-----------------------------------------------------------------------------------------------------------
NewLookAndFeel::NewLookAndFeel()
{
didLoadSkin = false;
}
//-----------------------------------------------------------------------------------------------------------
NewLookAndFeel::~NewLookAndFeel()
{
setDefaultLookAndFeel (0);
for (int x=0; x<9; x++) deleteAndZero(Background[x]);
didLoadSkin = false;
clearSingletonInstance();
}
//-----------------------------------------------------------------------------------------------------------
void NewLookAndFeel::drawImageSquare(Graphics& g,Image** images,int x,int y,int width,int height,float opacity)
{
g.setTiledImageFill(*images[4],x+images[3]->getWidth(),y+images[1]->getHeight(),opacity);
g.fillRect(x+images[3]->getWidth(),y+images[1]->getHeight(),width-images[3]->getWidth()-images[5]->getWidth(), height-images[1]->getHeight()-images[7]->getHeight());
g.setTiledImageFill(*images[1],x+images[0]->getWidth(),y,opacity);
g.fillRect(x+images[0]->getWidth(),y,width-images[0]->getWidth()-images[2]->getWidth(),images[1]->getHeight());
g.setTiledImageFill(*images[7],x+images[6]->getWidth(),y+height-images[7]->getHeight(),opacity);
g.fillRect(x+images[6]->getWidth(),y+height-images[7]->getHeight(),width-images[6]->getWidth()-images[8]->getWidth(),images[7]->getHeight());
g.setTiledImageFill(*images[3],x,y+images[0]->getHeight(),opacity);
g.fillRect(x,y+images[0]->getHeight(),images[3]->getWidth(),height-images[0]->getHeight()-images[6]->getHeight());
g.setTiledImageFill(*images[5],x+width-images[5]->getWidth(),y,opacity);
g.fillRect(x+width-images[5]->getWidth(),y+images[2]->getHeight(),images[5]->getWidth(),height-images[2]->getHeight()-images[8]->getHeight());
g.setTiledImageFill(*images[0],x,y,opacity);
g.fillRect(x,y,images[0]->getWidth(),images[0]->getHeight());
g.setTiledImageFill(*images[2],x+width-images[2]->getWidth(),y,opacity);
g.fillRect(x+width-images[2]->getWidth(),y,images[2]->getWidth(),images[2]->getHeight());
g.setTiledImageFill(*images[6],x,y+height-images[6]->getHeight(),opacity);
g.fillRect(x,y+height-images[6]->getHeight(),images[6]->getWidth(),images[6]->getHeight());
g.setTiledImageFill(*images[8],x+width-images[8]->getWidth(),y+height-images[8]->getHeight(),opacity);
g.fillRect(x+width-images[8]->getWidth(),y+height-images[8]->getHeight(),images[8]->getWidth(),images[8]->getHeight());
}
juce_ImplementSingleton (NewLookAndFeel)[/code]