41 lines
1.2 KiB
C++
41 lines
1.2 KiB
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.getX(), 0 };
|
|
break;
|
|
case SDLPP::OBJ_END:
|
|
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() };
|
|
default:
|
|
break;
|
|
}
|
|
return ret;
|
|
}
|