PocketEmpires/Cursor.cpp

139 lines
3.9 KiB
C++

/* *******************************************************************
* Includes
* ******************************************************************/
#include "Cursor.h"
#include "Camera.h"
#include <stdint.h>
/* *******************************************************************
* Defines
* ******************************************************************/
#define CURSOR_DEFAULT_X (static_cast<uint8_t>(80 >> 1))
#define CURSOR_DEFAULT_Y (static_cast<uint8_t>(44 >> 1))
/* *******************************************************************
* Types definition
* ******************************************************************/
/* *******************************************************************
* Global variables definition
* ******************************************************************/
/* *******************************************************************
* Local variables definition
* ******************************************************************/
/* *******************************************************************
* Local prototypes declaration
* ******************************************************************/
/* *******************************************************************
* Functions definition
* ******************************************************************/
/*****************************************************************//**
*
* \brief Constructor for Cursor class.
*
*********************************************************************/
Cursor::Cursor(const Camera& c) :
_x(CURSOR_DEFAULT_X),
_y(CURSOR_DEFAULT_Y),
_cam(c)
{
}
/*****************************************************************//**
*
* \brief This function moves the cursor to a given position,
* as long as X coordinates are between {0, CURSOR_DEFAULT_X}
* and Y coordinates are between {0, CURSOR_DEFAULT_Y}.
*
* \param x
* X position diff.
*
* \param y
* Y position diff.
*
*********************************************************************/
void Cursor::move(const int8_t x, const int8_t y)
{
if ((static_cast<int8_t>(_x) + x >= 0)
&&
(static_cast<int8_t>(_x) + x <= CURSOR_DEFAULT_X))
{
_x += x;
}
if ((static_cast<int8_t>(_y) + y >= 0)
&&
(static_cast<int8_t>(_y) + y <= CURSOR_DEFAULT_Y))
{
_y += y;
}
}
uint8_t Cursor::getScreenX(void)
{
return _x;
}
uint8_t Cursor::getScreenY(void)
{
return _y;
}
/*****************************************************************//**
*
* \brief This function simply returns cursor X position.
*
* \return Returns cursor X position.
*
*********************************************************************/
uint8_t Cursor::getX(void)
{
return _cam.getRealX(_x);
}
/*****************************************************************//**
*
* \brief This function simply returns cursor Y position.
*
* \return Returns cursor Y position.
*
*********************************************************************/
uint8_t Cursor::getY(void)
{
return _cam.getRealY(_y);
}
/*****************************************************************//**
*
* \brief This function returns whether cursor is on its initial
* X position.
*
* \return True if \ref Cursor object is on its initial X position,
* false otherwise.
*
*********************************************************************/
bool Cursor::isXCentered(void)
{
return _x == CURSOR_DEFAULT_X;
}
/*****************************************************************//**
*
* \brief This function returns whether cursor is on its initial
* Y position.
*
* \return True if \ref Cursor object is on its initial Y position,
* false otherwise.
*
*********************************************************************/
bool Cursor::isYCentered(void)
{
return _y == CURSOR_DEFAULT_Y;
}