Browse Source

Add Widget::onPathDrop() event, added dragging patches to window to load

them
tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
093fa99474
5 changed files with 37 additions and 1 deletions
  1. +1
    -0
      include/app.hpp
  2. +1
    -0
      include/widgets.hpp
  3. +12
    -0
      src/app/RackScene.cpp
  4. +10
    -1
      src/gui.cpp
  5. +13
    -0
      src/widgets/Widget.cpp

+ 1
- 0
include/app.hpp View File

@@ -366,6 +366,7 @@ struct RackScene : Scene {
void step() override;
void draw(NVGcontext *vg) override;
Widget *onHoverKey(Vec pos, int key) override;
bool onPathDrop(Vec pos, const std::list<std::string>& paths) override;
};

////////////////////


+ 1
- 0
include/widgets.hpp View File

@@ -147,6 +147,7 @@ struct Widget {
virtual void onDragEnter(Widget *origin) {}
virtual void onDragLeave(Widget *origin) {}
virtual void onDragDrop(Widget *origin) {}
virtual bool onPathDrop(Vec pos, const std::list<std::string>& paths);

virtual void onAction() {}
virtual void onChange() {}


+ 12
- 0
src/app/RackScene.cpp View File

@@ -118,5 +118,17 @@ Widget *RackScene::onHoverKey(Vec pos, int key) {
}


bool RackScene::onPathDrop(Vec pos, const std::list<std::string>& paths) {
if (paths.size() >= 1) {
const std::string& firstPath = paths.front();
if (extractExtension(firstPath) == "vcv") {
gRackWidget->loadPatch(firstPath);
return true;
}
}
return false;
}



} // namespace rack

+ 10
- 1
src/gui.cpp View File

@@ -203,7 +203,7 @@ void charCallback(GLFWwindow *window, unsigned int codepoint) {
}
}

void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
// onFocusKey
if (gFocusedWidget && gFocusedWidget->onFocusKey(key))
@@ -213,6 +213,14 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
}
}

void dropCallback(GLFWwindow *window, int count, const char **paths) {
std::list<std::string> pathsList;
for (int i = 0; i < count; i++) {
pathsList.push_back(paths[i]);
}
gScene->onPathDrop(gMousePos, pathsList);
}

void errorCallback(int error, const char *description) {
fprintf(stderr, "GLFW error %d: %s\n", error, description);
}
@@ -272,6 +280,7 @@ void guiInit() {
glfwSetScrollCallback(gWindow, scrollCallback);
glfwSetCharCallback(gWindow, charCallback);
glfwSetKeyCallback(gWindow, keyCallback);
glfwSetDropCallback(gWindow, dropCallback);

// Set up GLEW
glewExperimental = GL_TRUE;


+ 13
- 0
src/widgets/Widget.cpp View File

@@ -184,6 +184,19 @@ Widget *Widget::onScroll(Vec pos, Vec scrollRel) {
return NULL;
}

bool Widget::onPathDrop(Vec pos, const std::list<std::string>& paths) {
for (auto it = children.rbegin(); it != children.rend(); it++) {
Widget *child = *it;
if (!child->visible)
continue;
if (child->box.contains(pos)) {
if (child->onPathDrop(pos.minus(child->box.pos), paths));
return true;
}
}
return false;
}

void Widget::onZoom() {
for (auto it = children.rbegin(); it != children.rend(); it++) {
Widget *child = *it;


Loading…
Cancel
Save