mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-27 01:45:35 -05:00
add util geode::cocos::getMousePos
This commit is contained in:
parent
5f3c6587b3
commit
306fde70d0
2 changed files with 20 additions and 13 deletions
|
@ -682,19 +682,12 @@ namespace geode::cocos {
|
|||
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>> >
|
||||
// static std::map<K, V> ccDictToMap(cocos2d::CCDictionary* dict) {
|
||||
// auto res = std::map<K, V>();
|
||||
// cocos2d::CCDictElement* element = nullptr;
|
||||
// CCDICT_FOREACH(dict, element) {
|
||||
// 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;
|
||||
// }
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue