@@ -27,7 +27,7 @@ | |||||
#include "../jucer_JucerDocument.h" | #include "../jucer_JucerDocument.h" | ||||
#include "../jucer_UtilityFunctions.h" | #include "../jucer_UtilityFunctions.h" | ||||
#include "../../Project Saving/jucer_ResourceFile.h" | |||||
//============================================================================== | //============================================================================== | ||||
class JucerFillType | class JucerFillType | ||||
@@ -147,7 +147,7 @@ public: | |||||
case imageBrush: | case imageBrush: | ||||
{ | { | ||||
const String imageVariable ("cachedImage_" + imageResourceName + "_" + String (code.getUniqueSuffix())); | |||||
const String imageVariable ("cachedImage_" + imageResourceName.replace ("::", "_") + "_" + String (code.getUniqueSuffix())); | |||||
code.addImageResourceLoader (imageVariable, imageResourceName); | code.addImageResourceLoader (imageVariable, imageResourceName); | ||||
@@ -191,7 +191,7 @@ public: | |||||
+ ", 1=" + gradCol2.toString(); | + ", 1=" + gradCol2.toString(); | ||||
case imageBrush: | case imageBrush: | ||||
return "image: " + imageResourceName | |||||
return "image: " + imageResourceName.replaceCharacter (':', '#') | |||||
+ ", " | + ", " | ||||
+ String (imageOpacity) | + String (imageOpacity) | ||||
+ ", " | + ", " | ||||
@@ -236,7 +236,7 @@ public: | |||||
else if (toks[0] == "image") | else if (toks[0] == "image") | ||||
{ | { | ||||
mode = imageBrush; | mode = imageBrush; | ||||
imageResourceName = toks[1]; | |||||
imageResourceName = toks[1].replaceCharacter ('#', ':'); | |||||
imageOpacity = toks[2].getDoubleValue(); | imageOpacity = toks[2].getDoubleValue(); | ||||
imageAnchor= RelativePositionedRectangle(); | imageAnchor= RelativePositionedRectangle(); | ||||
imageAnchor.rect = PositionedRectangle (toks[3]); | imageAnchor.rect = PositionedRectangle (toks[3]); | ||||
@@ -340,7 +340,30 @@ private: | |||||
if (image.isNull()) | if (image.isNull()) | ||||
{ | { | ||||
if (document != nullptr) | if (document != nullptr) | ||||
image = document->getResources().getImageFromCache (imageResourceName); | |||||
{ | |||||
if (imageResourceName.contains ("::")) | |||||
{ | |||||
if (Project* project = document->getCppDocument().getProject()) | |||||
{ | |||||
ResourceFile resourceFile (*project); | |||||
for (int i = 0; i < resourceFile.getNumFiles(); ++i) | |||||
{ | |||||
const File& file = resourceFile.getFile(i); | |||||
if (imageResourceName == resourceFile.getClassName() + "::" + resourceFile.getDataVariableFor (file)) | |||||
{ | |||||
image = ImageCache::getFromFile (file); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
image = document->getResources().getImageFromCache (imageResourceName); | |||||
} | |||||
} | |||||
if (image.isNull()) | if (image.isNull()) | ||||
{ | { | ||||
@@ -25,6 +25,7 @@ | |||||
#ifndef __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__ | #ifndef __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__ | ||||
#define __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__ | #define __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__ | ||||
#include "../../Project Saving/jucer_ResourceFile.h" | |||||
//============================================================================== | //============================================================================== | ||||
/** | /** | ||||
@@ -44,12 +45,7 @@ public: | |||||
element (e), document (doc), | element (e), document (doc), | ||||
allowChoiceOfNoResource (allowChoiceOfNoResource_) | allowChoiceOfNoResource (allowChoiceOfNoResource_) | ||||
{ | { | ||||
choices.add ("-- create a new image resource -- "); | |||||
choices.add (String::empty); | |||||
if (allowChoiceOfNoResource_) | |||||
choices.add ("<< none >>"); | |||||
choices.addArray (doc.getResources().getResourceNames()); | |||||
refreshChoices(); | |||||
doc.addChangeListener (this); | doc.addChangeListener (this); | ||||
} | } | ||||
@@ -59,13 +55,7 @@ public: | |||||
element (e), document (*e->getDocument()), | element (e), document (*e->getDocument()), | ||||
allowChoiceOfNoResource (allowChoiceOfNoResource_) | allowChoiceOfNoResource (allowChoiceOfNoResource_) | ||||
{ | { | ||||
choices.add ("-- create a new image resource -- "); | |||||
choices.add (String::empty); | |||||
if (allowChoiceOfNoResource_) | |||||
choices.add ("<< none >>"); | |||||
choices.addArray (document.getResources().getResourceNames()); | |||||
refreshChoices(); | |||||
document.addChangeListener (this); | document.addChangeListener (this); | ||||
} | } | ||||
@@ -95,7 +85,7 @@ public: | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (choices[newIndex] == "<< none >>" && allowChoiceOfNoResource) | |||||
if (choices[newIndex] == getNoneText() && allowChoiceOfNoResource) | |||||
setResource (String::empty); | setResource (String::empty); | ||||
else | else | ||||
setResource (choices [newIndex]); | setResource (choices [newIndex]); | ||||
@@ -115,6 +105,36 @@ public: | |||||
refresh(); | refresh(); | ||||
} | } | ||||
void refreshChoices() | |||||
{ | |||||
choices.clear(); | |||||
choices.add ("-- create a new image resource -- "); | |||||
choices.add (String::empty); | |||||
if (allowChoiceOfNoResource) | |||||
choices.add (getNoneText()); | |||||
choices.addArray (document.getResources().getResourceNames()); | |||||
const SourceCodeDocument& cpp = document.getCppDocument(); | |||||
if (Project* project = cpp.getProject()) | |||||
{ | |||||
ResourceFile resourceFile (*project); | |||||
for (int i = 0; i < resourceFile.getNumFiles(); ++i) | |||||
{ | |||||
const File& file = resourceFile.getFile(i); | |||||
if (ImageFileFormat::findImageFormatForFileExtension(file)) | |||||
choices.add (resourceFile.getClassName() + "::" + resourceFile.getDataVariableFor (file)); | |||||
} | |||||
} | |||||
} | |||||
const char* getNoneText() noexcept { return "<< none >>"; } | |||||
protected: | protected: | ||||
mutable Component::SafePointer<ElementType> element; | mutable Component::SafePointer<ElementType> element; | ||||
JucerDocument& document; | JucerDocument& document; | ||||
@@ -100,7 +100,7 @@ public: | |||||
{ | { | ||||
if (dynamic_cast <const DrawableImage*> (getDrawable()) != 0) | if (dynamic_cast <const DrawableImage*> (getDrawable()) != 0) | ||||
{ | { | ||||
const String imageVariable ("cachedImage_" + resourceName); | |||||
const String imageVariable ("cachedImage_" + resourceName.replace ("::", "_")); | |||||
code.addImageResourceLoader (imageVariable, resourceName); | code.addImageResourceLoader (imageVariable, resourceName); | ||||
@@ -46,6 +46,8 @@ public: | |||||
String getSizeVariableFor (const File& file) const; | String getSizeVariableFor (const File& file) const; | ||||
int getNumFiles() const { return files.size(); } | int getNumFiles() const { return files.size(); } | ||||
const File& getFile (int index) const { return files.getReference (index); } | |||||
int64 getTotalDataSize() const; | int64 getTotalDataSize() const; | ||||
bool write (Array<File>& filesCreated, int maxFileSize); | bool write (Array<File>& filesCreated, int maxFileSize); | ||||