2014-08-02 16:31:16 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCGLVIEW_H__
|
|
|
|
#define __CCGLVIEW_H__
|
|
|
|
|
|
|
|
#include "base/ccTypes.h"
|
|
|
|
#include "base/CCEventTouch.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
|
|
|
typedef void* id;
|
|
|
|
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) */
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** There are some Resolution Policy for Adapt to the screen. */
|
2014-08-02 16:31:16 +08:00
|
|
|
enum class ResolutionPolicy
|
|
|
|
{
|
2015-03-23 18:37:28 +08:00
|
|
|
/** The entire application is visible in the specified area without trying to preserve the original aspect ratio.
|
|
|
|
* Distortion can occur, and the application may appear stretched or compressed.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
EXACT_FIT,
|
2015-03-23 18:37:28 +08:00
|
|
|
/** The entire application fills the specified area, without distortion but possibly with some cropping,
|
|
|
|
* while maintaining the original aspect ratio of the application.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
NO_BORDER,
|
2015-03-23 18:37:28 +08:00
|
|
|
/** The entire application is visible in the specified area without distortion while maintaining the original
|
|
|
|
* aspect ratio of the application. Borders can appear on two sides of the application.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
SHOW_ALL,
|
2015-03-23 18:37:28 +08:00
|
|
|
/** The application takes the height of the design resolution size and modifies the width of the internal
|
|
|
|
* canvas so that it fits the aspect ratio of the device.
|
|
|
|
* No distortion will occur however you must make sure your application works on different
|
|
|
|
* aspect ratios.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
FIXED_HEIGHT,
|
2015-03-23 18:37:28 +08:00
|
|
|
/** The application takes the width of the design resolution size and modifies the height of the internal
|
|
|
|
* canvas so that it fits the aspect ratio of the device.
|
|
|
|
* No distortion will occur however you must make sure your application works on different
|
|
|
|
* aspect ratios.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
FIXED_WIDTH,
|
|
|
|
|
|
|
|
UNKNOWN,
|
|
|
|
};
|
|
|
|
|
2015-03-27 11:39:31 +08:00
|
|
|
/** @struct GLContextAttrs
|
|
|
|
*
|
|
|
|
* There are six opengl Context Attrs.
|
|
|
|
*/
|
2014-08-22 16:22:16 +08:00
|
|
|
struct GLContextAttrs
|
2014-08-22 10:55:39 +08:00
|
|
|
{
|
|
|
|
int redBits;
|
|
|
|
int greenBits;
|
|
|
|
int blueBits;
|
|
|
|
int alphaBits;
|
|
|
|
int depthBits;
|
|
|
|
int stencilBits;
|
|
|
|
};
|
|
|
|
|
2014-08-02 16:31:16 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup platform
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-23 18:37:28 +08:00
|
|
|
/**
|
|
|
|
* @brief By GLView you can operate the frame information of EGL view through some function.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
class CC_DLL GLView : public Ref
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
GLView();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~GLView();
|
|
|
|
|
|
|
|
/** Force destroying EGL view, subclass must implement this method. */
|
|
|
|
virtual void end() = 0;
|
|
|
|
|
|
|
|
/** Get whether opengl render system is ready, subclass must implement this method. */
|
|
|
|
virtual bool isOpenGLReady() = 0;
|
|
|
|
|
|
|
|
/** Exchanges the front and back buffers, subclass must implement this method. */
|
|
|
|
virtual void swapBuffers() = 0;
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Open or close IME keyboard , subclass must implement this method.
|
|
|
|
*
|
|
|
|
* @param open Open or close IME keyboard.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void setIMEKeyboardState(bool open) = 0;
|
2014-09-25 07:41:51 +08:00
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
|
|
virtual void setIMEKeyboardState(bool open, std::string str) = 0;
|
|
|
|
#endif
|
2014-08-02 16:31:16 +08:00
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** When the window is closed, it will return false if the platforms is Ios or Android.
|
|
|
|
* If the platforms is windows or Mac,it will return true.
|
|
|
|
*
|
|
|
|
* @return In ios and android it will return false,if in windows or Mac it will return true.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual bool windowShouldClose() { return false; };
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Static method and member so that we can modify it on all platforms before create OpenGL context.
|
|
|
|
*
|
|
|
|
* @param glContextAttrs The OpenGL context attrs.
|
|
|
|
*/
|
2014-08-22 16:22:16 +08:00
|
|
|
static void setGLContextAttrs(GLContextAttrs& glContextAttrs);
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Return the OpenGL context attrs.
|
|
|
|
*
|
|
|
|
* @return Return the OpenGL context attrs.
|
|
|
|
*/
|
2014-08-22 16:22:16 +08:00
|
|
|
static GLContextAttrs getGLContextAttrs();
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** The OpenGL context attrs. */
|
2014-08-22 16:22:16 +08:00
|
|
|
static GLContextAttrs _glContextAttrs;
|
2014-08-21 09:35:32 +08:00
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** @deprecated
|
2014-08-02 16:31:16 +08:00
|
|
|
* Polls input events. Subclass must implement methods if platform
|
|
|
|
* does not provide event callbacks.
|
|
|
|
*/
|
|
|
|
CC_DEPRECATED_ATTRIBUTE virtual void pollInputEvents();
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Polls the events. */
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void pollEvents();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the frame size of EGL view.
|
|
|
|
* In general, it returns the screen size since the EGL view is a fullscreen view.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return The frame size of EGL view.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual const Size& getFrameSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the frame size of EGL view.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @param width The width of the fram size.
|
|
|
|
* @param height The height of the fram size.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual void setFrameSize(float width, float height);
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Set zoom factor for frame. This methods are for
|
|
|
|
* debugging big resolution (e.g.new ipad) app on desktop.
|
|
|
|
*
|
|
|
|
* @param zoomFactor The zoom factor for frame.
|
|
|
|
*/
|
2014-08-11 16:15:02 +08:00
|
|
|
virtual void setFrameZoomFactor(float zoomFactor) {}
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Get zoom factor for frame. This methods are for
|
|
|
|
* debugging big resolution (e.g.new ipad) app on desktop.
|
|
|
|
*
|
|
|
|
* @return The zoom factor for frame.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual float getFrameZoomFactor() const { return 1.0; }
|
2015-03-23 18:37:28 +08:00
|
|
|
|
2015-02-12 09:21:04 +08:00
|
|
|
/**
|
|
|
|
* Hide or Show the mouse cursor if there is one.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @param isVisible Hide or Show the mouse cursor if there is one.
|
2015-02-12 09:21:04 +08:00
|
|
|
*/
|
2015-03-03 15:29:15 +08:00
|
|
|
virtual void setCursorVisible(bool isVisible) {}
|
2015-02-12 09:21:04 +08:00
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Get retina factor.
|
|
|
|
*
|
|
|
|
* @return The retina factor.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual int getRetinaFactor() const { return 1; }
|
2014-08-11 16:15:02 +08:00
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Only works on ios platform. Set Content Scale of the Factor. */
|
2014-08-11 16:15:02 +08:00
|
|
|
virtual bool setContentScaleFactor(float scaleFactor) { return false; }
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Only works on ios platform. Get Content Scale of the Factor. */
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual float getContentScaleFactor() const { return 1.0; }
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Returns whether or not the view is in Retina Display mode.
|
|
|
|
*
|
|
|
|
* @return Returns whether or not the view is in Retina Display mode.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual bool isRetinaDisplay() const { return false; }
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
virtual void* getEAGLView() const { return nullptr; }
|
|
|
|
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) */
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
|
|
|
virtual Size getRenerTargetSize() const = 0;
|
|
|
|
virtual const Mat4& getOrientationMatrix() const = 0;
|
|
|
|
virtual const Mat4& getReverseOrientationMatrix() const = 0;
|
|
|
|
#endif
|
|
|
|
/**
|
|
|
|
* Get the visible area size of opengl viewport.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return The visible area size of opengl viewport.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual Size getVisibleSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the visible origin point of opengl viewport.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return The visible origin point of opengl viewport.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual Vec2 getVisibleOrigin() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the visible rectangle of opengl viewport.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return The visible rectangle of opengl viewport.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual Rect getVisibleRect() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the design resolution size.
|
|
|
|
* @param width Design resolution width.
|
|
|
|
* @param height Design resolution height.
|
|
|
|
* @param resolutionPolicy The resolution policy desired, you may choose:
|
|
|
|
* [1] EXACT_FIT Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.
|
|
|
|
* [2] NO_BORDER Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.
|
|
|
|
* [3] SHOW_ALL Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.
|
|
|
|
*/
|
|
|
|
virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);
|
|
|
|
|
|
|
|
/** Get design resolution size.
|
|
|
|
* Default resolution size is the same as 'getFrameSize'.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return The design resolution size.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual const Size& getDesignResolutionSize() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set opengl view port rectangle with points.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @param x Set the points of x.
|
|
|
|
* @param y Set the points of y.
|
|
|
|
* @param w Set the width of the view port
|
|
|
|
* @param h Set the Height of the view port.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Scissor rectangle with points.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @param x Set the points of x.
|
|
|
|
* @param y Set the points of y.
|
|
|
|
* @param w Set the width of the view port
|
|
|
|
* @param h Set the Height of the view port.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual void setScissorInPoints(float x , float y , float w , float h);
|
|
|
|
|
|
|
|
/**
|
2015-03-23 18:37:28 +08:00
|
|
|
* Get whether GL_SCISSOR_TEST is enable.
|
|
|
|
*
|
|
|
|
* @return Whether GL_SCISSOR_TEST is enable.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual bool isScissorEnabled();
|
|
|
|
|
|
|
|
/**
|
2015-03-23 18:37:28 +08:00
|
|
|
* Get the current scissor rectangle.
|
|
|
|
*
|
|
|
|
* @return The current scissor rectangle.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
virtual Rect getScissorRect() const;
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Set the view name.
|
|
|
|
*
|
|
|
|
* @param viewname A string will be set to the view as name.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void setViewName(const std::string& viewname);
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Get the view name.
|
|
|
|
*
|
|
|
|
* @return The view name.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
const std::string& getViewName() const;
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Touch events are handled by default; if you want to customize your handlers, please override this function.
|
|
|
|
*
|
|
|
|
* @param num The number of touch.
|
|
|
|
* @param ids The identity of the touch.
|
|
|
|
* @param xs The points of x.
|
|
|
|
* @param ys The points of y.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void handleTouchesBegin(int num, intptr_t ids[], float xs[], float ys[]);
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Touch events are handled by default; if you want to customize your handlers, please override this function.
|
|
|
|
*
|
|
|
|
* @param num The number of touch.
|
|
|
|
* @param ids The identity of the touch.
|
|
|
|
* @param xs The points of x.
|
|
|
|
* @param ys The points of y.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void handleTouchesMove(int num, intptr_t ids[], float xs[], float ys[]);
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Touch events are handled by default; if you want to customize your handlers, please override this function.
|
|
|
|
*
|
|
|
|
* @param num The number of touch.
|
|
|
|
* @param ids The identity of the touch.
|
|
|
|
* @param xs The points of x.
|
|
|
|
* @param ys The points of y.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void handleTouchesEnd(int num, intptr_t ids[], float xs[], float ys[]);
|
2015-03-23 18:37:28 +08:00
|
|
|
|
|
|
|
/** Touch events are handled by default; if you want to customize your handlers, please override this function.
|
|
|
|
*
|
|
|
|
* @param num The number of touch.
|
|
|
|
* @param ids The identity of the touch.
|
|
|
|
* @param xs The points of x.
|
|
|
|
* @param ys The points of y.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
virtual void handleTouchesCancel(int num, intptr_t ids[], float xs[], float ys[]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the opengl view port rectangle.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return Return the opengl view port rectangle.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
const Rect& getViewPortRect() const;
|
2014-06-26 18:40:33 +08:00
|
|
|
|
|
|
|
/**
|
2015-03-23 18:37:28 +08:00
|
|
|
* Get list of all active touches.
|
|
|
|
*
|
|
|
|
* @return A list of all active touches.
|
2014-06-26 18:40:33 +08:00
|
|
|
*/
|
|
|
|
std::vector<Touch*> getAllTouches() const;
|
2014-08-02 16:31:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get scale factor of the horizontal direction.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return Scale factor of the horizontal direction.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
float getScaleX() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get scale factor of the vertical direction.
|
2015-03-23 18:37:28 +08:00
|
|
|
*
|
|
|
|
* @return Scale factor of the vertical direction.
|
2014-08-02 16:31:16 +08:00
|
|
|
*/
|
|
|
|
float getScaleY() const;
|
|
|
|
|
2015-03-23 18:37:28 +08:00
|
|
|
/** Returns the current Resolution policy.
|
|
|
|
*
|
|
|
|
* @return The current Resolution policy.
|
|
|
|
*/
|
2014-08-02 16:31:16 +08:00
|
|
|
ResolutionPolicy getResolutionPolicy() const { return _resolutionPolicy; }
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
virtual HWND getWin32Window() = 0;
|
|
|
|
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
|
|
|
virtual id getCocoaWindow() = 0;
|
|
|
|
#endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) */
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void updateDesignResolutionSize();
|
|
|
|
|
|
|
|
void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, intptr_t ids[], float xs[], float ys[]);
|
|
|
|
|
|
|
|
// real screen size
|
|
|
|
Size _screenSize;
|
|
|
|
// resolution size, it is the size appropriate for the app resources.
|
|
|
|
Size _designResolutionSize;
|
|
|
|
// the view port size
|
|
|
|
Rect _viewPortRect;
|
|
|
|
// the view name
|
|
|
|
std::string _viewName;
|
|
|
|
|
|
|
|
float _scaleX;
|
|
|
|
float _scaleY;
|
|
|
|
ResolutionPolicy _resolutionPolicy;
|
|
|
|
};
|
|
|
|
|
|
|
|
// end of platform group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* __CCGLVIEW_H__ */
|