Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3_shadercompilefix

This commit is contained in:
huangshiwu 2014-09-12 15:38:29 +08:00
commit 0addaf3912
75 changed files with 1820 additions and 1238 deletions

View File

@ -1,6 +1,7 @@
cocos2d-x-3.3?? ??
[NEW] ActionManager: added removeAllActionsByTag()
[NEW] Audio: added new audio system for iOS and Android
[FIX] DrawNode: has any many functions as `DrawPrimitive`
[NEW] GLViewProtocol: added getAllTouches()
[NEW] Node: added stopAllActionsByTag()
[NEW] PhysicsWorld: add setSubsteps() and getSubsteps()
@ -16,6 +17,8 @@ cocos2d-x-3.3?? ??
[FIX] Node: setNormalizedPosition can not take effect if parent position is not changed
[FIX] External: ScrollView: scroll view hidden picks up the touch events
[FIX] TextureAtlas: may crash if only drawing part of it
[FIX] UI: Button: a button can not be touched if it only contains title
[FIX] UI: Button: title can not be scaled if a button is scaled
cocos2d-x-3.3alpha0 Aug.28 2014
[NEW] 3D: Added Camera, AABB, OBB and Ray

View File

@ -43,6 +43,7 @@ endif(DEBUG_MODE)
set(CMAKE_C_FLAGS_DEBUG "-DCOCOS2D_DEBUG=1")
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
# Compiler options
if(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-wd4251 -wd4244 -wd4334 -wd4005 -wd4820 -wd4710
@ -52,8 +53,12 @@ else()
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-exceptions -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -std=c++11 -Wno-deprecated-declarations -Wno-reorder")
if(CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif(MSVC)
# Some macro definitions
if(WINDOWS)
ADD_DEFINITIONS (-D_USRDLL -DCOCOS2DXWIN32_EXPORTS -D_WINDOWS -DWIN32)
set(PLATFORM_FOLDER win32)

View File

@ -28,6 +28,7 @@
#include "2d/CCClippingNode.h"
#include "2d/CCDrawingPrimitives.h"
#include "renderer/CCGLProgramCache.h"
#include "renderer/ccGLStateCache.h"
#include "renderer/CCRenderer.h"
#include "base/CCDirector.h"
@ -200,12 +201,40 @@ void ClippingNode::drawFullScreenQuadClearStencil()
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
Vec2 vertices[] = {
Vec2(-1, -1),
Vec2(1, -1),
Vec2(1, 1),
Vec2(-1, 1)
};
DrawPrimitives::drawSolidRect(Vec2(-1,-1), Vec2(1,1), Color4F(1, 1, 1, 1));
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
glProgram->retain();
int colorLocation = glProgram->getUniformLocation("u_color");
CHECK_GL_ERROR_DEBUG();
Color4F color(1, 1, 1, 1);
glProgram->use();
glProgram->setUniformsForBuiltins();
glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vec2)*4, vertices, GL_STREAM_DRAW);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void ClippingNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)

View File

