add DrawPrimitives Test code
This commit is contained in:
natural-law 2010-08-26 02:53:49 +00:00
parent 4f1e1996be
commit b47d47b3b5
8 changed files with 137 additions and 12 deletions

View File

@ -300,6 +300,10 @@
RelativePath=".\include\CCDirector.h"
>
</File>
<File
RelativePath=".\include\CCDrawingPrimitives.h"
>
</File>
<File
RelativePath=".\include\CCEaseAction.h"
>
@ -933,10 +937,6 @@
RelativePath=".\CCDrawingPrimitives.cpp"
>
</File>
<File
RelativePath=".\CCDrawingPrimitives.h"
>
</File>
<File
RelativePath=".\CCScheduler.cpp"
>

View File

@ -44,32 +44,32 @@ THE SOFTWARE.
namespace cocos2d {
/** draws a point given x and y coordinate */
void ccDrawPoint( CGPoint point );
void CCX_DLL ccDrawPoint( CGPoint point );
/** draws an array of points.
@since v0.7.2
*/
void ccDrawPoints( CGPoint *points, unsigned int numberOfPoints );
void CCX_DLL ccDrawPoints( CGPoint *points, unsigned int numberOfPoints );
/** draws a line given the origin and destination point */
void ccDrawLine( CGPoint origin, CGPoint destination );
void CCX_DLL ccDrawLine( CGPoint origin, CGPoint destination );
/** draws a poligon given a pointer to CGPoint coordiantes and the number of vertices. The polygon can be closed or open
*/
void ccDrawPoly( CGPoint *vertices, int numOfVertices, bool closePolygon );
void CCX_DLL ccDrawPoly( CGPoint *vertices, int numOfVertices, bool closePolygon );
/** draws a circle given the center, radius and number of segments. */
void ccDrawCircle( CGPoint center, float radius, float angle, int segments, bool drawLineToCenter);
void CCX_DLL ccDrawCircle( CGPoint center, float radius, float angle, int segments, bool drawLineToCenter);
/** draws a quad bezier path
@since v0.8
*/
void ccDrawQuadBezier(CGPoint origin, CGPoint control, CGPoint destination, int segments);
void CCX_DLL ccDrawQuadBezier(CGPoint origin, CGPoint control, CGPoint destination, int segments);
/** draws a cubic bezier path
@since v0.8
*/
void ccDrawCubicBezier(CGPoint origin, CGPoint control1, CGPoint control2, CGPoint destination, int segments);
void CCX_DLL ccDrawCubicBezier(CGPoint origin, CGPoint control1, CGPoint control2, CGPoint destination, int segments);
}//namespace cocos2d
#endif // __CCDRAWING_PRIMITIVES__

View File

@ -75,6 +75,7 @@ THE SOFTWARE.
#include "CCRadialTransition.h"
#include "CCProgressTimerActions.h"
#include "CCTouchDispatcher.h"
#include "CCDrawingPrimitives.h"
//
// cocoa includes

View File

@ -64,7 +64,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="WS2_32.Lib ..\..\PRJ_TG3\Common\SoftSupport\EosConfig.lib ..\..\PRJ_TG3\Common\SoftSupport\SoftSupport.lib ..\..\PRJ_TG3\Common\SoftSupport\TG3_DLL.lib libcocos2d.lib"
AdditionalDependencies="WS2_32.Lib ..\..\PRJ_TG3\Common\SoftSupport\EosConfig.lib ..\..\PRJ_TG3\Common\SoftSupport\SoftSupport.lib ..\..\PRJ_TG3\Common\SoftSupport\TG3_DLL.lib libcocos2d.lib libEGL.lib libgles_cm.lib"
OutputFile="$(OutDir)/test_uphone.dll"
LinkIncremental="2"
AdditionalLibraryDirectories="../../PRJ_TG3/Common/ICU/lib;../../PRJ_TG3/Mtapi/Win32/lib;../../PRJ_TG3/LIB/Win32Lib;../../PRJ_TG3/Common/SoftSupport;&quot;$(OutDir)&quot;"
@ -425,6 +425,18 @@
>
</File>
</Filter>
<Filter
Name="DrawPrimitivesTest"
>
<File
RelativePath=".\tests\DrawPrimitivesTest\DrawPrimitivesTest.cpp"
>
</File>
<File
RelativePath=".\tests\DrawPrimitivesTest\DrawPrimitivesTest.h"
>
</File>
</Filter>
</Filter>
<File
RelativePath=".\test_uphoneUnicodeScript.h"

View File

