Browse Source

Add allowCursorLock setting for touch screens and tablets

Prevent MomentarySwitch from randomizing
tags/v0.3.2
Andrew Belt 7 years ago
parent
commit
52d41865ef
7 changed files with 34 additions and 7 deletions
  1. +3
    -0
      include/app.hpp
  2. +1
    -0
      include/gui.hpp
  3. +1
    -1
      src/app/ModuleWidget.cpp
  4. +5
    -0
      src/app/ParamWidget.cpp
  5. +10
    -4
      src/gui.cpp
  6. +10
    -0
      src/settings.cpp
  7. +4
    -2
      src/widgets/SVGWidget.cpp

+ 3
- 0
include/app.hpp View File

@@ -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);
} }


+ 1
- 0
include/gui.hpp View File

@@ -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();


+ 1
- 1
src/app/ModuleWidget.cpp View File

@@ -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();


+ 5
- 0
src/app/ParamWidget.cpp View File

@@ -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);


+ 10
- 4
src/gui.cpp View File

@@ -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() {


+ 10
- 0
src/settings.cpp View File

@@ -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);
} }






+ 4
- 2
src/widgets/SVGWidget.cpp View File

@@ -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


Loading…
Cancel
Save