Browse Source

Add "cableColors" setting.

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
d6488601d1
3 changed files with 36 additions and 14 deletions
  1. +3
    -0
      include/settings.hpp
  2. +7
    -12
      src/app/CableWidget.cpp
  3. +26
    -2
      src/settings.cpp

+ 3
- 0
include/settings.hpp View File

@@ -2,6 +2,8 @@
#include "common.hpp" #include "common.hpp"
#include "math.hpp" #include "math.hpp"
#include "plugin/Model.hpp" #include "plugin/Model.hpp"
#include "color.hpp"
#include <set>
#include <jansson.h> #include <jansson.h>




@@ -37,6 +39,7 @@ extern bool frameRateSync;
extern bool skipLoadOnLaunch; extern bool skipLoadOnLaunch;
extern std::string patchPath; extern std::string patchPath;
extern std::set<plugin::Model*> favoriteModels; extern std::set<plugin::Model*> favoriteModels;
extern std::vector<NVGcolor> cableColors;


json_t *toJson(); json_t *toJson();
void fromJson(json_t *rootJ); void fromJson(json_t *rootJ);


+ 7
- 12
src/app/CableWidget.cpp View File

@@ -80,20 +80,15 @@ static void drawCable(NVGcontext *vg, math::Vec pos1, math::Vec pos2, NVGcolor c
} }




static const NVGcolor cableColors[] = {
nvgRGB(0xc9, 0xb7, 0x0e), // yellow
nvgRGB(0xc9, 0x18, 0x47), // red
nvgRGB(0x0c, 0x8e, 0x15), // green
nvgRGB(0x09, 0x86, 0xad), // blue
};


CableWidget::CableWidget() { CableWidget::CableWidget() {
int id = APP->scene->rack->nextCableColorId++;
APP->scene->rack->nextCableColorId %= LENGTHOF(cableColors);
color = cableColors[id];

cable = new engine::Cable; cable = new engine::Cable;

color = color::BLACK_TRANSPARENT;
if (!settings::cableColors.empty()) {
int id = APP->scene->rack->nextCableColorId++;
APP->scene->rack->nextCableColorId %= settings::cableColors.size();
color = settings::cableColors[id];
}
} }


CableWidget::~CableWidget() { CableWidget::~CableWidget() {


+ 26
- 2
src/settings.cpp View File

@@ -34,7 +34,13 @@ float frameRateLimit = 70.0;
bool frameRateSync = true; bool frameRateSync = true;
bool skipLoadOnLaunch = false; bool skipLoadOnLaunch = false;
std::string patchPath; std::string patchPath;
std::set<plugin::Model*> favoriteModels;
std::set<plugin::Model*> favoriteModels = {};
std::vector<NVGcolor> cableColors = {
nvgRGB(0xc9, 0xb7, 0x0e), // yellow
nvgRGB(0x0c, 0x8e, 0x15), // green
nvgRGB(0xc9, 0x18, 0x47), // red
nvgRGB(0x09, 0x86, 0xad), // blue
};




json_t *toJson() { json_t *toJson() {
@@ -91,6 +97,13 @@ json_t *toJson() {
} }
json_object_set_new(rootJ, "favoriteModels", favoriteModelsJ); json_object_set_new(rootJ, "favoriteModels", favoriteModelsJ);


json_t *cableColorsJ = json_array();
for (NVGcolor cableColor : cableColors) {
std::string colorStr = color::toHexString(cableColor);
json_array_append_new(cableColorsJ, json_string(colorStr.c_str()));
}
json_object_set_new(rootJ, "cableColors", cableColorsJ);

return rootJ; return rootJ;
} }


@@ -177,7 +190,6 @@ void fromJson(json_t *rootJ) {
if (patchPathJ) if (patchPathJ)
patchPath = json_string_value(patchPathJ); patchPath = json_string_value(patchPathJ);



json_t *favoriteModelsJ = json_object_get(rootJ, "favoriteModels"); json_t *favoriteModelsJ = json_object_get(rootJ, "favoriteModels");
// Legacy: "favorites" was defined under "moduleBrowser" until 1.0. // Legacy: "favorites" was defined under "moduleBrowser" until 1.0.
if (!favoriteModelsJ) { if (!favoriteModelsJ) {
@@ -186,6 +198,7 @@ void fromJson(json_t *rootJ) {
favoriteModelsJ = json_object_get(rootJ, "favorites"); favoriteModelsJ = json_object_get(rootJ, "favorites");
} }
if (favoriteModelsJ) { if (favoriteModelsJ) {
favoriteModels.clear();
size_t i; size_t i;
json_t *favoriteJ; json_t *favoriteJ;
json_array_foreach(favoriteModelsJ, i, favoriteJ) { json_array_foreach(favoriteModelsJ, i, favoriteJ) {
@@ -201,6 +214,17 @@ void fromJson(json_t *rootJ) {
favoriteModels.insert(model); favoriteModels.insert(model);
} }
} }

json_t *cableColorsJ = json_object_get(rootJ, "cableColors");
if (cableColorsJ) {
cableColors.clear();
size_t i;
json_t *cableColorJ;
json_array_foreach(cableColorsJ, i, cableColorJ) {
std::string colorStr = json_string_value(cableColorJ);
cableColors.push_back(color::fromHexString(colorStr));
}
}
} }


void save(const std::string &path) { void save(const std::string &path) {


Loading…
Cancel
Save