bool GraphComponent::keyPressed (const KeyPress& key) { if (key.isKeyCode (KeyPress::leftKey)) { for (int i = 0; i < selectedNodes.getNumSelected (); i++) { GraphNodeComponent* selected = selectedNodes.getSelectedItem (i); if (selected != inputs && selected != outputs) selected->setTopLeftPosition (selected->getX() - 1, selected->getY()); } } else if (key.isKeyCode (KeyPress::rightKey)) { for (int i = 0; i < selectedNodes.getNumSelected (); i++) { GraphNodeComponent* selected = selectedNodes.getSelectedItem (i); if (selected != inputs && selected != outputs) selected->setTopLeftPosition (selected->getX() + 1, selected->getY()); } } else if (key.isKeyCode (KeyPress::upKey)) { for (int i = 0; i < selectedNodes.getNumSelected (); i++) { GraphNodeComponent* selected = selectedNodes.getSelectedItem (i); if (selected != inputs && selected != outputs) selected->setTopLeftPosition (selected->getX(), selected->getY() - 1); } } else if (key.isKeyCode (KeyPress::downKey)) { for (int i = 0; i < selectedNodes.getNumSelected (); i++) { GraphNodeComponent* selected = selectedNodes.getSelectedItem (i); if (selected != inputs && selected != outputs) selected->setTopLeftPosition (selected->getX(), selected->getY() + 1); } } else if (key.isKeyCode (KeyPress::deleteKey)) { closeSelectedPlugins (); } else { return Component::keyPressed (key); } return true; }
//============================================================================== void GraphComponent::findLassoItemsInArea (Array<GraphNodeComponent*> &itemsFound, int x, int y, int width, int height) { for (int i = 0; i < nodes.size (); i++) { GraphNodeComponent* node = nodes.getUnchecked (i); if ((node->getX() >= x && node->getX() < x + width) && (node->getY() >= y && node->getY() < y + height)) { itemsFound.addIfNotAlreadyThere (node); selectedNodes.addToSelection (node); } else { selectedNodes.deselect (node); } } }
void GraphComponent::nodeMoved (GraphNodeComponent* node, const int deltaX, const int deltaY) { // DBG ("GraphComponent::nodeMoved " + String (deltaX) + " " + String (deltaY)); jassert (node != 0); for (int i = 0; i < selectedNodes.getNumSelected (); i++) { GraphNodeComponent* selected = selectedNodes.getSelectedItem (i); if (selected && selected != node && ! selected->isLocked ()) { BasePlugin* plugin = (BasePlugin*) selected->getUserData (); if (plugin) { int x = selected->getX() + deltaX; int y = selected->getY() + deltaY; x = jmax (0, jmin (getWidth () - selected->getWidth(), x)); y = jmax (0, jmin (getHeight () - selected->getHeight(), y)); plugin->setValue (PROP_GRAPHXPOS, x); plugin->setValue (PROP_GRAPHYPOS, y); selected->setTopLeftPosition (x, y); } } } BasePlugin* plugin = (BasePlugin*) node->getUserData (); if (plugin) { plugin->setValue (PROP_GRAPHXPOS, node->getX()); plugin->setValue (PROP_GRAPHYPOS, node->getY()); } Viewport* parent = findParentComponentOfClass ((Viewport*) 0); if (parent) { parent->notifyComponentChanged (); } }