1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Simplify code

This commit is contained in:
Ivan Savenko 2024-04-30 12:01:03 +03:00
parent 0d8d75afd4
commit 9a71614588
12 changed files with 7 additions and 41 deletions

View File

@ -209,9 +209,11 @@ void InputSourceGameController::handleEventAxisMotion(const SDL_ControllerAxisEv
void InputSourceGameController::tryToConvertCursor()
{
if(CCS && CCS->curh && CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
assert(CCS);
assert(CCS->curh);
if(CCS->curh->getShowType() == Cursor::ShowType::HARDWARE)
{
const Point & cursorPosition = CCS->curh->getCursorPosition();
const Point & cursorPosition = GH.getCursorPosition();
CCS->curh->ChangeCursor(Cursor::ShowType::SOFTWARE);
CCS->curh->cursorMove(cursorPosition.x, cursorPosition.y);
GH.input().setCursorPosition(cursorPosition);

View File

@ -76,8 +76,8 @@ void CGuiHandler::init()
windowHandlerInstance = std::make_unique<WindowHandler>();
screenHandlerInstance = std::make_unique<ScreenHandler>();
renderHandlerInstance = std::make_unique<RenderHandler>();
inputHandlerInstance = std::make_unique<InputHandler>(); // Must be after windowHandlerInstance
shortcutsHandlerInstance = std::make_unique<ShortcutHandler>();
inputHandlerInstance = std::make_unique<InputHandler>(); // Must be after windowHandlerInstance and shortcutsHandlerInstance
framerateManagerInstance = std::make_unique<FramerateManager>(settings["video"]["targetfps"].Integer());
}

View File

@ -315,8 +315,3 @@ void CursorHandler::ChangeCursor(Cursor::ShowType showType)
break;
}
}
const Point & CursorHandler::getCursorPosition()
{
return cursor->getCursorPosition();
}

View File

@ -186,7 +186,6 @@ public:
/// change cursor's positions to (x, y)
void cursorMove(const int & x, const int & y);
Cursor::ShowType getShowType();
void ChangeCursor(Cursor::ShowType showType);
const Point & getCursorPosition();
Cursor::ShowType getShowType();
void ChangeCursor(Cursor::ShowType showType);
};

View File

@ -24,6 +24,5 @@ public:
virtual void setCursorPosition( const Point & newPos ) = 0;
virtual void render() = 0;
virtual void setVisible( bool on) = 0;
virtual const Point & getCursorPosition() = 0;
};

View File

@ -43,7 +43,4 @@ public:
/// Window has focus
virtual bool hasFocus() = 0;
/// Get the scale value of screen
virtual void getRenderScale(float & scaleX, float & scaleY) = 0;
};

View File

@ -67,17 +67,6 @@ void CursorHardware::setImage(std::shared_ptr<IImage> image, const Point & pivot
});
}
const Point & CursorHardware::getCursorPosition()
{
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
float scaleX, scaleY;
GH.screenHandler().getRenderScale(scaleX, scaleY);
pos.x = int(mouseX / scaleX);
pos.y = int(mouseY / scaleY);
return pos;
}
void CursorHardware::setCursorPosition( const Point & newPos )
{
//no-op

View File

@ -33,6 +33,5 @@ public:
void setCursorPosition( const Point & newPos ) override;
void render() override;
void setVisible( bool on) override;
const Point & getCursorPosition() override;
};

View File

@ -81,11 +81,6 @@ void CursorSoftware::setVisible(bool on)
visible = on;
}
const Point & CursorSoftware::getCursorPosition()
{
return pos;
}
CursorSoftware::CursorSoftware():
cursorTexture(nullptr),
cursorSurface(nullptr),

View File

@ -40,6 +40,5 @@ public:
void setCursorPosition( const Point & newPos ) override;
void render() override;
void setVisible( bool on) override;
const Point & getCursorPosition() override;
};

View File

@ -582,8 +582,3 @@ bool ScreenHandler::hasFocus()
ui32 flags = SDL_GetWindowFlags(mainWindow);
return flags & SDL_WINDOW_INPUT_FOCUS;
}
void ScreenHandler::getRenderScale(float & scaleX, float & scaleY)
{
SDL_RenderGetScale(mainRenderer, &scaleX, &scaleY);
}

View File

@ -89,9 +89,6 @@ public:
/// Window has focus
bool hasFocus() final;
/// Get the scale value of screen
void getRenderScale(float & scaleX, float & scaleY);
std::vector<Point> getSupportedResolutions() const final;
std::vector<Point> getSupportedResolutions(int displayIndex) const;
std::tuple<int, int> getSupportedScalingRange() const final;