Browse Source

Ignore dynamic light/dark mode in headless builds

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.10
falkTX 2 years ago
parent
commit
930a0ca31e
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 24 additions and 0 deletions
  1. +6
    -0
      include/helpers.hpp
  2. +4
    -0
      src/custom/asset.cpp
  3. +14
    -0
      src/custom/dep.cpp

+ 6
- 0
include/helpers.hpp View File

@@ -36,9 +36,11 @@

namespace rack {

#ifndef HEADLESS
namespace asset {
void updateForcingBlackSilverScrewMode(std::string slug);
}
#endif

struct CardinalPluginModelHelper : plugin::Model {
virtual app::ModuleWidget* createModuleWidgetFromEngineLoad(engine::Module* m) = 0;
@@ -76,7 +78,9 @@ struct CardinalPluginModel : CardinalPluginModelHelper
}
tm = dynamic_cast<TModule*>(m);
}
#ifndef HEADLESS
asset::updateForcingBlackSilverScrewMode(slug);
#endif
app::ModuleWidget* const tmw = new TModuleWidget(tm);
DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(m != nullptr ? m->model->name.c_str() : "null", tmw->module == m, nullptr);
tmw->setModel(this);
@@ -91,7 +95,9 @@ struct CardinalPluginModel : CardinalPluginModelHelper
TModule* const tm = dynamic_cast<TModule*>(m);
DISTRHO_SAFE_ASSERT_RETURN(tm != nullptr, nullptr);

#ifndef HEADLESS
asset::updateForcingBlackSilverScrewMode(slug);
#endif
TModuleWidget* const tmw = new TModuleWidget(tm);
DISTRHO_SAFE_ASSERT_RETURN(tmw->module == m, nullptr);
tmw->setModel(this);


+ 4
- 0
src/custom/asset.cpp View File

@@ -31,8 +31,10 @@
namespace rack {
namespace asset {

#ifndef HEADLESS
extern bool forceBlackScrew;
extern bool forceSilverScrew;
#endif

std::string userDir; // ignored
std::string systemDir; // points to plugin resources dir (or installed/local Rack dir)
@@ -53,10 +55,12 @@ std::string user(std::string filename) {

// get system resource, trimming "res/" prefix if we are loaded as a plugin bundle
std::string system(std::string filename) {
#ifndef HEADLESS
/**/ if (forceBlackScrew && string::endsWith(filename, "/ScrewBlack.svg"))
filename = filename.substr(0, filename.size()-15) + "/./ScrewBlack.svg";
else if (forceSilverScrew && string::endsWith(filename, "/ScrewSilver.svg"))
filename = filename.substr(0, filename.size()-16) + "/./ScrewSilver.svg";
#endif
return system::join(systemDir, bundlePath.empty() ? filename : trim(filename));
}



+ 14
- 0
src/custom/dep.cpp View File

@@ -23,6 +23,7 @@
#include <string>

namespace rack {
#ifndef HEADLESS
namespace asset {
bool forceBlackScrew = false;
bool forceSilverScrew = false;
@@ -59,6 +60,7 @@ void updateForcingBlackSilverScrewMode(std::string slug) {
);
}
}
#endif
namespace settings {
bool darkMode = true;
int rateLimit = 0;
@@ -92,6 +94,7 @@ NVGcolor nvgRGBblank(const unsigned char r, const unsigned char g, const unsigne
#undef nsvgParseFromFile
#include <nanosvg.h>

#ifndef HEADLESS
enum DarkMode {
kMode21kHz,
kModeAaronStatic,
@@ -1149,12 +1152,14 @@ bool invertPaintForLightMode(const LightMode mode, NSVGshape* const shape, NSVGp
paint.color = invertColor(paint.color);
return true;
}
#endif // HEADLESS

extern "C" {
NSVGimage* nsvgParseFromFileCardinal(const char* filename, const char* units, float dpi);
void nsvgDeleteCardinal(NSVGimage*);
}

#ifndef HEADLESS
struct ExtendedNSVGimage {
NSVGimage* const handle;
NSVGimage* handleOrig;
@@ -1239,11 +1244,13 @@ void deleteExtendedNSVGimage(ExtendedNSVGimage& ext)
ext.handleOrig = nullptr;
}
}
#endif // HEADLESS

NSVGimage* nsvgParseFromFileCardinal(const char* const filename, const char* const units, const float dpi)
{
if (NSVGimage* const handle = nsvgParseFromFile(filename, units, dpi))
{
#ifndef HEADLESS
const size_t filenamelen = std::strlen(filename);

bool hasDarkMode = false;
@@ -1419,6 +1426,7 @@ postparse:
std::memcpy(handle, handleMOD, sizeof(NSVGimage));
}
}
#endif // HEADLESS

return handle;
}
@@ -1428,6 +1436,7 @@ postparse:

void nsvgDeleteCardinal(NSVGimage* const handle)
{
#ifndef HEADLESS
for (auto it = loadedDarkSVGs.begin(), end = loadedDarkSVGs.end(); it != end; ++it)
{
ExtendedNSVGimage& ext(*it);
@@ -1451,12 +1460,14 @@ void nsvgDeleteCardinal(NSVGimage* const handle)
loadedLightSVGs.erase(it);
break;
}
#endif

nsvgDelete(handle);
}

void switchDarkMode(const bool darkMode)
{
#ifndef HEADLESS
if (rack::settings::darkMode == darkMode)
return;

@@ -1477,12 +1488,14 @@ void switchDarkMode(const bool darkMode)
else if (ext.handleMOD != nullptr)
std::memcpy(ext.handle, !darkMode ? ext.handleMOD : ext.handleOrig, sizeof(NSVGimage));
}
#endif
}

namespace rack {
namespace asset {

void destroy() {
#ifndef HEADLESS
for (auto it = loadedDarkSVGs.begin(), end = loadedDarkSVGs.end(); it != end; ++it)
{
ExtendedNSVGimage& ext(*it);
@@ -1497,6 +1510,7 @@ void destroy() {

loadedDarkSVGs.clear();
loadedLightSVGs.clear();
#endif
}

}


Loading…
Cancel
Save