Skip to content

Commit 6de3d02

Browse files
authored
Merge pull request #204 from ntut-rick/pos
Fix PTSD Position & update docs
2 parents d76c488 + 457f62e commit 6de3d02

File tree

5 files changed

+28
-59
lines changed

5 files changed

+28
-59
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ set(TEST_FILES
113113
${TEST_DIR}/SimpleTest.cpp
114114
${TEST_DIR}/NotSimpleTest.cpp
115115
${TEST_DIR}/TransformTest.cpp
116-
${TEST_DIR}/PositionTest.cpp
117116
)
118117

119118
add_library(PTSD STATIC

include/Util/Input.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ class Input {
4545

4646
/**
4747
* @brief Retrieves the current position of the cursor.
48-
* @note The cursor position is relative to the upper-left corner of the
49-
* client area of the window.
5048
*
51-
* @return The cursor position as vec2(x, y).
49+
* @return The cursor position as a PTSDPosition (x, y).
5250
*
5351
* @see Util::Input::SetCursorPosition()
52+
* @see Util::PTSDPosition
5453
*/
5554
static Util::PTSDPosition GetCursorPosition();
5655

@@ -115,11 +114,11 @@ class Input {
115114
/**
116115
* @brief Sets the position of the cursor.
117116
* @param pos The position to set the cursor to.
118-
* @note The cursor position is relative to the upper-left corner of the
119-
* client area of the window.
120-
* @note It also generates a mouse motion event, which leads
121-
* Util::Input::IsMouseMoving() to return true in this update-cycle.
117+
* @note This also triggers a mouse motion event, making Util::Input::IsMouseMoving() return true
118+
* in the current update cycle.
119+
*
122120
* @see Util::Input::GetCursorPosition()
121+
* @see Util::PTSDPosition
123122
*/
124123
static void SetCursorPosition(const Util::PTSDPosition &pos);
125124

include/Util/Position.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ namespace Util {
77

88
struct PTSDPosition;
99

10+
/**
11+
* @struct SDLPosition
12+
* @brief A class representing a position in screen coordinates.
13+
*
14+
* This class is used to store the X and Y coordinates of a point in a screen coordinate system where:
15+
* - The origin (0, 0) is at the upper-left corner of the window.
16+
* - X increases to the right.
17+
* - Y increases downwards.
18+
*/
1019
struct SDLPosition {
1120
public:
1221
const int x;
@@ -20,6 +29,15 @@ struct SDLPosition {
2029
y(y) {}
2130
};
2231

32+
/**
33+
* @struct PTSDPosition
34+
* @brief A class representing a position in a Cartesian coordinates.
35+
*
36+
* This class is used to store the X and Y coordinates of a point in a Cartesian coordinate system where:
37+
* - The origin (0, 0) is at the center of the window.
38+
* - X increases to the right.
39+
* - Y increases upwards.
40+
*/
2341
struct PTSDPosition {
2442
float x{};
2543
float y{};

src/Util/Position.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ PTSDPosition PTSDPosition::FromSDL(int sdlx, int sdly) {
1010
return PTSDPosition{
1111
static_cast<float>(sdlx) -
1212
static_cast<float>(PTSD_Config::WINDOW_WIDTH) / 2.0F,
13-
static_cast<float>(sdly) -
14-
static_cast<float>(PTSD_Config::WINDOW_HEIGHT) / 2.0F};
13+
-(static_cast<float>(sdly) -
14+
static_cast<float>(PTSD_Config::WINDOW_HEIGHT) / 2.0F)};
1515
}
1616

1717
SDLPosition PTSDPosition::ToSDLPosition() const {
1818
return SDLPosition(
1919
static_cast<int>(this->x +
2020
static_cast<float>(PTSD_Config::WINDOW_WIDTH) / 2.0F),
21-
static_cast<int>(
22-
this->y + static_cast<float>(PTSD_Config::WINDOW_HEIGHT) / 2.0F));
21+
-(static_cast<int>(
22+
this->y + static_cast<float>(PTSD_Config::WINDOW_HEIGHT) / 2.0F)));
2323
}
2424
} // namespace Util

test/PositionTest.cpp

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)