mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
add CoordinateTools
This commit is contained in:
16
src/utils/CoordinateTools.cpp
Normal file
16
src/utils/CoordinateTools.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "CoordinateTools.h"
|
||||
|
||||
std::pair<int, int> physicalToLogical(const float screenX, const float screenY, SDL_Renderer* renderer) {
|
||||
// 将窗口坐标转为逻辑坐标
|
||||
float logicalX, logicalY;
|
||||
SDL_RenderCoordinatesFromWindow(
|
||||
renderer,
|
||||
static_cast<float>(screenX),
|
||||
static_cast<float>(screenY),
|
||||
&logicalX,
|
||||
&logicalY
|
||||
);
|
||||
int mouseX = static_cast<int>(logicalX);
|
||||
int mouseY = static_cast<int>(logicalY);
|
||||
return {logicalX, logicalY};
|
||||
}
|
||||
Reference in New Issue
Block a user