add util geode::cocos::getMousePos

This commit is contained in:
matcool 2023-03-11 11:40:03 -03:00
parent 5f3c6587b3
commit 306fde70d0
No known key found for this signature in database
GPG key ID: BF58756086D7AB1C
2 changed files with 20 additions and 13 deletions

View file

@ -682,19 +682,12 @@ namespace geode::cocos {
return res; return res;
} }
// template<typename K, typename V, /**
// typename = std::enable_if_t<std::is_same_v<K, std::string> || std::is_same_v<K, intptr_t>> > * Gets the mouse position in cocos2d coordinates.
// static std::map<K, V> ccDictToMap(cocos2d::CCDictionary* dict) { * On mobile platforms this will probably return (0, 0)
// auto res = std::map<K, V>(); * @returns The mouse position
// cocos2d::CCDictElement* element = nullptr; */
// CCDICT_FOREACH(dict, element) { GEODE_DLL cocos2d::CCPoint getMousePos();
// if constexpr (std::is_same_v<K, std::string>)
// res[element->getStrKey()] = element->getObject();
// if constexpr (std::is_same_v<K, intptr_t>)
// res[element->getIntKey()] = element->getObject();
// }
// return res;
// }
} }
// std specializations // std specializations

View file

@ -330,6 +330,20 @@ CCScene* geode::cocos::switchToScene(CCLayer* layer) {
return scene; return scene;
} }
CCPoint geode::cocos::getMousePos() {
#ifdef GEODE_IS_WINDOWS
auto* director = CCDirector::get();
auto* gl = director->getOpenGLView();
auto winSize = director->getWinSize();
auto frameSize = gl->getFrameSize();
auto mouse = gl->getMousePosition() / frameSize;
return ccp(mouse.x, 1.f - mouse.y) * winSize;
#else
// TODO: implement this for mac
return ccp(0, 0);
#endif
}
static CreateLayerFunc LOADING_FINISHED_SCENE = nullptr; static CreateLayerFunc LOADING_FINISHED_SCENE = nullptr;
void geode::cocos::reloadTextures(CreateLayerFunc returnTo) { void geode::cocos::reloadTextures(CreateLayerFunc returnTo) {