@ -27,9 +27,11 @@
#include "renderer/CCRenderer.h"
#include "renderer/ccGLStateCache.h"
#include "renderer/CCGLProgramState.h"
#include "renderer/CCGLProgramCache.h"
#include "base/CCDirector.h"
#include "base/CCEventListenerCustom.h"
#include "base/CCEventDispatcher.h"
#include "2d/CCActionCatmullRom.h"
#include "platform/CCGL.h"
NS_CC_BEGIN
@ -108,6 +110,20 @@ DrawNode::DrawNode()
, _bufferCount(0)
, _buffer(nullptr)
, _dirty(false)
, _vaoGLPoint(0)
, _vboGLPoint(0)
, _bufferCapacityGLPoint(0)
, _bufferCountGLPoint(0)
, _bufferGLPoint(nullptr)
, _pointColor(1,1,1,1)
, _pointSize(1)
, _dirtyGLPoint(false)
, _vaoGLLine(0)
, _vboGLLine(0)
, _bufferCapacityGLLine(0)
, _bufferCountGLLine(0)
, _bufferGLLine(nullptr)
, _dirtyGLLine(false)
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
}
@ -116,9 +132,17 @@ DrawNode::~DrawNode()
{
free(_buffer);
_buffer = nullptr;
free(_bufferGLPoint);
_bufferGLPoint = nullptr;
free(_bufferGLLine);
_bufferGLLine = nullptr;
glDeleteBuffers(1, &_vbo);
glDeleteBuffers(1, &_vboGLLine);
glDeleteBuffers(1, &_vboGLPoint);
_vbo = 0;
_vboGLPoint = 0;
_vboGLLine = 0;
if (Configuration::getInstance()->supportsShareableVAO())
{
@ -154,6 +178,28 @@ void DrawNode::ensureCapacity(int count)
}
}
void DrawNode::ensureCapacityGLPoint(int count)
{
CCASSERT(count>=0, "capacity must be >= 0");
if(_bufferCountGLPoint + count > _bufferCapacityGLPoint)
{
_bufferCapacityGLPoint += MAX(_bufferCapacityGLPoint, count);
_bufferGLPoint = (V2F_C4B_T2F*)realloc(_bufferGLPoint, _bufferCapacityGLPoint*sizeof(V2F_C4B_T2F));
}
}
void DrawNode::ensureCapacityGLLine(int count)
{
CCASSERT(count>=0, "capacity must be >= 0");
if(_bufferCountGLLine + count > _bufferCapacityGLLine)
{
_bufferCapacityGLLine += MAX(_bufferCapacityGLLine, count);
_bufferGLLine = (V2F_C4B_T2F*)realloc(_bufferGLLine, _bufferCapacityGLLine*sizeof(V2F_C4B_T2F));
}
}
bool DrawNode::init()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@ -161,27 +207,63 @@ bool DrawNode::init()
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR));
ensureCapacity(512);
ensureCapacityGLPoint(64);
ensureCapacityGLLine(256);
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
}
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vaoGLLine);
GL::bindVAO(_vaoGLLine);
}
glGenBuffers(1, &_vboGLLine);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLLine, _bufferGLLine, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vaoGLPoint);
GL::bindVAO(_vaoGLPoint);
}
glGenBuffers(1, &_vboGLPoint);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
// vertex
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_TEX_COORD);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
if (Configuration::getInstance()->supportsShareableVAO())
{
@ -191,6 +273,8 @@ bool DrawNode::init()
CHECK_GL_ERROR_DEBUG();
_dirty = true;
_dirtyGLLine = true;
_dirtyGLPoint = true;
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
@ -207,9 +291,26 @@ bool DrawNode::init()
void DrawNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
if(_bufferCount)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
if(_bufferCountGLPoint)
{
_customCommandGLPoint.init(_globalZOrder);
_customCommandGLPoint.func = CC_CALLBACK_0(DrawNode::onDrawGLPoint, this, transform, flags);
renderer->addCommand(&_customCommandGLPoint);
}
if(_bufferCountGLLine)
{
_customCommandGLLine.init(_globalZOrder);
_customCommandGLLine.func = CC_CALLBACK_0(DrawNode::onDrawGLLine, this, transform, flags);
renderer->addCommand(&_customCommandGLLine);
}
}
void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
@ -217,13 +318,14 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
auto glProgram = getGLProgram();
glProgram->use();
glProgram->setUniformsForBuiltins(transform);
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
if (_dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
_dirty = false;
}
if (Configuration::getInstance()->supportsShareableVAO())
@ -237,21 +339,287 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t flags)
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
}
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glDrawArrays(GL_TRIANGLES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount);
CHECK_GL_ERROR_DEBUG();
}
void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
{
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR);
glProgram->use();
glProgram->setUniformsForBuiltins(transform);
if (_dirtyGLLine)
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLLine, _bufferGLLine, GL_STREAM_DRAW);
_dirtyGLLine = false;
}
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vaoGLLine);
}
else
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
// texcood
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords));
}
glLineWidth(2);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
glDrawArrays(GL_LINES, 0, _bufferCountGLLine);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine);
CHECK_GL_ERROR_DEBUG();
}
void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
{
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
glProgram->use();
glProgram->setUniformsForBuiltins(transform);
glProgram->setUniformLocationWith4fv(glProgram->getUniformLocation("u_color"), (GLfloat*) &_pointColor.r, 1);
glProgram->setUniformLocationWith1f(glProgram->getUniformLocation("u_pointSize"), _pointSize);
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, vertices));
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors));
glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLPoint);
CHECK_GL_ERROR_DEBUG();
}
void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Color4F &color)
{
V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint);
V2F_C4B_T2F a = {position, Color4B(color), Tex2F(0.0, 0.0) };
*point = a;
_pointSize = pointSize;
_pointColor = color;
_bufferCountGLPoint += 1;
}
void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, const Color4F &color)
{
ensureCapacityGLPoint(numberOfPoints);
V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint);
for(int i=0; i<numberOfPoints; i++,point++)
{
V2F_C4B_T2F a = {position[i], Color4B(color), Tex2F(0.0, 0.0) };
*point = a;
}
_pointColor = color;
_bufferCountGLPoint += numberOfPoints;
}
void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color)
{
ensureCapacityGLLine(2);
V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLLine + _bufferCountGLLine);
V2F_C4B_T2F a = {origin, Color4B(color), Tex2F(0.0, 0.0)};
V2F_C4B_T2F b = {destination, Color4B(color), Tex2F(0.0, 0.0)};
*point = a;
*(point+1) = b;
_bufferCountGLLine += 2;
_dirtyGLLine = true;
}
void DrawNode::drawRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color)
{
drawLine(Vec2(origin.x, origin.y), Vec2(destination.x, origin.y), color);
drawLine(Vec2(destination.x, origin.y), Vec2(destination.x, destination.y), color);
drawLine(Vec2(destination.x, destination.y), Vec2(origin.x, destination.y), color);
drawLine(Vec2(origin.x, destination.y), Vec2(origin.x, origin.y), color);
}
void DrawNode::drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon, const Color4F &color)
{
unsigned int vertext_count;
if(closePolygon)
{
vertext_count = 2 * numberOfPoints;
ensureCapacityGLLine(vertext_count);
}
else
{
vertext_count = 2 * (numberOfPoints - 1);
ensureCapacityGLLine(vertext_count);
}
V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLLine + _bufferCountGLLine);
int i;
for(i=0; i<numberOfPoints-1; i++)
{
V2F_C4B_T2F a = {poli[i], Color4B(color), Tex2F(0.0, 0.0)};
V2F_C4B_T2F b = {poli[i+1], Color4B(color), Tex2F(0.0, 0.0)};
*point = a;
*(point+1) = b;
point += 2;
}
if(closePolygon)
{
V2F_C4B_T2F a = {poli[i], Color4B(color), Tex2F(0.0, 0.0)};
V2F_C4B_T2F b = {poli[0], Color4B(color), Tex2F(0.0, 0.0)};
*point = a;
*(point+1) = b;
}
_bufferCountGLLine += vertext_count;
}
void DrawNode::drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY, const Color4F &color)
{
const float coef = 2.0f * (float)M_PI/segments;
Vec2 *vertices = new (std::nothrow) Vec2[segments+2];
if( ! vertices )
return;
for(unsigned int i = 0;i <= segments; i++) {
float rads = i*coef;
GLfloat j = radius * cosf(rads + angle) * scaleX + center.x;
GLfloat k = radius * sinf(rads + angle) * scaleY + center.y;
vertices[i].x = j;
vertices[i].y = k;
}
if(drawLineToCenter)
{
vertices[segments+1].x = center.x;
vertices[segments+1].y = center.y;
drawPoly(vertices, segments+2, true, color);
}
else
drawPoly(vertices, segments+1, true, color);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawCircle(const Vec2 &center, float radius, float angle, unsigned int segments, bool drawLineToCenter, const Color4F &color)
{
drawCircle(center, radius, angle, segments, drawLineToCenter, 1.0f, 1.0f, color);
}
void DrawNode::drawQuadBezier(const Vec2 &origin, const Vec2 &control, const Vec2 &destination, unsigned int segments, const Color4F &color)
{
Vec2* vertices = new (std::nothrow) Vec2[segments + 1];
if( ! vertices )
return;
float t = 0.0f;
for(unsigned int i = 0; i < segments; i++)
{
vertices[i].x = powf(1 - t, 2) * origin.x + 2.0f * (1 - t) * t * control.x + t * t * destination.x;
vertices[i].y = powf(1 - t, 2) * origin.y + 2.0f * (1 - t) * t * control.y + t * t * destination.y;
t += 1.0f / segments;
}
vertices[segments].x = destination.x;
vertices[segments].y = destination.y;
drawPoly(vertices, segments+1, false, color);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawCubicBezier(const Vec2 &origin, const Vec2 &control1, const Vec2 &control2, const Vec2 &destination, unsigned int segments, const Color4F &color)
{
Vec2* vertices = new (std::nothrow) Vec2[segments + 1];
if( ! vertices )
return;
float t = 0;
for (unsigned int i = 0; i < segments; i++)
{
vertices[i].x = powf(1 - t, 3) * origin.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x;
vertices[i].y = powf(1 - t, 3) * origin.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y;
t += 1.0f / segments;
}
vertices[segments].x = destination.x;
vertices[segments].y = destination.y;
drawPoly(vertices, segments+1, false, color);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawCardinalSpline(PointArray *config, float tension, unsigned int segments, const Color4F &color)
{
Vec2* vertices = new (std::nothrow) Vec2[segments + 1];
if( ! vertices )
return;
ssize_t p;
float lt;
float deltaT = 1.0f / config->count();
for( unsigned int i=0; i < segments+1;i++) {
float dt = (float)i / segments;
// border
if( dt == 1 ) {
p = config->count() - 1;
lt = 1;
} else {
p = dt / deltaT;
lt = (dt - deltaT * (float)p) / deltaT;
}
// Interpolate
Vec2 pp0 = config->getControlPointAtIndex(p-1);
Vec2 pp1 = config->getControlPointAtIndex(p+0);
Vec2 pp2 = config->getControlPointAtIndex(p+1);
Vec2 pp3 = config->getControlPointAtIndex(p+2);
Vec2 newPos = ccCardinalSplineAt( pp0, pp1, pp2, pp3, tension, lt);
vertices[i].x = newPos.x;
vertices[i].y = newPos.y;
}
drawPoly(vertices, segments+1, false, color);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawCatmullRom(PointArray *points, unsigned int segments, const Color4F &color)
{
drawCardinalSpline( points, 0.5f, segments, color);
}
void DrawNode::drawDot(const Vec2 &pos, float radius, const Color4F &color)
{
unsigned int vertex_count = 2*3;
@ -273,6 +641,27 @@ void DrawNode::drawDot(const Vec2 &pos, float radius, const Color4F &color)
_dirty = true;
}
void DrawNode::drawRect(const Vec2 &lb, const Vec2 &lt, const Vec2 &rt, const Vec2& rb, const Color4F &color)
{
unsigned int vertex_count = 2*3;
ensureCapacity(vertex_count);
V2F_C4B_T2F a = {lb, Color4B(color), Tex2F(-1.0, -1.0) };
V2F_C4B_T2F b = {lt, Color4B(color), Tex2F(-1.0, 1.0) };
V2F_C4B_T2F c = {rt, Color4B(color), Tex2F( 1.0, 1.0) };
V2F_C4B_T2F d = {rb, Color4B(color), Tex2F( 1.0, -1.0) };
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
V2F_C4B_T2F_Triangle triangle0 = {a, b, c};
V2F_C4B_T2F_Triangle triangle1 = {a, c, d};
triangles[0] = triangle0;
triangles[1] = triangle1;
_bufferCount += vertex_count;
_dirty = true;
}
void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const Color4F &color)
{
unsigned int vertex_count = 6*3;
@ -346,7 +735,7 @@ void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const
_dirty = true;
}
void DrawNode::drawPolygon(Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor)
void DrawNode::drawPolygon(const Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor)
{
CCASSERT(count >= 0, "invalid count value");
@ -454,9 +843,54 @@ void DrawNode::drawPolygon(Vec2 *verts, int count, const Color4F &fillColor, flo
free(extrude);
}
void DrawNode::drawSolidRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color)
{
Vec2 vertices[] = {
origin,
Vec2(destination.x, origin.y),
destination,
Vec2(origin.x, destination.y)
};
drawSolidPoly(vertices, 4, color );
}
void DrawNode::drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, const Color4F &color)
{
drawPolygon(poli, numberOfPoints, color, 0.0, Color4F(0.0, 0.0, 0.0, 0.0));
}
void DrawNode::drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F &color)
{
const float coef = 2.0f * (float)M_PI/segments;
Vec2 *vertices = new (std::nothrow) Vec2[segments];
if( ! vertices )
return;
for(unsigned int i = 0;i < segments; i++)
{
float rads = i*coef;
GLfloat j = radius * cosf(rads + angle) * scaleX + center.x;
GLfloat k = radius * sinf(rads + angle) * scaleY + center.y;
vertices[i].x = j;
vertices[i].y = k;
}
drawSolidPoly(vertices, segments, color);
CC_SAFE_DELETE_ARRAY(vertices);
}
void DrawNode::drawSolidCircle( const Vec2& center, float radius, float angle, unsigned int segments, const Color4F& color)
{
drawSolidCircle(center, radius, angle, segments, 1.0f, 1.0f, color);
}
void DrawNode::drawTriangle(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Color4F &color)
{
unsigned int vertex_count = 2*3;
unsigned int vertex_count = 3;
ensureCapacity(vertex_count);
Color4B col = Color4B(color);
@ -472,72 +906,19 @@ void DrawNode::drawTriangle(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, cons
_dirty = true;
}
void DrawNode::drawCubicBezier(const Vec2& from, const Vec2& control1, const Vec2& control2, const Vec2& to, unsigned int segments, const Color4F &color)
{
unsigned int vertex_count = (segments + 1) * 3;
ensureCapacity(vertex_count);
Tex2F texCoord = Tex2F(0.0, 0.0);
Color4B col = Color4B(color);
Vec2 vertex;
Vec2 firstVertex = Vec2(from.x, from.y);
Vec2 lastVertex = Vec2(to.x, to.y);
float t = 0;
for(unsigned int i = segments + 1; i > 0; i--)
{
float x = powf(1 - t, 3) * from.x + 3.0f * powf(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * to.x;
float y = powf(1 - t, 3) * from.y + 3.0f * powf(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * to.y;
vertex = Vec2(x, y);
V2F_C4B_T2F a = {firstVertex, col, texCoord };
V2F_C4B_T2F b = {lastVertex, col, texCoord };
V2F_C4B_T2F c = {vertex, col, texCoord };
V2F_C4B_T2F_Triangle triangle = {a, b, c};
((V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount))[0] = triangle;
lastVertex = vertex;
t += 1.0f / segments;
_bufferCount += 3;
}
_dirty = true;
}
void DrawNode::drawQuadraticBezier(const Vec2& from, const Vec2& control, const Vec2& to, unsigned int segments, const Color4F &color)
{
unsigned int vertex_count = (segments + 1) * 3;
ensureCapacity(vertex_count);
Tex2F texCoord = Tex2F(0.0, 0.0);
Color4B col = Color4B(color);
Vec2 vertex;
Vec2 firstVertex = Vec2(from.x, from.y);
Vec2 lastVertex = Vec2(to.x, to.y);
float t = 0;
for(unsigned int i = segments + 1; i > 0; i--)
{
float x = powf(1 - t, 2) * from.x + 2.0f * (1 - t) * t * control.x + t * t * to.x;
float y = powf(1 - t, 2) * from.y + 2.0f * (1 - t) * t * control.y + t * t * to.y;
vertex = Vec2(x, y);
V2F_C4B_T2F a = {firstVertex, col, texCoord };
V2F_C4B_T2F b = {lastVertex, col, texCoord };
V2F_C4B_T2F c = {vertex, col, texCoord };
V2F_C4B_T2F_Triangle triangle = {a, b, c};
((V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount))[0] = triangle;
lastVertex = vertex;
t += 1.0f / segments;
_bufferCount += 3;
}
_dirty = true;
drawQuadBezier(from, control, to, segments, color);
}
void DrawNode::clear()
{
_bufferCount = 0;
_dirty = true;
_bufferCountGLLine = 0;
_dirtyGLLine = true;
_bufferCountGLPoint = 0;
_dirtyGLPoint = true;
}
const BlendFunc& DrawNode::getBlendFunc() const

View File

@ -34,6 +34,7 @@
#include "2d/CCNode.h"
#include "base/ccTypes.h"
#include "renderer/CCCustomCommand.h"
#include "math/CCMath.h"
NS_CC_BEGIN
@ -43,15 +44,51 @@ NS_CC_BEGIN
@since v2.1
*/
class PointArray;
class CC_DLL DrawNode : public Node
{
public:
/** creates and initialize a DrawNode node */
static DrawNode* create();
void drawPoint(const Vec2& point, const float pointSize, const Color4F &color);
void drawPoints(const Vec2 *position, unsigned int numberOfPoints, const Color4F &color);
void drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color);
void drawRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color);
void drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool closePolygon, const Color4F &color);
void drawCircle( const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY, const Color4F &color);
void drawCircle(const Vec2 &center, float radius, float angle, unsigned int segments, bool drawLineToCenter, const Color4F &color);
void drawQuadBezier(const Vec2 &origin, const Vec2 &control, const Vec2 &destination, unsigned int segments, const Color4F &color);
/** draw a cubic bezier curve with color and number of segments */
void drawCubicBezier(const Vec2 &origin, const Vec2 &control1, const Vec2 &control2, const Vec2 &destination, unsigned int segments, const Color4F &color);
void drawCardinalSpline(PointArray *config, float tension, unsigned int segments, const Color4F &color);
void drawCatmullRom(PointArray *points, unsigned int segments, const Color4F &color);
/** draw a dot at a position, with a given radius and color */
void drawDot(const Vec2 &pos, float radius, const Color4F &color);
void drawRect(const Vec2 &lb, const Vec2 &lt, const Vec2 &rt, const Vec2& rb, const Color4F &color);
void drawSolidRect(const Vec2 &origin, const Vec2 &destination, const Color4F &color);
void drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, const Color4F &color);
void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, const Color4F &color);
void drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, const Color4F& color);
/** draw a segment with a radius and color */
void drawSegment(const Vec2 &from, const Vec2 &to, float radius, const Color4F &color);
@ -62,16 +99,13 @@ public:
* In lua:local drawPolygon(local pointTable,local tableCount,local fillColor,local width,local borderColor)
* @endcode
*/
void drawPolygon(Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
void drawPolygon(const Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
/** draw a triangle with color */
void drawTriangle(const Vec2 &p1, const Vec2 &p2, const Vec2 &p3, const Color4F &color);
/** draw a cubic bezier curve with color and number of segments */
void drawCubicBezier(const Vec2& from, const Vec2& control1, const Vec2& control2, const Vec2& to, unsigned int segments, const Color4F &color);
/** draw a quadratic bezier curve with color and number of segments */
void drawQuadraticBezier(const Vec2& from, const Vec2& control, const Vec2& to, unsigned int segments, const Color4F &color);
/** draw a quadratic bezier curve with color and number of segments, use drawQuadBezier instead*/
CC_DEPRECATED_ATTRIBUTE void drawQuadraticBezier(const Vec2& from, const Vec2& control, const Vec2& to, unsigned int segments, const Color4F &color);
/** Clear the geometry in the node's buffer. */
void clear();
@ -90,6 +124,8 @@ public:
void setBlendFunc(const BlendFunc &blendFunc);
void onDraw(const Mat4 &transform, uint32_t flags);
void onDrawGLLine(const Mat4 &transform, uint32_t flags);
void onDrawGLPoint(const Mat4 &transform, uint32_t flags);
// Overrides
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
@ -101,18 +137,38 @@ CC_CONSTRUCTOR_ACCESS:
protected:
void ensureCapacity(int count);
void ensureCapacityGLPoint(int count);
void ensureCapacityGLLine(int count);
GLuint _vao;
GLuint _vbo;
GLuint _vaoGLPoint;
GLuint _vboGLPoint;
GLuint _vaoGLLine;
GLuint _vboGLLine;
int _bufferCapacity;
GLsizei _bufferCount;
V2F_C4B_T2F *_buffer;
int _bufferCapacityGLPoint;
GLsizei _bufferCountGLPoint;
V2F_C4B_T2F *_bufferGLPoint;
Color4F _pointColor;
int _pointSize;
int _bufferCapacityGLLine;
GLsizei _bufferCountGLLine;
V2F_C4B_T2F *_bufferGLLine;
BlendFunc _blendFunc;
CustomCommand _customCommand;
CustomCommand _customCommandGLPoint;
CustomCommand _customCommandGLLine;
bool _dirty;
bool _dirtyGLPoint;
bool _dirtyGLLine;
private:
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode);

View File

@ -79,85 +79,85 @@ class PointArray;
namespace DrawPrimitives
{
/** Initializes the drawing primitives */
void CC_DLL init();
CC_DEPRECATED_ATTRIBUTE void CC_DLL init();
/** Frees allocated resources by the drawing primitives */
void CC_DLL free();
CC_DEPRECATED_ATTRIBUTE void CC_DLL free();
/** draws a point given x and y coordinate measured in points */
void CC_DLL drawPoint(const Vec2& point);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawPoint(const Vec2& point);
/** draws an array of points.
@since v0.7.2
*/
void CC_DLL drawPoints(const Vec2 *points, unsigned int numberOfPoints);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawPoints(const Vec2 *points, unsigned int numberOfPoints);
/** draws a line given the origin and destination point measured in points */
void CC_DLL drawLine(const Vec2& origin, const Vec2& destination);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawLine(const Vec2& origin, const Vec2& destination);
/** draws a rectangle given the origin and destination point measured in points. */
void CC_DLL drawRect(Vec2 origin, Vec2 destination);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawRect(Vec2 origin, Vec2 destination);
/** draws a solid rectangle given the origin and destination point measured in points.
@since 1.1
*/
void CC_DLL drawSolidRect(Vec2 origin, Vec2 destination, Color4F color);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidRect(Vec2 origin, Vec2 destination, Color4F color);
/** draws a polygon given a pointer to point coordinates and the number of vertices measured in points.
The polygon can be closed or open
*/
void CC_DLL drawPoly(const Vec2 *vertices, unsigned int numOfVertices, bool closePolygon);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawPoly(const Vec2 *vertices, unsigned int numOfVertices, bool closePolygon);
/** draws a solid polygon given a pointer to CGPoint coordinates, the number of vertices measured in points, and a color.
*/
void CC_DLL drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidPoly(const Vec2 *poli, unsigned int numberOfPoints, Color4F color);
/** draws a circle given the center, radius and number of segments. */
void CC_DLL drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
void CC_DLL drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter, float scaleX, float scaleY);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCircle(const Vec2& center, float radius, float angle, unsigned int segments, bool drawLineToCenter);
/** draws a solid circle given the center, radius and number of segments. */
void CC_DLL drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
void CC_DLL drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawSolidCircle(const Vec2& center, float radius, float angle, unsigned int segments);
/** draws a quad bezier path
@warning This function could be pretty slow. Use it only for debugging purposes.
@since v0.8
*/
void CC_DLL drawQuadBezier(const Vec2& origin, const Vec2& control, const Vec2& destination, unsigned int segments);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawQuadBezier(const Vec2& origin, const Vec2& control, const Vec2& destination, unsigned int segments);
/** draws a cubic bezier path
@warning This function could be pretty slow. Use it only for debugging purposes.
@since v0.8
*/
void CC_DLL drawCubicBezier(const Vec2& origin, const Vec2& control1, const Vec2& control2, const Vec2& destination, unsigned int segments);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCubicBezier(const Vec2& origin, const Vec2& control1, const Vec2& control2, const Vec2& destination, unsigned int segments);
/** draws a Catmull Rom path.
@warning This function could be pretty slow. Use it only for debugging purposes.
@since v2.0
*/
void CC_DLL drawCatmullRom(PointArray *arrayOfControlPoints, unsigned int segments);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCatmullRom(PointArray *arrayOfControlPoints, unsigned int segments);
/** draws a Cardinal Spline path.
@warning This function could be pretty slow. Use it only for debugging purposes.
@since v2.0
*/
void CC_DLL drawCardinalSpline(PointArray *config, float tension, unsigned int segments);
CC_DEPRECATED_ATTRIBUTE void CC_DLL drawCardinalSpline(PointArray *config, float tension, unsigned int segments);
/** set the drawing color with 4 unsigned bytes
@since v2.0
*/
void CC_DLL setDrawColor4B(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
CC_DEPRECATED_ATTRIBUTE void CC_DLL setDrawColor4B(GLubyte r, GLubyte g, GLubyte b, GLubyte a);
/** set the drawing color with 4 floats
@since v2.0
*/
void CC_DLL setDrawColor4F(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
CC_DEPRECATED_ATTRIBUTE void CC_DLL setDrawColor4F(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
/** set the point size in points. Default 1.
@since v2.0
*/
void CC_DLL setPointSize(GLfloat pointSize);
CC_DEPRECATED_ATTRIBUTE void CC_DLL setPointSize(GLfloat pointSize);
};

View File

@ -252,19 +252,8 @@ void LabelAtlas::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
AtlasNode::draw(renderer, transform, transformUpdated);
_customDebugDrawCommand.init(_globalZOrder);
_customDebugDrawCommand.func = CC_CALLBACK_0(LabelAtlas::drawDebugData, this,transform,transformUpdated);
renderer->addCommand(&_customDebugDrawCommand);
}
void LabelAtlas::drawDebugData(const Mat4& transform, bool transformUpdated)
{
Director* director = Director::getInstance();
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
_debugDrawNode->clear();
auto size = getContentSize();
Vec2 vertices[4]=
{
Vec2::ZERO,
@ -272,10 +261,7 @@ void LabelAtlas::drawDebugData(const Mat4& transform, bool transformUpdated)
Vec2(size.width, size.height),
Vec2(0, size.height)
};
DrawPrimitives::drawPoly(vertices, 4, true);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
}
#endif

View File

@ -90,7 +90,12 @@ public:
CC_CONSTRUCTOR_ACCESS:
LabelAtlas()
:_string("")
{}
{
#if CC_LABELATLAS_DEBUG_DRAW
_debugDrawNode = DrawNode::create();
addChild(_debugDrawNode);
#endif
}
virtual ~LabelAtlas()
{
@ -101,8 +106,7 @@ protected:
virtual void updateColor() override;
#if CC_LABELATLAS_DEBUG_DRAW
CustomCommand _customDebugDrawCommand;
void drawDebugData(const Mat4& transform, bool transformUpdated);
DrawNode *_debugDrawNode;
#endif
// string to render

View File

@ -98,6 +98,11 @@ LabelBMFont::LabelBMFont()
this->addChild(_label);
this->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
_cascadeOpacityEnabled = true;
#if CC_LABELBMFONT_DEBUG_DRAW
_debugDrawNode = DrawNode::create();
addChild(_debugDrawNode);
#endif
}
LabelBMFont::~LabelBMFont()
@ -210,19 +215,8 @@ void LabelBMFont::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags
{
Node::draw(renderer, transform, transformUpdated);
_customDebugDrawCommand.init(_globalZOrder);
_customDebugDrawCommand.func = CC_CALLBACK_0(LabelBMFont::drawDebugData, this,transform,transformUpdated);
renderer->addCommand(&_customDebugDrawCommand);
}
void LabelBMFont::drawDebugData(const Mat4& transform, bool transformUpdated)
{
Director* director = Director::getInstance();
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
_debugDrawNode->clear();
auto size = getContentSize();
Vec2 vertices[4]=
{
Vec2::ZERO,
@ -230,10 +224,7 @@ void LabelBMFont::drawDebugData(const Mat4& transform, bool transformUpdated)
Vec2(size.width, size.height),
Vec2(0, size.height)
};
DrawPrimitives::drawPoly(vertices, 4, true);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
}
#endif

View File

@ -129,8 +129,7 @@ public:
private:
#if CC_LABELBMFONT_DEBUG_DRAW
CustomCommand _customDebugDrawCommand;
void drawDebugData(const Mat4& transform, bool transformUpdated);
DrawNode *_debugDrawNode;
#endif
// name of fntFile

View File

@ -263,6 +263,10 @@ Sprite::Sprite(void)
, _texture(nullptr)
, _insideBounds(true)
{
#if CC_SPRITE_DEBUG_DRAW
_debugDrawNode = DrawNode::create();
addChild(_debugDrawNode);
#endif //CC_SPRITE_DEBUG_DRAW
}
Sprite::~Sprite(void)
@ -585,32 +589,17 @@ void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
_quadCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, transform);
renderer->addCommand(&_quadCommand);
#if CC_SPRITE_DEBUG_DRAW
_customDebugDrawCommand.init(_globalZOrder);
_customDebugDrawCommand.func = CC_CALLBACK_0(Sprite::drawDebugData, this);
renderer->addCommand(&_customDebugDrawCommand);
_debugDrawNode->clear();
Vec2 vertices[4] = {
Vec2( _quad.bl.vertices.x, _quad.bl.vertices.y ),
Vec2( _quad.br.vertices.x, _quad.br.vertices.y ),
Vec2( _quad.tr.vertices.x, _quad.tr.vertices.y ),
Vec2( _quad.tl.vertices.x, _quad.tl.vertices.y ),
};
_debugDrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
#endif //CC_SPRITE_DEBUG_DRAW
}
}
#if CC_SPRITE_DEBUG_DRAW
void Sprite::drawDebugData()
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldModelView;
oldModelView = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
// draw bounding box
Vec2 vertices[4] = {
Vec2( _quad.bl.vertices.x, _quad.bl.vertices.y ),
Vec2( _quad.br.vertices.x, _quad.br.vertices.y ),
Vec2( _quad.tr.vertices.x, _quad.tr.vertices.y ),
Vec2( _quad.tl.vertices.x, _quad.tl.vertices.y ),
};
DrawPrimitives::drawPoly(vertices, 4, true);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldModelView);
}
#endif //CC_SPRITE_DEBUG_DRAW
// MARK: visit, draw, transform