@ -0,0 +1,87 @@
#include "drawPrimitivesTest.h"
DrawPrimitivesTest::DrawPrimitivesTest()
{
}
void DrawPrimitivesTest::draw()
{
__super::draw();
CGSize s = CCDirector::getSharedDirector()->getWinSize();
// draw a simple line
// The default state is:
// Line Width: 1
// color: 255,255,255,255 (white, non-transparent)
// Anti-Aliased
glEnable(GL_LINE_SMOOTH);
ccDrawLine( CGPointMake(0, 0), CGPointMake(s.width, s.height) );
// line: color, width, aliased
// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
glDisable(GL_LINE_SMOOTH);
glLineWidth( 5.0f );
glColor4ub(255,0,0,255);
ccDrawLine( CGPointMake(0, s.height), CGPointMake(s.width, 0) );
// TIP:
// If you are going to use always the same color or width, you don't
// need to call it before every draw
//
// Remember: OpenGL is a state-machine.
// draw big point in the center
glPointSize(64);
glColor4ub(0,0,255,128);
ccDrawPoint( CGPointMake(s.width / 2, s.height / 2) );
// draw 4 small points
CGPoint points[] = { CGPointMake(60,60), CGPointMake(70,70), CGPointMake(60,70), CGPointMake(70,60) };
glPointSize(4);
glColor4ub(0,255,255,255);
ccDrawPoints( points, 4);
// draw a green circle with 10 segments
glLineWidth(16);
glColor4ub(0, 255, 0, 255);
ccDrawCircle( CGPointMake(s.width/2, s.height/2), 100, 0, 10, false);
// draw a green circle with 50 segments with line to center
glLineWidth(2);
glColor4ub(0, 255, 255, 255);
ccDrawCircle( CGPointMake(s.width/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, true);
// open yellow poly
glColor4ub(255, 255, 0, 255);
glLineWidth(10);
CGPoint vertices[] = { CGPointMake(0,0), CGPointMake(50,50), CGPointMake(100,50), CGPointMake(100,100), CGPointMake(50,100) };
ccDrawPoly( vertices, 5, false);
// closed purble poly
glColor4ub(255, 0, 255, 255);
glLineWidth(2);
CGPoint vertices2[] = { CGPointMake(30,130), CGPointMake(30,230), CGPointMake(50,200) };
ccDrawPoly( vertices2, 3, true);
// draw quad bezier path
ccDrawQuadBezier(CGPointMake(0,s.height), CGPointMake(s.width/2,s.height/2), CGPointMake(s.width,s.height), 50);
// draw cubic bezier path
ccDrawCubicBezier(CGPointMake(s.width/2, s.height/2), CGPointMake(s.width/2+30,s.height/2+50), CGPointMake(s.width/2+60,s.height/2-50),CGPointMake(s.width, s.height/2),100);
// restore original values
glLineWidth(1);
glColor4ub(255,255,255,255);
glPointSize(1);
}
void DrawPrimitivesTestScene::runThisTest()
{
CCLayer* pLayer = new DrawPrimitivesTest();
addChild(pLayer);
CCDirector::getSharedDirector()->replaceScene(this);
}

View File

@ -0,0 +1,20 @@
#ifndef _DRAW_PRIMITIVES_TEST_H_
#define _DRAW_PRIMITIVES_TEST_H_
#include "cocos2d.h"
#include "../testBasic.h"
class DrawPrimitivesTest : public CCLayer
{
public:
DrawPrimitivesTest();
virtual void draw();
};
class DrawPrimitivesTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif

View File

@ -32,6 +32,8 @@ static TestScene* CreateTestScene(int nIdx)
pScene = new EaseActionsTestScene(); break;
case TEST_MOTION_STREAK:
pScene = new MotionStreakTestScene(); break;
case TEST_DRAW_PRIMITIVES:
pScene = new DrawPrimitivesTestScene(); break;
default:
break;
}

View File

@ -10,6 +10,7 @@
#include "ParticleTest/ParticleTest.h"
#include "EaseActionsTest/EaseActionsTest.h"
#include "MotionStreakTest/MotionStreakTest.h"
#include "DrawPrimitivesTest/DrawPrimitivesTest.h"
enum
{
@ -22,6 +23,7 @@ enum
TEST_PARTICLE,
TEST_EASE_ACTIONS,
TEST_MOTION_STREAK,
TEST_DRAW_PRIMITIVES,
// TEST_TEXTURE2D,
// TEST_SPRITE,
// TEST_LAYER,
@ -44,6 +46,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"ParticleTest",
"EaseActionsTest",
"MotionStreakTest",
"DrawPrimitivesTest",
// "Texture2dTest",
// "SpriteTest",
// "LayerTest",