Browse Source

Added BrowserOverlay to contain ModuleBrowser.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
38a7f6da22
2 changed files with 44 additions and 19 deletions
  1. +44
    -18
      src/app/ModuleBrowser.cpp
  2. +0
    -1
      src/app/Scene.cpp

+ 44
- 18
src/app/ModuleBrowser.cpp View File

@@ -23,7 +23,36 @@ namespace rack {
static std::set<Model*> sFavoriteModels;


struct ModuleBrowser;
struct BrowserOverlay : OpaqueWidget {
void step() override {
box = parent->box.zeroPos();
OpaqueWidget::step();
}

void onButton(const event::Button &e) override {
OpaqueWidget::onButton(e);
if (e.getConsumed() != this)
return;

if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
this->visible = false;
}
}

void onHoverKey(const event::HoverKey &e) override {
if (e.action == GLFW_PRESS) {
switch (e.key) {
case GLFW_KEY_ESCAPE: {
this->visible = false;
e.consume(this);
} break;
}
}

if (!e.getConsumed())
OpaqueWidget::onHoverKey(e);
}
};


struct ModuleBox : OpaqueWidget {
@@ -153,6 +182,8 @@ struct ModuleBrowser : OpaqueWidget {
}

void step() override {
box = parent->box.zeroPos().grow(math::Vec(-50, -50));

sidebar->box.size.y = box.size.y;

moduleScroll->box.pos.x = sidebar->box.size.x;
@@ -168,22 +199,10 @@ struct ModuleBrowser : OpaqueWidget {
bndMenuBackground(ctx.vg, 0.0, 0.0, box.size.x, box.size.y, 0);
Widget::draw(ctx);
}
};

void onHoverKey(const event::HoverKey &e) override {
if (e.action == GLFW_PRESS) {
switch (e.key) {
case GLFW_KEY_ESCAPE: {
// Close menu
this->visible = false;
e.consume(this);
} break;
}
}

if (!e.getConsumed())
OpaqueWidget::onHoverKey(e);
}
};
// Implementations to resolve dependencies


void ModuleBox::onButton(const event::Button &e) {
@@ -194,9 +213,10 @@ void ModuleBox::onButton(const event::Button &e) {
app()->scene->rackWidget->addModuleAtMouse(moduleWidget);
// This is a bit nonstandard/unsupported usage, but pretend the moduleWidget was clicked so it can be dragged in the RackWidget
// e.consume(moduleWidget);

// Close Module Browser
ModuleBrowser *moduleBrowser = getAncestorOfType<ModuleBrowser>();
moduleBrowser->visible = false;
BrowserOverlay *overlay = getAncestorOfType<BrowserOverlay>();
overlay->visible = false;

// Push ModuleAdd history action
history::ModuleAdd *h = new history::ModuleAdd;
@@ -209,8 +229,14 @@ void ModuleBox::onButton(const event::Button &e) {

// Global functions


Widget *moduleBrowserCreate() {
return new ModuleBrowser;
BrowserOverlay *overlay = new BrowserOverlay;

ModuleBrowser *browser = new ModuleBrowser;
overlay->addChild(browser);

return overlay;
}

json_t *moduleBrowserToJson() {


+ 0
- 1
src/app/Scene.cpp View File

@@ -53,7 +53,6 @@ void Scene::step() {
OpaqueWidget::step();

zoomWidget->box.size = rackWidget->box.size.mult(zoomWidget->zoom);
moduleBrowser->box.size = box.size;

// Autosave every 15 seconds
int frame = app()->window->frame;


Loading…
Cancel
Save