View File

@ -540,8 +540,7 @@ protected:
Texture2D* _texture; /// Texture2D object that is used to render the sprite
QuadCommand _quadCommand; /// quad command
#if CC_SPRITE_DEBUG_DRAW
CustomCommand _customDebugDrawCommand;
void drawDebugData();
DrawNode *_debugDrawNode;
#endif //CC_SPRITE_DEBUG_DRAW
//
// Shared data

View File

@ -32,8 +32,8 @@
#import "CCUserDefault.h"
#import "tinyxml2.h"
#import "CCPlatformConfig.h"
#import "CCPlatformMacros.h"
#import "platform/CCPlatformConfig.h"
#import "platform/CCPlatformMacros.h"
#import "base64.h"
#import "platform/CCFileUtils.h"

View File

@ -26,11 +26,10 @@ THE SOFTWARE.
#include "platform/CCPlatformConfig.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC
#import "CCApplication.h"
#import <Cocoa/Cocoa.h>
#include <algorithm>
#import "platform/CCApplication.h"
#include "platform/CCFileUtils.h"
#include "math/CCGeometry.h"
#include "base/CCDirector.h"

View File

@ -4417,7 +4417,7 @@ tolua_lerror:
/* function: DrawPoint in the DrawPrimitives namespace */
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_ccDrawPoint00
static int tolua_cocos2d_DrawPrimitives_drawPoint00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawPoint00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4445,7 +4445,7 @@ tolua_lerror:
/* function: drawPoints in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_DrawPoints00
static int tolua_cocos2d_DrawPrimitives_drawPoints00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawPoints00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4499,7 +4499,7 @@ tolua_lerror:
/* function: drawLine in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawLine00
static int tolua_cocos2d_DrawPrimitives_drawLine00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawLine00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4532,7 +4532,7 @@ tolua_lerror:
/* function: drawRect in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawRect00
static int tolua_cocos2d_DrawPrimitives_drawRect00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawRect00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4565,7 +4565,7 @@ tolua_lerror:
/* function: drawSolidRect in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_Cocos2d_DrawPrimitives_drawSolidRect00
static int tolua_cocos2d_DrawPrimitives_drawSolidRect00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawSolidRect00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4605,7 +4605,7 @@ tolua_lerror:
/* function: drawPoly in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawPoly00
static int tolua_cocos2d_DrawPrimitives_drawPoly00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawPoly00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4661,7 +4661,7 @@ tolua_lerror:
/* function: drawSolidPoly in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawSolidPoly00
static int tolua_cocos2d_DrawPrimitives_drawSolidPoly00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawSolidPoly00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4723,7 +4723,7 @@ tolua_lerror:
/* function: drawCircle in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawCircle00
static int tolua_cocos2d_DrawPrimitives_drawCircle00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawCircle00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4765,7 +4765,7 @@ tolua_lerror:
/* function: drawSolidCircle in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawSolidCircle00
static int tolua_cocos2d_DrawPrimitives_drawSolidCircle00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawSolidCircle00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4804,7 +4804,7 @@ tolua_lerror:
/* function: drawQuadBezier in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawQuadBezier00
static int tolua_cocos2d_DrawPrimitives_drawQuadBezier00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawQuadBezier00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4845,7 +4845,7 @@ tolua_lerror:
/* function: drawCubicBezier in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawCubicBezier00
static int tolua_cocos2d_DrawPrimitives_drawCubicBezier00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawCubicBezier00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4892,7 +4892,7 @@ tolua_lerror:
/* function: drawCatmullRom in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawCatmullRom00
int tolua_cocos2d_DrawPrimitives_drawCatmullRom00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE int tolua_cocos2d_DrawPrimitives_drawCatmullRom00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4938,7 +4938,7 @@ tolua_lerror:
/* function: drawCardinalSpline in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawCardinalSpline00
int tolua_cocos2d_DrawPrimitives_drawCardinalSpline00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE int tolua_cocos2d_DrawPrimitives_drawCardinalSpline00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -4984,7 +4984,7 @@ tolua_lerror:
/* function: drawColor4B in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawColor4B00
static int tolua_cocos2d_DrawPrimitives_drawColor4B00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawColor4B00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -5016,7 +5016,7 @@ tolua_lerror:
/* function: drawColor4F in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_drawColor4F00
static int tolua_cocos2d_DrawPrimitives_drawColor4F00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawColor4F00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@ -5048,7 +5048,7 @@ tolua_lerror:
/* function: setPointSize in the DrawPrimitives namespace*/
#ifndef TOLUA_DISABLE_tolua_cocos2d_DrawPrimitives_setPointSize00
static int tolua_cocos2d_DrawPrimitives_setPointSize00(lua_State* tolua_S)
CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_setPointSize00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;

View File

@ -2653,7 +2653,7 @@ tolua_lerror:
#endif
}
static int tolua_cocos2d_DrawNode_drawPolygon(lua_State* tolua_S)
static int tolua_cocos2dx_DrawNode_drawPolygon(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
@ -2748,6 +2748,370 @@ tolua_lerror:
#endif
}
int tolua_cocos2dx_DrawNode_drawSolidPoly(lua_State* tolua_S)
{
int argc = 0;
cocos2d::DrawNode* self = nullptr;
bool ok = true;
tolua_Error tolua_err;
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
self = (cocos2d::DrawNode*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!self)
{
tolua_error(tolua_S,"invalid 'self' in function 'lua_cocos2dx_DrawNode_drawSolidPoly'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 3)
{
unsigned int size;
luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawSolidPoly");
if ( size > 0 )
{
cocos2d::Vec2* points = new cocos2d::Vec2[size];
if (NULL == points)
return 0;
for (int i = 0; i < size; i++)
{
lua_pushnumber(tolua_S,i + 1);
lua_gettable(tolua_S,2);
if (!tolua_istable(tolua_S,-1, 0, &tolua_err))
{
CC_SAFE_DELETE_ARRAY(points);
#if COCOS2D_DEBUG >= 1
goto tolua_lerror;
#endif
}
if(!luaval_to_vec2(tolua_S, lua_gettop(tolua_S), &points[i], "cc.DrawNode:drawSolidPoly"))
{
lua_pop(tolua_S, 1);
CC_SAFE_DELETE_ARRAY(points);
return 0;
}
lua_pop(tolua_S, 1);
}
cocos2d::Color4F arg2;
ok &=luaval_to_color4f(tolua_S, 4, &arg2, "cc.DrawNode:drawSolidPoly");
if(!ok)
return 0;
self->drawSolidPoly(points, size, arg2);
CC_SAFE_DELETE_ARRAY(points);
return 0;
}
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:drawSolidPoly",argc, 3);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_DrawNode_drawSolidPoly'.",&tolua_err);
#endif
return 0;
}
int tolua_cocos2dx_DrawNode_drawPoly(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
DrawNode* self = nullptr;
bool ok = true;
tolua_Error tolua_err;
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<cocos2d::DrawNode*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (!self)
{
tolua_error(tolua_S,"invalid 'self' in function 'lua_cocos2dx_DrawNode_drawPoly'", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 4)
{
unsigned int size;
luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawPoly");
if ( size > 0 )
{
cocos2d::Vec2* points = new cocos2d::Vec2[size];
if (NULL == points)
return 0;
for (int i = 0; i < size; i++)
{
lua_pushnumber(tolua_S,i + 1);
lua_gettable(tolua_S,2);
if (!tolua_istable(tolua_S,-1, 0, &tolua_err))
{
CC_SAFE_DELETE_ARRAY(points);
#if COCOS2D_DEBUG >= 1
goto tolua_lerror;
#endif
}
if(!luaval_to_vec2(tolua_S, lua_gettop(tolua_S), &points[i], "cc.DrawNode:drawPoly"))
{
lua_pop(tolua_S, 1);
CC_SAFE_DELETE_ARRAY(points);
return 0;
}
lua_pop(tolua_S, 1);
}
bool arg2;
cocos2d::Color4F arg3;
ok &= luaval_to_boolean(tolua_S, 4,&arg2, "cc.DrawNode:drawPoly");
ok &= luaval_to_color4f(tolua_S, 5, &arg3, "cc.DrawNode:drawPoly");
if(!ok)
return 0;
self->drawPoly(points, size, arg2, arg3);
CC_SAFE_DELETE_ARRAY(points);
return 0;
}
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:drawPoly",argc, 4);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_DrawNode_drawPoly'.",&tolua_err);
#endif
return 0;
}
int tolua_cocos2dx_DrawNode_drawCardinalSpline(lua_State* tolua_S)
{
int argc = 0;
cocos2d::DrawNode* self = nullptr;
bool ok = true;
tolua_Error tolua_err;
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
self = (cocos2d::DrawNode*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!self)
{
tolua_error(tolua_S,"invalid 'self' in function 'lua_cocos2dx_DrawNode_drawCardinalSpline'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 4)
{
int num = 0;
cocos2d::Vec2 *arr = NULL;
if (!luaval_to_array_of_vec2(tolua_S, 2, &arr, &num, "cc.DrawNode:drawCardinalSpline"))
return 0;
PointArray* config = PointArray::create(num);
if (NULL == config)
{
CC_SAFE_DELETE_ARRAY(arr);
return 0;
}
for( int i = 0; i < num; i++) {
config->addControlPoint(arr[i]);
}
CC_SAFE_DELETE_ARRAY(arr);
double arg1;
unsigned int arg2;
cocos2d::Color4F arg3;
ok &= luaval_to_number(tolua_S, 3,&arg1, "cc.DrawNode:drawCardinalSpline");
ok &= luaval_to_uint32(tolua_S, 4,&arg2, "cc.DrawNode:drawCardinalSpline");
ok &= luaval_to_color4f(tolua_S, 5, &arg3, "cc.DrawNode:drawCardinalSpline");
if(!ok)
return 0;
self->drawCardinalSpline(config, arg1, arg2, arg3);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:drawCardinalSpline",argc, 4);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_DrawNode_drawCardinalSpline'.",&tolua_err);
#endif
return 0;
}
int tolua_cocos2dx_DrawNode_drawCatmullRom(lua_State* tolua_S)
{
int argc = 0;
cocos2d::DrawNode* self = nullptr;
bool ok = true;
tolua_Error tolua_err;
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
self = (cocos2d::DrawNode*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!self)
{
tolua_error(tolua_S,"invalid 'self' in function 'lua_cocos2dx_DrawNode_drawCatmullRom'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 3)
{
int num = 0;
cocos2d::Vec2 *arr = NULL;
if (!luaval_to_array_of_vec2(tolua_S, 2, &arr, &num, "cc.DrawNode:drawCatmullRom"))
return 0;
PointArray* config = PointArray::create(num);
if (NULL == config)
{
CC_SAFE_DELETE_ARRAY(arr);
return 0;
}
for( int i = 0; i < num; i++) {
config->addControlPoint(arr[i]);
}
CC_SAFE_DELETE_ARRAY(arr);
unsigned int arg1;
cocos2d::Color4F arg2;
ok &= luaval_to_uint32(tolua_S, 3,&arg1, "cc.DrawNode:drawCatmullRom");
ok &=luaval_to_color4f(tolua_S, 4, &arg2, "cc.DrawNode:drawCatmullRom");
if(!ok)
return 0;
self->drawCatmullRom(config, arg1, arg2);
return 0;
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:drawCatmullRom",argc, 3);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_DrawNode_drawCatmullRom'.",&tolua_err);
#endif
return 0;
}
int tolua_cocos2dx_DrawNode_drawPoints(lua_State* tolua_S)
{
int argc = 0;
cocos2d::DrawNode* self = nullptr;
bool ok = true;
tolua_Error tolua_err;
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"cc.DrawNode",0,&tolua_err)) goto tolua_lerror;
#endif
self = (cocos2d::DrawNode*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!self)
{
tolua_error(tolua_S,"invalid 'self' in function 'lua_cocos2dx_DrawNode_drawPoints'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 3)
{
unsigned int size;
luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawPoints");
if ( size > 0 )
{
cocos2d::Vec2* points = new cocos2d::Vec2[size];
if (NULL == points)
return 0;
for (int i = 0; i < size; i++)
{
lua_pushnumber(tolua_S,i + 1);
lua_gettable(tolua_S,2);
if (!tolua_istable(tolua_S,-1, 0, &tolua_err))
{
CC_SAFE_DELETE_ARRAY(points);
#if COCOS2D_DEBUG >= 1
goto tolua_lerror;
#endif
}
if(!luaval_to_vec2(tolua_S, lua_gettop(tolua_S), &points[i], "cc.DrawNode:drawPoints"))
{
lua_pop(tolua_S, 1);
CC_SAFE_DELETE_ARRAY(points);
return 0;
}
lua_pop(tolua_S, 1);
}
cocos2d::Color4F arg2;
ok &=luaval_to_color4f(tolua_S, 4, &arg2, "cc.DrawNode:drawPoints");
if(!ok)
return 0;
self->drawPoints(points, size, arg2);
return 0;
}
}
CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "cc.DrawNode:drawPoints",argc, 3);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_DrawNode_drawPoints'.",&tolua_err);
#endif
return 0;
}
// setBlendFunc
template<class T>
static int tolua_cocos2dx_setBlendFunc(lua_State* tolua_S,const char* className)
@ -4154,7 +4518,27 @@ static void extendDrawNode(lua_State* tolua_S)
if (lua_istable(tolua_S,-1))
{
lua_pushstring(tolua_S,"drawPolygon");
lua_pushcfunction(tolua_S,tolua_cocos2d_DrawNode_drawPolygon);
lua_pushcfunction(tolua_S,tolua_cocos2dx_DrawNode_drawPolygon);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"drawSolidPoly");
lua_pushcfunction(tolua_S,tolua_cocos2dx_DrawNode_drawSolidPoly);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"drawPoly");
lua_pushcfunction(tolua_S,tolua_cocos2dx_DrawNode_drawPoly);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"drawCardinalSpline");
lua_pushcfunction(tolua_S,tolua_cocos2dx_DrawNode_drawCardinalSpline);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"drawCatmullRom");
lua_pushcfunction(tolua_S,tolua_cocos2dx_DrawNode_drawCatmullRom);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"drawPoints");
lua_pushcfunction(tolua_S,tolua_cocos2dx_DrawNode_drawPoints);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"setBlendFunc");

View File

@ -37,6 +37,7 @@ static const int NORMAL_RENDERER_Z = (-2);
static const int PRESSED_RENDERER_Z = (-2);
static const int DISABLED_RENDERER_Z = (-2);
static const int TITLE_RENDERER_Z = (-1);
static const float ZOOM_ACTION_TIME_STEP = 0.05;
IMPLEMENT_CLASS_GUI_INFO(Button)
@ -361,17 +362,15 @@ void Button::onPressStateChangedToNormal()
{
if (_pressedActionEnabled)
{
_buttonNormalRenderer->stopAllActions();
_buttonClickedRenderer->stopAllActions();
Action *zoomAction = ScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize);
_buttonNormalRenderer->runAction(zoomAction);
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
this->stopAllActions();
Action *zoomAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1.0, 1.0);
this->runAction(zoomAction);
}
}
else
{
_buttonNormalRenderer->stopAllActions();
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
this->stopAllActions();
this->setScale(1.0, 1.0);
}
}
@ -385,11 +384,9 @@ void Button::onPressStateChangedToPressed()
if (_pressedActionEnabled)
{
_buttonNormalRenderer->stopAllActions();
_buttonClickedRenderer->stopAllActions();
Action *zoomAction = ScaleTo::create(0.05f, _pressedTextureScaleXInSize + _zoomScale, _pressedTextureScaleYInSize + _zoomScale);
_buttonClickedRenderer->runAction(zoomAction);
_buttonNormalRenderer->setScale(_pressedTextureScaleXInSize + _zoomScale, _pressedTextureScaleYInSize + _zoomScale);
this->stopAllActions();
Action *zoomAction = ScaleTo::create(ZOOM_ACTION_TIME_STEP, 1.0 + _zoomScale, 1.0 + _zoomScale);
this->runAction(zoomAction);
}
}
else
@ -403,8 +400,8 @@ void Button::onPressStateChangedToPressed()
}
else
{
_buttonNormalRenderer->stopAllActions();
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize +_zoomScale, _normalTextureScaleYInSize + _zoomScale);
this->stopAllActions();
this->setScale(1.0 +_zoomScale, 1.0 + _zoomScale);
}
}
}
@ -414,8 +411,6 @@ void Button::onPressStateChangedToDisabled()
_buttonNormalRenderer->setVisible(false);
_buttonClickedRenderer->setVisible(false);
_buttonDisableRenderer->setVisible(true);
_buttonNormalRenderer->setScale(_normalTextureScaleXInSize, _normalTextureScaleYInSize);
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
}
void Button::updateFlippedX()
@ -470,8 +465,12 @@ void Button::adaptRenderers()
}
}
const Size& Button::getVirtualRendererSize() const
Size Button::getVirtualRendererSize() const
{
Size titleSize = _titleRenderer->getContentSize();
if (!_normalTextureLoaded && _titleRenderer->getString().size() > 0) {
return titleSize;
}
return _normalTextureSize;
}

