bool ofxGuiPoints::mousePressed(int x, int y, int button) { ofxPoint2f point = mouseToLocal(x, y); if(isPointInsideMe(point)) { ofxPoint2f inside = fractionToValue(mouseToFraction(point)); bool onPoint = isPointWithinDistance(inside); if(button == 2) { if(onPoint) mList.deleteActivePoint(); else mList.addPointAtPosition(inside); } mMouseIsDown = true; mouseDragged(x, y, button); } else { mMouseIsDown = false; } return mMouseIsDown; }
bool ofxGuiGrid::mouseDragged( int x, int y, int button ) { if ( !mIsActive ) { //! This control is not active now return false; } ofxPoint2f inside = mouseToLocal( x, y ); mMouseIsDown = isPointInsideMe( inside ); if ( mMouseIsDown ) { if ( bDblClickMode ) { return true; } if ( mIsSelectable && mValidSelection) { int id = mouseToGridId( inside ); if ( id + mIndexOffset < utils->getCount() && id != -1 && !utils->isSelected( id + mIndexOffset ) ){ if ( !mDragging ) { //! Get the X/Y mouse position offset this->mDraggingXOffset = clickingPoint.x - getGridX( id ); this->mDraggingYOffset = clickingPoint.y - getGridY( 0 ); //! just one "line", so y == 0 mDragging = true; //! do not get the x/y again for this time. } mGlobals->mListener->handleGui( mParamId, kofxGui_Set_Grid_Dragging, &mCamIndex, sizeof(int) ); } } } return mMouseIsDown; }
bool ofxGuiRadar::mousePressed(int x, int y, int button) { mMouseIsDown = isPointInsideMe(mouseToLocal(x, y)); if (mMouseIsDown) mouseDragged(x, y, button); return mMouseIsDown; }
bool ofxGuiArrow::mousePressed( int x, int y, int button ) { mMouseIsDown = isPointInsideMe( mouseToLocal( x, y ) ); if ( mMouseIsDown ) { setValue( true ); // Pressed mGlobals->mListener->handleGui( mParamId, kofxGui_Set_Bool, &mValue, sizeof(bool) ); } return mMouseIsDown; }
bool ofxGuiFiles::mousePressed(int x, int y, int button) { mMouseIsDown = isPointInsideMe(mouseToLocal(x, y)); if(mMouseIsDown) { mMemory = mValue; mouseDragged(x, y, button); } return mMouseIsDown; }
bool ofxGuiColor::mousePressed(int x, int y, int button) { ofxPoint2f inside = mouseToLocal(x, y); mMouseIsDown = isPointInsideMe(inside); if(mMouseIsDown) { mSlider = mouseToSlider(mouseToFraction(inside).y); mouseDragged(x, y, button); } return mMouseIsDown; }
bool ofxGuiKnob::mousePressed(int x, int y, int button) { ofxPoint2f point = mouseToLocal(x, y); mMouseIsDown = isPointInsideMe(point); if (mMouseIsDown) { mFirstHit = point; mouseDragged(x, y, button); } return mMouseIsDown; }
bool ofxGuiFiles::mousePressed(int x, int y, int button) { mMouseIsDown = isPointInsideMe(mouseToLocal(x, y)); if(mMouseIsDown) { mSelected = !mSelected; mMemory = mValue; mouseDragged(x, y, button); mState = (mState + 1) % num_states; } return mMouseIsDown; }
bool ofxGuiGrid::mouseReleased( int x, int y, int button ) { if ( !mIsActive ) { //! This control is not active now return false; } bool handled = mMouseIsDown; if ( mMouseIsDown ) { mMouseIsDown = false; //! Check the Double Click Mode first if ( bDblClickMode ) { return true; } //! Handle the controls bool handled2 = false; for ( int i = 0; i < mObjects.size(); ++i ) { if ( (ofxGuiObject*)mObjects[i]->mouseReleased( x, y, button ) ) { return true; } } } if ( mDisplayMode == kofxGui_Grid_Display && mDraggingRawIndex != -1) { ofxPoint2f inside = mouseToLocal( x, y ); if ( isPointInsideMe( inside ) ) { int id = mouseToGridId( inside ); if ( id < mXGrid * mYGrid && id != -1 ) { printf( "\nofxGuiGrid::mouseReleased()\tid=%d\n", id ); printf( "\nofxGuiGrid::mouseReleased()\tmDraggingRawIndex=%d\n", mDraggingRawIndex ); if ( !utils->isUsed( id ) ) { utils->setCam( id, utils->getRawCam(mDraggingRawIndex) ); utils->setSelected( mDraggingRawIndex ); setImages(); //! Save the info for reset rawIdArray[id] = mDraggingRawIndex; mGlobals->mListener->handleGui( mParamId, kofxGui_Set_Grid_Released, &mDraggingRawIndex, sizeof(int) ); } } //! reset the index mDraggingRawIndex = -1; } } return handled; }
bool ofxGuiFiles::mouseReleased(int x, int y, int button) { bool handled = mMouseIsDown; if(mMouseIsDown) { if(isPointInsideMe(mouseToLocal(x, y))) mGlobals->mListener->handleGui(mParamId, kofxGui_Set_String, &mValue, sizeof(string)); else mValue = mMemory; mMouseIsDown = false; } return handled; }
bool ofxGuiButton::mousePressed(int x, int y, int button) { mMouseIsDown = isPointInsideMe(mouseToLocal(x, y)); if(mMouseIsDown) { if(mDisplay == kofxGui_Button_Trigger) setValue(true); else setValue(!mValue); mGlobals->mListener->handleGui(mParamId, kofxGui_Set_Bool, &mValue, sizeof(bool)); } return mMouseIsDown; }
bool ofxGuiMatrix::mousePressed(int x, int y, int button) { ofPoint inside = mouseToLocal(x, y); mMouseIsDown = isPointInsideMe(inside); if(mMouseIsDown) { int id = mouseToPadId(mouseToFraction(inside)); if (mDisplay == kofxGui_Button_Trigger) mBuffer[id] |= kofxGui_Matrix_Set; // = 1; else mBuffer[id] ^= kofxGui_Matrix_Set; // !mBuffer[id]; setValue(id); ofCell outVal = ofCell(mValue, mBuffer[mValue]); mGlobals->mListener->handleGui(mParamId, kofxGui_Set_Cell, &outVal, sizeof(ofCell)); } return mMouseIsDown; }
bool ofxGuiPanel::mousePressed(int x, int y, int button) { bool handled = false; ofxPoint2f inside = mouseToLocal(x, y); if(isPointInsideMe(inside)) { ofxGuiObject* tmpObj; for(int i = 0; i < mObjects.size(); i++) { tmpObj = (ofxGuiObject*)mObjects.at(i); handled = tmpObj->mousePressed(inside.x, inside.y, button); if(handled) break; } mMouseIsDown = true; } return handled; }
bool ofxGuiGrid::mousePressed( int x, int y, int button ) { if ( !mIsActive ) { //! This control is not active now return false; } ofxPoint2f inside = mouseToLocal( x, y ); mMouseIsDown = isPointInsideMe( inside ); if ( mMouseIsDown ) { // ----------------------- if ( bDblClickMode ) { // TODO mNowClickTime = ofGetSystemTime(); if ( mNowClickTime - mPrevClickTime <= OFXGUI_DBLCLICK_INTERVAL ) { mPrevClickTime = 0; // reset switchDblClickMode( false ); return true; } mPrevClickTime = mNowClickTime; return true; } // ----------------------- //! Check the controls first bool handled = false; for ( int i = 0; i < mObjects.size(); i++ ) { handled = (ofxGuiObject*)mObjects[i]->mousePressed( x, y, button ); if ( handled ) { return true; // we got the result } } // ----------------------- int id = mouseToGridId( inside ); setSelectedId( id ); mGlobals->mListener->handleGui( mParamId, kofxGui_Set_Int, &mCamIndex, sizeof(int) ); mDragging = false; //! reset the value if ( id != -1 ) { clickingPoint = inside; mValidSelection = true; } else { mValidSelection = false; } // ----------------------- //! Double click check mNowClickTime = ofGetSystemTime(); if ( id != -1 && utils->isUsed( id ) && mNowClickTime - mPrevClickTime <= OFXGUI_DBLCLICK_INTERVAL ) { mPrevClickTime = 0; // reset the time switchDblClickMode( true ); return true; } mPrevClickTime = mNowClickTime; // ------------------------ //! ----- Add controls ----- //! Control temp values int x, y, textWidth; string btnText = ""; ofxGuiButton* btn; //! The reset button if ( bShowResetBtn ) { removeControl( mResetBtnId ); if ( id != -1 && utils->isUsed( id )) { //! The position is relate with the panel x = mObjX + getGridX( id % mXGrid ) + 5; y = mObjY + getGridY( id / mXGrid ) + getGridHeight() - 5 - OFXGUI_BUTTON_HEIGHT; //! If the grid is too small, we remove the text btnText = "Reset"; textWidth = mGlobals->mParamFont.stringWidth( btnText ); if ( getGridWidth() < textWidth + 5 + OFXGUI_BUTTON_HEIGHT ) { btnText = ""; } btn = (ofxGuiButton*)addButton( mResetBtnId, btnText, x, y, OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger ); btn->setHighlightMode( true ); } } //! The setting button if ( bShowSettingBtn ) { removeControl( mSettingBtnId ); if ( id != -1 && utils->isUsed( id ) ) { y -= 15; btnText = "Setting"; textWidth = mGlobals->mParamFont.stringWidth( btnText ); if ( getGridWidth() < textWidth + 5 + OFXGUI_BUTTON_HEIGHT ) { btnText = ""; } btn = (ofxGuiButton*)addButton( mSettingBtnId, btnText, x, y, OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger ); btn->setHighlightMode( true ); } } } return mMouseIsDown; }