diff --git a/sdlpp/Makefile b/sdlpp/Makefile index e08cd29..01ee295 100644 --- a/sdlpp/Makefile +++ b/sdlpp/Makefile @@ -28,7 +28,7 @@ SDLPPLIBRARY = libsdlpp.dll LIBRARYFLAGS = endif -OBJECTFILES = sdlpp_circlecolider.${OBJEXT} sdlpp_circlerenderer.${OBJEXT} sdlpp_collision.${OBJEXT} sdlpp_common.${OBJEXT} sdlpp_font.${OBJEXT} sdlpp_linerenderer.${OBJEXT} sdlpp_rectcolider.${OBJEXT} sdlpp_rectrenderer.${OBJEXT} sdlpp_renderer.${OBJEXT} sdlpp_renderobject.${OBJEXT} sdlpp_scene.${OBJEXT} sdlpp_textrenderer.${OBJEXT} sdlpp_texture.${OBJEXT} sdlpp_window.${OBJEXT} sdlpp_fontconfiguration.${OBJEXT} +OBJECTFILES = sdlpp_circlecolider.${OBJEXT} sdlpp_circlerenderer.${OBJEXT} sdlpp_collision.${OBJEXT} sdlpp_common.${OBJEXT} sdlpp_font.${OBJEXT} sdlpp_linerenderer.${OBJEXT} sdlpp_rectcolider.${OBJEXT} sdlpp_rectrenderer.${OBJEXT} sdlpp_renderer.${OBJEXT} sdlpp_renderobject.${OBJEXT} sdlpp_scene.${OBJEXT} sdlpp_textrenderer.${OBJEXT} sdlpp_texture.${OBJEXT} sdlpp_window.${OBJEXT} sdlpp_fontconfiguration.${OBJEXT} sdlpp_mouse.${OBJEXT} all: ${SDLPPLIBRARY} diff --git a/sdlpp/sdlpp_mouse.cpp b/sdlpp/sdlpp_mouse.cpp new file mode 100644 index 0000000..020dd2d --- /dev/null +++ b/sdlpp/sdlpp_mouse.cpp @@ -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; +} diff --git a/sdlpp/sdlpp_mouse.hpp b/sdlpp/sdlpp_mouse.hpp new file mode 100644 index 0000000..cf0f932 --- /dev/null +++ b/sdlpp/sdlpp_mouse.hpp @@ -0,0 +1,19 @@ +#ifndef SDLPP_HPP_MOUSE +#define SDLPP_HPP_MOUSE + +#include "sdlpp_common.hpp" +#include "sdlpp_renderer.hpp" +#include "sdlpp_renderobject.hpp" +#include "sdlpp_vector.hpp" + +namespace SDLPP { +class SDLPPSCOPE Mouse { +public: + static Vec2D< int > getMousePosition(); + static Vec2D< double > + getMousePositionDouble( const Renderer &r, ObjectAlignment alignment_x, + ObjectAlignment alignment_y ); +}; +} // end of namespace SDLPP + +#endif