View File

@ -170,7 +170,7 @@ public:
virtual void ignoreContentAdaptWithSize(bool ignore) override;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -450,7 +450,7 @@ void CheckBox::adaptRenderers()
}
}
const Size& CheckBox::getVirtualRendererSize() const
Size CheckBox::getVirtualRendererSize() const
{
return _backGroundBoxRenderer->getContentSize();
}

View File

@ -184,7 +184,7 @@ public:
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -238,7 +238,7 @@ void ImageView::adaptRenderers()
}
}
const Size& ImageView::getVirtualRendererSize() const
Size ImageView::getVirtualRendererSize() const
{
return _imageTextureSize;
}

View File

@ -108,7 +108,7 @@ public:
*/
virtual std::string getDescription() const override;
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
CC_CONSTRUCTOR_ACCESS:

View File

@ -27,6 +27,7 @@ THE SOFTWARE.
#include "ui/UIScale9Sprite.h"
#include "renderer/CCGLProgram.h"
#include "renderer/CCGLProgramCache.h"
#include "renderer/ccGLStateCache.h"
#include "base/CCDirector.h"
#include "2d/CCDrawingPrimitives.h"
#include "renderer/CCRenderer.h"
@ -351,14 +352,44 @@ void Layout::drawFullScreenQuadClearStencil()
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Vec2 vertices[] = {
Vec2(-1, -1),
Vec2(1, -1),
Vec2(1, 1),
Vec2(-1, 1)
};
DrawPrimitives::drawSolidRect(Vec2(-1,-1), Vec2(1,1), Color4F(1, 1, 1, 1));
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
glProgram->retain();
int colorLocation = glProgram->getUniformLocation("u_color");
CHECK_GL_ERROR_DEBUG();
Color4F color(1, 1, 1, 1);
glProgram->use();
glProgram->setUniformsForBuiltins();
glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vec2)*4, vertices, GL_STREAM_DRAW);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

View File

@ -265,7 +265,7 @@ void LoadingBar::ignoreContentAdaptWithSize(bool ignore)
}
}
const Size& LoadingBar::getVirtualRendererSize() const
Size LoadingBar::getVirtualRendererSize() const
{
return _barRendererTextureSize;
}

View File

@ -130,7 +130,7 @@ public:
virtual void ignoreContentAdaptWithSize(bool ignore) override;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -451,7 +451,7 @@ void RichText::setAnchorPoint(const Vec2 &pt)
_elementRenderersContainer->setAnchorPoint(pt);
}
const Size& RichText::getVirtualRendererSize() const
Size RichText::getVirtualRendererSize() const
{
return _elementRenderersContainer->getContentSize();
}

View File

@ -106,7 +106,7 @@ public:
void setVerticalSpace(float space);
virtual void setAnchorPoint(const Vec2 &pt);
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
void formatText();
virtual void ignoreContentAdaptWithSize(bool ignore);
virtual std::string getDescription() const override;

View File

@ -449,7 +449,7 @@ void Slider::adaptRenderers()
}
}
const Size& Slider::getVirtualRendererSize() const
Size Slider::getVirtualRendererSize() const
{
return _barRenderer->getContentSize();
}

View File

@ -194,7 +194,7 @@ public:
virtual void onTouchCancelled(Touch *touch, Event *unusedEvent) override;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -292,7 +292,7 @@ void Text::adaptRenderers()
}
}
const Size& Text::getVirtualRendererSize() const
Size Text::getVirtualRendererSize() const
{
return _labelRenderer->getContentSize();
}

View File

@ -139,7 +139,7 @@ public:
bool isTouchScaleChangeEnabled()const;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -135,7 +135,7 @@ void TextAtlas::adaptRenderers()
}
}
const Size& TextAtlas::getVirtualRendererSize() const
Size TextAtlas::getVirtualRendererSize() const
{
return _labelAtlasRenderer->getContentSize();
}

View File

@ -93,7 +93,7 @@ public:
ssize_t getStringLength()const;
//override "getVirtualRendererSize" method of widget.
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;

View File

@ -129,7 +129,7 @@ void TextBMFont::adaptRenderers()
}
}
const Size& TextBMFont::getVirtualRendererSize() const
Size TextBMFont::getVirtualRendererSize() const
{
return _labelBMFontRenderer->getContentSize();
}

View File

@ -81,7 +81,7 @@ public:
*/
ssize_t getStringLength()const;
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
/**
* Returns the "class name" of widget.

View File

@ -737,7 +737,7 @@ void TextField::textfieldRendererScaleChangedWithSize()
_textFieldRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
}
const Size& TextField::getVirtualRendererSize() const
Size TextField::getVirtualRendererSize() const
{
return _textFieldRenderer->getContentSize();
}

View File

@ -187,7 +187,7 @@ public:
*/
virtual std::string getDescription() const override;
virtual const Size& getVirtualRendererSize() const override;
virtual Size getVirtualRendererSize() const override;
virtual Node* getVirtualRenderer() override;
void attachWithIME();
virtual void onEnter() override;

View File

@ -178,6 +178,11 @@ VideoPlayer::VideoPlayer()
{
_videoPlayerIndex = createVideoWidgetJNI();
s_allVideoPlayers[_videoPlayerIndex] = this;
#if CC_VIDEOPLAYER_DEBUG_DRAW
_debugDrawNode = DrawNode::create();
addchild(_debugDrawNode);
#endif
}
VideoPlayer::~VideoPlayer()
@ -224,9 +229,16 @@ void VideoPlayer::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags
}
#if CC_VIDEOPLAYER_DEBUG_DRAW
_customDebugDrawCommand.init(_globalZOrder);
_customDebugDrawCommand.func = CC_CALLBACK_0(VideoPlayer::drawDebugData, this);
renderer->addCommand(&_customDebugDrawCommand);
_debugDrawNode->clear();
auto size = getContentSize();
Point vertices[4]=
{
Point::ZERO,
Point(size.width, 0),
Point(size.width, size.height),
Point(0, size.height)
};
_debugdrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
#endif
}

View File

@ -275,6 +275,11 @@ VideoPlayer::VideoPlayer()
, _isPlaying(false)
{
_videoView = [[UIVideoViewWrapperIos alloc] init:this];
#if CC_VIDEOPLAYER_DEBUG_DRAW
_debugDrawNode = DrawNode::create();
addchild(_debugDrawNode);
#endif
}
VideoPlayer::~VideoPlayer()
@ -324,9 +329,16 @@ void VideoPlayer::draw(Renderer* renderer, const Mat4 &transform, uint32_t flags
}
#if CC_VIDEOPLAYER_DEBUG_DRAW
_customDebugDrawCommand.init(_globalZOrder);
_customDebugDrawCommand.func = CC_CALLBACK_0(VideoPlayer::drawDebugData, this);
renderer->addCommand(&_customDebugDrawCommand);
_debugDrawNode->clear();
auto size = getContentSize();
Point vertices[4]=
{
Point::ZERO,
Point(size.width, 0),
Point(size.width, size.height),
Point(0, size.height)
};
_debugdrawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
#endif
}
@ -349,31 +361,6 @@ void VideoPlayer::setKeepAspectRatioEnabled(bool enable)
}
}
#if CC_VIDEOPLAYER_DEBUG_DRAW
void VideoPlayer::drawDebugData()
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
auto size = getContentSize();
Point vertices[4]=
{
Point::ZERO,
Point(size.width, 0),
Point(size.width, size.height),
Point(0, size.height)
};
DrawPrimitives::drawPoly(vertices, 4, true);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
#endif
void VideoPlayer::play()
{
if (! _videoURL.empty())

View File

@ -84,8 +84,7 @@ namespace experimental{
virtual ~VideoPlayer();
#if CC_VIDEOPLAYER_DEBUG_DRAW
CustomCommand _customDebugDrawCommand;
void VideoPlayer::drawDebugData();
DrawNode *_debugDrawNode;
#endif
enum class Source

View File

@ -468,7 +468,7 @@ void Widget::onSizeChanged()
}
}
const Size& Widget::getVirtualRendererSize() const
Size Widget::getVirtualRendererSize() const
{
return _contentSize;
}

View File

@ -489,7 +489,7 @@ public:
virtual Node* getVirtualRenderer();
virtual const Size& getVirtualRendererSize() const;
virtual Size getVirtualRendererSize() const;
/**

View File

@ -203,8 +203,8 @@
"cocos/3d/CCAnimationCurve.inl",
"cocos/3d/CCAttachNode.cpp",
"cocos/3d/CCAttachNode.h",
"cocos/3d/CCBillBoard.cpp",
"cocos/3d/CCBillBoard.h",
"cocos/3d/CCBillBoard.cpp",
"cocos/3d/CCBillBoard.h",
"cocos/3d/CCBundle3D.cpp",
"cocos/3d/CCBundle3D.h",
"cocos/3d/CCBundle3DData.h",

View File

@ -23,7 +23,7 @@
****************************************************************************/
#import "AppController.h"
#import "CCEAGLView.h"
#import "platform/ios/CCEAGLView-ios.h"
#import "cocos2d.h"
#import "AppDelegate.h"
#import "RootViewController.h"

View File

@ -25,7 +25,7 @@
#import "RootViewController.h"
#import "cocos2d.h"
#import "CCEAGLView.h"
#import "platform/ios/CCEAGLView-ios.h"
@implementation RootViewController

View File

@ -29,7 +29,7 @@
#import "AppController.h"
#import "AppDelegate.h"
#import "RootViewController.h"
#import "CCEAGLView.h"
#import "platform/ios/CCEAGLView-ios.h"
@implementation AppController

View File

@ -25,7 +25,7 @@
#import "RootViewController.h"
#import "cocos2d.h"
#import "CCEAGLView.h"
#import "platform/ios/CCEAGLView-ios.h"
@implementation RootViewController

View File

@ -29,7 +29,7 @@
#import "AppController.h"
#import "AppDelegate.h"
#import "RootViewController.h"
#import "CCEAGLView.h"
#import "platform/ios/CCEAGLView-ios.h"
#include "ConfigParser.h"
@implementation AppController

View File

@ -1339,6 +1339,15 @@ void ActionFollow::onEnter()
centerSprites(1);
auto s = Director::getInstance()->getWinSize();
DrawNode* drawNode = DrawNode::create();
float x = s.width*2 - 100;
float y = s.height;
Vec2 vertices[] = { Vec2(5,5), Vec2(x-5,5), Vec2(x-5,y-5), Vec2(5,y-5) };
drawNode->drawPoly(vertices, 4, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
this->addChild(drawNode);
_grossini->setPosition(-200, s.height / 2);
auto move = MoveBy::create(2, Vec2(s.width * 3, 0));
auto move_back = move->reverse();
@ -1350,32 +1359,6 @@ void ActionFollow::onEnter()
this->runAction(Follow::create(_grossini, Rect(0, 0, s.width * 2 - 100, s.height)));
}
void ActionFollow::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionFollow::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void ActionFollow::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto winSize = Director::getInstance()->getWinSize();
float x = winSize.width*2 - 100;
float y = winSize.height;
Vec2 vertices[] = { Vec2(5,5), Vec2(x-5,5), Vec2(x-5,y-5), Vec2(5,y-5) };
DrawPrimitives::drawPoly(vertices, 4, true);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
std::string ActionFollow::subtitle() const
{
return "Follow action";
@ -1623,6 +1606,11 @@ void ActionCatmullRomStacked::onEnter()
MoveBy::create(0.05f, Vec2(-10,0)),
nullptr)));
auto drawNode1 = DrawNode::create();
drawNode1->setPosition(Vec2(50,50));
drawNode1->drawCatmullRom(array, 50, Color4F(1.0, 1.0, 0.0, 0.5));
this->addChild(drawNode1);
//
// sprite 2 (To)
//
@ -1652,54 +1640,13 @@ void ActionCatmullRomStacked::onEnter()
MoveBy::create(0.05f, Vec2(-10,0)),
nullptr)));
array->retain();
_array1 = array;
array2->retain();
_array2 = array2;
auto drawNode2 = DrawNode::create();
drawNode2->drawCatmullRom(array2, 50, Color4F(1.0, 0.0, 0.0, 0.5));
this->addChild(drawNode2);
}
ActionCatmullRomStacked::~ActionCatmullRomStacked()
{
CC_SAFE_RELEASE(_array1);
CC_SAFE_RELEASE(_array2);
}
void ActionCatmullRomStacked::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
ActionsDemo::draw(renderer, transform, flags);
// move to 50,50 since the "by" path will start at 50,50
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Mat4 translation;
//Create a rotation matrix using the axis and the angle
Mat4::createTranslation(50, 50, 0, &translation);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void ActionCatmullRomStacked::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldMat;
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCatmullRom(_array1,50);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
DrawPrimitives::drawCatmullRom(_array2,50);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
}
std::string ActionCatmullRomStacked::title() const
@ -1753,6 +1700,11 @@ void ActionCardinalSplineStacked::onEnter()
MoveBy::create(0.05f, Vec2(-10,0)),
nullptr)));
auto drawNode1 = DrawNode::create();
drawNode1->setPosition(Vec2(50,50));
drawNode1->drawCardinalSpline(array, 0, 100, Color4F(1.0, 0.0, 1.0, 1.0));
this->addChild(drawNode1);
//
// sprite 2 (By)
//
@ -1775,61 +1727,14 @@ void ActionCardinalSplineStacked::onEnter()
MoveBy::create(0.05f, Vec2(-10,0)),
nullptr)));
array->retain();
_array = array;
auto drawNode2 = DrawNode::create();
drawNode2->setPosition(Vec2(s.width/2,50));
drawNode2->drawCardinalSpline(array, 1, 100, Color4F(0.0, 0.0, 1.0, 1.0));
this->addChild(drawNode2);
}
ActionCardinalSplineStacked::~ActionCardinalSplineStacked()
{
CC_SAFE_RELEASE(_array);
}
void ActionCardinalSplineStacked::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
ActionsDemo::draw(renderer, transform, flags);
// move to 50,50 since the "by" path will start at 50,50
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Mat4 translation;
//Create a rotation matrix using the axis and the angle
Mat4::createTranslation(50, 50, 0, &translation);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto s = Director::getInstance()->getWinSize();
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
//Create a rotation matrix using the axis and the angle
Mat4::createTranslation(s.width/2, 50, 0, &translation);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void ActionCardinalSplineStacked::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldMat;
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
}
std::string ActionCardinalSplineStacked::title() const
@ -2163,6 +2068,10 @@ void ActionCatmullRom::onEnter()
_tamara->runAction(seq);
auto drawNode1 = DrawNode::create();
drawNode1->setPosition(Vec2(50,50));
drawNode1->drawCatmullRom(array, 50, Color4F(1.0, 0.0, 1.0, 1.0));
this->addChild(drawNode1);
//
// sprite 2 (To)
@ -2186,58 +2095,15 @@ void ActionCatmullRom::onEnter()
_kathia->runAction(seq2);
_array1 = array;
_array1->retain();
_array2 = array2;
_array2->retain();
auto drawNode2 = DrawNode::create();
drawNode2->drawCatmullRom(array2, 50, Color4F(0.0, 1.0, 1.0, 1.0));
this->addChild(drawNode2);
}
ActionCatmullRom::~ActionCatmullRom()
{
_array1->release();
_array2->release();
}
void ActionCatmullRom::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
ActionsDemo::draw(renderer, transform, flags);
// move to 50,50 since the "by" path will start at 50,50
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Mat4 translation;
//Create a rotation matrix using the axis and the angle
Mat4::createTranslation(50, 50, 0, &translation);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void ActionCatmullRom::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldMat;
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCatmullRom(_array1, 50);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
DrawPrimitives::drawCatmullRom(_array2,50);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
}
std::string ActionCatmullRom::title() const
{
return "CatmullRomBy / CatmullRomTo";
@ -2280,6 +2146,11 @@ void ActionCardinalSpline::onEnter()
_tamara->setPosition(50, 50);
_tamara->runAction(seq);
auto drawNode1 = DrawNode::create();
drawNode1->setPosition(Vec2(50,50));
drawNode1->drawCardinalSpline(array, 0, 100, Color4F(1.0, 0.0, 1.0, 1.0));
this->addChild(drawNode1);
//
// sprite 2 (By)
//
@ -2294,59 +2165,14 @@ void ActionCardinalSpline::onEnter()
_kathia->setPosition(s.width/2, 50);
_kathia->runAction(seq2);
_array = array;
array->retain();
auto drawNode2 = DrawNode::create();
drawNode2->setPosition(Vec2(s.width/2, 50));
drawNode2->drawCardinalSpline(array, 1, 100, Color4F(1.0, 0.0, 1.0, 1.0));
this->addChild(drawNode2);
}
ActionCardinalSpline::~ActionCardinalSpline()
{
_array->release();
}
void ActionCardinalSpline::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
ActionsDemo::draw(renderer, transform, flags);
// move to 50,50 since the "by" path will start at 50,50
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
Mat4 translation;
//Create a rotation matrix using the axis and the angle
Mat4::createTranslation(50, 50, 0, &translation);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
auto s = Director::getInstance()->getWinSize();
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
//Create a rotation matrix using the axis and the angle
Mat4::createTranslation(s.width/2, 50, 0, &translation);
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void ActionCardinalSpline::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
Mat4 oldMat;
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
}
std::string ActionCardinalSpline::title() const

