2021-04-29 17:48:05 +00:00
|
|
|
#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:
|
2021-05-31 12:30:28 +00:00
|
|
|
ret -= { additions.getX(), 0 };
|
2021-04-29 17:48:05 +00:00
|
|
|
break;
|
|
|
|
case SDLPP::OBJ_END:
|
2021-05-31 12:30:28 +00:00
|
|
|
ret -= { 2 * additions.getX(), 0 };
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch ( alignment_y ) {
|
|
|
|
case SDLPP::OBJ_CENTER:
|
|
|
|
ret -= { 0, additions.getY() };
|
|
|
|
break;
|
|
|
|
case SDLPP::OBJ_END:
|
|
|
|
ret -= { 0, 2 * additions.getY() };
|
2021-04-29 17:48:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|