SharedResourcePointer<Font> question


#1

How would I go about creating a SharedResourcePointer for a font that is created from a Typeface::Ptr?

 

I'm using a font added via IntroJucer into the BinaryData.h and am creating a typeface::ptr from it.

 

I'm trying to wrap my head around how to make this single font object accessible to all of my classes as a shared resource.

in each class I currently have to go: 

class A : public component
{
public: 
  A() {
    Typeface::Ptr js = Typeface::createSystemTypefaceFor( BinaryData::JosefinSansRegular_ttf, BinaryData::JosefinSansRegular_ttfSize );
    textFont = new Font(js);
  }
private:
  ScopedPointer<Font> textFont;
};

 

 


#2

oo, I think I figured it out:

struct MusicFont {
  MusicFont() {
    Typeface::Ptr mf = Typeface::createSystemTypefaceFor( BinaryData::MusiSync_ttf, BinaryData::MusiSync_ttfSize );
    musicFont = new Font( mf );
  }
  ScopedPointer<Font> musicFont;
};

and then in every class that needs to access that font:

SharedResourcePointer<MusicFont> musicFont;

Is that the proper method? 


#3

If you look at the docs for SharedResourcePointer, it gives an example of a class MySharedData - you'd just create a class like that, and put your font in it. Its constructor would obviously have to initialise the font.


#4

yeah, I followed that.   I guess I'm not quite understanding if using the ScopedPointer in my example above is the right way to do things.  that's the only way I know how to initialize the font with that Typeface::Ptr.   

Font musicFont ( Typeface::createSystemTypefaceFor( BinaryData::MusiSync_ttf, BinaryData::MusiSync_ttfSize ) ); doesn't make the compiler happy, even tho you have a constructor in the font class that accepts TypeFace::Ptr's

edit:

but it does like:

struct MusicFont {
  MusicFont() {
    Typeface::Ptr mf = Typeface::createSystemTypefaceFor( BinaryData::MusiSync_ttf, BinaryData::MusiSync_ttfSize );
    musicFont = Font( mf );
  }
  Font musicFont;
};