View File

@ -379,13 +379,7 @@ public:
CREATE_FUNC(ActionFollow);
virtual void onEnter() override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
CustomCommand _customCommand;
};
class ActionTargeted : public ActionsDemo
@ -454,20 +448,9 @@ public:
CREATE_FUNC(ActionCatmullRomStacked);
virtual ~ActionCatmullRomStacked();
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
//cached data and callback
Mat4 _modelViewMV1;
Mat4 _modelViewMV2;
PointArray* _array1;
PointArray* _array2;
CustomCommand _customCommand;
};
class ActionCardinalSplineStacked : public ActionsDemo
@ -476,18 +459,9 @@ public:
CREATE_FUNC(ActionCardinalSplineStacked);
virtual ~ActionCardinalSplineStacked();
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
Mat4 _modelViewMV1;
Mat4 _modelViewMV2;
CustomCommand _customCommand;
PointArray* _array;
};
class Issue1305 : public ActionsDemo
@ -584,18 +558,8 @@ public:
~ActionCatmullRom();
virtual void onEnter() override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
virtual std::string title() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
Mat4 _modelViewMV1;
Mat4 _modelViewMV2;
CustomCommand _customCommand;
PointArray *_array1;
PointArray *_array2;
};
class ActionCardinalSpline : public ActionsDemo
@ -606,17 +570,8 @@ public:
~ActionCardinalSpline();
virtual void onEnter() override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
virtual std::string title() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
PointArray *_array;
Mat4 _modelViewMV1;
Mat4 _modelViewMV2;
CustomCommand _customCommand;
};
class PauseResumeActions : public ActionsDemo

View File

@ -677,15 +677,75 @@ void RawStencilBufferTest::onBeforeDrawClip(int planeIndex, const Vec2& pt)
{
this->setupStencilForClippingOnPlane(planeIndex);
CHECK_GL_ERROR_DEBUG();
DrawPrimitives::drawSolidRect(Vec2::ZERO, pt, Color4F(1, 1, 1, 1));
Vec2 vertices[] = {
Vec2::ZERO,
Vec2(pt.x, 0),
pt,
Vec2(0, pt.y)
};
auto glProgram= GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
glProgram->retain();
int colorLocation = glProgram->getUniformLocation("u_color");
CHECK_GL_ERROR_DEBUG();
Color4F color(1, 1, 1, 1);
glProgram->use();
glProgram->setUniformsForBuiltins();
glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vec2)*4, vertices, GL_STREAM_DRAW);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
}
void RawStencilBufferTest::onBeforeDrawSprite(int planeIndex, const Vec2& pt)
{
this->setupStencilForDrawingOnPlane(planeIndex);
CHECK_GL_ERROR_DEBUG();
DrawPrimitives::drawSolidRect(Vec2::ZERO, pt, _planeColor[planeIndex]);
Vec2 vertices[] = {
Vec2::ZERO,
Vec2(pt.x, 0),
pt,
Vec2(0, pt.y)
};
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
glProgram->retain();
int colorLocation = glProgram->getUniformLocation("u_color");
CHECK_GL_ERROR_DEBUG();
Color4F color = _planeColor[planeIndex];
glProgram->use();
glProgram->setUniformsForBuiltins();
glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vec2)*4, vertices, GL_STREAM_DRAW);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
}
void RawStencilBufferTest::setupStencilForClippingOnPlane(GLint plane)
@ -861,7 +921,40 @@ void RawStencilBufferTest6::setupStencilForClippingOnPlane(GLint plane)
glStencilMask(planeMask);
glStencilFunc(GL_NEVER, 0, planeMask);
glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
DrawPrimitives::drawSolidRect(Vec2::ZERO, Vec2(Director::getInstance()->getWinSize()), Color4F(1, 1, 1, 1));
Vec2 pt = Director::getInstance()->getWinSize();
Vec2 vertices[] = {
Vec2::ZERO,
Vec2(pt.x, 0),
pt,
Vec2(0, pt.y)
};
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR);
glProgram->retain();
int colorLocation = glProgram->getUniformLocation("u_color");
CHECK_GL_ERROR_DEBUG();
Color4F color(1, 1, 1, 1);
glProgram->use();
glProgram->setUniformsForBuiltins();
glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1);
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vec2)*4, vertices, GL_STREAM_DRAW);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4);
glStencilFunc(GL_NEVER, planeMask, planeMask);
glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
glDisable(GL_DEPTH_TEST);

View File

