summaryrefslogtreecommitdiff
path: root/Cursor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Cursor.cpp')
-rw-r--r--Cursor.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/Cursor.cpp b/Cursor.cpp
new file mode 100644
index 0000000..2b02ad6
--- /dev/null
+++ b/Cursor.cpp
@@ -0,0 +1,126 @@
+/* *******************************************************************
+ * Includes
+ * ******************************************************************/
+
+#include "Cursor.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(void) :
+_x(CURSOR_DEFAULT_X),
+_y(CURSOR_DEFAULT_Y)
+{
+}
+
+/*****************************************************************//**
+ *
+ * \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;
+ }
+}
+
+/*****************************************************************//**
+ *
+ * \brief This function simply returns cursor X position.
+ *
+ * \return Returns cursor X position.
+ *
+ *********************************************************************/
+uint8_t Cursor::getX(void)
+{
+ return _x;
+}
+
+/*****************************************************************//**
+ *
+ * \brief This function simply returns cursor Y position.
+ *
+ * \return Returns cursor Y position.
+ *
+ *********************************************************************/
+uint8_t Cursor::getY(void)
+{
+ return _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;
+}