Browse Source

Rename WidgetState to event::Context, move color.hpp implementations to source

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
92951206b6
67 changed files with 239 additions and 231 deletions
  1. +0
    -38
      include/WidgetState.hpp
  2. +2
    -2
      include/app/AudioWidget.hpp
  3. +1
    -1
      include/app/CircularShadow.hpp
  4. +1
    -1
      include/app/Component.hpp
  5. +2
    -2
      include/app/Knob.hpp
  6. +1
    -1
      include/app/LedDisplay.hpp
  7. +1
    -1
      include/app/LightWidget.hpp
  8. +2
    -2
      include/app/MidiWidget.hpp
  9. +2
    -2
      include/app/ModuleLightWidget.hpp
  10. +1
    -1
      include/app/ModuleWidget.hpp
  11. +1
    -1
      include/app/MomentarySwitch.hpp
  12. +2
    -2
      include/app/MultiLightWidget.hpp
  13. +1
    -1
      include/app/ParamWidget.hpp
  14. +1
    -1
      include/app/PluginManagerWidget.hpp
  15. +1
    -1
      include/app/Port.hpp
  16. +1
    -1
      include/app/RackRail.hpp
  17. +1
    -1
      include/app/RackScene.hpp
  18. +1
    -1
      include/app/RackScrollWidget.hpp
  19. +3
    -3
      include/app/RackWidget.hpp
  20. +1
    -1
      include/app/SVGButton.hpp
  21. +2
    -2
      include/app/SVGKnob.hpp
  22. +1
    -1
      include/app/SVGPanel.hpp
  23. +2
    -2
      include/app/SVGPort.hpp
  24. +1
    -1
      include/app/SVGSlider.hpp
  25. +1
    -1
      include/app/SVGSwitch.hpp
  26. +1
    -1
      include/app/ToggleSwitch.hpp
  27. +1
    -1
      include/app/Toolbar.hpp
  28. +2
    -2
      include/app/WireContainer.hpp
  29. +1
    -1
      include/app/WireWidget.hpp
  30. +12
    -73
      include/color.hpp
  31. +26
    -0
      include/event.hpp
  32. +2
    -2
      include/helpers.hpp
  33. +0
    -2
      include/rack.hpp
  34. +1
    -1
      include/ui/Button.hpp
  35. +1
    -1
      include/ui/ChoiceButton.hpp
  36. +1
    -1
      include/ui/IconButton.hpp
  37. +1
    -1
      include/ui/Label.hpp
  38. +1
    -1
      include/ui/List.hpp
  39. +1
    -1
      include/ui/Menu.hpp
  40. +1
    -1
      include/ui/MenuEntry.hpp
  41. +3
    -3
      include/ui/MenuItem.hpp
  42. +1
    -1
      include/ui/MenuLabel.hpp
  43. +1
    -1
      include/ui/MenuOverlay.hpp
  44. +1
    -1
      include/ui/MenuSeparator.hpp
  45. +2
    -2
      include/ui/PasswordField.hpp
  46. +1
    -1
      include/ui/ProgressBar.hpp
  47. +1
    -1
      include/ui/RadioButton.hpp
  48. +1
    -1
      include/ui/Scene.hpp
  49. +3
    -3
      include/ui/ScrollWidget.hpp
  50. +1
    -1
      include/ui/SequentialLayout.hpp
  51. +1
    -1
      include/ui/Slider.hpp
  52. +5
    -5
      include/ui/TextField.hpp
  53. +1
    -1
      include/ui/Tooltip.hpp
  54. +1
    -1
      include/ui/TooltipOverlay.hpp
  55. +1
    -1
      include/ui/WindowOverlay.hpp
  56. +1
    -1
      include/ui/WindowWidget.hpp
  57. +5
    -5
      src/Core/MIDICCToCVInterface.cpp
  58. +3
    -3
      src/Core/MIDITriggerToCVInterface.cpp
  59. +2
    -2
      src/app/LedDisplay.cpp
  60. +2
    -2
      src/app/ModuleBrowser.cpp
  61. +2
    -2
      src/app/WireWidget.cpp
  62. +4
    -4
      src/app/app.cpp
  63. +2
    -2
      src/asset.cpp
  64. +82
    -0
      src/color.cpp
  65. +13
    -12
      src/event.cpp
  66. +2
    -2
      src/widgets/Widget.cpp
  67. +12
    -12
      src/window.cpp