@ -257,6 +257,60 @@ DrawNodeTest::DrawNodeTest()
auto draw = DrawNode::create();
addChild(draw, 10);
draw->drawPoint(Vec2(s.width/2-120, s.height/2-120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
draw->drawPoint(Vec2(s.width/2+120, s.height/2+120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
// draw 4 small points
Vec2 position[] = { Vec2(60,60), Vec2(70,70), Vec2(60,70), Vec2(70,60) };
draw->drawPoints( position, 4, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
// draw a line
draw->drawLine(Vec2(0,0), Vec2(s.width, s.height), Color4F(1.0, 0.0, 0.0, 0.5));
// draw a rectangle
draw->drawRect(Vec2(23,23), Vec2(7,7), Color4F(1,1,0,1));
// draw a circle
draw->drawCircle(VisibleRect::center() + Vec2(140,0), 100, CC_DEGREES_TO_RADIANS(90), 50, true, 1.0f, 2.0f, Color4F(1.0, 0.0, 0.0, 0.5));
draw->drawCircle(VisibleRect::center() - Vec2(140,0), 50, CC_DEGREES_TO_RADIANS(90), 30, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
// Draw some beziers
draw->drawQuadBezier(Vec2(s.width - 150, s.height - 150), Vec2(s.width - 70, s.height - 10), Vec2(s.width - 10, s.height - 10), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
draw->drawQuadBezier(Vec2(0, s.height), Vec2(s.width/2, s.height/2), Vec2(s.width, s.height), 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
draw->drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x+30,VisibleRect::center().y+50), Vec2(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
draw->drawCubicBezier(Vec2(s.width - 250, 40), Vec2(s.width - 70, 100), Vec2(s.width - 30, 250), Vec2(s.width - 10, s.height - 50), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
auto array = PointArray::create(20);
array->addControlPoint(Vec2(0,0));
array->addControlPoint(Vec2(80,80));
array->addControlPoint(Vec2(s.width-80,80));
array->addControlPoint(Vec2(s.width-80,s.height-80));
array->addControlPoint(Vec2(80,s.height-80));
array->addControlPoint(Vec2(80,80));
array->addControlPoint(Vec2(s.width/2, s.height/2));
draw->drawCardinalSpline(array, 0.5, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
auto array2 = PointArray::create(20);
array2->addControlPoint(Vec2(s.width / 2, 30));
array2->addControlPoint(Vec2(s.width -80, 30));
array2->addControlPoint(Vec2(s.width - 80, s.height - 80));
array2->addControlPoint(Vec2(s.width / 2, s.height - 80));
array2->addControlPoint(Vec2(s.width / 2, 30));
draw->drawCatmullRom(array2, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
// open random color poly
Vec2 vertices[] = { Vec2(0,0), Vec2(50,50), Vec2(100,50), Vec2(100,100), Vec2(50,100) };
draw->drawPoly( vertices, 5, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
// closed random color poly
Vec2 vertices2[] = { Vec2(30,130), Vec2(30,230), Vec2(50,200) };
draw->drawPoly( vertices2, 3, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
// Draw 10 circles
for( int i=0; i < 10; i++)
{
@ -265,7 +319,7 @@ DrawNodeTest::DrawNodeTest()
// Draw polygons
Vec2 points[] = { Vec2(s.height/4,0), Vec2(s.width,s.height/5), Vec2(s.width/3*2,s.height) };
draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), Color4F(1,0,0,0.5), 4, Color4F(0,0,1,1));
draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), Color4F(1,0,0,0.5), 4, Color4F(0,0,1,0.5));
// star poly (triggers buggs)
{
@ -297,19 +351,23 @@ DrawNodeTest::DrawNodeTest()
draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1,0,0,0.5), 1, Color4F(0,0,1,1));
}
//draw a solid polygon
Vec2 vertices3[] = {Vec2(60,160), Vec2(70,190), Vec2(100,190), Vec2(90,160)};
draw->drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) );
//draw a solid rectangle
draw->drawSolidRect(Vec2(10,10), Vec2(20,20), Color4F(1,1,0,1));
//draw a solid circle
draw->drawSolidCircle( VisibleRect::center() + Vec2(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 2.0f, 2.0f, Color4F(0.0, 1.0, 0.0, 1.0));
// Draw segment
draw->drawSegment(Vec2(20,s.height), Vec2(20,s.height/2), 10, Color4F(0, 1, 0, 1));
draw->drawSegment(Vec2(10,s.height/2), Vec2(s.width/2, s.height/2), 40, Color4F(1, 0, 1, 0.5));
// Draw triangle
draw->drawTriangle(Vec2(10, 10), Vec2(70, 30), Vec2(100, 140), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
// Draw some beziers
draw->drawQuadraticBezier(Vec2(s.width - 150, s.height - 150), Vec2(s.width - 70, s.height - 10), Vec2(s.width - 10, s.height - 10), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
draw->drawCubicBezier(Vec2(s.width - 250, 40), Vec2(s.width - 70, 100), Vec2(s.width - 30, 250), Vec2(s.width - 10, s.height - 50), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
}
string DrawNodeTest::title() const

View File

@ -764,6 +764,10 @@ void TestColliderDetector::onEnter()
bullet = cocos2d::extension::PhysicsSprite::createWithSpriteFrameName("25.png");
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
bullet = Sprite::createWithSpriteFrameName("25.png");
drawNode = DrawNode::create();
addChild(drawNode, -1);
#endif
addChild(bullet);
@ -1070,21 +1074,35 @@ void TestColliderDetector::update(float delta)
}
void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(TestColliderDetector::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void TestColliderDetector::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
armature2->drawContour();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
for(auto& element : armature2->getBoneDic())
{
Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();
if (!detector)
continue;
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
for (auto& object : bodyList)
{
ColliderBody *body = static_cast<ColliderBody*>(object);
const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();
unsigned long length = vertexList.size();
Vec2 *points = new Vec2[length];
for (unsigned long i = 0; i<length; i++)
{
Vec2 p = vertexList.at(i);
points[i].x = p.x;
points[i].y = p.y;
}
drawNode->clear();
drawNode->drawPoly(points, (unsigned int)length, true, Color4F(1.0, 1.0, 1.0, 1.0));
delete []points;
}
}
}
#endif
@ -1104,6 +1122,9 @@ void TestBoundingBox::onEnter()
Sprite *sprite = Sprite::create("Images/background3.png");
armature->addChild(sprite);
_drawNode = DrawNode::create();
this->addChild(_drawNode);
}
std::string TestBoundingBox::title() const
{
@ -1111,21 +1132,9 @@ std::string TestBoundingBox::title() const
}
void TestBoundingBox::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(TestBoundingBox::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void TestBoundingBox::onDraw(const Mat4 &transform, uint32_t flags)
{
getGLProgram()->use();
getGLProgram()->setUniformsForBuiltins(transform);
rect = armature->getBoundingBox();
DrawPrimitives::setDrawColor4B(100, 100, 100, 255);
DrawPrimitives::drawRect(rect.origin, Vec2(rect.getMaxX(), rect.getMaxY()));
_drawNode->clear();
_drawNode->drawRect(rect.origin, Vec2(rect.getMaxX(), rect.getMaxY()), Color4F(1.0, 0.5, 0.5, 1.0));
}
void TestAnchorPoint::onEnter()

View File

@ -272,7 +272,6 @@ public:
virtual std::string title() const override;
virtual void update(float delta);
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
void onDraw(const Mat4 &transform, uint32_t flags);
void onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex);
@ -280,7 +279,7 @@ public:
cocostudio::Armature *armature;
cocostudio::Armature *armature2;
CustomCommand _customCommand; //new render needed this for drawing primitives
DrawNode *drawNode;
cocos2d::Sprite *bullet;
};
#endif
@ -298,11 +297,9 @@ public:
cocostudio::Armature *armature;
Rect rect;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
CustomCommand _customCommand;
DrawNode* _drawNode;
};
class TestAnchorPoint : public ArmatureTestLayer

View File

@ -484,12 +484,17 @@ Atlas4::Atlas4()
{
_time = 0;
auto s = Director::getInstance()->getWinSize();
auto drawNode = DrawNode::create();
drawNode->drawLine( Vec2(0, s.height/2), Vec2(s.width, s.height/2), Color4F(1.0, 1.0, 1.0, 1.0) );
drawNode->drawLine( Vec2(s.width/2, 0), Vec2(s.width/2, s.height), Color4F(1.0, 1.0, 1.0, 1.0) );
addChild(drawNode, -1);
// Upper Label
auto label = LabelBMFont::create("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt");
addChild(label);
auto s = Director::getInstance()->getWinSize();
label->setPosition( Vec2(s.width/2, s.height/2) );
label->setAnchorPoint( Vec2::ANCHOR_MIDDLE );
@ -532,27 +537,6 @@ Atlas4::Atlas4()
schedule( schedule_selector(Atlas4::step), 0.1f);
}
void Atlas4::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(Atlas4::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void Atlas4::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto s = Director::getInstance()->getWinSize();
DrawPrimitives::drawLine( Vec2(0, s.height/2), Vec2(s.width, s.height/2) );
DrawPrimitives::drawLine( Vec2(s.width/2, 0), Vec2(s.width/2, s.height) );
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void Atlas4::step(float dt)
{
_time += dt;
@ -1644,36 +1628,13 @@ LabelBMFontBounds::LabelBMFontBounds()
addChild(layer, -10);
// LabelBMFont
label1 = LabelBMFont::create("Testing Glyph Designer", "fonts/boundsTestFont.fnt");
auto label1 = LabelBMFont::create("Testing Glyph Designer", "fonts/boundsTestFont.fnt");
addChild(label1);
label1->setPosition(Vec2(s.width/2, s.height/2));
}
std::string LabelBMFontBounds::title() const
{
return "Testing LabelBMFont Bounds";
}
std::string LabelBMFontBounds::subtitle() const
{
return "You should see string enclosed by a box";
}
void LabelBMFontBounds::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(LabelBMFontBounds::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void LabelBMFontBounds::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto drawNode = DrawNode::create();
auto labelSize = label1->getContentSize();
auto origin = Director::getInstance()->getWinSize();
@ -1687,9 +1648,18 @@ void LabelBMFontBounds::onDraw(const Mat4 &transform, uint32_t flags)
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
Vec2(origin.width, labelSize.height + origin.height)
};
DrawPrimitives::drawPoly(vertices, 4, true);
drawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
addChild(drawNode);
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
std::string LabelBMFontBounds::title() const
{
return "Testing LabelBMFont Bounds";
}
std::string LabelBMFontBounds::subtitle() const
{
return "You should see string enclosed by a box";
}
// LabelBMFontCrashTest

View File

@ -108,14 +108,9 @@ public:
Atlas4();
virtual void step(float dt);
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
protected:
CustomCommand _customCommand;
};
class Atlas5 : public AtlasDemo
@ -383,14 +378,8 @@ public:
LabelBMFontBounds();
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
void onDraw(const Mat4 &transform, uint32_t flags);
private:
LabelBMFont *label1;
CustomCommand _customCommand;
};
class NewLabelTTFUnicode : public AtlasDemo

View File

@ -263,12 +263,18 @@ std::string LabelFNTColorAndOpacity::subtitle() const
LabelFNTSpriteActions::LabelFNTSpriteActions()
{
_time = 0;
auto s = Director::getInstance()->getWinSize();
auto drawNode = DrawNode::create();
drawNode->drawLine( Vec2(0, s.height/2), Vec2(s.width, s.height/2), Color4F(1.0, 1.0, 1.0, 1.0) );
drawNode->drawLine( Vec2(s.width/2, 0), Vec2(s.width/2, s.height), Color4F(1.0, 1.0, 1.0, 1.0) );
addChild(drawNode, -1);
// Upper Label
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas");
addChild(label);
auto s = Director::getInstance()->getWinSize();
label->setPosition( Vec2(s.width/2, s.height/2) );
@ -310,28 +316,6 @@ LabelFNTSpriteActions::LabelFNTSpriteActions()
schedule( schedule_selector(LabelFNTSpriteActions::step), 0.1f);
}
void LabelFNTSpriteActions::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(LabelFNTSpriteActions::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void LabelFNTSpriteActions::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto s = Director::getInstance()->getWinSize();
DrawPrimitives::drawLine( Vec2(0, s.height/2), Vec2(s.width, s.height/2) );
DrawPrimitives::drawLine( Vec2(s.width/2, 0), Vec2(s.width/2, s.height) );
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void LabelFNTSpriteActions::step(float dt)
{
_time += dt;
@ -894,35 +878,11 @@ LabelFNTBounds::LabelFNTBounds()
addChild(layer, -10);
// LabelBMFont
label1 = Label::createWithBMFont("fonts/boundsTestFont.fnt", "Testing Glyph Designer", TextHAlignment::CENTER,s.width);
auto label1 = Label::createWithBMFont("fonts/boundsTestFont.fnt", "Testing Glyph Designer", TextHAlignment::CENTER,s.width);
addChild(label1);
label1->setPosition(Vec2(s.width/2, s.height/2));
}
std::string LabelFNTBounds::title() const
{
return "New Label + .FNT + Bounds";
}
std::string LabelFNTBounds::subtitle() const
{
return "You should see string enclosed by a box";
}
void LabelFNTBounds::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(LabelFNTBounds::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void LabelFNTBounds::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto drawNode = DrawNode::create();
auto labelSize = label1->getContentSize();
auto origin = Director::getInstance()->getWinSize();
@ -936,9 +896,18 @@ void LabelFNTBounds::onDraw(const Mat4 &transform, uint32_t flags)
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
Vec2(origin.width, labelSize.height + origin.height)
};
DrawPrimitives::drawPoly(vertices, 4, true);
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
drawNode->drawPoly(vertices, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
addChild(drawNode);
}
std::string LabelFNTBounds::title() const
{
return "New Label + .FNT + Bounds";
}
std::string LabelFNTBounds::subtitle() const
{
return "You should see string enclosed by a box";
}
LabelTTFLongLineWrapping::LabelTTFLongLineWrapping()
@ -1508,16 +1477,8 @@ LabelTTFOldNew::LabelTTFOldNew()
auto label2 = Label::createWithTTF(ttfConfig, "Cocos2d-x Label Test");
addChild(label2, 0, kTagBitmapAtlas2);
label2->setPosition(Vec2(s.width/2, delta * 2));
}
void LabelTTFOldNew::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto label1 = (Label*)getChildByTag(kTagBitmapAtlas1);
auto drawNode = DrawNode::create();
auto labelSize = label1->getContentSize();
auto origin = Director::getInstance()->getWinSize();
@ -1531,16 +1492,14 @@ void LabelTTFOldNew::onDraw(const Mat4 &transform, uint32_t flags)
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
Vec2(origin.width, labelSize.height + origin.height)
};
DrawPrimitives::setDrawColor4B(Color4B::RED.r,Color4B::RED.g,Color4B::RED.b,Color4B::RED.a);
DrawPrimitives::drawPoly(vertices, 4, true);
auto label2 = (Label*)getChildByTag(kTagBitmapAtlas2);
drawNode->drawPoly(vertices, 4, true, Color4F(1.0, 0.0, 0.0, 1.0));
labelSize = label2->getContentSize();
origin = Director::getInstance()->getWinSize();
origin.width = origin.width / 2 - (labelSize.width / 2);
origin.height = origin.height / 2 - (labelSize.height / 2);
Vec2 vertices2[4]=
{
Vec2(origin.width, origin.height),
@ -1548,17 +1507,9 @@ void LabelTTFOldNew::onDraw(const Mat4 &transform, uint32_t flags)
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
Vec2(origin.width, labelSize.height + origin.height)
};
DrawPrimitives::setDrawColor4B(Color4B::WHITE.r,Color4B::WHITE.g,Color4B::WHITE.b,Color4B::WHITE.a);
DrawPrimitives::drawPoly(vertices2, 4, true);
drawNode->drawPoly(vertices2, 4, true, Color4F(1.0, 1.0, 1.0, 1.0));
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void LabelTTFOldNew::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(LabelTTFOldNew::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
addChild(drawNode);
}
std::string LabelTTFOldNew::title() const

View File

@ -58,14 +58,9 @@ public:
LabelFNTSpriteActions();
virtual void step(float dt);
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class LabelFNTPadding : public AtlasDemoNew
@ -224,14 +219,8 @@ public:
LabelFNTBounds();
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
Label *label1;
};
class LabelTTFLongLineWrapping : public AtlasDemoNew
@ -430,14 +419,8 @@ public:
LabelTTFOldNew();
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class LabelFontNameTest : public AtlasDemoNew

View File

@ -1,7 +1,7 @@
#include "MutiTouchTest.h"
static const Color3B* s_TouchColors[EventTouch::MAX_TOUCHES] = {
static const Color3B* s_TouchColors[5] = {
&Color3B::YELLOW,
&Color3B::BLUE,
&Color3B::GREEN,
@ -12,44 +12,25 @@ static const Color3B* s_TouchColors[EventTouch::MAX_TOUCHES] = {
class TouchPoint : public Node
{
public:
TouchPoint()
TouchPoint(const Vec2 &touchPoint, const Color3B &touchColor)
{
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
DrawNode* drawNode = DrawNode::create();
auto s = Director::getInstance()->getWinSize();
Color4F color(touchColor.r/255.0f, touchColor.g/255.0f, touchColor.b/255.0f, 1.0f);
drawNode->drawLine(Vec2(0, touchPoint.y), Vec2(s.width, touchPoint.y), color);
drawNode->drawLine(Vec2(touchPoint.x, 0), Vec2(touchPoint.x, s.height), color);
drawNode->drawDot(touchPoint, 3, color);
addChild(drawNode);
}
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
static TouchPoint* touchPointWithParent(Node* pParent, const Vec2 &touchPoint, const Color3B &touchColor)
{
DrawPrimitives::setDrawColor4B(_touchColor.r, _touchColor.g, _touchColor.b, 255);
glLineWidth(10);
DrawPrimitives::drawLine( Vec2(0, _touchPoint.y), Vec2(getContentSize().width, _touchPoint.y) );
DrawPrimitives::drawLine( Vec2(_touchPoint.x, 0), Vec2(_touchPoint.x, getContentSize().height) );
glLineWidth(1);
DrawPrimitives::setPointSize(30);
DrawPrimitives::drawPoint(_touchPoint);
}
void setTouchPos(const Vec2& pt)
{
_touchPoint = pt;
}
void setTouchColor(Color3B color)
{
_touchColor = color;
}
static TouchPoint* touchPointWithParent(Node* pParent)
{
auto pRet = new (std::nothrow) TouchPoint();
auto pRet = new (std::nothrow) TouchPoint(touchPoint, touchColor);
pRet->setContentSize(pParent->getContentSize());
pRet->setAnchorPoint(Vec2(0.0f, 0.0f));
pRet->autorelease();
return pRet;
}
private:
Vec2 _touchPoint;
Color3B _touchColor;
};
bool MutiTouchTestLayer::init()
@ -78,11 +59,8 @@ void MutiTouchTestLayer::onTouchesBegan(const std::vector<Touch*>& touches, Even
for ( auto &item: touches )
{
auto touch = item;
auto touchPoint = TouchPoint::touchPointWithParent(this);
auto location = touch->getLocation();
touchPoint->setTouchPos(location);
touchPoint->setTouchColor(*s_TouchColors[touch->getID()]);
auto touchPoint = TouchPoint::touchPointWithParent(this, location, *s_TouchColors[touch->getID()%5]);
addChild(touchPoint);
s_map.insert(touch->getID(), touchPoint);
@ -96,7 +74,13 @@ void MutiTouchTestLayer::onTouchesMoved(const std::vector<Touch*>& touches, Even
auto touch = item;
auto pTP = s_map.at(touch->getID());
auto location = touch->getLocation();
pTP->setTouchPos(location);
removeChild(pTP, true);
s_map.erase(touch->getID());
auto touchPointNew = TouchPoint::touchPointWithParent(this, location, *s_TouchColors[touch->getID()%5]);
addChild(touchPointNew);
s_map.insert(touch->getID(), touchPointNew);
}
}

View File

@ -757,28 +757,9 @@ TMXOrthoObjectsTest::TMXOrthoObjectsTest()
Value objectsVal = Value(objects);
CCLOG("%s", objectsVal.getDescription().c_str());
}
void TMXOrthoObjectsTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(TMXOrthoObjectsTest::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void TMXOrthoObjectsTest::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto drawNode = DrawNode::create();
auto map = static_cast<TMXTiledMap*>( getChildByTag(kTagTileMap) );
auto pos = map->getPosition();
auto group = map->getObjectGroup("Object Group 1");
auto& objects = group->getObjects();
for (auto& obj : objects)
{
ValueMap& dict = obj.asValueMap();
@ -788,17 +769,14 @@ void TMXOrthoObjectsTest::onDraw(const Mat4 &transform, uint32_t flags)
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
glLineWidth(3);
Color4F color(1.0, 1.0, 1.0, 1.0);
DrawPrimitives::drawLine( pos + Vec2(x, y), pos + Vec2((x+width), y) );
DrawPrimitives::drawLine( pos + Vec2((x+width), y), pos + Vec2((x+width), (y+height)) );
DrawPrimitives::drawLine( pos + Vec2((x+width), (y+height)), pos + Vec2(x, (y+height)) );
DrawPrimitives::drawLine( pos + Vec2(x, (y+height)), pos + Vec2(x, y) );
glLineWidth(1);
drawNode->drawLine( Vec2(x, y), Vec2((x+width), y), color );
drawNode->drawLine( Vec2((x+width), y), Vec2((x+width), (y+height)), color );
drawNode->drawLine( Vec2((x+width), (y+height)), Vec2(x, (y+height)), color );
drawNode->drawLine( Vec2(x, (y+height)), Vec2(x, y), color );
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
map->addChild(drawNode);
}
std::string TMXOrthoObjectsTest::title() const
@ -832,46 +810,26 @@ TMXIsoObjectsTest::TMXIsoObjectsTest()
Value objectsVal = Value(objects);
CCLOG("%s", objectsVal.getDescription().c_str());
}
void TMXIsoObjectsTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(TMXIsoObjectsTest::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void TMXIsoObjectsTest::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
auto pos = map->getPosition();
auto group = map->getObjectGroup("Object Group 1");
auto& objects = group->getObjects();
auto drawNode = DrawNode::create();
for (auto& obj : objects)
{
ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat();
float y = dict["y"].asFloat();
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
glLineWidth(3);
Color4F color(1.0, 1.0, 1.0, 1.0);
DrawPrimitives::drawLine( pos + Vec2(x,y), pos + Vec2(x+width,y) );
DrawPrimitives::drawLine( pos + Vec2(x+width,y), pos + Vec2(x+width,y+height) );
DrawPrimitives::drawLine( pos + Vec2(x+width,y+height), pos + Vec2(x,y+height) );
DrawPrimitives::drawLine( pos + Vec2(x,y+height), pos + Vec2(x,y) );
glLineWidth(1);
drawNode->drawLine( Vec2(x, y), Vec2((x+width), y), color );
drawNode->drawLine( Vec2((x+width), y), Vec2((x+width), (y+height)), color );
drawNode->drawLine( Vec2((x+width), (y+height)), Vec2(x, (y+height)), color );
drawNode->drawLine( Vec2(x, (y+height)), Vec2(x, y), color );
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
map->addChild(drawNode, 10);
}
std::string TMXIsoObjectsTest::title() const
@ -1519,28 +1477,10 @@ TMXGIDObjectsTest::TMXGIDObjectsTest()
CCLOG("Contentsize: %f, %f", s.width, s.height);
CCLOG("----> Iterating over all the group objets");
//auto group = map->objectGroupNamed("Object Layer 1");
}
void TMXGIDObjectsTest::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(TMXGIDObjectsTest::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void TMXGIDObjectsTest::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
auto pos = map->getPosition();
auto group = map->getObjectGroup("Object Layer 1");
auto drawNode = DrawNode::create();
Color4F color(1.0, 1.0, 1.0, 1.0);
auto group = map->getObjectGroup("Object Layer 1");
auto& objects = group->getObjects();
for (auto& obj : objects)
{
@ -1551,17 +1491,12 @@ void TMXGIDObjectsTest::onDraw(const Mat4 &transform, uint32_t flags)
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
glLineWidth(3);
DrawPrimitives::drawLine(pos + Vec2(x, y), pos + Vec2(x + width, y));
DrawPrimitives::drawLine(pos + Vec2(x + width, y), pos + Vec2(x + width, y + height));
DrawPrimitives::drawLine(pos + Vec2(x + width,y + height), pos + Vec2(x,y + height));
DrawPrimitives::drawLine(pos + Vec2(x,y + height), pos + Vec2(x,y));
glLineWidth(1);
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
map->addChild(drawNode);
}
std::string TMXGIDObjectsTest::title() const

View File

@ -134,11 +134,7 @@ public:
TMXOrthoObjectsTest(void);
virtual std::string title() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TMXIsoObjectsTest : public TileDemo
@ -147,11 +143,7 @@ public:
TMXIsoObjectsTest(void);
virtual std::string title() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TMXResizeTest : public TileDemo
@ -291,13 +283,7 @@ class TMXGIDObjectsTest : public TileDemo
public:
TMXGIDObjectsTest();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
virtual std::string subtitle() const override;
};
class TileMapTestScene : public TestScene

View File

@ -728,28 +728,9 @@ TMXOrthoObjectsTestNew::TMXOrthoObjectsTestNew()
Value objectsVal = Value(objects);
CCLOG("%s", objectsVal.getDescription().c_str());
}
void TMXOrthoObjectsTestNew::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(TMXOrthoObjectsTestNew::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void TMXOrthoObjectsTestNew::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto map = static_cast<cocos2d::experimental::TMXTiledMap*>( getChildByTag(kTagTileMap) );
auto pos = map->getPosition();
auto group = map->getObjectGroup("Object Group 1");
auto& objects = group->getObjects();
auto drawNode = DrawNode::create();
Color4F color(1.0, 1.0, 1.0, 1.0);
for (auto& obj : objects)
{
ValueMap& dict = obj.asValueMap();
@ -759,17 +740,12 @@ void TMXOrthoObjectsTestNew::onDraw(const Mat4 &transform, uint32_t flags)
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
glLineWidth(3);
DrawPrimitives::drawLine( pos + Vec2(x, y), pos + Vec2((x+width), y) );
DrawPrimitives::drawLine( pos + Vec2((x+width), y), pos + Vec2((x+width), (y+height)) );
DrawPrimitives::drawLine( pos + Vec2((x+width), (y+height)), pos + Vec2(x, (y+height)) );
DrawPrimitives::drawLine( pos + Vec2(x, (y+height)), pos + Vec2(x, y) );
glLineWidth(1);
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
map->addChild(drawNode);
}
std::string TMXOrthoObjectsTestNew::title() const
@ -803,46 +779,24 @@ TMXIsoObjectsTestNew::TMXIsoObjectsTestNew()
Value objectsVal = Value(objects);
CCLOG("%s", objectsVal.getDescription().c_str());
}
void TMXIsoObjectsTestNew::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(TMXIsoObjectsTestNew::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void TMXIsoObjectsTestNew::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto map = (cocos2d::experimental::TMXTiledMap*) getChildByTag(kTagTileMap);
auto pos = map->getPosition();
auto group = map->getObjectGroup("Object Group 1");
auto& objects = group->getObjects();
auto drawNode = DrawNode::create();
Color4F color(1.0, 1.0, 1.0, 1.0);
for (auto& obj : objects)
{
ValueMap& dict = obj.asValueMap();
float x = dict["x"].asFloat();
float y = dict["y"].asFloat();
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
glLineWidth(3);
DrawPrimitives::drawLine( pos + Vec2(x,y), pos + Vec2(x+width,y) );
DrawPrimitives::drawLine( pos + Vec2(x+width,y), pos + Vec2(x+width,y+height) );
DrawPrimitives::drawLine( pos + Vec2(x+width,y+height), pos + Vec2(x,y+height) );
DrawPrimitives::drawLine( pos + Vec2(x,y+height), pos + Vec2(x,y) );
glLineWidth(1);
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
map->addChild(drawNode, 10);
}
std::string TMXIsoObjectsTestNew::title() const
@ -1460,29 +1414,11 @@ TMXGIDObjectsTestNew::TMXGIDObjectsTestNew()
CCLOG("Contentsize: %f, %f", s.width, s.height);
CCLOG("----> Iterating over all the group objets");
//auto group = map->objectGroupNamed("Object Layer 1");
}
void TMXGIDObjectsTestNew::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_renderCmd.init(_globalZOrder);
_renderCmd.func = CC_CALLBACK_0(TMXGIDObjectsTestNew::onDraw, this, transform, flags);
renderer->addCommand(&_renderCmd);
}
void TMXGIDObjectsTestNew::onDraw(const Mat4 &transform, uint32_t flags)
{
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
auto map = (cocos2d::experimental::TMXTiledMap*)getChildByTag(kTagTileMap);
auto pos = map->getPosition();
auto group = map->getObjectGroup("Object Layer 1");
auto& objects = group->getObjects();
auto drawNode = DrawNode::create();
Color4F color(1.0, 1.0, 1.0, 1.0);
auto group = map->getObjectGroup("Object Layer 1");
auto objects = group->getObjects();
for (auto& obj : objects)
{
ValueMap& dict = obj.asValueMap();
@ -1492,17 +1428,12 @@ void TMXGIDObjectsTestNew::onDraw(const Mat4 &transform, uint32_t flags)
float width = dict["width"].asFloat();
float height = dict["height"].asFloat();
glLineWidth(3);
DrawPrimitives::drawLine(pos + Vec2(x, y), pos + Vec2(x + width, y));
DrawPrimitives::drawLine(pos + Vec2(x + width, y), pos + Vec2(x + width, y + height));
DrawPrimitives::drawLine(pos + Vec2(x + width,y + height), pos + Vec2(x,y + height));
DrawPrimitives::drawLine(pos + Vec2(x,y + height), pos + Vec2(x,y));
glLineWidth(1);
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
}
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
map->addChild(drawNode, 10);
}
std::string TMXGIDObjectsTestNew::title() const

View File

@ -134,11 +134,7 @@ public:
TMXOrthoObjectsTestNew(void);
virtual std::string title() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TMXIsoObjectsTestNew : public TileDemoNew
@ -147,11 +143,7 @@ public:
TMXIsoObjectsTestNew(void);
virtual std::string title() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
virtual std::string subtitle() const override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
};
class TMXResizeTestNew : public TileDemoNew
@ -291,13 +283,7 @@ class TMXGIDObjectsTestNew : public TileDemoNew
public:
TMXGIDObjectsTestNew();
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
protected:
CustomCommand _renderCmd;
void onDraw(const Mat4 &transform, uint32_t flags);
virtual std::string subtitle() const override;
};
class TileMapTestSceneNew : public TestScene

View File

@ -89,7 +89,7 @@ g_guisTests[] =
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
sceneManager->setCurrentUISceneId(kUIButtonTest);
sceneManager->setMinUISceneId(kUIButtonTest);
sceneManager->setMaxUISceneId(kUIButtonTestZoomScale);
sceneManager->setMaxUISceneId(kUIButtonIgnoreContentSizeTest);
Scene* scene = sceneManager->currentUIScene();
Director::getInstance()->replaceScene(scene);
}

