Small improvements in breadcrumb. Minor refactor of EventDispatcher::getMousePos.

This commit is contained in:
Martín Lucas Golini
2024-09-11 20:27:14 -03:00
parent 16c2ac84f0
commit 4d0da818c0
9 changed files with 29 additions and 28 deletions

View File

@@ -173,9 +173,6 @@ class EE_API Input {
/** @return The Mouse position vector */
Vector2i getMousePos() const;
/** @return The position vector converted to float */
Vector2f getMousePosf();
/** This will change the value of the mouse pos, will not REALLY move the mouse ( for that is
* InjectMousePos ). */
void setMousePos( const Vector2i& Pos );

View File

@@ -422,7 +422,8 @@ void UICodeEditor::scheduledUpdate( const Time& ) {
if ( mMouseDown ) {
if ( !( getUISceneNode()->getWindow()->getInput()->getPressTrigger() & EE_BUTTON_LMASK ) ) {
stopMinimapDragging( getUISceneNode()->getWindow()->getInput()->getMousePosf() );
stopMinimapDragging(
getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() );
mMouseDown = false;
getUISceneNode()->getWindow()->getInput()->captureMouse( false );
} else if ( !isMouseOverMeOrChilds() || mMinimapDragging ) {
@@ -1009,7 +1010,7 @@ Uint32 UICodeEditor::onFocus( NodeFocusReason reason ) {
Uint32 UICodeEditor::onFocusLoss() {
if ( mMouseDown )
getUISceneNode()->getWindow()->getInput()->captureMouse( false );
stopMinimapDragging( getUISceneNode()->getWindow()->getInput()->getMousePosf() );
stopMinimapDragging( getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() );
mMouseDown = false;
mCursorVisible = false;
getSceneNode()->getWindow()->stopTextInput();
@@ -1474,8 +1475,8 @@ Uint32 UICodeEditor::onMouseMove( const Vector2i& position, const Uint32& flags
Vector2f localPos( convertToNodeSpace( position.asFloat() ) );
if ( !minimapHover && isTextSelectionEnabled() &&
!getUISceneNode()->getEventDispatcher()->isNodeDragging() && NULL != mFont && mMouseDown &&
( flags & EE_BUTTON_LMASK ) && ( localPos.y <= 0 || localPos.y >= mPluginsTopSpace ) ) {
!getUISceneNode()->getEventDispatcher()->isNodeDragging() && NULL != mFont &&
mMouseDown ) {
TextRange selection = mDoc->getSelection();
selection.setStart( resolveScreenPosition( position.asFloat() ) );
mDoc->setSelection( selection );

View File

@@ -68,7 +68,7 @@ void UIPopUpMenu::showAtScreenPosition( Vector2f pos ) {
}
void UIPopUpMenu::showOverMouseCursor() {
showAtScreenPosition( getUISceneNode()->getWindow()->getInput()->getMousePosf() );
showAtScreenPosition( getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() );
}
bool UIPopUpMenu::hide() {

View File

@@ -312,10 +312,6 @@ void Input::setMousePos( const Vector2i& Pos ) {
mMousePos = Pos;
}
Vector2f Input::getMousePosf() {
return Vector2f( (Float)mMousePos.x, (Float)mMousePos.y );
}
Vector2f Input::getMousePosFromView( const View& View ) {
return mWindow->mapPixelToCoords( getMousePos(), View );
}

View File

@@ -107,7 +107,7 @@ void mainLoop() {
}
Float p;
Vector2f mf = imp->getMousePosf();
Vector2f mf = imp->getMousePos().asFloat();
Float tratio = tw / th;
Float touchX = ( mf.x / tw - 1 ) * tratio;
Float touchY = -( mf.y / th - 1 );

View File

@@ -597,7 +597,8 @@ void physicsCreate() {
void physicsUpdate() {
// Creates a joint to drag any grabable object on the scene
mMousePoint = cVectNew( KM->getMousePosf().x, KM->getMousePosf().y );
const Vector2f mousePos( KM->getMousePos().asFloat() );
mMousePoint = cVectNew( mousePos.x, mousePos.y );
cVect newPoint = tovect( cpvlerp( tocpv( mMousePoint_last ), tocpv( mMousePoint ), 0.25 ) );
mMouseBody->setPos( newPoint );
mMouseBody->setVel( ( newPoint - mMousePoint_last ) * (cpFloat)mWindow->getFPS() );
@@ -605,7 +606,7 @@ void physicsUpdate() {
if ( KM->isMouseLeftPressed() ) {
if ( NULL == mMouseJoint ) {
cVect point = cVectNew( KM->getMousePosf().x, KM->getMousePosf().y );
cVect point = cVectNew( mousePos.x, mousePos.y );
Shape* shape = mSpace->pointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP );

View File

@@ -1272,7 +1272,7 @@ void EETest::onQuitClick( const Event* event ) {
void EETest::showMenu() {
if ( NULL != Menu && Menu->show() ) {
Vector2f Pos = KM->getMousePosf();
Vector2f Pos = KM->getMousePos().asFloat();
UIMenu::findBestMenuPos( Pos, Menu );
Menu->setPixelsPosition( Pos );
}
@@ -2470,7 +2470,8 @@ void EETest::physicsCreate() {
void EETest::physicsUpdate() {
#ifndef EE_PLATFORM_TOUCH
mMousePoint = cVectNew( KM->getMousePosf().x, KM->getMousePosf().y );
const Vector2f mousePos( KM->getMousePos().asFloat() );
mMousePoint = cVectNew( mousePos.x, mousePos.y );
cVect newPoint = tovect( cpvlerp( tocpv( mMousePoint_last ), tocpv( mMousePoint ), 0.25 ) );
mMouseBody->setPos( newPoint );
mMouseBody->setVel( ( newPoint - mMousePoint_last ) * (cpFloat)mWindow->getFPS() );
@@ -2478,7 +2479,7 @@ void EETest::physicsUpdate() {
if ( KM->isMouseLeftPressed() ) {
if ( NULL == mMouseJoint ) {
cVect point = cVectNew( KM->getMousePosf().x, KM->getMousePosf().y );
cVect point = cVectNew( mousePos.x, mousePos.y );
Shape* shape = mSpace->pointQueryFirst( point, GRABABLE_MASK_BIT, CP_NO_GROUP );

View File

@@ -605,14 +605,18 @@ TextDocument* LSPClientPlugin::getDocumentFromURI( const URI& uri ) {
bool LSPClientPlugin::onMouseClick( UICodeEditor* editor, const Vector2i& pos,
const Uint32& flags ) {
const Vector2f localPos( mBreadcrumb && ( flags & EE_BUTTON_LMASK )
? editor->convertToNodeSpace( pos.asFloat() )
: Vector2f::Zero );
if ( mBreadcrumb && ( flags & EE_BUTTON_LMASK ) && localPos.y < mPluginTopSpace &&
const bool breadcrumbClick = mBreadcrumb && ( flags & EE_BUTTON_LMASK );
const Vector2f localPos( breadcrumbClick ? editor->convertToNodeSpace( pos.asFloat() )
: Vector2f::Zero );
if ( breadcrumbClick && localPos.y < mPluginTopSpace &&
localPos.x < editor->getPixelsSize().getWidth() - editor->getMinimapWidth() ) {
editor->getDocument().execute( "lsp-show-document-symbols", editor );
return true;
const Vector2f downLocalPos( editor->convertToNodeSpace(
editor->getEventDispatcher()->getMouseDownPos().asFloat() ) );
if ( downLocalPos.y < mPluginTopSpace &&
downLocalPos.x < editor->getPixelsSize().getWidth() - editor->getMinimapWidth() ) {
editor->getDocument().execute( "lsp-show-document-symbols", editor );
return true;
}
}
Input* input = editor->getUISceneNode()->getWindow()->getInput();
@@ -1714,7 +1718,7 @@ void LSPClientPlugin::hideTooltip( UICodeEditor* editor ) {
TextPosition currentMouseTextPosition( UICodeEditor* editor ) {
return editor->resolveScreenPosition(
editor->getUISceneNode()->getWindow()->getInput()->getMousePosf() );
editor->getUISceneNode()->getWindow()->getInput()->getMousePos().asFloat() );
}
void LSPClientPlugin::tryHideTooltip( UICodeEditor* editor, const Vector2i& position ) {
@@ -1830,7 +1834,8 @@ bool LSPClientPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& positio
if ( !editor->getScreenRect().contains( editor->getUISceneNode()
->getWindow()
->getInput()
->getMousePosf() ) )
->getMousePos()
.asFloat() ) )
return;
tryDisplayTooltip( editor, resp, position );
} );

View File

@@ -504,7 +504,7 @@ void StatusBuildOutputController::createContainer() {
UITableCell* cell = mTableIssues->getCellFromIndex( idx );
if ( modelEvent->getTriggerEvent()->getType() == Event::MouseClick ||
cell == nullptr ) {
Vector2f pos( mApp->getWindow()->getInput()->getMousePosf() );
Vector2f pos( mApp->getWindow()->getInput()->getMousePos().asFloat() );
menu->nodeToWorldTranslation( pos );
UIMenu::findBestMenuPos( pos, menu );
menu->setPixelsPosition( pos );