@@ -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 |
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "LedDisplay.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/LedDisplay.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ParamWidget.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/ParamWidget.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "LedDisplay.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/LedDisplay.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "MultiLightWidget.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/MultiLightWidget.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
#include "plugin.hpp" | #include "plugin.hpp" | ||||
#include "engine.hpp" | #include "engine.hpp" | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "LightWidget.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/LightWidget.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
#include "engine.hpp" | #include "engine.hpp" | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,7 +1,7 @@ | |||||
#pragma once | #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" | #include "engine.hpp" | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
#include "engine.hpp" | #include "engine.hpp" | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "CircularShadow.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/CircularShadow.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "Port.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/Port.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "WireWidget.hpp" | |||||
#include "app/common.hpp" | |||||
#include "app/WireWidget.hpp" | |||||
#include "engine.hpp" | #include "engine.hpp" | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "app/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,4 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | #include "common.hpp" | ||||
#include "string.hpp" | #include "string.hpp" | ||||
#include "nanovg.h" | #include "nanovg.h" | ||||
@@ -11,86 +10,26 @@ namespace color { | |||||
static const NVGcolor BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00); | static const NVGcolor BLACK_TRANSPARENT = nvgRGBA(0x00, 0x00, 0x00, 0x00); | ||||
static const NVGcolor BLACK = nvgRGB(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 = nvgRGB(0xff, 0xff, 0xff); | ||||
static const NVGcolor WHITE_TRANSPARENT = nvgRGB(0xff, 0xff, 0xff); | |||||
static const NVGcolor RED = nvgRGB(0xff, 0x00, 0x00); | static const NVGcolor RED = nvgRGB(0xff, 0x00, 0x00); | ||||
static const NVGcolor GREEN = nvgRGB(0x00, 0xff, 0x00); | static const NVGcolor GREEN = nvgRGB(0x00, 0xff, 0x00); | ||||
static const NVGcolor BLUE = nvgRGB(0x00, 0x00, 0xff); | 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 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 */ | /** 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 | } // namespace color | ||||
@@ -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 event | ||||
} // namespace rack | } // namespace rack |
@@ -1,7 +1,7 @@ | |||||
#include "plugin.hpp" | #include "plugin.hpp" | ||||
#include "engine.hpp" | #include "engine.hpp" | ||||
#include "app.hpp" | #include "app.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -145,7 +145,7 @@ inline Menu *createMenu() { | |||||
MenuOverlay *menuOverlay = new MenuOverlay; | MenuOverlay *menuOverlay = new MenuOverlay; | ||||
menuOverlay->addChild(o); | menuOverlay->addChild(o); | ||||
gWidgetState->rootWidget->addChild(menuOverlay); | |||||
event::gContext->rootWidget->addChild(menuOverlay); | |||||
return o; | return o; | ||||
} | } | ||||
@@ -1,6 +1,4 @@ | |||||
#pragma once | #pragma once | ||||
// Include headers that plugins will likely use, for convenience | |||||
#include "common.hpp" | #include "common.hpp" | ||||
#include "math.hpp" | #include "math.hpp" | ||||
#include "string.hpp" | #include "string.hpp" | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "Button.hpp" | |||||
#include "ui/Button.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "MenuEntry.hpp" | |||||
#include "ui/MenuEntry.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "MenuOverlay.hpp" | |||||
#include "ui/common.hpp" | |||||
#include "ui/MenuOverlay.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -15,7 +15,7 @@ struct MenuItem : MenuEntry { | |||||
void draw(NVGcontext *vg) override { | void draw(NVGcontext *vg) override { | ||||
// Get state | // 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); | Menu *parentMenu = dynamic_cast<Menu*>(parent); | ||||
if (parentMenu && parentMenu->activeEntry == this) { | if (parentMenu && parentMenu->activeEntry == this) { | ||||
state = BND_ACTIVE; | state = BND_ACTIVE; | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "TextField.hpp" | |||||
#include "ui/common.hpp" | |||||
#include "ui/TextField.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "WidgetState.hpp" | |||||
#include "ui/common.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -110,7 +110,7 @@ struct ScrollWidget : OpaqueWidget { | |||||
void onHover(event::Hover &e) override { | void onHover(event::Hover &e) override { | ||||
// Scroll with arrow keys | // Scroll with arrow keys | ||||
if (!gWidgetState->selectedWidget) { | |||||
if (!event::gContext->selectedWidget) { | |||||
float arrowSpeed = 30.0; | float arrowSpeed = 30.0; | ||||
if (windowIsShiftPressed() && windowIsModPressed()) | if (windowIsShiftPressed() && windowIsModPressed()) | ||||
arrowSpeed /= 16.0; | arrowSpeed /= 16.0; | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,6 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "WidgetState.hpp" | |||||
#include "ui/common.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -25,9 +25,9 @@ struct TextField : OpaqueWidget { | |||||
nvgScissor(vg, 0, 0, box.size.x, box.size.y); | nvgScissor(vg, 0, 0, box.size.x, box.size.y); | ||||
BNDwidgetState state; | BNDwidgetState state; | ||||
if (this == gWidgetState->selectedWidget) | |||||
if (this == event::gContext->selectedWidget) | |||||
state = BND_ACTIVE; | state = BND_ACTIVE; | ||||
else if (this == gWidgetState->hoveredWidget) | |||||
else if (this == event::gContext->hoveredWidget) | |||||
state = BND_HOVER; | state = BND_HOVER; | ||||
else | else | ||||
state = BND_DEFAULT; | state = BND_DEFAULT; | ||||
@@ -51,7 +51,7 @@ struct TextField : OpaqueWidget { | |||||
} | } | ||||
void onHover(event::Hover &e) override { | void onHover(event::Hover &e) override { | ||||
if (this == gWidgetState->draggedWidget) { | |||||
if (this == event::gContext->draggedWidget) { | |||||
int pos = getTextPosition(e.pos); | int pos = getTextPosition(e.pos); | ||||
if (pos != selection) { | if (pos != selection) { | ||||
cursor = pos; | cursor = pos; | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -1,5 +1,5 @@ | |||||
#pragma once | #pragma once | ||||
#include "common.hpp" | |||||
#include "ui/common.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -2,7 +2,7 @@ | |||||
#include "midi.hpp" | #include "midi.hpp" | ||||
#include "dsp/filter.hpp" | #include "dsp/filter.hpp" | ||||
#include "window.hpp" | #include "window.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
struct MIDICCToCVInterface : Module { | struct MIDICCToCVInterface : Module { | ||||
@@ -130,8 +130,8 @@ struct MidiCcChoice : GridChoice { | |||||
else { | else { | ||||
text = string::f("%d", module->learnedCcs[id]); | text = string::f("%d", module->learnedCcs[id]); | ||||
color.a = 1.0; | 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 { | 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) { | if (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) { | ||||
event::Deselect eDeselect; | event::Deselect eDeselect; | ||||
onDeselect(eDeselect); | onDeselect(eDeselect); | ||||
gWidgetState->selectedWidget = NULL; | |||||
event::gContext->selectedWidget = NULL; | |||||
e.target = this; | e.target = this; | ||||
} | } | ||||
} | } | ||||
@@ -1,6 +1,6 @@ | |||||
#include "Core.hpp" | #include "Core.hpp" | ||||
#include "midi.hpp" | #include "midi.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
struct MIDITriggerToCVInterface : Module { | struct MIDITriggerToCVInterface : Module { | ||||
@@ -172,8 +172,8 @@ struct MidiTrigChoice : GridChoice { | |||||
text = string::f("%s%d", noteNames[semi], oct); | text = string::f("%s%d", noteNames[semi], oct); | ||||
color.a = 1.0; | color.a = 1.0; | ||||
if (gWidgetState->selectedWidget == this) | |||||
gWidgetState->selectedWidget = NULL; | |||||
if (event::gContext->selectedWidget == this) | |||||
event::gContext->selectedWidget = NULL; | |||||
} | } | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
#include "app.hpp" | #include "app.hpp" | ||||
#include "asset.hpp" | #include "asset.hpp" | ||||
#include "window.hpp" | #include "window.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -85,7 +85,7 @@ void LedDisplayTextField::draw(NVGcontext *vg) { | |||||
NVGcolor highlightColor = color; | NVGcolor highlightColor = color; | ||||
highlightColor.a = 0.5; | highlightColor.a = 0.5; | ||||
int begin = std::min(cursor, selection); | 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, | bndIconLabelCaret(vg, textOffset.x, textOffset.y, | ||||
box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, | box.size.x - 2*textOffset.x, box.size.y - 2*textOffset.y, | ||||
-1, color, 12, text.c_str(), highlightColor, begin, end); | -1, color, 12, text.c_str(), highlightColor, begin, end); | ||||
@@ -2,7 +2,7 @@ | |||||
#include "plugin.hpp" | #include "plugin.hpp" | ||||
#include "window.hpp" | #include "window.hpp" | ||||
#include "helpers.hpp" | #include "helpers.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
#include <set> | #include <set> | ||||
#include <algorithm> | #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); | 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); | box.size.y = std::min(box.size.y, moduleScroll->box.getBottomRight().y); | ||||
gWidgetState->selectedWidget = searchField; | |||||
event::gContext->selectedWidget = searchField; | |||||
Widget::step(); | Widget::step(); | ||||
} | } | ||||
}; | }; | ||||
@@ -2,7 +2,7 @@ | |||||
#include "engine.hpp" | #include "engine.hpp" | ||||
#include "componentlibrary.hpp" | #include "componentlibrary.hpp" | ||||
#include "window.hpp" | #include "window.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -172,7 +172,7 @@ void WireWidget::draw(NVGcontext *vg) { | |||||
opacity = 1.0; | opacity = 1.0; | ||||
} | } | ||||
else { | else { | ||||
Port *hoveredPort = dynamic_cast<Port*>(gWidgetState->hoveredWidget); | |||||
Port *hoveredPort = dynamic_cast<Port*>(event::gContext->hoveredWidget); | |||||
if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort)) | if (hoveredPort && (hoveredPort == outputPort || hoveredPort == inputPort)) | ||||
opacity = 1.0; | opacity = 1.0; | ||||
} | } | ||||
@@ -38,8 +38,8 @@ static void checkVersion() { | |||||
void appInit(bool devMode) { | void appInit(bool devMode) { | ||||
gRackScene = new RackScene; | gRackScene = new RackScene; | ||||
gWidgetState = new WidgetState; | |||||
gWidgetState->rootWidget = gRackScene; | |||||
event::gContext = new event::Context; | |||||
event::gContext->rootWidget = gRackScene; | |||||
// Request latest version from server | // Request latest version from server | ||||
if (!devMode && gCheckVersion) { | if (!devMode && gCheckVersion) { | ||||
@@ -53,8 +53,8 @@ void appDestroy() { | |||||
delete gRackScene; | delete gRackScene; | ||||
gRackScene = NULL; | gRackScene = NULL; | ||||
delete gWidgetState; | |||||
gWidgetState = NULL; | |||||
delete event::gContext; | |||||
event::gContext = NULL; | |||||
} | } | ||||
@@ -15,8 +15,8 @@ | |||||
#include <pwd.h> | #include <pwd.h> | ||||
#endif | #endif | ||||
#include "rack.hpp" | |||||
#include "osdialog.h" | |||||
#include "asset.hpp" | |||||
#include "system.hpp" | |||||
namespace rack { | namespace rack { | ||||
@@ -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 |
@@ -1,13 +1,13 @@ | |||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | #include "event.hpp" | ||||
#include "widgets.hpp" | |||||
#include "widgets/Widget.hpp" | |||||
#include "logger.hpp" | #include "logger.hpp" | ||||
namespace rack { | 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 | ||||
event::Button eButton; | event::Button eButton; | ||||
eButton.pos = pos; | 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) { | if (draggedWidget) { | ||||
// event::DragMove | // event::DragMove | ||||
event::DragMove eDragMove; | event::DragMove eDragMove; | ||||
@@ -139,7 +139,7 @@ void WidgetState::handleHover(Vec pos, Vec mouseDelta) { | |||||
} | } | ||||
} | } | ||||
void WidgetState::handleLeave() { | |||||
void Context::handleLeave() { | |||||
if (hoveredWidget) { | if (hoveredWidget) { | ||||
// event::Leave | // event::Leave | ||||
event::Leave eLeave; | event::Leave eLeave; | ||||
@@ -148,7 +148,7 @@ void WidgetState::handleLeave() { | |||||
hoveredWidget = NULL; | hoveredWidget = NULL; | ||||
} | } | ||||
void WidgetState::handleScroll(Vec pos, Vec scrollDelta) { | |||||
void Context::handleScroll(Vec pos, Vec scrollDelta) { | |||||
// event::HoverScroll | // event::HoverScroll | ||||
event::HoverScroll eHoverScroll; | event::HoverScroll eHoverScroll; | ||||
eHoverScroll.pos = pos; | eHoverScroll.pos = pos; | ||||
@@ -156,7 +156,7 @@ void WidgetState::handleScroll(Vec pos, Vec scrollDelta) { | |||||
rootWidget->onHoverScroll(eHoverScroll); | 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 | ||||
event::PathDrop ePathDrop; | event::PathDrop ePathDrop; | ||||
ePathDrop.pos = pos; | ePathDrop.pos = pos; | ||||
@@ -164,7 +164,7 @@ void WidgetState::handleDrop(Vec pos, std::vector<std::string> paths) { | |||||
rootWidget->onPathDrop(ePathDrop); | rootWidget->onPathDrop(ePathDrop); | ||||
} | } | ||||
void WidgetState::handleText(Vec pos, int codepoint) { | |||||
void Context::handleText(Vec pos, int codepoint) { | |||||
if (selectedWidget) { | if (selectedWidget) { | ||||
// event::SelectText | // event::SelectText | ||||
event::SelectText eSelectText; | event::SelectText eSelectText; | ||||
@@ -181,7 +181,7 @@ void WidgetState::handleText(Vec pos, int codepoint) { | |||||
rootWidget->onHoverText(eHoverText); | 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) { | if (selectedWidget) { | ||||
// event::SelectKey | // event::SelectKey | ||||
event::SelectKey eSelectKey; | event::SelectKey eSelectKey; | ||||
@@ -204,7 +204,7 @@ void WidgetState::handleKey(Vec pos, int key, int scancode, int action, int mods | |||||
rootWidget->onHoverKey(eHoverKey); | rootWidget->onHoverKey(eHoverKey); | ||||
} | } | ||||
void WidgetState::finalizeWidget(Widget *w) { | |||||
void Context::finalizeWidget(Widget *w) { | |||||
if (hoveredWidget == w) hoveredWidget = NULL; | if (hoveredWidget == w) hoveredWidget = NULL; | ||||
if (draggedWidget == w) draggedWidget = NULL; | if (draggedWidget == w) draggedWidget = NULL; | ||||
if (dragHoveredWidget == w) dragHoveredWidget = NULL; | if (dragHoveredWidget == w) dragHoveredWidget = NULL; | ||||
@@ -212,7 +212,7 @@ void WidgetState::finalizeWidget(Widget *w) { | |||||
if (scrollWidget == w) scrollWidget = NULL; | if (scrollWidget == w) scrollWidget = NULL; | ||||
} | } | ||||
void WidgetState::handleZoom() { | |||||
void Context::handleZoom() { | |||||
// event::Zoom | // event::Zoom | ||||
event::Zoom eZoom; | event::Zoom eZoom; | ||||
rootWidget->onZoom(eZoom); | rootWidget->onZoom(eZoom); | ||||
@@ -220,7 +220,8 @@ void WidgetState::handleZoom() { | |||||
// TODO Move this elsewhere | // TODO Move this elsewhere | ||||
WidgetState *gWidgetState = NULL; | |||||
Context *gContext = NULL; | |||||
} // namespace event | |||||
} // namespace rack | } // namespace rack |
@@ -1,6 +1,6 @@ | |||||
#include "widgets.hpp" | #include "widgets.hpp" | ||||
#include "app.hpp" | #include "app.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
#include <algorithm> | #include <algorithm> | ||||
@@ -9,7 +9,7 @@ namespace rack { | |||||
Widget::~Widget() { | Widget::~Widget() { | ||||
// You should only delete orphaned widgets | // You should only delete orphaned widgets | ||||
assert(!parent); | assert(!parent); | ||||
gWidgetState->finalizeWidget(this); | |||||
event::gContext->finalizeWidget(this); | |||||
clearChildren(); | clearChildren(); | ||||
} | } | ||||
@@ -13,7 +13,7 @@ | |||||
#include "rack.hpp" | #include "rack.hpp" | ||||
#include "keyboard.hpp" | #include "keyboard.hpp" | ||||
#include "gamepad.hpp" | #include "gamepad.hpp" | ||||
#include "WidgetState.hpp" | |||||
#include "event.hpp" | |||||
#define NANOVG_GL2_IMPLEMENTATION 1 | #define NANOVG_GL2_IMPLEMENTATION 1 | ||||
// #define NANOVG_GL3_IMPLEMENTATION 1 | // #define NANOVG_GL3_IMPLEMENTATION 1 | ||||
@@ -60,7 +60,7 @@ static void mouseButtonCallback(GLFWwindow *window, int button, int action, int | |||||
} | } | ||||
#endif | #endif | ||||
gWidgetState->handleButton(gMousePos, button, action, mods); | |||||
event::gContext->handleButton(gMousePos, button, action, mods); | |||||
} | } | ||||
struct MouseButtonArguments { | struct MouseButtonArguments { | ||||
@@ -107,12 +107,12 @@ void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { | |||||
gMousePos = mousePos; | gMousePos = mousePos; | ||||
gWidgetState->handleHover(mousePos, mouseDelta); | |||||
event::gContext->handleHover(mousePos, mouseDelta); | |||||
} | } | ||||
void cursorEnterCallback(GLFWwindow* window, int entered) { | void cursorEnterCallback(GLFWwindow* window, int entered) { | ||||
if (!entered) { | if (!entered) { | ||||
gWidgetState->handleLeave(); | |||||
event::gContext->handleLeave(); | |||||
} | } | ||||
} | } | ||||
@@ -124,15 +124,15 @@ void scrollCallback(GLFWwindow *window, double x, double y) { | |||||
#endif | #endif | ||||
scrollDelta = scrollDelta.mult(50.0); | scrollDelta = scrollDelta.mult(50.0); | ||||
gWidgetState->handleScroll(gMousePos, scrollDelta); | |||||
event::gContext->handleScroll(gMousePos, scrollDelta); | |||||
} | } | ||||
void charCallback(GLFWwindow *window, unsigned int codepoint) { | 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) { | 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 | // Keyboard MIDI driver | ||||
if (!(mods & (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER))) { | 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++) { | for (int i = 0; i < count; i++) { | ||||
pathsVec.push_back(paths[i]); | pathsVec.push_back(paths[i]); | ||||
} | } | ||||
gWidgetState->handleDrop(gMousePos, pathsVec); | |||||
event::gContext->handleDrop(gMousePos, pathsVec); | |||||
} | } | ||||
void errorCallback(int error, const char *description) { | void errorCallback(int error, const char *description) { | ||||
@@ -166,7 +166,7 @@ void renderGui() { | |||||
nvgReset(gVg); | nvgReset(gVg); | ||||
nvgScale(gVg, gPixelRatio, gPixelRatio); | nvgScale(gVg, gPixelRatio, gPixelRatio); | ||||
gWidgetState->rootWidget->draw(gVg); | |||||
event::gContext->rootWidget->draw(gVg); | |||||
glViewport(0, 0, width, height); | glViewport(0, 0, width, height); | ||||
glClearColor(0.0, 0.0, 0.0, 1.0); | glClearColor(0.0, 0.0, 0.0, 1.0); | ||||
@@ -319,7 +319,7 @@ void windowRun() { | |||||
glfwGetWindowContentScale(gWindow, &pixelRatio, NULL); | glfwGetWindowContentScale(gWindow, &pixelRatio, NULL); | ||||
pixelRatio = roundf(pixelRatio); | pixelRatio = roundf(pixelRatio); | ||||
if (pixelRatio != gPixelRatio) { | if (pixelRatio != gPixelRatio) { | ||||
gWidgetState->handleZoom(); | |||||
event::gContext->handleZoom(); | |||||
gPixelRatio = pixelRatio; | gPixelRatio = pixelRatio; | ||||
} | } | ||||
@@ -330,10 +330,10 @@ void windowRun() { | |||||
glfwGetWindowSize(gWindow, &windowWidth, &windowHeight); | glfwGetWindowSize(gWindow, &windowWidth, &windowHeight); | ||||
gWindowRatio = (float)width / windowWidth; | 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 | // Step scene | ||||
gWidgetState->rootWidget->step(); | |||||
event::gContext->rootWidget->step(); | |||||
// Render | // Render | ||||
bool visible = glfwGetWindowAttrib(gWindow, GLFW_VISIBLE) && !glfwGetWindowAttrib(gWindow, GLFW_ICONIFIED); | bool visible = glfwGetWindowAttrib(gWindow, GLFW_VISIBLE) && !glfwGetWindowAttrib(gWindow, GLFW_ICONIFIED); | ||||