Merge branch 'develop' of https://github.com/cocos2d/cocos2d-x into developNewUI

This commit is contained in:
samuele3hu 2014-01-09 17:24:37 +08:00
commit 8826659cf1
7 changed files with 104 additions and 7 deletions

View File

@ -356,6 +356,7 @@ Developers:
ThePickleMan
Adding 'rotationIsDir' property to ParticleSystem.
DrawNode supports to draw triangle, quad bezier, cubic bezier.
Jianghua (jxhgzs)
Adding an additional transform for CCNode.

View File

@ -4,6 +4,7 @@ cocos2d-x-3.0final ?.? ?
[FIX] ControlSlider doesn't support to set selected thumb sprite.
[FIX] ControlButton doesn't support to set scale ratio of touchdown state.
[FIX] Websocket doesn't support send/receive data which larger than 4096 bytes.
[NEW] DrawNode supports to draw triangle, quad bezier, cubic bezier.
cocos2d-x-3.0beta Jan.7 2014
[All]
[NEW] New label: shadow, outline, glow support

View File

@ -456,6 +456,86 @@ void DrawNode::drawPolygon(Point *verts, int count, const Color4F &fillColor, fl
free(extrude);
}
void DrawNode::drawTriangle(const Point &p1, const Point &p2, const Point &p3, const Color4F &color)
{
unsigned int vertex_count = 2*3;
ensureCapacity(vertex_count);
Color4B col = Color4B(color);
V2F_C4B_T2F a = {Vertex2F(p1.x, p1.y), col, Tex2F(0.0, 0.0) };
V2F_C4B_T2F b = {Vertex2F(p2.x, p2.y), col, Tex2F(0.0, 0.0) };
V2F_C4B_T2F c = {Vertex2F(p3.x, p3.y), col, Tex2F(0.0, 0.0) };
V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount);
V2F_C4B_T2F_Triangle triangle = {a, b, c};
triangles[0] = triangle;
_bufferCount += vertex_count;
_dirty = true;
}
void DrawNode::drawCubicBezier(const Point& from, const Point& control1, const Point& control2, const Point& 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);
Vertex2F vertex;
Vertex2F firstVertex = Vertex2F(from.x, from.y);
Vertex2F lastVertex = Vertex2F(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 = Vertex2F(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 Point& from, const Point& control, const Point& 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);
Vertex2F vertex;
Vertex2F firstVertex = Vertex2F(from.x, from.y);
Vertex2F lastVertex = Vertex2F(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 = Vertex2F(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::clear()
{
_bufferCount = 0;

View File

@ -63,6 +63,15 @@ public:
* @endcode
*/
void drawPolygon(Point *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor);
/** draw a triangle with color */
void drawTriangle(const Point &p1, const Point &p2, const Point &p3, const Color4F &color);
/** draw a cubic bezier curve with color and number of segments */
void drawCubicBezier(const Point& from, const Point& control1, const Point& control2, const Point& to, unsigned int segments, const Color4F &color);
/** draw a quadratic bezier curve with color and number of segments */
void drawQuadraticBezier(const Point& from, const Point& control, const Point& to, unsigned int segments, const Color4F &color);
/** Clear the geometry in the node's buffer. */
void clear();

View File

@ -376,7 +376,7 @@ namespace
//////////////////////////////////////////////////////////////////////////
Image::Image()
: _data(0)
: _data(nullptr)
, _dataLen(0)
, _width(0)
, _height(0)
@ -391,10 +391,7 @@ Image::Image()
Image::~Image()
{
if (_data != nullptr)
{
free(_data);
}
CC_SAFE_FREE(_data);
}
bool Image::initWithImageFile(const std::string& path)
@ -1539,7 +1536,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
}while(false);
if (!ret)
if (ret)
{
const unsigned char tgaSuffix[] = ".tga";
for(int i = 0; i < 4; ++i)
@ -1556,6 +1553,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
if (tgaData->imageData != nullptr)
{
free(tgaData->imageData);
_data = nullptr;
}
}

View File

@ -109,7 +109,7 @@ bool ControlSlider::initWithSprites(Sprite * backgroundSprite, Sprite* progressS
Sprite* selectedThumbSprite = Sprite::createWithTexture(thumbSprite->getTexture(),
thumbSprite->getTextureRect());
selectedThumbSprite->setColor(Color3B::GRAY);
this->initWithSprites(backgroundSprite, progressSprite, thumbSprite, selectedThumbSprite);
return this->initWithSprites(backgroundSprite, progressSprite, thumbSprite, selectedThumbSprite);
}
bool ControlSlider::initWithSprites(Sprite * backgroundSprite, Sprite* progressSprite, Sprite* thumbSprite,

View File

@ -302,6 +302,14 @@ DrawNodeTest::DrawNodeTest()
draw->drawSegment(Point(20,s.height), Point(20,s.height/2), 10, Color4F(0, 1, 0, 1));
draw->drawSegment(Point(10,s.height/2), Point(s.width/2, s.height/2), 40, Color4F(1, 0, 1, 0.5));
// Draw triangle
draw->drawTriangle(Point(10, 10), Point(70, 30), Point(100, 140), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
// Draw some beziers
draw->drawQuadraticBezier(Point(s.width - 150, s.height - 150), Point(s.width - 70, s.height - 10), Point(s.width - 10, s.height - 10), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
draw->drawCubicBezier(Point(s.width - 250, 40), Point(s.width - 70, 100), Point(s.width - 30, 250), Point(s.width - 10, s.height - 50), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
}
string DrawNodeTest::title() const