diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index d1bb45fc..0ae26094 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -682,19 +682,12 @@ namespace geode::cocos { return res; } - // template || std::is_same_v> > - // static std::map ccDictToMap(cocos2d::CCDictionary* dict) { - // auto res = std::map(); - // cocos2d::CCDictElement* element = nullptr; - // CCDICT_FOREACH(dict, element) { - // if constexpr (std::is_same_v) - // res[element->getStrKey()] = element->getObject(); - // if constexpr (std::is_same_v) - // res[element->getIntKey()] = element->getObject(); - // } - // return res; - // } + /** + * Gets the mouse position in cocos2d coordinates. + * On mobile platforms this will probably return (0, 0) + * @returns The mouse position + */ + GEODE_DLL cocos2d::CCPoint getMousePos(); } // std specializations diff --git a/loader/src/utils/cocos.cpp b/loader/src/utils/cocos.cpp index 977d4c1f..10c2a9bd 100644 --- a/loader/src/utils/cocos.cpp +++ b/loader/src/utils/cocos.cpp @@ -330,6 +330,20 @@ CCScene* geode::cocos::switchToScene(CCLayer* layer) { 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; void geode::cocos::reloadTextures(CreateLayerFunc returnTo) {