mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-14 00:14:18 +00:00
Introjucer: added ability to use BinaryData resources as images in the old GUI editor.
This commit is contained in:
parent
5054b4959a
commit
dc79ef6094
4 changed files with 65 additions and 20 deletions
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include "../jucer_JucerDocument.h"
|
||||
#include "../jucer_UtilityFunctions.h"
|
||||
|
||||
#include "../../Project Saving/jucer_ResourceFile.h"
|
||||
|
||||
//==============================================================================
|
||||
class JucerFillType
|
||||
|
|
@ -147,7 +147,7 @@ public:
|
|||
|
||||
case imageBrush:
|
||||
{
|
||||
const String imageVariable ("cachedImage_" + imageResourceName + "_" + String (code.getUniqueSuffix()));
|
||||
const String imageVariable ("cachedImage_" + imageResourceName.replace ("::", "_") + "_" + String (code.getUniqueSuffix()));
|
||||
|
||||
code.addImageResourceLoader (imageVariable, imageResourceName);
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ public:
|
|||
+ ", 1=" + gradCol2.toString();
|
||||
|
||||
case imageBrush:
|
||||
return "image: " + imageResourceName
|
||||
return "image: " + imageResourceName.replaceCharacter (':', '#')
|
||||
+ ", "
|
||||
+ String (imageOpacity)
|
||||
+ ", "
|
||||
|
|
@ -236,7 +236,7 @@ public:
|
|||
else if (toks[0] == "image")
|
||||
{
|
||||
mode = imageBrush;
|
||||
imageResourceName = toks[1];
|
||||
imageResourceName = toks[1].replaceCharacter ('#', ':');
|
||||
imageOpacity = toks[2].getDoubleValue();
|
||||
imageAnchor= RelativePositionedRectangle();
|
||||
imageAnchor.rect = PositionedRectangle (toks[3]);
|
||||
|
|
@ -340,7 +340,30 @@ private:
|
|||
if (image.isNull())
|
||||
{
|
||||
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())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#ifndef __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__
|
||||
#define __JUCER_IMAGERESOURCEPROPERTY_JUCEHEADER__
|
||||
|
||||
#include "../../Project Saving/jucer_ResourceFile.h"
|
||||
|
||||
//==============================================================================
|
||||
/**
|
||||
|
|
@ -44,12 +45,7 @@ public:
|
|||
element (e), document (doc),
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -59,13 +55,7 @@ public:
|
|||
element (e), document (*e->getDocument()),
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +85,7 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
if (choices[newIndex] == "<< none >>" && allowChoiceOfNoResource)
|
||||
if (choices[newIndex] == getNoneText() && allowChoiceOfNoResource)
|
||||
setResource (String::empty);
|
||||
else
|
||||
setResource (choices [newIndex]);
|
||||
|
|
@ -115,6 +105,36 @@ public:
|
|||
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:
|
||||
mutable Component::SafePointer<ElementType> element;
|
||||
JucerDocument& document;
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public:
|
|||
{
|
||||
if (dynamic_cast <const DrawableImage*> (getDrawable()) != 0)
|
||||
{
|
||||
const String imageVariable ("cachedImage_" + resourceName);
|
||||
const String imageVariable ("cachedImage_" + resourceName.replace ("::", "_"));
|
||||
|
||||
code.addImageResourceLoader (imageVariable, resourceName);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ public:
|
|||
String getSizeVariableFor (const File& file) const;
|
||||
|
||||
int getNumFiles() const { return files.size(); }
|
||||
const File& getFile (int index) const { return files.getReference (index); }
|
||||
|
||||
int64 getTotalDataSize() const;
|
||||
|
||||
bool write (Array<File>& filesCreated, int maxFileSize);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue