Added button checks
This commit is contained in:
parent
970d6a89ae
commit
5daae26a12
6 changed files with 78 additions and 2 deletions
|
@ -2,7 +2,7 @@ set(PNAME SDLU)
|
|||
|
||||
add_library(${PNAME}
|
||||
alibi.cpp SDLU.hpp Util.hpp
|
||||
"structures/Color.cpp")
|
||||
"structures/Color.cpp" "structures/Mouse.cpp")
|
||||
|
||||
set_property(TARGET ${PNAME} PROPERTY CXX_STANDARD 17)
|
||||
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
|
||||
#include "graphics/RenderWindow.hpp"
|
||||
|
||||
#include "structures/Mouse.hpp"
|
||||
|
||||
#include "exceptions/Exceptions.hpp"
|
|
@ -2,4 +2,6 @@ target_sources(${PNAME} PRIVATE
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/Vector2.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Color.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Color.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Mouse.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Mouse.cpp
|
||||
)
|
16
SDLU/structures/Mouse.cpp
Normal file
16
SDLU/structures/Mouse.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "Mouse.hpp"
|
||||
|
||||
#include <SDL_mouse.h>
|
||||
|
||||
namespace sdlu
|
||||
{
|
||||
Uint32 Mouse::GetButtonState()
|
||||
{
|
||||
return SDL_GetMouseState(NULL, NULL);
|
||||
}
|
||||
|
||||
bool Mouse::IsButtonDown(Button button)
|
||||
{
|
||||
return (GetButtonState() & SDL_BUTTON(button));
|
||||
}
|
||||
}
|
46
SDLU/structures/Mouse.hpp
Normal file
46
SDLU/structures/Mouse.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @file Mouse.hpp
|
||||
* @brief A static class to provide easy handling of the mouse
|
||||
* @author Lauchmelder23
|
||||
* @date 19.05.2020
|
||||
*/
|
||||
#pragma once
|
||||
#include <SDL_mouse.h>
|
||||
#include <structures/Vector2.hpp>
|
||||
|
||||
namespace sdlu
|
||||
{
|
||||
/**
|
||||
* @brief A static class that contains/handles data about
|
||||
* mouse position and button states
|
||||
*/
|
||||
class Mouse
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Mouse buttons
|
||||
*/
|
||||
enum Button {
|
||||
Left = SDL_BUTTON_LEFT,
|
||||
Right = SDL_BUTTON_RIGHT,
|
||||
Middle = SDL_BUTTON_MIDDLE,
|
||||
XButton1 = SDL_BUTTON_X1,
|
||||
XButton2 = SDL_BUTTON_X2
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Returns the current mouse button state
|
||||
*
|
||||
* @return A 32-bit mask of the current button state
|
||||
*/
|
||||
static Uint32 GetButtonState();
|
||||
|
||||
/**
|
||||
* @brief Checks if a specific button is pressed
|
||||
*
|
||||
* @param[in] button The button to check
|
||||
* @return True if the button is pressed
|
||||
*/
|
||||
static bool IsButtonDown(Button button);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue