Skip to content

Commit 5ad4827

Browse files
committed
mouse interaction: added activate/deactivate cable with shift-click
1 parent 9ad765d commit 5ad4827

File tree

6 files changed

+85
-9
lines changed

6 files changed

+85
-9
lines changed

src/PatchObject.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,37 @@ void PatchObject::update(map<int,shared_ptr<PatchObject>> &patchObjects, pdsp::E
143143
if(!outPut[i]->isDisabled && outPut[i]->fromOutletID == out && patchObjects[outPut[i]->toObjectID]!=nullptr && !patchObjects[outPut[i]->toObjectID]->getWillErase()){
144144
outPut[i]->posFrom = getOutletPosition(out);
145145
outPut[i]->posTo = patchObjects[outPut[i]->toObjectID]->getInletPosition(outPut[i]->toInletID);
146+
147+
// check first if link is deactivated by shift click
148+
outPut[i]->isDeactivated = false;
149+
for(size_t di=0;di<linksDeactivated.size();di++){
150+
if(outPut[i]->id == linksDeactivated.at(di)){
151+
outPut[i]->isDeactivated = true;
152+
break;
153+
}
154+
}
146155
// send data through links
147-
patchObjects[outPut[i]->toObjectID]->_inletParams[outPut[i]->toInletID] = _outletParams[out];
156+
if(!outPut[i]->isDeactivated){
157+
patchObjects[outPut[i]->toObjectID]->inletsConnected[outPut[i]->toInletID] = true;
158+
if(outPut[i]->type == VP_LINK_AUDIO && patchObjects[outPut[i]->toObjectID]->getIsPDSPPatchableObject()){
159+
if(this->getIsPDSPPatchableObject() || this->getName() == "audio device"){
160+
this->pdspOut[outPut[i]->fromOutletID] >> patchObjects[outPut[i]->toObjectID]->pdspIn[outPut[i]->toInletID];
161+
}
162+
}else if(outPut[i]->type == VP_LINK_TEXTURE){
163+
// TODO
164+
}
165+
patchObjects[outPut[i]->toObjectID]->_inletParams[outPut[i]->toInletID] = _outletParams[out];
166+
}else{
167+
patchObjects[outPut[i]->toObjectID]->inletsConnected[outPut[i]->toInletID] = false;
168+
if(outPut[i]->type == VP_LINK_AUDIO){
169+
if(patchObjects[outPut[i]->toObjectID]->getIsPDSPPatchableObject() && patchObjects[outPut[i]->toObjectID]->pdspIn[outPut[i]->toInletID].getInputsList().size() > 0){
170+
patchObjects[outPut[i]->toObjectID]->pdspIn[outPut[i]->toInletID].disconnectIn();
171+
}
172+
}else if(outPut[i]->type == VP_LINK_TEXTURE){
173+
// TODO
174+
}
175+
176+
}
148177
}
149178
}
150179
}
@@ -303,7 +332,10 @@ void PatchObject::drawImGuiNode(ImGuiEx::NodeCanvas& _nodeCanvas, map<int,shared
303332

304333

305334
// Refresh links to eventually disconnect ( backspace key )
306-
linksToDisconnect = _nodeCanvas.getSelectedLinks();
335+
linksToDisconnect = _nodeCanvas.getSelectedLinks();
336+
337+
// Refresh links deactivated
338+
linksDeactivated = _nodeCanvas.getDeactivatedLinks();
307339

308340
// Refresh objects selected to eventually duplicate or delete ( cmd-d or backsapce )
309341
objectsSelected = _nodeCanvas.getSelectedNodes();
@@ -392,6 +424,7 @@ bool PatchObject::connectTo(map<int,shared_ptr<PatchObject>> &patchObjects, int
392424
tempLink->toObjectID = this->getId();
393425
tempLink->toInletID = toInlet;
394426
tempLink->isDisabled = false;
427+
tempLink->isDeactivated = false;
395428

396429
patchObjects[fromObjectID]->outPut.push_back(tempLink);
397430

src/PatchObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct PatchLink{
7070
int toInletID;
7171
int id;
7272
bool isDisabled;
73+
bool isDeactivated;
7374
};
7475

7576

@@ -199,6 +200,7 @@ class PatchObject : public ofxVPHasUID {
199200
// patch object connections
200201
vector<shared_ptr<PatchLink>> outPut;
201202
vector<int> linksToDisconnect;
203+
vector<int> linksDeactivated;
202204
vector<int> objectsSelected;
203205
vector<bool> inletsConnected;
204206

src/core/imgui_node_canvas.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,14 @@ ImGuiEx::NodeConnectData ImGuiEx::NodeCanvas::AddNodePin( const int nodeID, cons
853853
}
854854
}
855855

856+
// reset deactivated links
857+
for(unsigned int i=0;i<_linksData.size();i++){
858+
std::vector<int>::iterator it = std::find(deactivated_links.begin(), deactivated_links.end(),_linksData.at(i)._linkID);
859+
if (it!=deactivated_links.end()){
860+
deactivated_links.erase(it);
861+
}
862+
}
863+
856864
}
857865

858866
activePin = "";
@@ -920,7 +928,7 @@ ImGuiEx::NodeConnectData ImGuiEx::NodeCanvas::AddNodePin( const int nodeID, cons
920928
const bool is_hovered = is_mouse_hovering_near_link(link_data.bezier);
921929

922930
if(ImGui::IsMouseClicked(0) && !isAnyCanvasNodeHovered){
923-
if (is_hovered){
931+
if (is_hovered && !ImGui::GetIO().KeyShift){
924932
if (std::find(selected_links.begin(), selected_links.end(),_linksData.at(i)._linkID)==selected_links.end()){
925933
selected_links.push_back(_linksData.at(i)._linkID);
926934
}
@@ -929,12 +937,27 @@ ImGuiEx::NodeConnectData ImGuiEx::NodeCanvas::AddNodePin( const int nodeID, cons
929937
if (it!=selected_links.end()){
930938
selected_links.erase(it);
931939
}
940+
}else if(is_hovered && ImGui::GetIO().KeyShift){
941+
// deactivate if activated
942+
if (std::find(deactivated_links.begin(), deactivated_links.end(),_linksData.at(i)._linkID)==deactivated_links.end()){
943+
deactivated_links.push_back(_linksData.at(i)._linkID);
944+
}else{ // else the opposite
945+
std::vector<int>::iterator it = std::find(deactivated_links.begin(), deactivated_links.end(),_linksData.at(i)._linkID);
946+
if (it!=deactivated_links.end()){
947+
deactivated_links.erase(it);
948+
}
949+
}
932950
}
933951
}
934952

935953

936954
static ImU32 _tempColor;
937955
_tempColor = _color;
956+
957+
if (std::find(deactivated_links.begin(), deactivated_links.end(),_linksData.at(i)._linkID)!=deactivated_links.end()){ // disabled
958+
_tempColor = IM_COL32(255,255,255,70);
959+
}
960+
938961
if (std::find(selected_links.begin(), selected_links.end(),_linksData.at(i)._linkID)!=selected_links.end()){ // selected
939962
_tempColor = IM_COL32(255,0,0,255);
940963
}

src/core/imgui_node_canvas.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ struct NodeCanvas {
292292
// Returns selected links
293293
std::vector<int> getSelectedLinks(){ return selected_links; }
294294

295+
// Returns deactivated links
296+
std::vector<int> getDeactivatedLinks(){ return deactivated_links; }
297+
295298
// Returns active node
296299
int getActiveNode() { return activeNode; }
297300
void setActiveNode(int objID) { activeNode = objID; }
@@ -342,8 +345,9 @@ struct NodeCanvas {
342345
// Patch Control data
343346
std::map<int,std::map<int,ImVec2>> inletPinsPositions;
344347
std::map<int,std::map<int,ImVec2>> outletPinsPositions;
345-
std::vector<int> selected_nodes; // for group actions (copy, duplicate, delete) -- TO IMPLEMENT
346-
std::vector<int> selected_links; // for delete links (one or multiple) -- IMPLEMENTED
348+
std::vector<int> selected_nodes; // for group actions (copy, duplicate, delete) -- TO IMPLEMENT
349+
std::vector<int> selected_links; // for delete links (one or multiple) -- IMPLEMENTED
350+
std::vector<int> deactivated_links; // for activating/deactivating links (one or multiple) -- IMPLEMENTED
347351
std::string activePin;
348352
std::string activePinType;
349353
int activeNode = 0; // for node inspector

src/objects/gui/moVideoViewer.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ moVideoViewer::moVideoViewer() : PatchObject("video viewer"){
4444

4545
_outletParams[0] = new ofTexture(); // texture
4646

47+
kuro = new ofImage();
48+
4749
posX = posY = drawW = drawH = 0.0f;
4850

4951
this->width *= 2;
@@ -75,13 +77,14 @@ void moVideoViewer::newObject(){
7577
//--------------------------------------------------------------
7678
void moVideoViewer::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
7779
unusedArgs(mainWindow);
80+
81+
// load kuro
82+
kuro->load("images/kuro.jpg");
7883
}
7984

8085
//--------------------------------------------------------------
8186
void moVideoViewer::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchObjects){
82-
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
83-
*static_cast<ofTexture *>(_outletParams[0]) = *static_cast<ofTexture *>(_inletParams[0]);
84-
}
87+
unusedArgs(patchObjects);
8588

8689
if(!loaded){
8790
loaded = true;
@@ -94,7 +97,16 @@ void moVideoViewer::updateObjectContent(map<int,shared_ptr<PatchObject>> &patchO
9497

9598
//--------------------------------------------------------------
9699
void moVideoViewer::drawObjectContent(ofTrueTypeFont *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
100+
unusedArgs(font,glRenderer);
101+
97102
ofSetColor(255);
103+
104+
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
105+
*static_cast<ofTexture *>(_outletParams[0]) = *static_cast<ofTexture *>(_inletParams[0]);
106+
}else{
107+
*static_cast<ofTexture *>(_outletParams[0]) = kuro->getTexture();
108+
}
109+
98110
// draw node texture preview with OF
99111
if(static_cast<ofTexture *>(_outletParams[0])->isAllocated()){
100112
if(scaledObjW*canvasZoom > 90.0f){
@@ -162,7 +174,7 @@ void moVideoViewer::drawObjectNodeConfig(){
162174

163175
//--------------------------------------------------------------
164176
void moVideoViewer::removeObjectContent(bool removeFileFromData){
165-
177+
unusedArgs(removeFileFromData);
166178
}
167179

168180
OBJECT_REGISTER( moVideoViewer, "video viewer", OFXVP_OBJECT_CAT_GUI)

src/objects/gui/moVideoViewer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class moVideoViewer : public PatchObject {
5252

5353
void removeObjectContent(bool removeFileFromData=false) override;
5454

55+
ofImage *kuro;
56+
5557
float posX, posY, drawW, drawH;
5658

5759
float prevW, prevH;

0 commit comments

Comments
 (0)