| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- /****************************************************************************
- Copyright (c) 2010-2012 cocos2d-x.org
- Copyright (c) 2013-2016 Chukong Technologies Inc.
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- #pragma once
- #include "platform/CCGL.h"
- #include "base/ccMacros.h"
- #include "platform/CCApplication.h"
- #include "glfw3/glfw3.h"
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
- #ifndef GLFW_EXPOSE_NATIVE_WIN32
- #define GLFW_EXPOSE_NATIVE_WIN32
- #endif
- #ifndef GLFW_EXPOSE_NATIVE_WGL
- #define GLFW_EXPOSE_NATIVE_WGL
- #endif
- #include "glfw3/glfw3native.h"
- #endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
- #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
- #ifndef GLFW_EXPOSE_NATIVE_NSGL
- #define GLFW_EXPOSE_NATIVE_NSGL
- #endif
- #ifndef GLFW_EXPOSE_NATIVE_COCOA
- #define GLFW_EXPOSE_NATIVE_COCOA
- #endif
- #include "glfw3/glfw3native.h"
- #endif // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
- NS_CC_BEGIN
- class CC_DLL GLView final
- {
- public:
- GLView(Application *application, const std::string& name, int x, int y, int width, int height,
- Application::PixelFormat pixelformat, Application::DepthFormat depthFormat, int multiSampleCount);
- ~GLView();
- bool windowShouldClose() const;
- void pollEvents();
- void swapBuffers();
- float getScale() const;
- GLint getMainFBO() const;
- void setIsEditboxEditing(bool value);
- inline GLFWwindow* getGLFWWindow() const {return _mainWindow;};
-
- private:
- bool initGlew();
- void computeScale();
- // GLFW callbacks
- void onGLFWError(int errorID, const char* errorDesc);
- void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify);
- void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
- void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y);
- void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
- void onGLFWCharCallback(GLFWwindow* window, unsigned int character);
- void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified);
- void onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int height);
- GLFWwindow* _mainWindow = nullptr;
- GLFWmonitor* _monitor = nullptr;
- GLint _mainFBO = -1;
- std::string _glfwError;
-
- Application *_application = nullptr;
- float _mouseX = 0;
- float _mouseY = 0;
-
- // (framebuffer size) / (window size)
- float _scale = 1.0f;
-
- bool _isEditboxEditing = false;
- friend class GLFWEventHandler;
- };
- class CC_DLL GLFWEventHandler final
- {
- public:
- static void onGLFWError(int errorID, const char* errorDesc)
- {
- _view->onGLFWError(errorID, errorDesc);
- }
- static void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify)
- {
- _view->onGLFWMouseCallBack(window, button, action, modify);
- }
- static void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y)
- {
- _view->onGLFWMouseMoveCallBack(window, x, y);
- }
- static void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y)
- {
- _view->onGLFWMouseScrollCallback(window, x, y);
- }
- static void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
- {
- _view->onGLFWKeyCallback(window, key, scancode, action, mods);
- }
- static void onGLFWCharCallback(GLFWwindow* window, unsigned int character)
- {
- _view->onGLFWCharCallback(window, character);
- }
- static void setGLView(GLView* view)
- {
- _view = view;
- }
- static void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified)
- {
- _view->onGLFWWindowIconifyCallback(window, iconified);
- }
- static void onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int height)
- {
- _view->onGLFWWindowSizeFunCallback(window, width, height);
- }
- private:
- static GLView* _view;
- };
- NS_CC_END // end of namespace cocos2d
|