1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

Projucer: Enforce that Icons instances are created from files

This commit is contained in:
reuk 2025-07-22 12:15:00 +01:00
parent 217e7ab444
commit cfbe853f69
No known key found for this signature in database
7 changed files with 59 additions and 55 deletions

View file

@ -1632,19 +1632,6 @@ Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.
String Project::Item::getID() const { return state [Ids::ID]; }
void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
std::unique_ptr<Drawable> Project::Item::loadAsImageFile() const
{
const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
if (! mml.lockWasGained())
return nullptr;
if (isValid())
return Drawable::createFromImageFile (getFile());
return {};
}
Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
{
Item group (project, ValueTree (Ids::GROUP), isModuleCode);

View file

@ -453,9 +453,6 @@ public:
void setID (const String& newID);
Item findItemWithID (const String& targetId) const; // (recursive search)
String getImageFileID() const;
std::unique_ptr<Drawable> loadAsImageFile() const;
//==============================================================================
Value getNameValue();
String getName() const;

View file

@ -1424,15 +1424,15 @@ private:
{
const auto icons = getIcons();
if (icons.big != nullptr && icons.small != nullptr)
if (icons.getBig() != nullptr && icons.getSmall() != nullptr)
{
auto step = jmax (icons.big->getWidth(), icons.big->getHeight()) / 8;
auto step = jmax (icons.getBig()->getWidth(), icons.getBig()->getHeight()) / 8;
writeIcon (folder.getChildFile ("drawable-xhdpi/icon.png"), build_tools::getBestIconForSize (icons, step * 8, false));
writeIcon (folder.getChildFile ("drawable-hdpi/icon.png"), build_tools::getBestIconForSize (icons, step * 6, false));
writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), build_tools::getBestIconForSize (icons, step * 4, false));
writeIcon (folder.getChildFile ("drawable-ldpi/icon.png"), build_tools::getBestIconForSize (icons, step * 3, false));
}
else if (auto* icon = (icons.big != nullptr ? icons.big.get() : icons.small.get()))
else if (auto* icon = (icons.getBig() != nullptr ? icons.getBig() : icons.getSmall()))
{
writeIcon (folder.getChildFile ("drawable-mdpi/icon.png"), build_tools::rescaleImageForIcon (*icon, icon->getWidth()));
}
@ -1829,7 +1829,7 @@ private:
{
const auto icons = getIcons();
if (icons.big != nullptr || icons.small != nullptr)
if (icons.getBig() != nullptr || icons.getSmall() != nullptr)
app->setAttribute ("android:icon", "@drawable/icon");
}

View file

@ -869,12 +869,18 @@ void ProjectExporter::createDefaultConfigs()
build_tools::Icons ProjectExporter::getIcons() const
{
const auto loadIcon = [this] (auto id)
const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
if (! mml.lockWasGained())
return {};
const auto getFile = [this] (auto id)
{
return project.getMainGroup().findItemWithID (settings[id]).loadAsImageFile();
return project.getMainGroup().findItemWithID (settings[id]).getFile();
};
return { loadIcon (Ids::smallIcon), loadIcon (Ids::bigIcon) };
return build_tools::Icons::fromFilesSmallAndBig (getFile (Ids::smallIcon),
getFile (Ids::bigIcon));
}
//==============================================================================