View File

@ -36,13 +36,12 @@ bool UIButtonTest::init()
_uiLayer->addChild(alert);
// Create the button
Button* button = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
Button* button = Button::create("cocosui/animationbuttonnormal.png");
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
// button->addTouchEventListener(this, toucheventselector(UIButtonTest::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest::touchEvent, this));
button->setZoomScale(0.4);
button->setPressedActionEnabled(true);
_uiLayer->addChild(button);
// button->setColor(Color3B::RED);
button->setOpacity(100);
// Create the imageview
ImageView* imageView = ImageView::create();
@ -133,6 +132,7 @@ bool UIButtonTest_Scale9::init()
button->setScale9Enabled(true);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->setContentSize(Size(150, 70));
button->setPressedActionEnabled(true);
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest_Scale9::touchEvent, this));
_uiLayer->addChild(button);
@ -297,7 +297,7 @@ bool UIButtonTest_Title::init()
// Create the button with title
Button* button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
button->setTitleText("Title Button");
button->setTitleText("Title Button!");
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->setTitleColor(Color3B::YELLOW);
CCASSERT(button->getTitleColor() == Color3B::YELLOW, "Button setTitleColotr & getTitleColor not match!");
@ -539,7 +539,7 @@ bool UIButtonTestZoomScale::init()
Size widgetSize = _widget->getContentSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create("Zoom Scale: 0.1", "fonts/Marker Felt.ttf",32);
_displayValueLabel = Text::create("Zoom Scale: -0.5", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
_uiLayer->addChild(_displayValueLabel);
@ -592,3 +592,103 @@ void UIButtonTestZoomScale::sliderEvent(Ref *pSender, Slider::EventType type)
_displayValueLabel->setString(String::createWithFormat("Zoom Scale: %f", zoomScale)->getCString());
}
}
// UIButtonTextOnly
UIButtonTextOnly::UIButtonTextOnly()
: _displayValueLabel(nullptr)
{
}
UIButtonTextOnly::~UIButtonTextOnly()
{
}
bool UIButtonTextOnly::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create("Text Only Button", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
auto button = Button::create();
button->setNormalizedPosition(Vec2(0.5, 0.5));
button->setTitleText("PLAY GAME");
button->setZoomScale(0.3);
button->setPressedActionEnabled(true);
button->addClickEventListener([this](Ref* sender) {
CCLOG("clicked!");
});
_uiLayer->addChild(button);
return true;
}
return false;
}
// UIButtonIgnoreContentSizeTest
UIButtonIgnoreContentSizeTest::UIButtonIgnoreContentSizeTest()
: _displayValueLabel(nullptr)
{
}
UIButtonIgnoreContentSizeTest::~UIButtonIgnoreContentSizeTest()
{
}
bool UIButtonIgnoreContentSizeTest::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create("Button IgnoreContent Size Test", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
auto button = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
button->ignoreContentAdaptWithSize(false);
button->setContentSize(Size(200,100));
button->setNormalizedPosition(Vec2(0.5, 0.5));
button->setTitleText("PLAY GAME");
button->setZoomScale(0.3);
button->setPressedActionEnabled(true);
button->addClickEventListener([this](Ref* sender) {
CCLOG("touched!");
});
_uiLayer->addChild(button);
return true;
}
return false;
}

View File

@ -118,4 +118,27 @@ protected:
Text* _displayValueLabel;
};
class UIButtonTextOnly : public UIScene
{
public:
UIButtonTextOnly();
~UIButtonTextOnly();
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIButtonTextOnly)
Text* _displayValueLabel;
};
class UIButtonIgnoreContentSizeTest : public UIScene
{
public:
UIButtonIgnoreContentSizeTest();
~UIButtonIgnoreContentSizeTest();
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIButtonIgnoreContentSizeTest)
Text* _displayValueLabel;
};
#endif /* defined(__TestCpp__UIButtonTest__) */

View File

@ -39,6 +39,9 @@ static const char* s_testArray[] =
"UIButtonTest_RemoveSelf",
"UIButtonTestSwitchScale9",
"UIButtonTestZoomScale",
"UIButtonTextOnly",
"UIButtonIgnoreContentSizeTest",
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
"UIEditBoxTest",
#endif
@ -195,6 +198,11 @@ Scene *UISceneManager::currentUIScene()
return UIButtonTestSwitchScale9::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonTestZoomScale:
return UIButtonTestZoomScale::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonTextOnly:
return UIButtonTextOnly::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonIgnoreContentSizeTest:
return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUICheckBoxTest:
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);

View File

@ -38,6 +38,8 @@ enum
kUIButtonTest_RemoveSelf,
kUIButtonTestSwitchScale9,
kUIButtonTestZoomScale,
kUIButtonTextOnly,
kUIButtonIgnoreContentSizeTest,
kUIEditBoxTest,
kUICheckBoxTest,
kUISliderTest,

View File

@ -311,27 +311,17 @@ local function ActionCardinalSpline()
kathia:setPosition(cc.p(size.width / 2, 50))
kathia:runAction(seq2)
--[[
local function drawCardinalSpline()
kmGLPushMatrix()
kmGLTranslatef(50, 50, 0)
cc.DrawPrimitives.drawCardinalSpline(array, 0, 100)
kmGLPopMatrix()
local drawNode1 = cc.DrawNode:create()
drawNode1:setPosition(50, 50)
drawNode1:drawCardinalSpline(array, 0, 100, cc.c4f(0,0,1,1))
layer:addChild(drawNode1)
local drawNode2 = cc.DrawNode:create()
drawNode2:setPosition(size.width/2, 50)
drawNode2:drawCardinalSpline(array, 1, 100, cc.c4f(0,0,1,1))
layer:addChild(drawNode2)
kmGLPushMatrix()
kmGLTranslatef(size.width / 2, 50, 0)
cc.DrawPrimitives.drawCardinalSpline(array, 1, 100)
kmGLPopMatrix()
end
array:retain()
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(size.width, size.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:registerScriptDrawHandler(drawCardinalSpline)
layer:addChild(glNode,-10)
glNode:setPosition( size.width / 2, size.height / 2)
]]--
Helper.titleLabel:setString("CardinalSplineBy / CardinalSplineAt")
Helper.subtitleLabel:setString("Cardinal Spline paths.\nTesting different tensions for one array")
return layer
@ -374,25 +364,15 @@ local function ActionCatmullRom()
local reverse2 = action2:reverse()
local seq2 = cc.Sequence:create(action2, reverse2)
kathia:runAction(seq2)
--[[
local function drawCatmullRom()
kmGLPushMatrix()
kmGLTranslatef(50, 50, 0)
cc.DrawPrimitives.drawCatmullRom(array, 50)
kmGLPopMatrix()
cc.DrawPrimitives.drawCatmullRom(array2,50)
end
array:retain()
array2:retain()
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(size.width, size.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:registerScriptDrawHandler(drawCatmullRom)
layer:addChild(glNode,-10)
glNode:setPosition( size.width / 2, size.height / 2)
]]--
local drawNode1 = cc.DrawNode:create()
drawNode1:setPosition(50, 50)
drawNode1:drawCatmullRom(array, 50, cc.c4f(0,0,1,1))
layer:addChild(drawNode1)
local drawNode2 = cc.DrawNode:create()
--drawNode2:setPosition(size.width/2, 50)
drawNode2:drawCatmullRom(array2, 50, cc.c4f(0,0,1,1))
layer:addChild(drawNode2)
Helper.titleLabel:setString("CatmullRomBy / CatmullRomTo")
Helper.subtitleLabel:setString("Catmull Rom spline paths. Testing reverse too")
@ -965,21 +945,14 @@ local function ActionFollow()
grossini:runAction(rep)
layer:runAction(cc.Follow:create(grossini, cc.rect(0, 0, size.width * 2 - 100, size.height)))
local function draw()
local winSize = cc.Director:getInstance():getWinSize()
local x = winSize.width * 2 - 100
local y = winSize.height
local vertices = { cc.p(5, 5), cc.p(x - 5, 5), cc.p(x - 5,y - 5), cc.p(5,y - 5) }
cc.DrawPrimitives.drawPoly(vertices, 4, true)
end
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(size.width, size.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:registerScriptDrawHandler(draw)
layer:addChild(glNode,-10)
glNode:setPosition( size.width / 2, size.height / 2)
local drawNode = cc.DrawNode:create()
local winSize = cc.Director:getInstance():getWinSize()
local x = winSize.width * 2 - 100
local y = winSize.height
local vertices = { cc.p(5, 5), cc.p(x - 5, 5), cc.p(x - 5,y - 5), cc.p(5,y - 5) }
drawNode:drawPoly(vertices, 4, true, cc.c4f(0,0,1,1))
layer:addChild(drawNode)
Helper.subtitleLabel:setString("Follow action")
return layer

View File

@ -175,9 +175,69 @@ local function drawPrimitivesMainLayer()
local draw = cc.DrawNode:create()
layer:addChild(draw, 10)
--draw 1 point
draw:drawPoint(cc.p(60,60), 4, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 1))
--draw 4 small points
local fourpoints = { cc.p(60,60), cc.p(70,70), cc.p(60,70), cc.p(70,60) }
draw:drawPoints(fourpoints, 4, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 1))
--draw a line
draw:drawLine(cc.p(0,0), cc.p(size.width, size.height), cc.c4f(0,1,0,1))
--draw a rectangle
draw:drawRect(cc.p(23,23), cc.p(7,7), cc.c4f(1,1,0,1))
--draw a solid polygon
local vertices3 = { cc.p(60,160), cc.p(70,190), cc.p(100,190), cc.p(90,160) }
draw:drawSolidPoly( vertices3, 4, cc.c4f(0,0,1,1) )
--draw a solid rectangle
draw:drawSolidRect(cc.p(10,10), cc.p(20,20), cc.c4f(1,1,0,1))
--draw a solid circle
draw:drawSolidCircle(cc.p(VisibleRect:center().x + 140 ,VisibleRect:center().y), 100, math.pi/2, 50, 1.0, 2.0, cc.c4f(1,0,0,0.2))
--draw open random color poly
local vertices = { cc.p(0,0), cc.p(50,50), cc.p(100,50), cc.p(100,100), cc.p(50,100) }
draw:drawPoly( vertices, 5, false, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 1))
--draw closed random color poly
local vertices2 = { cc.p(30,130), cc.p(30,230), cc.p(50,200) }
draw:drawPoly( vertices2, 3, true, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 1))
--draw two circle
draw:drawCircle(cc.p(VisibleRect:center().x + 140 ,VisibleRect:center().y), 110, math.pi/2, 50, true, 1.0, 2.0, cc.c4f(1.0, 0.0, 0.0, 0.5))
draw:drawCircle(cc.p(VisibleRect:center().x - 140 ,VisibleRect:center().y), 50, math.pi/2, 30, false, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 1))
--draw some beziers
draw:drawQuadBezier(cc.p(size.width - 150, size.height - 150), cc.p(size.width - 70, size.height - 10), cc.p(size.width - 10, size.height - 10), 10, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 0.5))
draw:drawQuadBezier(cc.p(0, size.height), cc.p(size.width/2, size.height/2), cc.p(size.width, size.height), 50, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 0.5))
draw:drawCubicBezier(cc.p(VisibleRect:center()), cc.p(VisibleRect:center().x+30,VisibleRect:center().y+50), cc.p(VisibleRect:center().x+60,VisibleRect:center().y-50),VisibleRect:right(),100, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 0.5))
--draw Cardinal spline and catmullrom
local array = {
cc.p(0, 0),
cc.p(size.width / 2 - 30, 0),
cc.p(size.width / 2 - 30, size.height - 80),
cc.p(0, size.height - 80),
cc.p(0, 0) }
draw:drawCardinalSpline(array, 0.5, 50, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 0.5))
local array2 = {
cc.p(size.width / 2, 30),
cc.p(size.width - 80, 30),
cc.p(size.width - 80, size.height - 80),
cc.p(size.width / 2, size.height - 80),
cc.p(size.width / 2, 30) }
draw:drawCatmullRom(array2, 50, cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 0.5))
--Draw 10 circles
for i=1, 10 do
draw:drawDot(cc.p(size.width/2, size.height/2), 10*(10-i), cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 1))
draw:drawDot(cc.p(size.width/2, size.height/2), 10*(10-i), cc.c4f(math.random(0,1), math.random(0,1), math.random(0,1), 0.5))
end
--Draw polygons

