Skip to content

Commit 21e72cf

Browse files
committed
added mouse data as outlet at output window object
1 parent 70e50d2 commit 21e72cf

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

src/objects/windowing/OutputWindow.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@
4141
OutputWindow::OutputWindow() : PatchObject("output window"){
4242

4343
this->numInlets = 2;
44-
this->numOutlets = 0;
44+
this->numOutlets = 1;
4545

4646
_inletParams[0] = new ofTexture(); // projector
4747
_inletParams[1] = new LiveCoding(); // script reference
4848

49+
_outletParams[0] = new vector<float>(); // mouse
50+
4951
this->specialLinkTypeName = "LiveCoding";
5052

5153
this->initInletsState();
@@ -91,6 +93,8 @@ void OutputWindow::newObject(){
9193
this->addInlet(VP_LINK_TEXTURE,"projector");
9294
this->addInlet(VP_LINK_SPECIAL,"script");
9395

96+
this->addOutlet(VP_LINK_ARRAY,"mouse");
97+
9498
this->setCustomVar(static_cast<float>(isFullscreen),"FULLSCREEN");
9599
this->setCustomVar(static_cast<float>(this->output_width),"OUTPUT_WIDTH");
96100
this->setCustomVar(static_cast<float>(this->output_height),"OUTPUT_HEIGHT");
@@ -159,6 +163,9 @@ void OutputWindow::setupObjectContent(shared_ptr<ofAppGLFWWindow> &mainWindow){
159163
window_asRatio = reduceToAspectRatio(window->getWidth(),window->getHeight());
160164
scaleTextureToWindow(window->getWidth(),window->getHeight());
161165

166+
// init outlet mouse data
167+
static_cast<vector<float> *>(_outletParams[0])->assign(3,0.0f);
168+
162169
}
163170

164171
//--------------------------------------------------------------
@@ -668,64 +675,87 @@ void OutputWindow::mouseMoved(ofMouseEventArgs &e){
668675
warpController->onMouseMoved(window->events().getMouseX(),window->events().getMouseY());
669676
}
670677

678+
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
671679
if(this->inletsConnected[0] && this->inletsConnected[1] && _inletParams[1] != nullptr && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
672-
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
673680
if(static_cast<LiveCoding *>(_inletParams[1])->lua.isValid()){
674681
static_cast<LiveCoding *>(_inletParams[1])->lua.scriptMouseMoved(static_cast<int>(tm.x),static_cast<int>(tm.y));
675682
}
676683
}
684+
685+
static_cast<vector<float> *>(_outletParams[0])->at(0) = tm.x;
686+
static_cast<vector<float> *>(_outletParams[0])->at(1) = tm.y;
687+
static_cast<vector<float> *>(_outletParams[0])->at(2) = e.button;
688+
677689
}
678690

679691
//--------------------------------------------------------------
680692
void OutputWindow::mouseDragged(ofMouseEventArgs &e){
681693
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated() && isFullscreen){
682694
warpController->onMouseDragged(window->events().getMouseX(),window->events().getMouseY());
683695
}
696+
697+
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
684698
if(this->inletsConnected[0] && this->inletsConnected[1] && _inletParams[1] != nullptr && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
685-
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
686699
if(static_cast<LiveCoding *>(_inletParams[1])->lua.isValid()){
687700
static_cast<LiveCoding *>(_inletParams[1])->lua.scriptMouseDragged(static_cast<int>(tm.x),static_cast<int>(tm.y), e.button);
688701
}
689702
}
703+
704+
static_cast<vector<float> *>(_outletParams[0])->at(0) = tm.x;
705+
static_cast<vector<float> *>(_outletParams[0])->at(1) = tm.y;
706+
static_cast<vector<float> *>(_outletParams[0])->at(2) = e.button;
690707
}
691708

692709
//--------------------------------------------------------------
693710
void OutputWindow::mousePressed(ofMouseEventArgs &e){
694711
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated() && isFullscreen){
695712
warpController->onMousePressed(window->events().getMouseX(),window->events().getMouseY());
696713
}
714+
715+
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
697716
if(this->inletsConnected[0] && this->inletsConnected[1] && _inletParams[1] != nullptr && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
698-
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
699717
if(static_cast<LiveCoding *>(_inletParams[1])->lua.isValid()){
700718
static_cast<LiveCoding *>(_inletParams[1])->lua.scriptMousePressed(static_cast<int>(tm.x),static_cast<int>(tm.y), e.button);
701719
}
702720
}
721+
722+
static_cast<vector<float> *>(_outletParams[0])->at(0) = tm.x;
723+
static_cast<vector<float> *>(_outletParams[0])->at(1) = tm.y;
724+
static_cast<vector<float> *>(_outletParams[0])->at(2) = e.button;
703725
}
704726

705727
//--------------------------------------------------------------
706728
void OutputWindow::mouseReleased(ofMouseEventArgs &e){
707729
if(this->inletsConnected[0] && static_cast<ofTexture *>(_inletParams[0])->isAllocated() && isFullscreen){
708730
warpController->onMouseReleased(window->events().getMouseX(),window->events().getMouseY());
709731
}
732+
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
710733
if(this->inletsConnected[0] && this->inletsConnected[1] && _inletParams[1] != nullptr && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
711-
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
712734
if(static_cast<LiveCoding *>(_inletParams[1])->lua.isValid()){
713735
static_cast<LiveCoding *>(_inletParams[1])->lua.scriptMouseReleased(static_cast<int>(tm.x),static_cast<int>(tm.y), e.button);
714736
}
715737
}
716738

739+
static_cast<vector<float> *>(_outletParams[0])->at(0) = tm.x;
740+
static_cast<vector<float> *>(_outletParams[0])->at(1) = tm.y;
741+
static_cast<vector<float> *>(_outletParams[0])->at(2) = e.button;
742+
717743
this->setCustomVar(window->getWindowPosition().x,"OUTPUT_POSX");
718744
this->setCustomVar(window->getWindowPosition().y,"OUTPUT_POSY");
719745
}
720746

721747
//--------------------------------------------------------------
722748
void OutputWindow::mouseScrolled(ofMouseEventArgs &e){
749+
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
723750
if(this->inletsConnected[0] && this->inletsConnected[1] && _inletParams[1] != nullptr && static_cast<ofTexture *>(_inletParams[0])->isAllocated()){
724-
ofVec2f tm = ofVec2f(((window->events().getMouseX()-thposX)/thdrawW * this->output_width),((window->events().getMouseY()-thposY)/thdrawH * this->output_height));
725751
if(static_cast<LiveCoding *>(_inletParams[1])->lua.isValid()){
726752
static_cast<LiveCoding *>(_inletParams[1])->lua.scriptMouseScrolled(static_cast<int>(tm.x),static_cast<int>(tm.y), e.scrollX,e.scrollY);
727753
}
728754
}
755+
756+
static_cast<vector<float> *>(_outletParams[0])->at(0) = tm.x;
757+
static_cast<vector<float> *>(_outletParams[0])->at(1) = tm.y;
758+
static_cast<vector<float> *>(_outletParams[0])->at(2) = e.button;
729759
}
730760

731761
//--------------------------------------------------------------

0 commit comments

Comments
 (0)