commit 117daf8fe70684f7aed350971e33a3664e08dfbc
parent f090d6e922344cc8c5c5b0cff1860148e28e50c4
Author: Adam M <aemalone@gmail.com>
Date: Thu, 7 Nov 2019 11:10:29 -0600
Add JW license, left resize handle
Diffstat:
2 files changed, 101 insertions(+), 46 deletions(-)
diff --git a/src/ComputerscareBlank.cpp b/src/ComputerscareBlank.cpp
@@ -16,19 +16,17 @@ const int numOutputs = 16;
struct ComputerscareBlank : Module {
int counter = 0;
std::string path;
- float width=8 * 15;
- float height= 380;
+ float width = 120;
+ float height = 380;
ComputerscareSVGPanel* panelRef;
enum ParamIds {
-
NUM_PARAMS
-
};
enum InputIds {
NUM_INPUTS
};
enum OutputIds {
- NUM_OUTPUTS
+ NUM_OUTPUTS
};
enum LightIds {
NUM_LIGHTS
@@ -62,13 +60,16 @@ struct ComputerscareBlank : Module {
this->path = path;
}
+ void setWidth(float w) {
+ this->width = w;
+ printf("setWidth width:%f\n", this->width);
+ }
json_t *dataToJson() override {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "path", json_string(path.c_str()));
- json_object_set_new(rootJ, "width", json_real(width));
- json_object_set_new(rootJ, "height", json_real(height));
+ //json_object_set_new(rootJ, "width", json_real(width));
return rootJ;
}
@@ -78,13 +79,9 @@ struct ComputerscareBlank : Module {
path = json_string_value(pathJ);
setPath(path);
}
- json_t *widthJ = json_object_get(rootJ, "width");
- if (widthJ)
- width = json_number_value(widthJ);
-
- json_t *heightJ = json_object_get(rootJ, "height");
- if (heightJ)
- height = json_number_value(heightJ);
+ /*json_t *widthJ = json_object_get(rootJ, "width");
+ if (widthJ)
+ this->setWidth(json_number_value(widthJ));*/
}
};
@@ -117,11 +114,11 @@ struct PNGDisplay : TransparentWidget {
nvgBeginPath(args.vg);
//if (module->width>0 && module->height>0)
- //nvgScale(args.vg, width/module->width, height/module->height);
- NVGpaint imgPaint = nvgImagePattern(args.vg, 0, 0, module->width,module->height, 0, img, 1.0f);
- nvgRect(args.vg, 0, 0, module->width, module->height);
- nvgFillPaint(args.vg, imgPaint);
- nvgFill(args.vg);
+ //nvgScale(args.vg, width/module->width, height/module->height);
+ NVGpaint imgPaint = nvgImagePattern(args.vg, 0, 0, module->width, module->height, 0, img, 1.0f);
+ nvgRect(args.vg, 0, 0, module->width, module->height);
+ nvgFillPaint(args.vg, imgPaint);
+ nvgFill(args.vg);
nvgClosePath(args.vg);
}
}
@@ -130,36 +127,40 @@ struct ComputerscareBlankWidget : ModuleWidget {
ComputerscareBlankWidget(ComputerscareBlank *module) {
setModule(module);
- this->blankModule=module;
- box.size = Vec(module->width, module->height);
- //setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareKnolyPobsPanel.svg")));
- box.size = Vec(module->width,module->height);
+ if (module) {
+ this->blankModule = module;
+ printf("width:%f\n", module->width);
+ box.size = Vec(module->width, module->height);
+ } else {
+ box.size = Vec(8 * 15, 380);
+ }
{
ComputerscareSVGPanel *panel = new ComputerscareSVGPanel();
panel->box.size = box.size;
panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareKnolyPobsPanel.svg")));
-
- this->panel=panel;
- //module->panelRef = panel;
-
+ this->panel = panel;
addChild(panel);
-
}
+ if (module) {
+ {
+ PNGDisplay *pngDisplay = new PNGDisplay();
+ pngDisplay->module = module;
+ pngDisplay->box.pos = Vec(0, 0);
- {
- PNGDisplay *pngDisplay = new PNGDisplay();
- pngDisplay->module = module;
- pngDisplay->box.pos = Vec(0, 0);
- pngDisplay->box.size = Vec(module->width, module->height);
- this->pngDisplay=pngDisplay;
- addChild(pngDisplay);
+ pngDisplay->box.size = Vec( module->width , module->height );
+
+ this->pngDisplay = pngDisplay;
+ addChild(pngDisplay);
+ }
}
+ ComputerscareResizeHandle *leftHandle = new ComputerscareResizeHandle();
- ComputerscareResizeHandle *rightHandle = new ComputerscareResizeHandle();
- rightHandle->right = true;
- this->rightHandle = rightHandle;
- addChild(rightHandle);
+ ComputerscareResizeHandle *rightHandle = new ComputerscareResizeHandle();
+ rightHandle->right = true;
+ this->rightHandle = rightHandle;
+ addChild(leftHandle);
+ addChild(rightHandle);
}
@@ -168,7 +169,7 @@ struct ComputerscareBlankWidget : ModuleWidget {
menu->addChild(new MenuEntry);
- LoadScriptItem* loadScriptItem = createMenuItem<LoadScriptItem>("Load image (PNG)");
+ LoadScriptItem* loadScriptItem = createMenuItem<LoadScriptItem>("Load image");
loadScriptItem->module = module;
menu->addChild(loadScriptItem);
@@ -179,17 +180,37 @@ struct ComputerscareBlankWidget : ModuleWidget {
PNGDisplay *pngDisplay;
ComputerscareSVGPanel *panel;
TransparentWidget *display;
+ ComputerscareResizeHandle *leftHandle;
ComputerscareResizeHandle *rightHandle;
SmallLetterDisplay* smallLetterDisplay;
+ json_t *toJson() override;
+ void fromJson(json_t *rootJ) override;
};
void ComputerscareBlankWidget::step() {
- blankModule->width=box.size.x;
+ if (module) {
+ if (box.size.x != blankModule->width) {
+ blankModule->setWidth(box.size.x);
+
+ panel->box.size = box.size;
+ //display->box.size = Vec(box.size.x, box.size.y);
+ pngDisplay->box.size.x = box.size.x;
+ rightHandle->box.pos.x = box.size.x - rightHandle->box.size.x;
+ }
+ ModuleWidget::step();
+ }
+}
+json_t *ComputerscareBlankWidget::toJson() {
+ json_t *rootJ = ModuleWidget::toJson();
+ json_object_set_new(rootJ, "width", json_real(box.size.x));
+ return rootJ;
+}
+
+void ComputerscareBlankWidget::fromJson(json_t *rootJ) {
+ ModuleWidget::fromJson(rootJ);
+ json_t *widthJ = json_object_get(rootJ, "width");
+ if (widthJ)
+ box.size.x = json_number_value(widthJ);
- panel->box.size = box.size;
- //display->box.size = Vec(box.size.x, box.size.y);
- pngDisplay->box.size.x = box.size.x;
- rightHandle->box.pos.x = box.size.x - rightHandle->box.size.x;
- ModuleWidget::step();
}
Model *modelComputerscareBlank = createModel<ComputerscareBlank, ComputerscareBlankWidget>("computerscare-blank");
diff --git a/src/ComputerscareResizableHandle.hpp b/src/ComputerscareResizableHandle.hpp
@@ -1,3 +1,37 @@
+//copied from JW Modules https://github.com/jeremywen/JW-Modules/blob/master/src/JWResizableHandle.hpp
+
+/*
+BSD 3-Clause License
+
+Copyright (c) 2017, Jeremy Wentworth
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
#pragma once
#include "rack.hpp"