| @@ -30,7 +30,8 @@ struct Plugin { | |||||
| To guarantee uniqueness, it is a good idea to prefix the slug by your "company name" if available, e.g. "MyCompany-MyPlugin" | To guarantee uniqueness, it is a good idea to prefix the slug by your "company name" if available, e.g. "MyCompany-MyPlugin" | ||||
| */ | */ | ||||
| std::string slug; | std::string slug; | ||||
| /** Your plugin's latest version, using the guidelines at https://github.com/VCVRack/Rack/issues/266. Do not include the "v" prefix. | |||||
| /** Your plugin's latest version. | |||||
| Do not include the "v" prefix. | |||||
| */ | */ | ||||
| std::string version; | std::string version; | ||||
| /** The license type of your plugin. Use "proprietary" if all rights are reserved. If your license is in the [SPDX license list](https://spdx.org/licenses/), use its abbreviation in the "Identifier" column. | /** The license type of your plugin. Use "proprietary" if all rights are reserved. If your license is in the [SPDX license list](https://spdx.org/licenses/), use its abbreviation in the "Identifier" column. | ||||
| @@ -19,14 +19,18 @@ The bounding box of a Widget is a rectangle specified by `box` relative to their | |||||
| The appearance is defined by overriding `draw()`, and the behavior is defined by overriding `step()` and `on*()` event handlers. | The appearance is defined by overriding `draw()`, and the behavior is defined by overriding `step()` and `on*()` event handlers. | ||||
| */ | */ | ||||
| struct Widget : WeakBase { | struct Widget : WeakBase { | ||||
| /** Stores position and size */ | |||||
| /** Position relative to parent and size of widget. */ | |||||
| math::Rect box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY)); | math::Rect box = math::Rect(math::Vec(), math::Vec(INFINITY, INFINITY)); | ||||
| /** Automatically set when Widget is added as a child to another Widget */ | /** Automatically set when Widget is added as a child to another Widget */ | ||||
| Widget* parent = NULL; | Widget* parent = NULL; | ||||
| std::list<Widget*> children; | std::list<Widget*> children; | ||||
| /** Disables rendering but allow stepping */ | |||||
| /** Disables rendering but allow stepping. | |||||
| Use isVisible(), setVisible(), show(), or hide() instead of using this variable directly. | |||||
| */ | |||||
| bool visible = true; | bool visible = true; | ||||
| /** If set to true, parent will delete Widget in the next step() */ | |||||
| /** If set to true, parent will delete Widget in the next step(). | |||||
| Use requestDelete() instead of using this variable directly. | |||||
| */ | |||||
| bool requestedDelete = false; | bool requestedDelete = false; | ||||
| virtual ~Widget(); | virtual ~Widget(); | ||||
| @@ -8,15 +8,14 @@ namespace widget { | |||||
| /** A Widget with a dynamic zoom level. */ | /** A Widget with a dynamic zoom level. */ | ||||
| struct ZoomWidget : Widget { | struct ZoomWidget : Widget { | ||||
| /** Use setZoom() and getZoom() instead of using this variable directly. */ | |||||
| float zoom = 1.f; | float zoom = 1.f; | ||||
| math::Vec getRelativeOffset(math::Vec v, Widget* ancestor) override; | math::Vec getRelativeOffset(math::Vec v, Widget* ancestor) override; | ||||
| float getRelativeZoom(Widget* ancestor) override; | float getRelativeZoom(Widget* ancestor) override; | ||||
| math::Rect getViewport(math::Rect r) override; | math::Rect getViewport(math::Rect r) override; | ||||
| float getZoom(); | |||||
| void setZoom(float zoom); | void setZoom(float zoom); | ||||
| float getZoom() { | |||||
| return zoom; | |||||
| } | |||||
| void draw(const DrawArgs& args) override; | void draw(const DrawArgs& args) override; | ||||
| void drawLayer(const DrawArgs& args, int layer) override; | void drawLayer(const DrawArgs& args, int layer) override; | ||||
| @@ -29,9 +29,10 @@ namespace window { | |||||
| struct Font { | struct Font { | ||||
| NVGcontext* vg; | NVGcontext* vg; | ||||
| int handle = -1; | int handle = -1; | ||||
| ~Font(); | |||||
| /** Don't call this directly but instead use `APP->window->loadFont()` */ | /** Don't call this directly but instead use `APP->window->loadFont()` */ | ||||
| void loadFile(const std::string& filename, NVGcontext* vg); | void loadFile(const std::string& filename, NVGcontext* vg); | ||||
| ~Font(); | |||||
| /** Use `APP->window->loadFont()` instead. */ | /** Use `APP->window->loadFont()` instead. */ | ||||
| DEPRECATED static std::shared_ptr<Font> load(const std::string& filename); | DEPRECATED static std::shared_ptr<Font> load(const std::string& filename); | ||||
| }; | }; | ||||
| @@ -41,9 +42,10 @@ struct Font { | |||||
| struct Image { | struct Image { | ||||
| NVGcontext* vg; | NVGcontext* vg; | ||||
| int handle = -1; | int handle = -1; | ||||
| ~Image(); | |||||
| /** Don't call this directly but instead use `APP->window->loadImage()` */ | /** Don't call this directly but instead use `APP->window->loadImage()` */ | ||||
| void loadFile(const std::string& filename, NVGcontext* vg); | void loadFile(const std::string& filename, NVGcontext* vg); | ||||
| ~Image(); | |||||
| /** Use `APP->window->loadImage()` instead. */ | /** Use `APP->window->loadImage()` instead. */ | ||||
| DEPRECATED static std::shared_ptr<Image> load(const std::string& filename); | DEPRECATED static std::shared_ptr<Image> load(const std::string& filename); | ||||
| }; | }; | ||||
| @@ -57,10 +59,10 @@ struct Window { | |||||
| GLFWwindow* win = NULL; | GLFWwindow* win = NULL; | ||||
| NVGcontext* vg = NULL; | NVGcontext* vg = NULL; | ||||
| NVGcontext* fbVg = NULL; | NVGcontext* fbVg = NULL; | ||||
| /** The scaling ratio */ | |||||
| /** UI scaling ratio */ | |||||
| float pixelRatio = 1.f; | float pixelRatio = 1.f; | ||||
| /* The ratio between the framebuffer size and the window size reported by the OS. | |||||
| This is not equal to gPixelRatio in general. | |||||
| /** Ratio between the framebuffer size and the window size reported by the OS. | |||||
| This is not equal to pixelRatio in general. | |||||
| */ | */ | ||||
| float windowRatio = 1.f; | float windowRatio = 1.f; | ||||
| std::shared_ptr<Font> uiFont; | std::shared_ptr<Font> uiFont; | ||||
| @@ -1414,9 +1414,9 @@ NVGcolor RackWidget::getNextCableColor() { | |||||
| return color::WHITE; | return color::WHITE; | ||||
| int id = internal->nextCableColorId++; | int id = internal->nextCableColorId++; | ||||
| if (id >= settings::cableColors.size()) | |||||
| if (id >= (int) settings::cableColors.size()) | |||||
| id = 0; | id = 0; | ||||
| if (internal->nextCableColorId >= settings::cableColors.size()) | |||||
| if (internal->nextCableColorId >= (int) settings::cableColors.size()) | |||||
| internal->nextCableColorId = 0; | internal->nextCableColorId = 0; | ||||
| return settings::cableColors[id]; | return settings::cableColors[id]; | ||||
| } | } | ||||
| @@ -27,6 +27,11 @@ math::Rect ZoomWidget::getViewport(math::Rect r) { | |||||
| } | } | ||||
| float ZoomWidget::getZoom() { | |||||
| return zoom; | |||||
| } | |||||
| void ZoomWidget::setZoom(float zoom) { | void ZoomWidget::setZoom(float zoom) { | ||||
| if (zoom == this->zoom) | if (zoom == this->zoom) | ||||
| return; | return; | ||||
| @@ -30,6 +30,11 @@ namespace window { | |||||
| static const math::Vec WINDOW_SIZE_MIN = math::Vec(480, 320); | static const math::Vec WINDOW_SIZE_MIN = math::Vec(480, 320); | ||||
| Font::~Font() { | |||||
| // There is no NanoVG deleteFont() function yet, so do nothing | |||||
| } | |||||
| void Font::loadFile(const std::string& filename, NVGcontext* vg) { | void Font::loadFile(const std::string& filename, NVGcontext* vg) { | ||||
| this->vg = vg; | this->vg = vg; | ||||
| handle = nvgCreateFont(vg, filename.c_str(), filename.c_str()); | handle = nvgCreateFont(vg, filename.c_str(), filename.c_str()); | ||||
| @@ -39,13 +44,15 @@ void Font::loadFile(const std::string& filename, NVGcontext* vg) { | |||||
| } | } | ||||
| Font::~Font() { | |||||
| // There is no NanoVG deleteFont() function yet, so do nothing | |||||
| std::shared_ptr<Font> Font::load(const std::string& filename) { | |||||
| return APP->window->loadFont(filename); | |||||
| } | } | ||||
| std::shared_ptr<Font> Font::load(const std::string& filename) { | |||||
| return APP->window->loadFont(filename); | |||||
| Image::~Image() { | |||||
| // TODO What if handle is invalid? | |||||
| if (handle >= 0) | |||||
| nvgDeleteImage(vg, handle); | |||||
| } | } | ||||
| @@ -58,13 +65,6 @@ void Image::loadFile(const std::string& filename, NVGcontext* vg) { | |||||
| } | } | ||||
| Image::~Image() { | |||||
| // TODO What if handle is invalid? | |||||
| if (handle >= 0) | |||||
| nvgDeleteImage(vg, handle); | |||||
| } | |||||
| std::shared_ptr<Image> Image::load(const std::string& filename) { | std::shared_ptr<Image> Image::load(const std::string& filename) { | ||||
| return APP->window->loadImage(filename); | return APP->window->loadImage(filename); | ||||
| } | } | ||||