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();
void fromJson(json_t *root);
virtual void randomize();
void onMouseDownOpaque(int button);
void onChange();
};
@@ -227,6 +228,8 @@ struct ToggleSwitch : virtual Switch {

/** A switch that is turned on when held */
struct MomentarySwitch : virtual Switch {
/** Don't randomize state */
void randomize() {}
void onDragStart() {
setValue(maxValue);
}


+ 1
- 0
include/gui.hpp View File

@@ -19,6 +19,7 @@ extern GLFWwindow *gWindow;
extern NVGcontext *gVg;
extern std::shared_ptr<Font> gGuiFont;
extern float gPixelRatio;
extern bool gAllowCursorLock;


void guiInit();


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

@@ -115,7 +115,7 @@ void ModuleWidget::initialize() {

void ModuleWidget::randomize() {
for (ParamWidget *param : params) {
param->setValue(rescalef(randomf(), 0.0, 1.0, param->minValue, param->maxValue));
param->randomize();
}
if (module) {
module->randomize();


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

@@ -4,6 +4,7 @@

namespace rack {


json_t *ParamWidget::toJson() {
json_t *paramJ = json_real(value);
return paramJ;
@@ -13,6 +14,10 @@ void ParamWidget::fromJson(json_t *rootJ) {
setValue(json_number_value(rootJ));
}

void ParamWidget::randomize() {
setValue(rescalef(randomf(), 0.0, 1.0, minValue, maxValue));
}

void ParamWidget::onMouseDownOpaque(int button) {
if (button == 1) {
setValue(defaultValue);


+ 10
- 4
src/gui.cpp View File

@@ -14,6 +14,7 @@
#define BLENDISH_IMPLEMENTATION
#include "../ext/oui-blendish/blendish.h"
#define NANOSVG_IMPLEMENTATION
#define NANOSVG_ALL_COLOR_KEYWORDS
#include "../ext/nanosvg/src/nanosvg.h"

#ifdef ARCH_MAC
@@ -24,9 +25,10 @@
namespace rack {

GLFWwindow *gWindow = NULL;
std::shared_ptr<Font> gGuiFont;
NVGcontext *gVg = NULL;
std::shared_ptr<Font> gGuiFont;
float gPixelRatio = 0.0;
bool gAllowCursorLock = true;


void windowSizeCallback(GLFWwindow* window, int width, int height) {
@@ -307,15 +309,19 @@ void guiClose() {
}

void guiCursorLock() {
if (gAllowCursorLock) {
#ifdef ARCH_MAC
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
#else
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
#endif
}
}

void guiCursorUnlock() {
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
if (gAllowCursorLock) {
glfwSetInputMode(gWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
}

bool guiIsModPressed() {


+ 10
- 0
src/settings.cpp View File

@@ -1,5 +1,6 @@
#include "settings.hpp"
#include "app.hpp"
#include "gui.hpp"
#include "plugin.hpp"
#include <jansson.h>

@@ -25,6 +26,10 @@ static json_t *settingsToJson() {
json_t *tensionJ = json_real(tension);
json_object_set_new(rootJ, "wireTension", tensionJ);

// allowCursorLock
json_t *allowCursorLockJ = json_boolean(gAllowCursorLock);
json_object_set_new(rootJ, "allowCursorLock", allowCursorLockJ);

return rootJ;
}

@@ -43,6 +48,11 @@ static void settingsFromJson(json_t *rootJ) {
json_t *tensionJ = json_object_get(rootJ, "wireTension");
if (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)
nvgClosePath(vg);

if (path->next)
nvgPathWinding(vg, NVG_HOLE);
// if ()
// nvgPathWinding(vg, NVG_SOLID);
// else
// nvgPathWinding(vg, NVG_HOLE);
}

// Fill shape


Loading…
Cancel
Save