blob: 2b02ad661a09017dfd5256a2d3f3b64b0dad691c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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;
}
|