Browse Source

Add ResizeHandle to Scene.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
fa2f3d0234
3 changed files with 54 additions and 5 deletions
  1. +2
    -0
      include/window.hpp
  2. +35
    -4
      src/app/Scene.cpp
  3. +17
    -1
      src/window.cpp

+ 2
- 0
include/window.hpp View File

@@ -60,6 +60,8 @@ struct Window {

Window();
~Window();
math::Vec getSize();
void setSize(math::Vec size);
void run();
void step();
/** Takes a screenshot of the screen and saves it to a PNG file. */


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

@@ -19,10 +19,6 @@ namespace rack {
namespace app {


struct Scene::Internal {
};


struct FrameRateWidget : widget::TransparentWidget {
void draw(const DrawArgs& args) override {
std::string text = string::f("%.2lf Hz", 1.0 / APP->window->getLastFrameDuration());
@@ -31,6 +27,35 @@ struct FrameRateWidget : widget::TransparentWidget {
};


struct ResizeHandle : widget::OpaqueWidget {
math::Vec size;

void draw(const DrawArgs& args) override {
nvgBeginPath(args.vg);
nvgMoveTo(args.vg, box.size.x, box.size.y);
nvgLineTo(args.vg, 0, box.size.y);
nvgLineTo(args.vg, box.size.x, 0);
nvgClosePath(args.vg);
nvgFillColor(args.vg, nvgRGBAf(1, 1, 1, 0.15));
nvgFill(args.vg);
}

void onDragStart(const DragStartEvent& e) override {
size = APP->window->getSize();
}

void onDragMove(const DragMoveEvent& e) override {
size = size.plus(e.mouseDelta);
APP->window->setSize(size.round());
}
};


struct Scene::Internal {
ResizeHandle* resizeHandle;
};


Scene::Scene() {
internal = new Internal;

@@ -54,6 +79,10 @@ Scene::Scene() {
// frameRateWidget->box.size = math::Vec(80.0, 30.0);
// frameRateWidget->hide();
// addChild(frameRateWidget);

internal->resizeHandle = new ResizeHandle;
internal->resizeHandle->box.size = math::Vec(15, 15);
addChild(internal->resizeHandle);
}

Scene::~Scene() {
@@ -73,6 +102,8 @@ void Scene::step() {

// frameRateWidget->box.pos.x = box.size.x - frameRateWidget->box.size.x;

internal->resizeHandle->box.pos = box.size.minus(internal->resizeHandle->box.size);

// Resize owned descendants
menuBar->box.size.x = box.size.x;
rackScroll->box.size = box.size.minus(rackScroll->box.pos);


+ 17
- 1
src/window.cpp View File

@@ -26,6 +26,9 @@
namespace rack {


static const math::Vec minWindowSize = math::Vec(640, 480);


void Font::loadFile(const std::string& filename, NVGcontext* vg) {
this->vg = vg;
handle = nvgCreateFont(vg, filename.c_str(), filename.c_str());
@@ -240,7 +243,7 @@ Window::Window() {
glfwGetWindowContentScale(win, &contentScale, NULL);
INFO("Window content scale: %f", contentScale);

glfwSetWindowSizeLimits(win, 640, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);
glfwSetWindowSizeLimits(win, minWindowSize.x, minWindowSize.y, GLFW_DONT_CARE, GLFW_DONT_CARE);
if (settings::windowSize.isZero()) {
glfwMaximizeWindow(win);
}
@@ -342,6 +345,19 @@ Window::~Window() {
}


math::Vec Window::getSize() {
int width, height;
glfwGetWindowSize(win, &width, &height);
return math::Vec(width, height);
}


void Window::setSize(math::Vec size) {
size = size.max(minWindowSize);
glfwSetWindowSize(win, size.x, size.y);
}


void Window::run() {
internal->frame = 0;
while (!glfwWindowShouldClose(win)) {


Loading…
Cancel
Save