SDLPP: mouse position functions

This commit is contained in:
2021-04-29 19:48:05 +02:00
parent 90dc26251b
commit 4f20274f11
3 changed files with 51 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
#include "sdlpp_mouse.hpp"
#include "sdlpp_renderobject.hpp"
SDLPP::Vec2D< int > SDLPP::Mouse::getMousePosition() {
int x, y;
SDL_GetMouseState( &x, &y );
return { x, y };
}
SDLPP::Vec2D< double >
SDLPP::Mouse::getMousePositionDouble( const SDLPP::Renderer &r,
SDLPP::ObjectAlignment alignment_x,
SDLPP::ObjectAlignment alignment_y ) {
auto pixel_pos = getMousePosition();
auto smaller = r.getSmallerSide();
Vec2D< double > ret = { static_cast< double >( pixel_pos.getX() ) / smaller,
static_cast< double >( pixel_pos.getY() ) /
smaller };
Vec2D< double > additions =
( r.getDoubleDimensions() - Vec2D< double >( 1.0, 1.0 ) ) / 2;
switch ( alignment_x ) {
case SDLPP::OBJ_CENTER:
ret -= additions;
break;
case SDLPP::OBJ_END:
ret -= 2 * additions;
default:
break;
}
return ret;
}