Skip to content

Commit a5edb59

Browse files
committed
Shared
1 parent 6d214c6 commit a5edb59

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

demo/source/core/SharedObjects.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ SharedObjects::SharedObjects() :
1616
fullscreen.setValue (false);
1717

1818
using namespace BinaryData;
19-
lato = std::make_unique<FontFamily> ("Lato", LatoRegular_ttf, LatoRegular_ttfSize);
19+
lato = std::make_shared<FontFamily> ("Lato", LatoRegular_ttf, LatoRegular_ttfSize);
2020
jassert (lato != nullptr && lato->isValid());
2121

22-
lato->regular.thin = Typeface::createSystemTypefaceFor (LatoThin_ttf, LatoThin_ttfSize);
23-
lato->regular.light = Typeface::createSystemTypefaceFor (LatoLight_ttf, LatoLight_ttfSize);
24-
lato->regular.bold = Typeface::createSystemTypefaceFor (LatoBold_ttf, LatoBold_ttfSize);
25-
lato->regular.black = Typeface::createSystemTypefaceFor (LatoBlack_ttf, LatoBlack_ttfSize);
26-
lato->italic.thin = Typeface::createSystemTypefaceFor (LatoThinItalic_ttf, LatoThin_ttfSize);
27-
lato->italic.light = Typeface::createSystemTypefaceFor (LatoLightItalic_ttf, LatoLightItalic_ttfSize);
28-
lato->italic.normal = Typeface::createSystemTypefaceFor (LatoItalic_ttf, LatoItalic_ttfSize);
29-
lato->italic.bold = Typeface::createSystemTypefaceFor (LatoBoldItalic_ttf, LatoBoldItalic_ttfSize);
30-
lato->italic.black = Typeface::createSystemTypefaceFor (LatoBlackItalic_ttf, LatoBlackItalic_ttfSize);
31-
32-
defaultFamily = lato.get();
22+
lato->regular.thin = Typeface::createSystemTypefaceFor (LatoThin_ttf, LatoThin_ttfSize);
23+
lato->regular.light = Typeface::createSystemTypefaceFor (LatoLight_ttf, LatoLight_ttfSize);
24+
lato->regular.bold = Typeface::createSystemTypefaceFor (LatoBold_ttf, LatoBold_ttfSize);
25+
lato->regular.black = Typeface::createSystemTypefaceFor (LatoBlack_ttf, LatoBlack_ttfSize);
26+
lato->italic.thin = Typeface::createSystemTypefaceFor (LatoThinItalic_ttf, LatoThin_ttfSize);
27+
lato->italic.light = Typeface::createSystemTypefaceFor (LatoLightItalic_ttf, LatoLightItalic_ttfSize);
28+
lato->italic.normal = Typeface::createSystemTypefaceFor (LatoItalic_ttf, LatoItalic_ttfSize);
29+
lato->italic.bold = Typeface::createSystemTypefaceFor (LatoBoldItalic_ttf, LatoBoldItalic_ttfSize);
30+
lato->italic.black = Typeface::createSystemTypefaceFor (LatoBlackItalic_ttf, LatoBlackItalic_ttfSize);
31+
defaultFamily = lato;
32+
33+
threadPool = std::make_shared<ThreadPool>();
34+
imageFormatManager = std::make_shared<ImageFormatManager> (threadPool);
35+
imageFormatManager->registerBasicFormats();
3336
}
3437

3538
SharedObjects::~SharedObjects()

demo/source/core/SharedObjects.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ class SharedObjects final : public Value::Listener
9292

9393
Value fullscreen;
9494

95-
std::unique_ptr<FontFamily> lato;
96-
FontFamily* defaultFamily = nullptr;
95+
std::shared_ptr<FontFamily> lato, defaultFamily;
96+
97+
std::shared_ptr<ThreadPool> threadPool;
98+
std::shared_ptr<ImageFormatManager> imageFormatManager;
9799

98100
private:
99101
//==============================================================================

demo/source/demos/ImageDemo.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ class ImageDemo final : public DemoBase,
66
public:
77
/** */
88
ImageDemo (SharedObjects& sharedObjs) :
9-
DemoBase (sharedObjs, NEEDS_TRANS ("Image Formats"))
9+
DemoBase (sharedObjs, NEEDS_TRANS ("Image Formats")),
10+
imageFormatManager (sharedObjs.imageFormatManager)
1011
{
11-
imageFormatManager.registerBasicFormats();
12-
1312
SafePointer sp (this);
1413

1514
open.onClick = [this, sp]()
@@ -25,7 +24,7 @@ class ImageDemo final : public DemoBase,
2524

2625
fileChooser = std::make_unique<FileChooser> (TRANS ("Find an image to load."),
2726
File::getSpecialLocation (File::userPicturesDirectory),
28-
imageFormatManager.getWildcardForAllFormats());
27+
imageFormatManager->getWildcardForAllFormats());
2928

3029
fileChooser->launchAsync (FileBrowserComponent::openMode | FileBrowserComponent::canSelectFiles,
3130
[sp] (const FileChooser& chooser)
@@ -64,15 +63,15 @@ class ImageDemo final : public DemoBase,
6463
*/
6564
void setImage (const File& file)
6665
{
67-
setImage (imageFormatManager.loadFrom (file));
66+
setImage (imageFormatManager->loadFrom (file));
6867
}
6968

7069
/** Changes the currently displayed with one from the given URL.
7170
If the given image fails to load, the underlying image component will be cleared.
7271
*/
7372
void setImage (const URL& url)
7473
{
75-
setImage (imageFormatManager.loadFrom (url));
74+
setImage (imageFormatManager->loadFrom (url));
7675
}
7776

7877
//==============================================================================
@@ -105,7 +104,7 @@ class ImageDemo final : public DemoBase,
105104
{
106105
for (const auto& path : files)
107106
if (const File file (path); file.existsAsFile())
108-
if (imageFormatManager.findFormatForFile (File (path)) != nullptr)
107+
if (imageFormatManager->findFormatForFile (File (path)) != nullptr)
109108
return true;
110109

111110
return false;
@@ -117,7 +116,7 @@ class ImageDemo final : public DemoBase,
117116
for (const auto& path : files)
118117
{
119118
const File file (path);
120-
if (file.existsAsFile() && imageFormatManager.findFormatForFile (file) != nullptr)
119+
if (file.existsAsFile() && imageFormatManager->findFormatForFile (file) != nullptr)
121120
{
122121
setImage (file);
123122
return;
@@ -129,7 +128,7 @@ class ImageDemo final : public DemoBase,
129128
void textDropped (const String& text, int, int) override
130129
{
131130
if (isPossiblyBase64 (text))
132-
setImage (imageFormatManager.fromBase64 (text));
131+
setImage (imageFormatManager->fromBase64 (text));
133132
}
134133

135134
void updateWithNewTranslations() override
@@ -140,7 +139,7 @@ class ImageDemo final : public DemoBase,
140139

141140
private:
142141
//==============================================================================
143-
ImageFormatManager imageFormatManager;
142+
std::shared_ptr<ImageFormatManager> imageFormatManager;
144143
HighQualityImageComponent imageComponent;
145144
TextButton open;
146145
std::unique_ptr<FileChooser> fileChooser;

0 commit comments

Comments
 (0)