+ 0
- 38
include/WidgetState.hpp View File

@@ -1,38 +0,0 @@
#pragma once
#include "math.hpp"
#include <vector>


namespace rack {


struct Widget;


struct WidgetState {
Widget *rootWidget = NULL;
Widget *hoveredWidget = NULL;
Widget *draggedWidget = NULL;
Widget *dragHoveredWidget = NULL;
Widget *selectedWidget = NULL;
/** For middle-click dragging */
Widget *scrollWidget = NULL;

void handleButton(Vec pos, int button, int action, int mods);
void handleHover(Vec pos, Vec mouseDelta);
void handleLeave();
void handleScroll(Vec pos, Vec scrollDelta);
void handleText(Vec pos, int codepoint);
void handleKey(Vec pos, int key, int scancode, int action, int mods);
void handleDrop(Vec pos, std::vector<std::string> paths);
void handleZoom();
/** Prepares a widget for deletion */
void finalizeWidget(Widget *w);
};


// TODO Move this elsewhere
extern WidgetState *gWidgetState;


} // namespace rack

+ 2
- 2
include/app/AudioWidget.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "LedDisplay.hpp"
#include "app/common.hpp"
#include "app/LedDisplay.hpp"


namespace rack {


+ 1
- 1
include/app/CircularShadow.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/Component.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 2
- 2
include/app/Knob.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "ParamWidget.hpp"
#include "app/common.hpp"
#include "app/ParamWidget.hpp"


namespace rack {


+ 1
- 1
include/app/LedDisplay.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/LightWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 2
- 2
include/app/MidiWidget.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "LedDisplay.hpp"
#include "app/common.hpp"
#include "app/LedDisplay.hpp"


namespace rack {


+ 2
- 2
include/app/ModuleLightWidget.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "MultiLightWidget.hpp"
#include "app/common.hpp"
#include "app/MultiLightWidget.hpp"


namespace rack {


+ 1
- 1
include/app/ModuleWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"
#include "plugin.hpp"
#include "engine.hpp"



+ 1
- 1
include/app/MomentarySwitch.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 2
- 2
include/app/MultiLightWidget.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "LightWidget.hpp"
#include "app/common.hpp"
#include "app/LightWidget.hpp"


namespace rack {


+ 1
- 1
include/app/ParamWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"
#include "engine.hpp"




+ 1
- 1
include/app/PluginManagerWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/Port.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/RackRail.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/RackScene.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/RackScrollWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 3
- 3
include/app/RackWidget.hpp View File

@@ -1,7 +1,7 @@
#pragma once
#include "common.hpp"
#include "WireWidget.hpp"
#include "WireContainer.hpp"
#include "app/common.hpp"
#include "app/WireWidget.hpp"
#include "app/WireContainer.hpp"
#include "engine.hpp"




+ 1
- 1
include/app/SVGButton.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"
#include "engine.hpp"




+ 2
- 2
include/app/SVGKnob.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "CircularShadow.hpp"
#include "app/common.hpp"
#include "app/CircularShadow.hpp"


namespace rack {


+ 1
- 1
include/app/SVGPanel.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 2
- 2
include/app/SVGPort.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "Port.hpp"
#include "app/common.hpp"
#include "app/Port.hpp"


namespace rack {


+ 1
- 1
include/app/SVGSlider.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/SVGSwitch.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/ToggleSwitch.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 1
- 1
include/app/Toolbar.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 2
- 2
include/app/WireContainer.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "WireWidget.hpp"
#include "app/common.hpp"
#include "app/WireWidget.hpp"
#include "engine.hpp"




+ 1
- 1
include/app/WireWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "app/common.hpp"


namespace rack {


+ 12
- 73
include/color.hpp View File

@@ -1,5 +1,4 @@
#pragma once

#include "common.hpp"
#include "string.hpp"
#include "nanovg.h"
@@ -11,86 +10,26 @@ namespace color {

static const NVGcolor BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00);
static const NVGcolor BLACK = nvgRGB(0x00, 0x00, 0x00);
static const NVGcolor WHITE_TRANSPARENT = nvgRGBA(0xff, 0xff, 0xff, 0x00);
static const NVGcolor WHITE = nvgRGB(0xff, 0xff, 0xff);
static const NVGcolor WHITE_TRANSPARENT = nvgRGB(0xff, 0xff, 0xff);
static const NVGcolor RED = nvgRGB(0xff, 0x00, 0x00);
static const NVGcolor GREEN = nvgRGB(0x00, 0xff, 0x00);
static const NVGcolor BLUE = nvgRGB(0x00, 0x00, 0xff);
static const NVGcolor YELLOW = nvgRGB(0xff, 0xff, 0x00);
static const NVGcolor MAGENTA = nvgRGB(0xff, 0x00, 0xff);
static const NVGcolor CYAN = nvgRGB(0x00, 0xff, 0xff);
static const NVGcolor MAGENTA = nvgRGB(0xff, 0x00, 0xff);
static const NVGcolor YELLOW = nvgRGB(0xff, 0xff, 0x00);


inline NVGcolor clip(NVGcolor a) {
for (int i = 0; i < 4; i++)
a.rgba[i] = clamp(a.rgba[i], 0.f, 1.f);
return a;
}

inline NVGcolor minus(NVGcolor a, NVGcolor b) {
for (int i = 0; i < 3; i++)
a.rgba[i] -= b.rgba[i];
return a;
}

inline NVGcolor plus(NVGcolor a, NVGcolor b) {
for (int i = 0; i < 3; i++)
a.rgba[i] += b.rgba[i];
return a;
}

inline NVGcolor mult(NVGcolor a, NVGcolor b) {
for (int i = 0; i < 3; i++)
a.rgba[i] *= b.rgba[i];
return a;
}

inline NVGcolor mult(NVGcolor a, float x) {
for (int i = 0; i < 3; i++)
a.rgba[i] *= x;
return a;
}

NVGcolor clip(NVGcolor a);
NVGcolor minus(NVGcolor a, NVGcolor b);
NVGcolor plus(NVGcolor a, NVGcolor b);
NVGcolor mult(NVGcolor a, NVGcolor b);
NVGcolor mult(NVGcolor a, float x);
/** Screen blending with alpha compositing */
inline NVGcolor screen(NVGcolor a, NVGcolor b) {
if (a.a == 0.0)
return b;
if (b.a == 0.0)
return a;

a = mult(a, a.a);
b = mult(b, b.a);
NVGcolor c = minus(plus(a, b), mult(a, b));
c.a = a.a + b.a - a.a * b.a;
c = mult(c, 1.f / c.a);
c = clip(c);
return c;
}

inline NVGcolor alpha(NVGcolor a, float alpha) {
a.a *= alpha;
return a;
}

inline NVGcolor fromHexString(std::string s) {
uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;
uint8_t a = 255;
sscanf(s.c_str(), "#%2hhx%2hhx%2hhx%2hhx", &r, &g, &b, &a);
return nvgRGBA(r, g, b, a);
}

inline std::string toHexString(NVGcolor c) {
uint8_t r = std::round(c.r * 255);
uint8_t g = std::round(c.g * 255);
uint8_t b = std::round(c.b * 255);
uint8_t a = std::round(c.a * 255);
if (a == 255)
return string::f("#%02x%02x%02x", r, g, b);
else
return string::f("#%02x%02x%02x%02x", r, g, b, a);
}
NVGcolor screen(NVGcolor a, NVGcolor b);
NVGcolor alpha(NVGcolor a, float alpha);
NVGcolor fromHexString(std::string s);
std::string toHexString(NVGcolor c);


} // namespace color


+ 26
- 0
include/event.hpp View File

@@ -207,5 +207,31 @@ struct Zoom : Event {
};


struct Context {
Widget *rootWidget = NULL;
Widget *hoveredWidget = NULL;
Widget *draggedWidget = NULL;
Widget *dragHoveredWidget = NULL;
Widget *selectedWidget = NULL;
/** For middle-click dragging */
Widget *scrollWidget = NULL;

void handleButton(Vec pos, int button, int action, int mods);
void handleHover(Vec pos, Vec mouseDelta);
void handleLeave();
void handleScroll(Vec pos, Vec scrollDelta);
void handleText(Vec pos, int codepoint);
void handleKey(Vec pos, int key, int scancode, int action, int mods);
void handleDrop(Vec pos, std::vector<std::string> paths);
void handleZoom();
/** Prepares a widget for deletion */
void finalizeWidget(Widget *w);
};


// TODO Move this into a global context class
extern Context *gContext;


} // namespace event
} // namespace rack

+ 2
- 2
include/helpers.hpp View File

@@ -1,7 +1,7 @@
#include "plugin.hpp"
#include "engine.hpp"
#include "app.hpp"
#include "WidgetState.hpp"
#include "event.hpp"


namespace rack {
@@ -145,7 +145,7 @@ inline Menu *createMenu() {
MenuOverlay *menuOverlay = new MenuOverlay;
menuOverlay->addChild(o);

gWidgetState->rootWidget->addChild(menuOverlay);
event::gContext->rootWidget->addChild(menuOverlay);
return o;
}



+ 0
- 2
include/rack.hpp View File

@@ -1,6 +1,4 @@
#pragma once

// Include headers that plugins will likely use, for convenience
#include "common.hpp"
#include "math.hpp"
#include "string.hpp"


+ 1
- 1
include/ui/Button.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/ChoiceButton.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "Button.hpp"
#include "ui/Button.hpp"


namespace rack {


+ 1
- 1
include/ui/IconButton.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/Label.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/List.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/Menu.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "MenuEntry.hpp"
#include "ui/MenuEntry.hpp"


namespace rack {


+ 1
- 1
include/ui/MenuEntry.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 3
- 3
include/ui/MenuItem.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "MenuOverlay.hpp"
#include "ui/common.hpp"
#include "ui/MenuOverlay.hpp"


namespace rack {
@@ -15,7 +15,7 @@ struct MenuItem : MenuEntry {

void draw(NVGcontext *vg) override {
// Get state
BNDwidgetState state = (gWidgetState->hoveredWidget == this) ? BND_HOVER : BND_DEFAULT;
BNDwidgetState state = (event::gContext->hoveredWidget == this) ? BND_HOVER : BND_DEFAULT;
Menu *parentMenu = dynamic_cast<Menu*>(parent);
if (parentMenu && parentMenu->activeEntry == this) {
state = BND_ACTIVE;


+ 1
- 1
include/ui/MenuLabel.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/MenuOverlay.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/MenuSeparator.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 2
- 2
include/ui/PasswordField.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "TextField.hpp"
#include "ui/common.hpp"
#include "ui/TextField.hpp"


namespace rack {


+ 1
- 1
include/ui/ProgressBar.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/RadioButton.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/Scene.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 3
- 3
include/ui/ScrollWidget.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "WidgetState.hpp"
#include "ui/common.hpp"
#include "event.hpp"


namespace rack {
@@ -110,7 +110,7 @@ struct ScrollWidget : OpaqueWidget {

void onHover(event::Hover &e) override {
// Scroll with arrow keys
if (!gWidgetState->selectedWidget) {
if (!event::gContext->selectedWidget) {
float arrowSpeed = 30.0;
if (windowIsShiftPressed() && windowIsModPressed())
arrowSpeed /= 16.0;


+ 1
- 1
include/ui/SequentialLayout.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/Slider.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 5
- 5
include/ui/TextField.hpp View File

@@ -1,6 +1,6 @@
#pragma once
#include "common.hpp"
#include "WidgetState.hpp"
#include "ui/common.hpp"
#include "event.hpp"


namespace rack {
@@ -25,9 +25,9 @@ struct TextField : OpaqueWidget {
nvgScissor(vg, 0, 0, box.size.x, box.size.y);

BNDwidgetState state;
if (this == gWidgetState->selectedWidget)
if (this == event::gContext->selectedWidget)
state = BND_ACTIVE;
else if (this == gWidgetState->hoveredWidget)
else if (this == event::gContext->hoveredWidget)
state = BND_HOVER;
else
state = BND_DEFAULT;
@@ -51,7 +51,7 @@ struct TextField : OpaqueWidget {
}

void onHover(event::Hover &e) override {
if (this == gWidgetState->draggedWidget) {
if (this == event::gContext->draggedWidget) {
int pos = getTextPosition(e.pos);
if (pos != selection) {
cursor = pos;


+ 1
- 1
include/ui/Tooltip.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/TooltipOverlay.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/WindowOverlay.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 1
- 1
include/ui/WindowWidget.hpp View File

@@ -1,5 +1,5 @@
#pragma once
#include "common.hpp"
#include "ui/common.hpp"


namespace rack {


+ 5
- 5
src/Core/MIDICCToCVInterface.cpp View File

@@ -2,7 +2,7 @@
#include "midi.hpp"
#include "dsp/filter.hpp"
#include "window.hpp"
#include "WidgetState.hpp"
#include "event.hpp"


struct MIDICCToCVInterface : Module {
@@ -130,8 +130,8 @@ struct MidiCcChoice : GridChoice {
else {
text = string::f("%d", module->learnedCcs[id]);
color.a = 1.0;
if (gWidgetState->selectedWidget == this)
gWidgetState->selectedWidget = NULL;
if (event::gContext->selectedWidget == this)
event::gContext->selectedWidget = NULL;
}
}

@@ -159,11 +159,11 @@ struct MidiCcChoice : GridChoice {
}

void onSelectKey(event::SelectKey &e) override {
if (gWidgetState->selectedWidget == this) {
if (event::gContext->selectedWidget == this) {
if (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) {
event::Deselect eDeselect;
onDeselect(eDeselect);
gWidgetState->selectedWidget = NULL;
event::gContext->selectedWidget = NULL;
e.target = this;
}
}


+ 3
- 3
src/Core/MIDITriggerToCVInterface.cpp View File

@@ -1,6 +1,6 @@
#include "Core.hpp"
#include "midi.hpp"
#include "WidgetState.hpp"
#include "event.hpp"


struct MIDITriggerToCVInterface : Module {
@@ -172,8 +172,8 @@ struct MidiTrigChoice : GridChoice {
text = string::f("%s%d", noteNames[semi], oct);
color.a = 1.0;

if (gWidgetState->selectedWidget == this)
gWidgetState->selectedWidget = NULL;
if (event::gContext->selectedWidget == this)
event::gContext->selectedWidget = NULL;
}
}



+ 2
- 2
src/app/LedDisplay.cpp View File

@@ -1,7 +1,7 @@
#include "app.hpp"
#include "asset.hpp"
#include "window.hpp"
#include "WidgetState.hpp"
#include "event.hpp"


namespace rack {
@@ -85,7 +85,7 @@ void LedDisplayTextField::draw(NVGcontext *vg) {
NVGcolor highlightColor = color;
highlightColor.a = 0.5;
int begin = std::min(cursor, selection);
int end = (this == gWidgetState->selectedWidget) ? std::max(cursor, selection) : -1;
int end = (this == event::gContext->selectedWidget) ? std::max(cursor, selection) : -1;
bndIconLabelCaret(vg, textOffset.x, textOffset.y,
box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y,
-1, color, 12, text.c_str(), highlightColor, begin, end);


+ 2
- 2
src/app/ModuleBrowser.cpp View File

@@ -2,7 +2,7 @@
#include "plugin.hpp"
#include "window.hpp"
#include "helpers.hpp"
#include "WidgetState.hpp"
#include "event.hpp"
#include <set>
#include <algorithm>

@@ -430,7 +430,7 @@ struct ModuleBrowser : OpaqueWidget {
moduleScroll->box.size.y = std::min(box.size.y - moduleScroll->box.pos.y, moduleList->box.size.y);
box.size.y = std::min(box.size.y, moduleScroll->box.getBottomRight().y);

gWidgetState->selectedWidget = searchField;
event::gContext->selectedWidget = searchField;
Widget::step();
}
};


+ 2
- 2
src/app/WireWidget.cpp View File

@@ -2,7 +2,7 @@
#include "engine.hpp"
#include "componentlibrary.hpp"
#include "window.hpp"
#include "WidgetState.hpp"
#include "event.hpp"


namespace rack {
@@ -172,7 +172,7 @@ void WireWidget::draw(NVGcontext *vg) {
opacity = 1.0;
}
else {
Port *hoveredPort = dynamic_cast<Port*>(gWidgetState->hoveredWidget);
Port *hoveredPort = dynamic_cast<Port*>(event::gContext->hoveredWidget);
if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort))
opacity = 1.0;
}


+ 4
- 4
src/app/app.cpp View File

@@ -38,8 +38,8 @@ static void checkVersion() {
void appInit(bool devMode) {
gRackScene = new RackScene;

gWidgetState = new WidgetState;
gWidgetState->rootWidget = gRackScene;
event::gContext = new event::Context;
event::gContext->rootWidget = gRackScene;

// Request latest version from server
if (!devMode && gCheckVersion) {
@@ -53,8 +53,8 @@ void appDestroy() {
delete gRackScene;
gRackScene = NULL;

delete gWidgetState;
gWidgetState = NULL;
delete event::gContext;
event::gContext = NULL;
}




+ 2
- 2
src/asset.cpp View File

@@ -15,8 +15,8 @@
#include <pwd.h>
#endif

#include "rack.hpp"
#include "osdialog.h"
#include "asset.hpp"
#include "system.hpp"


namespace rack {


+ 82
- 0
src/color.cpp View File

@@ -0,0 +1,82 @@
#include "color.hpp"
#include "math.hpp"


namespace rack {
namespace color {


NVGcolor clip(NVGcolor a) {
for (int i = 0; i < 4; i++)
a.rgba[i] = clamp(a.rgba[i], 0.f, 1.f);
return a;
}

NVGcolor minus(NVGcolor a, NVGcolor b) {
for (int i = 0; i < 3; i++)
a.rgba[i] -= b.rgba[i];
return a;
}

NVGcolor plus(NVGcolor a, NVGcolor b) {
for (int i = 0; i < 3; i++)
a.rgba[i] += b.rgba[i];
return a;
}

NVGcolor mult(NVGcolor a, NVGcolor b) {
for (int i = 0; i < 3; i++)
a.rgba[i] *= b.rgba[i];
return a;
}

NVGcolor mult(NVGcolor a, float x) {
for (int i = 0; i < 3; i++)
a.rgba[i] *= x;
return a;
}

/** Screen blending with alpha compositing */
NVGcolor screen(NVGcolor a, NVGcolor b) {
if (a.a == 0.f)
return b;
if (b.a == 0.f)
return a;

a = mult(a, a.a);
b = mult(b, b.a);
NVGcolor c = minus(plus(a, b), mult(a, b));
c.a = a.a + b.a - a.a * b.a;
c = mult(c, 1.f / c.a);
c = clip(c);
return c;
}

NVGcolor alpha(NVGcolor a, float alpha) {
a.a *= alpha;
return a;
}

NVGcolor fromHexString(std::string s) {
uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;
uint8_t a = 255;
sscanf(s.c_str(), "#%2hhx%2hhx%2hhx%2hhx", &r, &g, &b, &a);
return nvgRGBA(r, g, b, a);
}

std::string toHexString(NVGcolor c) {
uint8_t r = std::round(c.r * 255);
uint8_t g = std::round(c.g * 255);
uint8_t b = std::round(c.b * 255);
uint8_t a = std::round(c.a * 255);
if (a == 255)
return string::f("#%02x%02x%02x", r, g, b);
else
return string::f("#%02x%02x%02x%02x", r, g, b, a);
}


} // namespace network
} // namespace rack

src/WidgetState.cpp → src/event.cpp View File

@@ -1,13 +1,13 @@
#include "WidgetState.hpp"
#include "event.hpp"
#include "widgets.hpp"
#include "widgets/Widget.hpp"
#include "logger.hpp"


namespace rack {
namespace event {


void WidgetState::handleButton(Vec pos, int button, int action, int mods) {
void Context::handleButton(Vec pos, int button, int action, int mods) {
// event::Button
event::Button eButton;
eButton.pos = pos;
@@ -74,7 +74,7 @@ void WidgetState::handleButton(Vec pos, int button, int action, int mods) {
}


void WidgetState::handleHover(Vec pos, Vec mouseDelta) {
void Context::handleHover(Vec pos, Vec mouseDelta) {
if (draggedWidget) {
// event::DragMove
event::DragMove eDragMove;
@@ -139,7 +139,7 @@ void WidgetState::handleHover(Vec pos, Vec mouseDelta) {
}
}

void WidgetState::handleLeave() {
void Context::handleLeave() {
if (hoveredWidget) {
// event::Leave
event::Leave eLeave;
@@ -148,7 +148,7 @@ void WidgetState::handleLeave() {
hoveredWidget = NULL;
}

void WidgetState::handleScroll(Vec pos, Vec scrollDelta) {
void Context::handleScroll(Vec pos, Vec scrollDelta) {
// event::HoverScroll
event::HoverScroll eHoverScroll;
eHoverScroll.pos = pos;
@@ -156,7 +156,7 @@ void WidgetState::handleScroll(Vec pos, Vec scrollDelta) {
rootWidget->onHoverScroll(eHoverScroll);
}

void WidgetState::handleDrop(Vec pos, std::vector<std::string> paths) {
void Context::handleDrop(Vec pos, std::vector<std::string> paths) {
// event::PathDrop
event::PathDrop ePathDrop;
ePathDrop.pos = pos;
@@ -164,7 +164,7 @@ void WidgetState::handleDrop(Vec pos, std::vector<std::string> paths) {
rootWidget->onPathDrop(ePathDrop);
}

void WidgetState::handleText(Vec pos, int codepoint) {
void Context::handleText(Vec pos, int codepoint) {
if (selectedWidget) {
// event::SelectText
event::SelectText eSelectText;
@@ -181,7 +181,7 @@ void WidgetState::handleText(Vec pos, int codepoint) {
rootWidget->onHoverText(eHoverText);
}

void WidgetState::handleKey(Vec pos, int key, int scancode, int action, int mods) {
void Context::handleKey(Vec pos, int key, int scancode, int action, int mods) {
if (selectedWidget) {
// event::SelectKey
event::SelectKey eSelectKey;
@@ -204,7 +204,7 @@ void WidgetState::handleKey(Vec pos, int key, int scancode, int action, int mods
rootWidget->onHoverKey(eHoverKey);
}

void WidgetState::finalizeWidget(Widget *w) {
void Context::finalizeWidget(Widget *w) {
if (hoveredWidget == w) hoveredWidget = NULL;
if (draggedWidget == w) draggedWidget = NULL;
if (dragHoveredWidget == w) dragHoveredWidget = NULL;
@@ -212,7 +212,7 @@ void WidgetState::finalizeWidget(Widget *w) {
if (scrollWidget == w) scrollWidget = NULL;
}

void WidgetState::handleZoom() {
void Context::handleZoom() {
// event::Zoom
event::Zoom eZoom;
rootWidget->onZoom(eZoom);
@@ -220,7 +220,8 @@ void WidgetState::handleZoom() {


// TODO Move this elsewhere
WidgetState *gWidgetState = NULL;
Context *gContext = NULL;


} // namespace event
} // namespace rack

+ 2
- 2
src/widgets/Widget.cpp View File

@@ -1,6 +1,6 @@
#include "widgets.hpp"
#include "app.hpp"
#include "WidgetState.hpp"
#include "event.hpp"
#include <algorithm>


@@ -9,7 +9,7 @@ namespace rack {
Widget::~Widget() {
// You should only delete orphaned widgets
assert(!parent);
gWidgetState->finalizeWidget(this);
event::gContext->finalizeWidget(this);
clearChildren();
}



+ 12
- 12
src/window.cpp View File

@@ -13,7 +13,7 @@
#include "rack.hpp"
#include "keyboard.hpp"
#include "gamepad.hpp"
#include "WidgetState.hpp"
#include "event.hpp"

#define NANOVG_GL2_IMPLEMENTATION 1
// #define NANOVG_GL3_IMPLEMENTATION 1
@@ -60,7 +60,7 @@ static void mouseButtonCallback(GLFWwindow *window, int button, int action, int
}
#endif

gWidgetState->handleButton(gMousePos, button, action, mods);
event::gContext->handleButton(gMousePos, button, action, mods);
}

struct MouseButtonArguments {
@@ -107,12 +107,12 @@ void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {

gMousePos = mousePos;

gWidgetState->handleHover(mousePos, mouseDelta);
event::gContext->handleHover(mousePos, mouseDelta);
}

void cursorEnterCallback(GLFWwindow* window, int entered) {
if (!entered) {
gWidgetState->handleLeave();
event::gContext->handleLeave();
}
}

@@ -124,15 +124,15 @@ void scrollCallback(GLFWwindow *window, double x, double y) {
#endif
scrollDelta = scrollDelta.mult(50.0);

gWidgetState->handleScroll(gMousePos, scrollDelta);
event::gContext->handleScroll(gMousePos, scrollDelta);
}

void charCallback(GLFWwindow *window, unsigned int codepoint) {
gWidgetState->handleText(gMousePos, codepoint);
event::gContext->handleText(gMousePos, codepoint);
}

void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
gWidgetState->handleKey(gMousePos, key, scancode, action, mods);
event::gContext->handleKey(gMousePos, key, scancode, action, mods);

// Keyboard MIDI driver
if (!(mods & (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER))) {
@@ -150,7 +150,7 @@ void dropCallback(GLFWwindow *window, int count, const char **paths) {
for (int i = 0; i < count; i++) {
pathsVec.push_back(paths[i]);
}
gWidgetState->handleDrop(gMousePos, pathsVec);
event::gContext->handleDrop(gMousePos, pathsVec);
}

void errorCallback(int error, const char *description) {
@@ -166,7 +166,7 @@ void renderGui() {

nvgReset(gVg);
nvgScale(gVg, gPixelRatio, gPixelRatio);
gWidgetState->rootWidget->draw(gVg);
event::gContext->rootWidget->draw(gVg);

glViewport(0, 0, width, height);
glClearColor(0.0, 0.0, 0.0, 1.0);
@@ -319,7 +319,7 @@ void windowRun() {
glfwGetWindowContentScale(gWindow, &pixelRatio, NULL);
pixelRatio = roundf(pixelRatio);
if (pixelRatio != gPixelRatio) {
gWidgetState->handleZoom();
event::gContext->handleZoom();
gPixelRatio = pixelRatio;
}

@@ -330,10 +330,10 @@ void windowRun() {
glfwGetWindowSize(gWindow, &windowWidth, &windowHeight);
gWindowRatio = (float)width / windowWidth;

gWidgetState->rootWidget->box.size = Vec(width, height).div(gPixelRatio);
event::gContext->rootWidget->box.size = Vec(width, height).div(gPixelRatio);

// Step scene
gWidgetState->rootWidget->step();
event::gContext->rootWidget->step();

// Render
bool visible = glfwGetWindowAttrib(gWindow, GLFW_VISIBLE) && !glfwGetWindowAttrib(gWindow, GLFW_ICONIFIED);


Loading…
Cancel
Save