mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 14:24:10 +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};
|
||||||
|
}
|
||||||
6
src/utils/CoordinateTools.h
Normal file
6
src/utils/CoordinateTools.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
std::pair<int, int> physicalToLogical(const float screenX, const float screenY, SDL_Renderer* renderer);
|
||||||
|
|
||||||
Reference in New Issue
Block a user