void ImGui_ImplCinder_MouseButtonCallback(ci::app::MouseEvent e, bool isDown) { ImGui_ImplCinder_MouseState state = isDown ? MouseState_Pressed : MouseState_Released; if (e.isLeft()) g_MousePressed[0] = state; else if (e.isRight()) g_MousePressed[1] = state; else if (e.isMiddle()) g_MousePressed[2] = state; }
void Game::mouseUp(ci::app::MouseEvent e) { int button; if (e.isLeft()) button = Button::LEFT; else if (e.isRight()) button = Button::RIGHT; else if (e.isMiddle()) button = Button::MIDDLE; else return; mEngine.mouseEvent(false, button); }
void BSplineEditor::input( const ci::app::MouseEvent &event ) { vec2 hp = getHitPercent( event.getPos() ); hp.x = std::min( std::max( hp.x, 0.0f ), 1.0f ); hp.y = std::min( std::max( hp.y, 0.0f ), 1.0f ); hp = vec2( lmap<float>( hp.x, 0.0, 1.0, mFormat.mMin.x, mFormat.mMax.x ), lmap<float>( hp.y, 0.0, 1.0, mFormat.mMin.y, mFormat.mMax.y ) ); if( event.isMetaDown() || mFormat.mSticky ) { if( mFormat.mGrid ) { float w = mHitRect.getWidth(); float h = mHitRect.getHeight(); float sv = h > w ? h : w; sv = mFormat.mGridSize / sv; hp.x = ceil( hp.x / sv ) * sv; hp.y = ceil( hp.y / sv ) * sv; } else { hp.x = ceil( hp.x / mFormat.mStickyValue ) * mFormat.mStickyValue; hp.y = ceil( hp.y / mFormat.mStickyValue ) * mFormat.mStickyValue; } } if( getState() == State::NORMAL || getState() == State::OVER ) { mHitIndex = -1; } else if( mHitIndex == -1 ) { float distance = 100000.0; int index = -1; std::map<float, int> distMap; int totalCtrlPts = mControlPoints.size(); bool addToEnd = true; for( int i = 0; i < totalCtrlPts; i++ ) { float len = length( hp - mControlPoints[i] ); distMap[len] = i; if( len < distance ) { distance = len; index = i; } } if( distance < ( length( mFormat.mMax - mFormat.mMin ) * mFormat.mThreshold ) ) { mHitIndex = index; if( ( event.isRight() || event.isMetaDown() ) ) { mControlPoints.erase( mControlPoints.begin() + mHitIndex ); updateSplineRef(); mHitIndex = -1; } addToEnd = false; } else { float thres = 0.1f * length( mFormat.mMax - mFormat.mMin ); float tpp = 1.0f / float( totalCtrlPts - 1.0f ); float bestDistance = 1000000; float bestTime = -1; int bestIndex = -1; if( mValid ) { for( auto &it : distMap ) { int id = it.second; int bid = ( id > 0 ) ? ( id - 1 ) : id; int eid = ( ( id + 1 ) == totalCtrlPts ) ? id : ( id + 1 ); if( bid == eid ) { continue; } float startTime = bid * tpp; float endTime = eid * tpp; for( float t = startTime; t <= endTime; t += 0.01f ) { vec2 pt = mSplineRef->getPosition( t ); float d = length( hp - pt ); if( d < bestDistance ) { bestDistance = d; bestTime = t; bestIndex = id; } } if( bestDistance < thres ) { int insertIndex = bid + 1; if( bestTime > ( id * tpp ) ) { insertIndex = id + 1; } mControlPoints.insert( mControlPoints.begin() + insertIndex, hp ); updateSplineRef(); addToEnd = false; break; } } } } if( addToEnd ) { mHitIndex = mControlPoints.size(); mControlPoints.push_back( hp ); updateSplineRef(); } } else { mControlPoints[mHitIndex] = hp; updateSplineRef(); } }