2014-01-07 11:25:07 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-01-31 09:28:12 +08:00
|
|
|
#ifndef __CCGLVIEWPROTOCOL_H__
|
|
|
|
#define __CCGLVIEWPROTOCOL_H__
|
2012-04-23 14:30:38 +08:00
|
|
|
|
|
|
|
#include "ccTypes.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCEventTouch.h"
|
2013-09-12 14:26:39 +08:00
|
|
|
|
|
|
|
#include <vector>
|
2012-04-23 14:30:38 +08:00
|
|
|
|
2013-07-26 18:18:58 +08:00
|
|
|
enum class ResolutionPolicy
|
2012-08-01 16:56:12 +08:00
|
|
|
{
|
2012-10-16 14:42:30 +08:00
|
|
|
// The entire application is visible in the specified area without trying to preserve the original aspect ratio.
|
2012-08-09 10:23:39 +08:00
|
|
|
// Distortion can occur, and the application may appear stretched or compressed.
|
2013-07-26 20:07:41 +08:00
|
|
|
EXACT_FIT,
|
2012-10-16 14:42:30 +08:00
|
|
|
// The entire application fills the specified area, without distortion but possibly with some cropping,
|
2012-08-09 10:23:39 +08:00
|
|
|
// while maintaining the original aspect ratio of the application.
|
2013-07-26 18:18:58 +08:00
|
|
|
NO_BORDER,
|
2012-10-16 14:42:30 +08:00
|
|
|
// The entire application is visible in the specified area without distortion while maintaining the original
|
2012-08-09 10:23:39 +08:00
|
|
|
// aspect ratio of the application. Borders can appear on two sides of the application.
|
2013-07-26 18:18:58 +08:00
|
|
|
SHOW_ALL,
|
2013-03-19 03:06:01 +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
|
2013-07-26 18:18:58 +08:00
|
|
|
FIXED_HEIGHT,
|
2013-03-19 03:06:01 +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
|
2013-07-26 18:18:58 +08:00
|
|
|
FIXED_WIDTH,
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2013-07-26 18:18:58 +08:00
|
|
|
UNKNOWN,
|
2012-08-01 16:56:12 +08:00
|
|
|
};
|
|
|
|
|
2012-04-23 14:30:38 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class EGLTouchDelegate;
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup platform
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-01-31 07:40:56 +08:00
|
|
|
class CC_DLL GLViewProtocol
|
2012-04-23 14:30:38 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2014-01-31 07:40:56 +08:00
|
|
|
GLViewProtocol();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-01-31 07:40:56 +08:00
|
|
|
virtual ~GLViewProtocol();
|
2012-04-23 14:30:38 +08:00
|
|
|
|
2012-09-16 05:19:14 +08:00
|
|
|
/** Force destroying EGL view, subclass must implement this method. */
|
2014-01-31 07:11:11 +08:00
|
|
|
virtual void end() = 0;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/** Get whether opengl render system is ready, subclass must implement this method. */
|
2014-01-31 07:11:11 +08:00
|
|
|
virtual bool isOpenGLReady() = 0;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/** Exchanges the front and back buffers, subclass must implement this method. */
|
2014-01-31 07:11:11 +08:00
|
|
|
virtual void swapBuffers() = 0;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/** Open or close IME keyboard , subclass must implement this method. */
|
2014-01-31 07:11:11 +08:00
|
|
|
virtual void setIMEKeyboardState(bool open) = 0;
|
2012-04-23 14:30:38 +08:00
|
|
|
|
2013-07-08 10:26:53 +08:00
|
|
|
/**
|
|
|
|
* Polls input events. Subclass must implement methods if platform
|
|
|
|
* does not provide event callbacks.
|
|
|
|
*/
|
|
|
|
virtual void pollInputEvents();
|
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
|
|
|
* Get the frame size of EGL view.
|
|
|
|
* In general, it returns the screen size since the EGL view is a fullscreen view.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual const Size& getFrameSize() const;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
|
|
|
* Set the frame size of EGL view.
|
|
|
|
*/
|
2012-10-09 00:38:04 +08:00
|
|
|
virtual void setFrameSize(float width, float height);
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
|
|
|
* Get the visible area size of opengl viewport.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual Size getVisibleSize() const;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
|
|
|
* Get the visible origin point of opengl viewport.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual Point getVisibleOrigin() const;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
|
|
|
/**
|
2012-09-15 06:26:38 +08:00
|
|
|
* Set the design resolution size.
|
2012-08-15 14:33:56 +08:00
|
|
|
* @param width Design resolution width.
|
|
|
|
* @param height Design resolution height.
|
2012-09-15 06:26:38 +08:00
|
|
|
* @param resolutionPolicy The resolution policy desired, you may choose:
|
2013-07-26 20:07:41 +08:00
|
|
|
* [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.
|
2013-07-26 18:18:58 +08:00
|
|
|
* [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.
|
2012-08-15 14:33:56 +08:00
|
|
|
*/
|
|
|
|
virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-10-23 10:50:47 +08:00
|
|
|
/** Get design resolution size.
|
2012-10-23 14:01:48 +08:00
|
|
|
* Default resolution size is the same as 'getFrameSize'.
|
2012-10-23 10:50:47 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual const Size& getDesignResolutionSize() const;
|
2012-10-23 10:50:47 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
|
|
|
* Set opengl view port rectangle with points.
|
|
|
|
*/
|
|
|
|
virtual void setViewPortInPoints(float x , float y , float w , float h);
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
|
|
|
* Set Scissor rectangle with points.
|
|
|
|
*/
|
|
|
|
virtual void setScissorInPoints(float x , float y , float w , float h);
|
2012-09-20 01:56:58 +08:00
|
|
|
|
2013-03-29 17:21:29 +08:00
|
|
|
/**
|
2013-03-29 01:28:26 +08:00
|
|
|
* Get whether GL_SCISSOR_TEST is enable
|
|
|
|
*/
|
2013-03-29 17:19:47 +08:00
|
|
|
virtual bool isScissorEnabled();
|
2013-03-29 01:28:26 +08:00
|
|
|
|
2013-03-29 17:21:29 +08:00
|
|
|
/**
|
2013-03-29 01:28:26 +08:00
|
|
|
* Get the current scissor rectangle
|
|
|
|
*/
|
2013-11-23 08:09:05 +08:00
|
|
|
virtual Rect getScissorRect() const;
|
2013-03-29 01:28:26 +08:00
|
|
|
|
2013-11-23 08:09:05 +08:00
|
|
|
virtual void setViewName(const std::string& viewname);
|
|
|
|
const std::string& getViewName() const;
|
2012-05-02 17:50:26 +08:00
|
|
|
|
2012-09-15 06:26:38 +08:00
|
|
|
/** Touch events are handled by default; if you want to customize your handlers, please override these functions: */
|
2013-12-05 17:19:01 +08:00
|
|
|
virtual void handleTouchesBegin(int num, int ids[], float xs[], float ys[]);
|
|
|
|
virtual void handleTouchesMove(int num, int ids[], float xs[], float ys[]);
|
|
|
|
virtual void handleTouchesEnd(int num, int ids[], float xs[], float ys[]);
|
|
|
|
virtual void handleTouchesCancel(int num, int ids[], float xs[], float ys[]);
|
2012-04-23 14:30:38 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
2012-09-15 06:26:38 +08:00
|
|
|
* Get the opengl view port rectangle.
|
2012-08-15 14:33:56 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
const Rect& getViewPortRect() const;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
2012-09-15 06:26:38 +08:00
|
|
|
* Get scale factor of the horizontal direction.
|
2012-08-15 14:33:56 +08:00
|
|
|
*/
|
|
|
|
float getScaleX() const;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
/**
|
2012-09-15 06:26:38 +08:00
|
|
|
* Get scale factor of the vertical direction.
|
2012-08-15 14:33:56 +08:00
|
|
|
*/
|
|
|
|
float getScaleY() const;
|
2013-11-23 08:09:05 +08:00
|
|
|
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2012-04-23 14:30:38 +08:00
|
|
|
protected:
|
2013-12-05 17:19:01 +08:00
|
|
|
void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, int ids[], float xs[], float ys[]);
|
2013-11-23 08:09:05 +08:00
|
|
|
|
2012-09-15 06:26:38 +08:00
|
|
|
// real screen size
|
2013-06-20 14:13:12 +08:00
|
|
|
Size _screenSize;
|
2012-09-15 06:26:38 +08:00
|
|
|
// resolution size, it is the size appropriate for the app resources.
|
2013-06-20 14:13:12 +08:00
|
|
|
Size _designResolutionSize;
|
2012-08-01 16:56:12 +08:00
|
|
|
// the view port size
|
2013-06-20 14:13:12 +08:00
|
|
|
Rect _viewPortRect;
|
2012-08-15 14:33:56 +08:00
|
|
|
// the view name
|
2013-11-23 08:09:05 +08:00
|
|
|
std::string _viewName;
|
2012-10-16 14:42:30 +08:00
|
|
|
|
2014-01-31 07:11:11 +08:00
|
|
|
float _scaleX;
|
|
|
|
float _scaleY;
|
2013-06-15 14:03:30 +08:00
|
|
|
ResolutionPolicy _resolutionPolicy;
|
2012-04-23 14:30:38 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of platform group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-23 14:30:38 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2014-01-31 09:28:12 +08:00
|
|
|
#endif /* __CCGLVIEWPROTOCOL_H__ */
|