32 lines
1010 B
C++
32 lines
1010 B
C++
#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;
|
|
}
|