View File

@ -542,6 +542,9 @@ local function TMXOrthoObjectsTest()
local s = map:getContentSize()
cclog("ContentSize: %f, %f", s.width,s.height)
local drawNode = cc.DrawNode:create()
map:addChild(drawNode, 10)
--------cclog("---: Iterating over all the group objets")
local group = map:getObjectGroup("Object Group 1")
@ -558,30 +561,7 @@ local function TMXOrthoObjectsTest()
break
end
--------cclog("object: %x", dict)
end
--------cclog("---: Fetching 1 object by name")
-- local platform = group:objectNamed("platform")
--------cclog("platform: %x", platform)
return ret
end
local function draw()
local map = tolua.cast(getChildByTag(kTagTileMap), "cc.TMXTiledMap")
local group = map:getObjectGroup("Object Group 1")
local objects = group:getObjects()
local dict = nil
local i = 0
local len = table.getn(objects)
for i = 0, len-1, 1 do
dict = objects[i + 1]
if dict == nil then
break
end
local key = "x"
local x = dict["x"]
key = "y"
@ -590,16 +570,21 @@ local function draw()
local width = dict["width"]--dynamic_cast<NSNumber*>(dict:objectForKey("width")):getNumber()
key = "height"
local height = dict["height"]--dynamic_cast<NSNumber*>(dict:objectForKey("height")):getNumber()
glLineWidth(3)
cc.DrawPrimitives.drawLine( cc.p(x, y), cc.p((x+width), y) )
cc.DrawPrimitives.drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)) )
cc.DrawPrimitives.drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)) )
cc.DrawPrimitives.drawLine( cc.p(x, (y+height)), cc.p(x, y) )
glLineWidth(1)
local color = cc.c4f(1,1,1,1)
drawNode:drawLine( cc.p(x, y), cc.p((x+width), y), color)
drawNode:drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)), color)
drawNode:drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)), color)
drawNode:drawLine( cc.p(x, (y+height)), cc.p(x, y), color)
end
--------cclog("---: Fetching 1 object by name")
-- local platform = group:objectNamed("platform")
--------cclog("platform: %x", platform)
return ret
end
--------------------------------------------------------------------
@ -615,6 +600,9 @@ local function TMXIsoObjectsTest()
local s = map:getContentSize()
cclog("ContentSize: %f, %f", s.width,s.height)
local drawNode = cc.DrawNode:create()
map:addChild(drawNode, 10)
local group = map:getObjectGroup("Object Group 1")
@ -624,51 +612,30 @@ local function TMXIsoObjectsTest()
local dict = nil
local i = 0
local len = table.getn(objects)
for i = 0, len-1, 1 do
-- dict = tolua.cast(objects[i + 1], "cc.Dictionary")
-- if dict == nil then
-- break
-- end
--------cclog("object: %x", dict)
end
return ret
end
local function draw()
local map = tolua.cast(getChildByTag(kTagTileMap), "cc.TMXTiledMap")
local group = map:getObjectGroup("Object Group 1")
local objects = group:getObjects()
local dict = nil
local i = 0
local len = table.getn(objects)
for i = 0, len-1, 1 do
dict = tolua.cast(objects[i + 1], "cc.Dictionary")
if dict == nil then
break
end
--------cclog("object: %x", dict)
local key = "x"
local x = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("x")):getNumber()
local x = dict["x"]
key = "y"
local y = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("y")):getNumber()
local y = dict["y"]--dynamic_cast<NSNumber*>(dict:objectForKey("y")):getNumber()
key = "width"
local width = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("width")):getNumber()
local width = dict["width"]--dynamic_cast<NSNumber*>(dict:objectForKey("width")):getNumber()
key = "height"
local height = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("height")):getNumber()
glLineWidth(3)
cc.DrawPrimitives.drawLine( cc.p(x,y), cc.p(x+width,y) )
cc.DrawPrimitives.drawLine( cc.p(x+width,y), cc.p(x+width,y+height) )
cc.DrawPrimitives.drawLine( cc.p(x+width,y+height), cc.p(x,y+height) )
cc.DrawPrimitives.drawLine( cc.p(x,y+height), cc.p(x,y) )
glLineWidth(1)
local height = dict["height"]--dynamic_cast<NSNumber*>(dict:objectForKey("height")):getNumber()
local color = cc.c4f(1,1,1,1)
drawNode:drawLine( cc.p(x, y), cc.p((x+width), y), color)
drawNode:drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)), color)
drawNode:drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)), color)
drawNode:drawLine( cc.p(x, (y+height)), cc.p(x, y), color)
end
return ret
end
--------------------------------------------------------------------

View File

@ -263,13 +263,18 @@ function Atlas4.create()
local layer = cc.Layer:create()
Helper.initWithLayer(layer)
Atlas4.layer = layer
local s = cc.Director:getInstance():getWinSize()
local drawNode = cc.DrawNode:create()
drawNode:drawLine( cc.p(0, s.height/2), cc.p(s.width, s.height/2), cc.c4f(1,1,1,1))
drawNode:drawLine( cc.p(s.width/2, 0), cc.p(s.width/2, s.height), cc.c4f(1,1,1,1))
layer:addChild(drawNode, -10)
-- Upper Label
local label = cc.LabelBMFont:create("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt")
layer:addChild(label)
local s = cc.Director:getInstance():getWinSize()
label:setPosition( cc.p(s.width/2, s.height/2) )
label:setAnchorPoint( cc.p(0.5, 0.5) )
@ -311,19 +316,11 @@ function Atlas4.create()
local lastChar = label2:getChildByTag(3)
lastChar:runAction(rot_4ever:clone())
layer:registerScriptHandler(Atlas4.onNodeEvent)
Helper.titleLabel:setString("LabelBMFont")
Helper.subtitleLabel:setString( "Using fonts as cc.Sprite objects. Some characters should rotate.")
return layer
end
function Atlas4.draw()
local s = cc.Director:getInstance():getWinSize()
cc.DrawPrimitives.drawLine( cc.p(0, s.height/2), cc.p(s.width, s.height/2) )
cc.DrawPrimitives.drawLine( cc.p(s.width/2, 0), cc.p(s.width/2, s.height) )
end
function Atlas4.step(dt)
m_time = m_time + dt

View File

@ -119,12 +119,18 @@ function LabelFNTSpriteActions.create()
local layer = cc.Layer:create()
Helper.initWithLayer(layer)
LabelFNTSpriteActions.layer = layer
local s = cc.Director:getInstance():getWinSize()
local drawNode = cc.DrawNode:create()
drawNode:drawLine( cc.p(0, s.height/2), cc.p(s.width, s.height/2), cc.c4f(1,1,1,1))
drawNode:drawLine( cc.p(s.width/2, 0), cc.p(s.width/2, s.height), cc.c4f(1,1,1,1))
layer:addChild(drawNode, -10)
-- Upper Label
local label = cc.Label:createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas")
layer:addChild(label)
local s = cc.Director:getInstance():getWinSize()
label:setPosition( cc.p(s.width/2, s.height/2) )
label:setAnchorPoint( cc.p(0.5, 0.5) )
@ -174,12 +180,6 @@ function LabelFNTSpriteActions.create()
return layer
end
function LabelFNTSpriteActions.draw()
local s = cc.Director:getInstance():getWinSize()
cc.DrawPrimitives.drawLine( cc.p(0, s.height/2), cc.p(s.width, s.height/2) )
cc.DrawPrimitives.drawLine( cc.p(s.width/2, 0), cc.p(s.width/2, s.height) )
end
function LabelFNTSpriteActions.step(dt)
m_time = m_time + dt
@ -1652,6 +1652,21 @@ function LabelTTFOldNew.create()
label1:setPosition(cc.p(s.width/2, delta * 2))
label1:setColor(cc.c3b(255, 0, 0))
local labelSize = label1:getContentSize()
local origin = cc.Director:getInstance():getWinSize()
origin.width = origin.width / 2 - (labelSize.width / 2)
origin.height = origin.height / 2 - (labelSize.height / 2)
local vertices =
{
cc.p(origin.width, origin.height),
cc.p(labelSize.width + origin.width, origin.height),
cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
cc.p(origin.width, labelSize.height + origin.height),
}
local drawNode = cc.DrawNode:create()
drawNode:drawPoly(vertices, 4, true, cc.c4f(1,0,0,1))
layer:addChild(drawNode)
local ttfConfig = {}
ttfConfig.fontFilePath = "fonts/arial.ttf"
ttfConfig.fontSize = 24
@ -1659,54 +1674,20 @@ function LabelTTFOldNew.create()
layer:addChild(label2, 0, kTagBitmapAtlas2)
label2:setPosition(cc.p(s.width/2, delta * 2))
local function onDraw(transform, transformUpdated)
kmGLPushMatrix()
kmGLLoadMatrix(transform)
local label1 = layer:getChildByTag(kTagBitmapAtlas1)
local labelSize = label1:getContentSize()
local origin = cc.Director:getInstance():getWinSize()
origin.width = origin.width / 2 - (labelSize.width / 2)
origin.height = origin.height / 2 - (labelSize.height / 2)
local vertices =
{
cc.p(origin.width, origin.height),
cc.p(labelSize.width + origin.width, origin.height),
cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
cc.p(origin.width, labelSize.height + origin.height),
}
cc.DrawPrimitives.drawColor4B(255, 0, 0, 255)
cc.DrawPrimitives.drawPoly(vertices, 4, true)
local label2 = layer:getChildByTag(kTagBitmapAtlas2)
labelSize = label2:getContentSize()
origin = cc.Director:getInstance():getWinSize()
origin.width = origin.width / 2 - (labelSize.width / 2)
origin.height = origin.height / 2 - (labelSize.height / 2)
local vertices2 =
{
cc.p(origin.width, origin.height),
cc.p(labelSize.width + origin.width, origin.height),
cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
cc.p(origin.width, labelSize.height + origin.height),
}
cc.DrawPrimitives.drawColor4B(255, 255, 255, 255)
cc.DrawPrimitives.drawPoly(vertices2, 4, true)
kmGLPopMatrix()
end
local glNode = gl.glNodeCreate()
glNode:setContentSize(cc.size(s.width, s.height))
glNode:setAnchorPoint(cc.p(0.5, 0.5))
glNode:setPosition( s.width / 2, s.height / 2)
glNode:registerScriptDrawHandler(onDraw)
layer:addChild(glNode,-10)
labelSize = label2:getContentSize()
origin = cc.Director:getInstance():getWinSize()
origin.width = origin.width / 2 - (labelSize.width / 2)
origin.height = origin.height / 2 - (labelSize.height / 2)
local vertices2 =
{
cc.p(origin.width, origin.height),
cc.p(labelSize.width + origin.width, origin.height),
cc.p(labelSize.width + origin.width, labelSize.height + origin.height),
cc.p(origin.width, labelSize.height + origin.height),
}
local drawNode2 = cc.DrawNode:create()
drawNode2:drawPoly(vertices2, 4, true, cc.c4f(1,1,1,1))
layer:addChild(drawNode2)
return layer
end

View File

@ -625,6 +625,9 @@ local function TMXOrthoObjectsTest()
local s = map:getContentSize()
cclog("ContentSize: %f, %f", s.width,s.height)
local drawNode = cc.DrawNode:create()
map:addChild(drawNode, 10)
--------cclog("---: Iterating over all the group objets")
local group = map:getObjectGroup("Object Group 1")
@ -641,30 +644,7 @@ local function TMXOrthoObjectsTest()
break
end
--------cclog("object: %x", dict)
end
--------cclog("---: Fetching 1 object by name")
-- local platform = group:objectNamed("platform")
--------cclog("platform: %x", platform)
return ret
end
local function draw()
local map = tolua.cast(getChildByTag(kTagTileMap), "cc.TMXTiledMap")
local group = map:getObjectGroup("Object Group 1")
local objects = group:getObjects()
local dict = nil
local i = 0
local len = table.getn(objects)
for i = 0, len-1, 1 do
dict = objects[i + 1]
if dict == nil then
break
end
local key = "x"
local x = dict["x"]
key = "y"
@ -673,16 +653,19 @@ local function draw()
local width = dict["width"]--dynamic_cast<NSNumber*>(dict:objectForKey("width")):getNumber()
key = "height"
local height = dict["height"]--dynamic_cast<NSNumber*>(dict:objectForKey("height")):getNumber()
glLineWidth(3)
cc.DrawPrimitives.drawLine( cc.p(x, y), cc.p((x+width), y) )
cc.DrawPrimitives.drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)) )
cc.DrawPrimitives.drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)) )
cc.DrawPrimitives.drawLine( cc.p(x, (y+height)), cc.p(x, y) )
glLineWidth(1)
local color = cc.c4f(1,1,1,1)
drawNode:drawLine( cc.p(x, y), cc.p((x+width), y), color)
drawNode:drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)), color)
drawNode:drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)), color)
drawNode:drawLine( cc.p(x, (y+height)), cc.p(x, y), color)
end
--------cclog("---: Fetching 1 object by name")
-- local platform = group:objectNamed("platform")
--------cclog("platform: %x", platform)
return ret
end
--------------------------------------------------------------------
@ -701,6 +684,9 @@ local function TMXIsoObjectsTest()
local group = map:getObjectGroup("Object Group 1")
local drawNode = cc.DrawNode:create()
map:addChild(drawNode, 10)
--UxMutableArray* objects = group:objects()
local objects = group:getObjects()
--UxMutableDictionary<std:string>* dict
@ -714,26 +700,7 @@ local function TMXIsoObjectsTest()
break
end
--------cclog("object: %x", dict)
end
return ret
end
local function draw()
local map = tolua.cast(getChildByTag(kTagTileMap), "cc.TMXTiledMap")
local group = map:getObjectGroup("Object Group 1")
local objects = group:getObjects()
local dict = nil
local i = 0
local len = table.getn(objects)
for i = 0, len-1, 1 do
dict = tolua.cast(objects[i + 1], "cc.Dictionary")
if dict == nil then
break
end
local key = "x"
local x = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("x")):getNumber()
key = "y"
@ -742,16 +709,14 @@ local function draw()
local width = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("width")):getNumber()
key = "height"
local height = (tolua.cast(dict:objectForKey(key), "cc.String")):intValue()--dynamic_cast<NSNumber*>(dict:objectForKey("height")):getNumber()
glLineWidth(3)
cc.DrawPrimitives.drawLine( cc.p(x,y), cc.p(x+width,y) )
cc.DrawPrimitives.drawLine( cc.p(x+width,y), cc.p(x+width,y+height) )
cc.DrawPrimitives.drawLine( cc.p(x+width,y+height), cc.p(x,y+height) )
cc.DrawPrimitives.drawLine( cc.p(x,y+height), cc.p(x,y) )
glLineWidth(1)
local color = cc.c4f(1,1,1,1)
drawNode:drawLine( cc.p(x, y), cc.p((x+width), y), color)
drawNode:drawLine( cc.p((x+width), y), cc.p((x+width), (y+height)), color)
drawNode:drawLine( cc.p((x+width), (y+height)), cc.p(x, (y+height)), color)
drawNode:drawLine( cc.p(x, (y+height)), cc.p(x, y), color)
end
return ret
end
--------------------------------------------------------------------

View File

@ -43,7 +43,7 @@ skip = Node::[setGLServerState description getUserObject .*UserData getGLServerS
ParticleBatchNode::[getBlendFunc setBlendFunc],
LayerColor::[getBlendFunc setBlendFunc],
ParticleSystem::[(g|s)etBlendFunc updateQuadWithParticle initParticle],
DrawNode::[getBlendFunc setBlendFunc drawPolygon listenBackToForeground],
DrawNode::[getBlendFunc setBlendFunc drawPolygon drawSolidPoly drawPoly drawCardinalSpline drawCatmullRom drawPoints listenBackToForeground],
Director::[getAccelerometer getProjection getFrustum getRenderer],
Layer.*::[didAccelerate (g|s)etBlendFunc keyPressed keyReleased],
Menu.*::[.*Target getSubItems create initWithItems alignItemsInRows alignItemsInColumns],