Prevent MomentarySwitch from randomizingtags/v0.3.2
@@ -146,6 +146,7 @@ struct ParamWidget : OpaqueWidget, QuantityWidget { | |||||
json_t *toJson(); | json_t *toJson(); | ||||
void fromJson(json_t *root); | void fromJson(json_t *root); | ||||
virtual void randomize(); | |||||
void onMouseDownOpaque(int button); | void onMouseDownOpaque(int button); | ||||
void onChange(); | void onChange(); | ||||
}; | }; | ||||
@@ -227,6 +228,8 @@ struct ToggleSwitch : virtual Switch { | |||||
/** A switch that is turned on when held */ | /** A switch that is turned on when held */ | ||||
struct MomentarySwitch : virtual Switch { | struct MomentarySwitch : virtual Switch { | ||||
/** Don't randomize state */ | |||||
void randomize() {} | |||||
void onDragStart() { | void onDragStart() { | ||||
setValue(maxValue); | setValue(maxValue); | ||||
} | } | ||||
@@ -19,6 +19,7 @@ extern GLFWwindow *gWindow; | |||||
extern NVGcontext *gVg; | extern NVGcontext *gVg; | ||||
extern std::shared_ptr<Font> gGuiFont; | extern std::shared_ptr<Font> gGuiFont; | ||||
extern float gPixelRatio; | extern float gPixelRatio; | ||||
extern bool gAllowCursorLock; | |||||
void guiInit(); | void guiInit(); | ||||
@@ -115,7 +115,7 @@ void ModuleWidget::initialize() { | |||||
void ModuleWidget::randomize() { | void ModuleWidget::randomize() { | ||||
for (ParamWidget *param : params) { | for (ParamWidget *param : params) { | ||||
param->setValue(rescalef(randomf(), 0.0, 1.0, param->minValue, param->maxValue)); | |||||
param->randomize(); | |||||
} | } | ||||
if (module) { | if (module) { | ||||
module->randomize(); | module->randomize(); | ||||
@@ -4,6 +4,7 @@ | |||||
namespace rack { | namespace rack { | ||||
json_t *ParamWidget::toJson() { | json_t *ParamWidget::toJson() { | ||||
json_t *paramJ = json_real(value); | json_t *paramJ = json_real(value); | ||||
return paramJ; | return paramJ; | ||||
@@ -13,6 +14,10 @@ void ParamWidget::fromJson(json_t *rootJ) { | |||||
setValue(json_number_value(rootJ)); | setValue(json_number_value(rootJ)); | ||||
} | } | ||||
void ParamWidget::randomize() { | |||||
setValue(rescalef(randomf(), 0.0, 1.0, minValue, maxValue)); | |||||
} | |||||
void ParamWidget::onMouseDownOpaque(int button) { | void ParamWidget::onMouseDownOpaque(int button) { | ||||
if (button == 1) { | if (button == 1) { | ||||
setValue(defaultValue); | setValue(defaultValue); | ||||
@@ -14,6 +14,7 @@ | |||||
#define BLENDISH_IMPLEMENTATION | #define BLENDISH_IMPLEMENTATION | ||||
#include "../ext/oui-blendish/blendish.h" | #include "../ext/oui-blendish/blendish.h" | ||||
#define NANOSVG_IMPLEMENTATION | #define NANOSVG_IMPLEMENTATION | ||||
#define NANOSVG_ALL_COLOR_KEYWORDS | |||||
#include "../ext/nanosvg/src/nanosvg.h" | #include "../ext/nanosvg/src/nanosvg.h" | ||||
#ifdef ARCH_MAC | #ifdef ARCH_MAC | ||||
@@ -24,9 +25,10 @@ | |||||
namespace rack { | namespace rack { | ||||
GLFWwindow *gWindow = NULL; | GLFWwindow *gWindow = NULL; | ||||
std::shared_ptr<Font> gGuiFont; | |||||
NVGcontext *gVg = NULL; | NVGcontext *gVg = NULL; | ||||
std::shared_ptr<Font> gGuiFont; | |||||
float gPixelRatio = 0.0; | float gPixelRatio = 0.0; | ||||
bool gAllowCursorLock = true; | |||||
void windowSizeCallback(GLFWwindow* window, int width, int height) { | void windowSizeCallback(GLFWwindow* window, int width, int height) { | ||||
@@ -307,15 +309,19 @@ void guiClose() { | |||||
} | } | ||||
void guiCursorLock() { | void guiCursorLock() { | ||||
if (gAllowCursorLock) { | |||||
#ifdef ARCH_MAC | #ifdef ARCH_MAC | ||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); | |||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); | |||||
#else | #else | ||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); | |||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED); | |||||
#endif | #endif | ||||
} | |||||
} | } | ||||
void guiCursorUnlock() { | void guiCursorUnlock() { | ||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); | |||||
if (gAllowCursorLock) { | |||||
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL); | |||||
} | |||||
} | } | ||||
bool guiIsModPressed() { | bool guiIsModPressed() { | ||||
@@ -1,5 +1,6 @@ | |||||
#include "settings.hpp" | #include "settings.hpp" | ||||
#include "app.hpp" | #include "app.hpp" | ||||
#include "gui.hpp" | |||||
#include "plugin.hpp" | #include "plugin.hpp" | ||||
#include <jansson.h> | #include <jansson.h> | ||||
@@ -25,6 +26,10 @@ static json_t *settingsToJson() { | |||||
json_t *tensionJ = json_real(tension); | json_t *tensionJ = json_real(tension); | ||||
json_object_set_new(rootJ, "wireTension", tensionJ); | json_object_set_new(rootJ, "wireTension", tensionJ); | ||||
// allowCursorLock | |||||
json_t *allowCursorLockJ = json_boolean(gAllowCursorLock); | |||||
json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ); | |||||
return rootJ; | return rootJ; | ||||
} | } | ||||
@@ -43,6 +48,11 @@ static void settingsFromJson(json_t *rootJ) { | |||||
json_t *tensionJ = json_object_get(rootJ, "wireTension"); | json_t *tensionJ = json_object_get(rootJ, "wireTension"); | ||||
if (tensionJ) | if (tensionJ) | ||||
dynamic_cast<RackScene*>(gScene)->toolbar->wireTensionSlider->value = json_number_value(tensionJ); | dynamic_cast<RackScene*>(gScene)->toolbar->wireTensionSlider->value = json_number_value(tensionJ); | ||||
// allowCursorLock | |||||
json_t *allowCursorLockJ = json_object_get(rootJ, "allowCursorLock"); | |||||
if (allowCursorLockJ) | |||||
gAllowCursorLock = json_is_true(allowCursorLockJ); | |||||
} | } | ||||
@@ -44,8 +44,10 @@ static void drawSVG(NVGcontext *vg, NSVGimage *svg) { | |||||
if (path->closed) | if (path->closed) | ||||
nvgClosePath(vg); | nvgClosePath(vg); | ||||
if (path->next) | |||||
nvgPathWinding(vg, NVG_HOLE); | |||||
// if () | |||||
// nvgPathWinding(vg, NVG_SOLID); | |||||
// else | |||||
// nvgPathWinding(vg, NVG_HOLE); | |||||
} | } | ||||
// Fill shape | // Fill shape | ||||