Adds new commands to Console

* resolution
* projection
This commit is contained in:
Ricardo Quesada 2014-02-08 12:35:11 -08:00
parent c7a999335c
commit 13aa3ad2b5
5 changed files with 136 additions and 8 deletions

View File

@ -151,7 +151,15 @@ void GLViewProtocol::setFrameSize(float width, float height)
_designResolutionSize = _screenSize = Size(width, height);
}
Size GLViewProtocol::getVisibleSize() const
Rect GLViewProtocol::getVisibleRect() const
{
Rect ret;
ret.size = getVisibleSize();
ret.origin = getVisibleOrigin();
return ret;
}
Size GLViewProtocol::getVisibleSize() const
{
if (_resolutionPolicy == ResolutionPolicy::NO_BORDER)
{

View File

@ -117,6 +117,11 @@ public:
*/
virtual Point getVisibleOrigin() const;
/**
* Get the visible rectangle of opengl viewport.
*/
virtual Rect getVisibleRect() const;
/**
* Set the design resolution size.
* @param width Design resolution width.
@ -177,6 +182,8 @@ public:
*/
float getScaleY() const;
/** returns the current Resolution policy */
ResolutionPolicy getResolutionPolicy() const { return _resolutionPolicy; }
protected:
void handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num, int ids[], float xs[], float ys[]);

View File

@ -29,6 +29,7 @@
#include <functional>
#include <cctype>
#include <locale>
#include <sstream>
#include <stdio.h>
#include <time.h>
@ -56,6 +57,7 @@
#include "platform/CCFileUtils.h"
#include "CCConfiguration.h"
#include "CCTextureCache.h"
#include "CCGLView.h"
NS_CC_BEGIN
@ -246,6 +248,8 @@ Console::Console()
}
} },
{ "help", "Print this message", std::bind(&Console::commandHelp, this, std::placeholders::_1, std::placeholders::_2) },
{ "projection", "[2d | 3d] Changes or print the current projection", std::bind(&Console::commandProjection, this, std::placeholders::_1, std::placeholders::_2) },
{ "resolution", "[width height | ] Changes or print the window resolution", std::bind(&Console::commandResolution, this, std::placeholders::_1, std::placeholders::_2) },
{ "scene graph", "Print the scene graph", std::bind(&Console::commandSceneGraph, this, std::placeholders::_1, std::placeholders::_2) },
{ "texture", "[flush | ] Flush or print the TextureCache info", std::bind(&Console::commandTextures, this, std::placeholders::_1, std::placeholders::_2) },
};
@ -422,6 +426,90 @@ void Console::commandConfig(int fd, const std::string& args)
);
}
void Console::commandResolution(int fd, const std::string& args)
{
if(args.length()==0) {
auto director = Director::getInstance();
Size points = director->getWinSize();
Size pixels = director->getWinSizeInPixels();
auto glview = director->getOpenGLView();
Size design = glview->getDesignResolutionSize();
ResolutionPolicy res = glview->getResolutionPolicy();
Rect visibleRect = glview->getVisibleRect();
mydprintf(fd, "Window Size:\n"
"\t%d x %d (points)\n"
"\t%d x %d (pixels)\n"
"\t%d x %d (design resolution)\n"
"Resolution Policy: %d\n"
"Visible Rect:\n"
"\torigin: %d x %d\n"
"\tsize: %d x %d",
(int)points.width, (int)points.height,
(int)pixels.width, (int)pixels.height,
(int)design.width, (int)design.height,
(int)res,
(int)visibleRect.origin.x, (int)visibleRect.origin.y,
(int)visibleRect.size.width, (int)visibleRect.size.height
);
} else {
int width, height, policy;
std::istringstream stream( args );
stream >> width >> height>> policy;
Scheduler *sched = Director::getInstance()->getScheduler();
sched->performFunctionInCocosThread( [&](){
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(width, height, static_cast<ResolutionPolicy>(policy));
} );
}
}
void Console::commandProjection(int fd, const std::string& args)
{
auto director = Director::getInstance();
Scheduler *sched = director->getScheduler();
if(args.length()==0)
{
char buf[20];
auto proj = director->getProjection();
switch (proj) {
case cocos2d::Director::Projection::_2D:
sprintf(buf,"2d");
break;
case cocos2d::Director::Projection::_3D:
sprintf(buf,"3d");
break;
case cocos2d::Director::Projection::CUSTOM:
sprintf(buf,"custom");
break;
default:
sprintf(buf,"unknown");
break;
}
mydprintf(fd, "Current projection: %s", buf);
}
else if( args.compare("2d") == 0)
{
sched->performFunctionInCocosThread( [&](){
director->setProjection(Director::Projection::_2D);
} );
}
else if( args.compare("3d") == 0)
{
sched->performFunctionInCocosThread( [&](){
director->setProjection(Director::Projection::_3D);
} );
}
else
{
mydprintf(fd, "Unsupported argument: '%s'. Supported arguments: '2d' or '3d'", args.c_str());
}
}
void Console::commandTextures(int fd, const std::string& args)
{
Scheduler *sched = Director::getInstance()->getScheduler();

View File

@ -112,6 +112,8 @@ protected:
void commandFileUtils(int fd, const std::string &args);
void commandConfig(int fd, const std::string &args);
void commandTextures(int fd, const std::string &args);
void commandResolution(int fd, const std::string &args);
void commandProjection(int fd, const std::string &args);
// file descriptor: socket, console, etc.
int _listenfd;

View File

@ -1,21 +1,44 @@
/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
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.
****************************************************************************/
#include "VisibleRect.h"
Rect VisibleRect::s_visibleRect;
void VisibleRect::lazyInit()
{
if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f)
{
auto glView = Director::getInstance()->getOpenGLView();
s_visibleRect.origin = glView->getVisibleOrigin();
s_visibleRect.size = glView->getVisibleSize();
}
// if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f)
s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
}
Rect VisibleRect::getVisibleRect()
{
lazyInit();
return Rect(s_visibleRect.origin.x, s_visibleRect.origin.y, s_visibleRect.size.width, s_visibleRect.size.height);
return s_visibleRect;
}
Point VisibleRect::left()