| @@ -2,6 +2,7 @@ | |||||
| #include <vector> | #include <vector> | ||||
| #include <jansson.h> | #include <jansson.h> | ||||
| #include "widgets.hpp" | #include "widgets.hpp" | ||||
| #include "ui.hpp" | |||||
| static const float SVG_DPI = 75.0; | static const float SVG_DPI = 75.0; | ||||
| @@ -5,7 +5,9 @@ | |||||
| #include "asset.hpp" | #include "asset.hpp" | ||||
| #include "plugin.hpp" | #include "plugin.hpp" | ||||
| #include "engine.hpp" | #include "engine.hpp" | ||||
| #include "widgets.hpp" | |||||
| #include "app.hpp" | #include "app.hpp" | ||||
| #include "ui.hpp" | |||||
| #include "componentlibrary.hpp" | #include "componentlibrary.hpp" | ||||
| @@ -0,0 +1,200 @@ | |||||
| #pragma once | |||||
| #include "widgets.hpp" | |||||
| #include "../ext/oui-blendish/blendish.h" | |||||
| namespace rack { | |||||
| struct Label : Widget { | |||||
| std::string text; | |||||
| Label() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| /** Deletes itself from parent when clicked */ | |||||
| struct MenuOverlay : OpaqueWidget { | |||||
| void step() override; | |||||
| void onMouseDown(EventMouseDown &e) override; | |||||
| void onHoverKey(EventHoverKey &e) override; | |||||
| }; | |||||
| struct MenuEntry; | |||||
| struct Menu : OpaqueWidget { | |||||
| Menu *parentMenu = NULL; | |||||
| Menu *childMenu = NULL; | |||||
| /** The entry which created the child menu */ | |||||
| MenuEntry *activeEntry = NULL; | |||||
| Menu() { | |||||
| box.size = Vec(0, 0); | |||||
| } | |||||
| ~Menu(); | |||||
| // Resizes menu and calls addChild() | |||||
| void pushChild(Widget *child) DEPRECATED { | |||||
| addChild(child); | |||||
| } | |||||
| void setChildMenu(Menu *menu); | |||||
| void step() override; | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onScroll(EventScroll &e) override; | |||||
| }; | |||||
| struct MenuEntry : OpaqueWidget { | |||||
| std::string text; | |||||
| MenuEntry() { | |||||
| box.size = Vec(0, BND_WIDGET_HEIGHT); | |||||
| } | |||||
| }; | |||||
| struct MenuLabel : MenuEntry { | |||||
| void draw(NVGcontext *vg) override; | |||||
| void step() override; | |||||
| }; | |||||
| struct MenuItem : MenuEntry { | |||||
| std::string rightText; | |||||
| void draw(NVGcontext *vg) override; | |||||
| void step() override; | |||||
| virtual Menu *createChildMenu() {return NULL;} | |||||
| void onMouseEnter(EventMouseEnter &e) override; | |||||
| void onDragDrop(EventDragDrop &e) override; | |||||
| }; | |||||
| struct WindowOverlay : OpaqueWidget { | |||||
| }; | |||||
| struct Window : OpaqueWidget { | |||||
| std::string title; | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onDragMove(EventDragMove &e) override; | |||||
| }; | |||||
| struct Button : OpaqueWidget { | |||||
| std::string text; | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| Button() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onMouseEnter(EventMouseEnter &e) override; | |||||
| void onMouseLeave(EventMouseLeave &e) override; | |||||
| void onDragStart(EventDragStart &e) override; | |||||
| void onDragEnd(EventDragEnd &e) override; | |||||
| void onDragDrop(EventDragDrop &e) override; | |||||
| }; | |||||
| struct ChoiceButton : Button { | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct RadioButton : OpaqueWidget, QuantityWidget { | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| RadioButton() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onMouseEnter(EventMouseEnter &e) override; | |||||
| void onMouseLeave(EventMouseLeave &e) override; | |||||
| void onDragDrop(EventDragDrop &e) override; | |||||
| }; | |||||
| struct Slider : OpaqueWidget, QuantityWidget { | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| Slider() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onDragStart(EventDragStart &e) override; | |||||
| void onDragMove(EventDragMove &e) override; | |||||
| void onDragEnd(EventDragEnd &e) override; | |||||
| void onMouseDown(EventMouseDown &e) override; | |||||
| }; | |||||
| /** Parent must be a ScrollWidget */ | |||||
| struct ScrollBar : OpaqueWidget { | |||||
| enum { VERTICAL, HORIZONTAL } orientation; | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| float offset = 0.0; | |||||
| float size = 0.0; | |||||
| ScrollBar() { | |||||
| box.size = Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onDragStart(EventDragStart &e) override; | |||||
| void onDragMove(EventDragMove &e) override; | |||||
| void onDragEnd(EventDragEnd &e) override; | |||||
| }; | |||||
| /** Handles a container with ScrollBar */ | |||||
| struct ScrollWidget : OpaqueWidget { | |||||
| Widget *container; | |||||
| ScrollBar *horizontalScrollBar; | |||||
| ScrollBar *verticalScrollBar; | |||||
| Vec offset; | |||||
| ScrollWidget(); | |||||
| void draw(NVGcontext *vg) override; | |||||
| void step() override; | |||||
| void onMouseMove(EventMouseMove &e) override; | |||||
| void onScroll(EventScroll &e) override; | |||||
| }; | |||||
| struct TextField : OpaqueWidget { | |||||
| std::string text; | |||||
| std::string placeholder; | |||||
| bool multiline = false; | |||||
| int begin = 0; | |||||
| int end = 0; | |||||
| TextField() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onMouseDown(EventMouseDown &e) override; | |||||
| void onFocus(EventFocus &e) override; | |||||
| void onText(EventText &e) override; | |||||
| void onKey(EventKey &e) override; | |||||
| void insertText(std::string newText); | |||||
| virtual void onTextChange() {} | |||||
| }; | |||||
| struct PasswordField : TextField { | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct ProgressBar : TransparentWidget, QuantityWidget { | |||||
| ProgressBar() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct Tooltip : Widget { | |||||
| void step() override; | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct Scene : OpaqueWidget { | |||||
| Widget *overlay = NULL; | |||||
| void setOverlay(Widget *w); | |||||
| Menu *createMenu(); | |||||
| void step() override; | |||||
| }; | |||||
| //////////////////// | |||||
| // globals | |||||
| //////////////////// | |||||
| extern Scene *gScene; | |||||
| } // namespace rack | |||||
| @@ -3,7 +3,6 @@ | |||||
| #include <memory> | #include <memory> | ||||
| #include "../ext/nanovg/src/nanovg.h" | #include "../ext/nanovg/src/nanovg.h" | ||||
| #include "../ext/oui-blendish/blendish.h" | |||||
| #include "../ext/nanosvg/src/nanosvg.h" | #include "../ext/nanosvg/src/nanosvg.h" | ||||
| #include "util/common.hpp" | #include "util/common.hpp" | ||||
| @@ -279,193 +278,6 @@ struct QuantityWidget : virtual Widget { | |||||
| std::string getText(); | std::string getText(); | ||||
| }; | }; | ||||
| //////////////////// | |||||
| // GUI widgets | |||||
| //////////////////// | |||||
| struct Label : Widget { | |||||
| std::string text; | |||||
| Label() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| /** Deletes itself from parent when clicked */ | |||||
| struct MenuOverlay : OpaqueWidget { | |||||
| void step() override; | |||||
| void onMouseDown(EventMouseDown &e) override; | |||||
| void onHoverKey(EventHoverKey &e) override; | |||||
| }; | |||||
| struct MenuEntry; | |||||
| struct Menu : OpaqueWidget { | |||||
| Menu *parentMenu = NULL; | |||||
| Menu *childMenu = NULL; | |||||
| /** The entry which created the child menu */ | |||||
| MenuEntry *activeEntry = NULL; | |||||
| Menu() { | |||||
| box.size = Vec(0, 0); | |||||
| } | |||||
| ~Menu(); | |||||
| // Resizes menu and calls addChild() | |||||
| void pushChild(Widget *child) DEPRECATED { | |||||
| addChild(child); | |||||
| } | |||||
| void setChildMenu(Menu *menu); | |||||
| void step() override; | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onScroll(EventScroll &e) override; | |||||
| }; | |||||
| struct MenuEntry : OpaqueWidget { | |||||
| std::string text; | |||||
| MenuEntry() { | |||||
| box.size = Vec(0, BND_WIDGET_HEIGHT); | |||||
| } | |||||
| }; | |||||
| struct MenuLabel : MenuEntry { | |||||
| void draw(NVGcontext *vg) override; | |||||
| void step() override; | |||||
| }; | |||||
| struct MenuItem : MenuEntry { | |||||
| std::string rightText; | |||||
| void draw(NVGcontext *vg) override; | |||||
| void step() override; | |||||
| virtual Menu *createChildMenu() {return NULL;} | |||||
| void onMouseEnter(EventMouseEnter &e) override; | |||||
| void onDragDrop(EventDragDrop &e) override; | |||||
| }; | |||||
| struct WindowOverlay : OpaqueWidget { | |||||
| }; | |||||
| struct Window : OpaqueWidget { | |||||
| std::string title; | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onDragMove(EventDragMove &e) override; | |||||
| }; | |||||
| struct Button : OpaqueWidget { | |||||
| std::string text; | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| Button() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onMouseEnter(EventMouseEnter &e) override; | |||||
| void onMouseLeave(EventMouseLeave &e) override; | |||||
| void onDragStart(EventDragStart &e) override; | |||||
| void onDragEnd(EventDragEnd &e) override; | |||||
| void onDragDrop(EventDragDrop &e) override; | |||||
| }; | |||||
| struct ChoiceButton : Button { | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct RadioButton : OpaqueWidget, QuantityWidget { | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| RadioButton() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onMouseEnter(EventMouseEnter &e) override; | |||||
| void onMouseLeave(EventMouseLeave &e) override; | |||||
| void onDragDrop(EventDragDrop &e) override; | |||||
| }; | |||||
| struct Slider : OpaqueWidget, QuantityWidget { | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| Slider() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onDragStart(EventDragStart &e) override; | |||||
| void onDragMove(EventDragMove &e) override; | |||||
| void onDragEnd(EventDragEnd &e) override; | |||||
| void onMouseDown(EventMouseDown &e) override; | |||||
| }; | |||||
| /** Parent must be a ScrollWidget */ | |||||
| struct ScrollBar : OpaqueWidget { | |||||
| enum { VERTICAL, HORIZONTAL } orientation; | |||||
| BNDwidgetState state = BND_DEFAULT; | |||||
| float offset = 0.0; | |||||
| float size = 0.0; | |||||
| ScrollBar() { | |||||
| box.size = Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onDragStart(EventDragStart &e) override; | |||||
| void onDragMove(EventDragMove &e) override; | |||||
| void onDragEnd(EventDragEnd &e) override; | |||||
| }; | |||||
| /** Handles a container with ScrollBar */ | |||||
| struct ScrollWidget : OpaqueWidget { | |||||
| Widget *container; | |||||
| ScrollBar *horizontalScrollBar; | |||||
| ScrollBar *verticalScrollBar; | |||||
| Vec offset; | |||||
| ScrollWidget(); | |||||
| void draw(NVGcontext *vg) override; | |||||
| void step() override; | |||||
| void onMouseMove(EventMouseMove &e) override; | |||||
| void onScroll(EventScroll &e) override; | |||||
| }; | |||||
| struct TextField : OpaqueWidget { | |||||
| std::string text; | |||||
| std::string placeholder; | |||||
| bool multiline = false; | |||||
| int begin = 0; | |||||
| int end = 0; | |||||
| TextField() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| void onMouseDown(EventMouseDown &e) override; | |||||
| void onFocus(EventFocus &e) override; | |||||
| void onText(EventText &e) override; | |||||
| void onKey(EventKey &e) override; | |||||
| void insertText(std::string newText); | |||||
| virtual void onTextChange() {} | |||||
| }; | |||||
| struct PasswordField : TextField { | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct ProgressBar : TransparentWidget, QuantityWidget { | |||||
| ProgressBar() { | |||||
| box.size.y = BND_WIDGET_HEIGHT; | |||||
| } | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct Tooltip : Widget { | |||||
| void step() override; | |||||
| void draw(NVGcontext *vg) override; | |||||
| }; | |||||
| struct Scene : OpaqueWidget { | |||||
| Widget *overlay = NULL; | |||||
| void setOverlay(Widget *w); | |||||
| Menu *createMenu(); | |||||
| void step() override; | |||||
| }; | |||||
| //////////////////// | //////////////////// | ||||
| // globals | // globals | ||||
| @@ -476,7 +288,5 @@ extern Widget *gDraggedWidget; | |||||
| extern Widget *gDragHoveredWidget; | extern Widget *gDragHoveredWidget; | ||||
| extern Widget *gFocusedWidget; | extern Widget *gFocusedWidget; | ||||
| extern Scene *gScene; | |||||
| } // namespace rack | } // namespace rack | ||||
| @@ -0,0 +1,9 @@ | |||||
| #include "ui.hpp" | |||||
| namespace rack { | |||||
| Scene *gScene = NULL; | |||||
| } // namespace rack | |||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| // for gVg | // for gVg | ||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| // for key codes | // for key codes | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| #include "gui.hpp" | #include "gui.hpp" | ||||
| @@ -1,4 +1,4 @@ | |||||
| #include "widgets.hpp" | |||||
| #include "ui.hpp" | |||||
| namespace rack { | namespace rack { | ||||
| @@ -2,12 +2,11 @@ | |||||
| namespace rack { | namespace rack { | ||||
| Widget *gHoveredWidget = NULL; | Widget *gHoveredWidget = NULL; | ||||
| Widget *gDraggedWidget = NULL; | Widget *gDraggedWidget = NULL; | ||||
| Widget *gDragHoveredWidget = NULL; | Widget *gDragHoveredWidget = NULL; | ||||
| Widget *gFocusedWidget = NULL; | Widget *gFocusedWidget = NULL; | ||||
| Scene *gScene = NULL; | |||||
| } // namespace rack | } // namespace rack | ||||