PuzzleSDK
DrawNodeTest类 参考

#include <DrawPrimitivesTest.h>

+ 类 DrawNodeTest 继承关系图:
+ DrawNodeTest 的协作图:

Public 成员函数

 CREATE_FUNC (DrawNodeTest)
 
 DrawNodeTest ()
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 
virtual void onEnter () override
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 DrawPrimitivesTest.h39 行定义.

构造及析构函数说明

◆ DrawNodeTest()

DrawNodeTest::DrawNodeTest ( )

在文件 DrawPrimitivesTest.cpp45 行定义.

46{
47 auto s = Director::getInstance()->getWinSize();
48
49 auto draw = DrawNode::create();
50 addChild(draw, 10);
51
52 draw->drawPoint(Vec2(s.width/2-120, s.height/2-120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
53
54 draw->drawPoint(Vec2(s.width/2+120, s.height/2+120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
55
56 // draw 4 small points
57 Vec2 position[] = { Vec2(60,60), Vec2(70,70), Vec2(60,70), Vec2(70,60) };
58 draw->drawPoints( position, 4, 5, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
59
60 // draw a line
61 draw->drawLine(Vec2(0,0), Vec2(s.width, s.height), Color4F(1.0, 0.0, 0.0, 0.5));
62
63 // draw a rectangle
64 draw->drawRect(Vec2(23,23), Vec2(7,7), Color4F(1,1,0,1));
65
66 draw->drawRect(Vec2(15,30), Vec2(30,15), Vec2(15,0), Vec2(0,15), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
67
68 // draw a circle
69 draw->drawCircle(VisibleRect::center() + Vec2(140,0), 100, CC_DEGREES_TO_RADIANS(90), 50, true, 1.0f, 2.0f, Color4F(1.0f, 0.0f, 0.0f, 0.5f));
70
71 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.0f));
72
73 // Draw some beziers
74 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.5f));
75
76 draw->drawQuadBezier(Vec2(0.0f, 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.5f));
77
78 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.5f));
79
80 draw->drawCubicBezier(Vec2(s.width - 250, 40.0f), Vec2(s.width - 70, 100.0f), Vec2(s.width - 30, 250.0f), Vec2(s.width - 10, s.height - 50), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5f));
81
82 auto array = PointArray::create(20);
83 array->addControlPoint(Vec2(0.0f,0.0f));
84 array->addControlPoint(Vec2(80.0f,80.0f));
85 array->addControlPoint(Vec2(s.width-80,80.0f));
86 array->addControlPoint(Vec2(s.width-80,s.height-80));
87 array->addControlPoint(Vec2(80.0f,s.height-80));
88 array->addControlPoint(Vec2(80.0f,80.0f));
89 array->addControlPoint(Vec2(s.width/2, s.height/2));
90 draw->drawCardinalSpline(array, 0.5f, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5f));
91
92 auto array2 = PointArray::create(20);
93 array2->addControlPoint(Vec2(s.width / 2, 30.0f));
94 array2->addControlPoint(Vec2(s.width -80, 30.0f));
95 array2->addControlPoint(Vec2(s.width - 80, s.height - 80));
96 array2->addControlPoint(Vec2(s.width / 2, s.height - 80));
97 array2->addControlPoint(Vec2(s.width / 2, 30.0f));
98 draw->drawCatmullRom(array2, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5f));
99
100 // open random color poly
101 Vec2 vertices[] = { Vec2(0.0f,0.0f), Vec2(50.0f,50.0f), Vec2(100.0f,50.0f), Vec2(100.0f,100.0f), Vec2(50.0f,100.0f) };
102 draw->drawPoly( vertices, 5, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1.0f));
103
104 // closed random color poly
105 Vec2 vertices2[] = { Vec2(30.0f,130.0f), Vec2(30.0f,230.0f), Vec2(50.0f,200.0f) };
106 draw->drawPoly( vertices2, 3, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1.0f));
107
108 // Draw 10 circles
109 for( int i=0; i < 10; i++)
110 {
111 draw->drawDot(Vec2(s.width/2, s.height/2), 10*(10-i), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1.0f));
112 }
113
114 // Draw polygons
115 Vec2 points[] = { Vec2(s.height/4,0.0f), Vec2(s.width,s.height/5), Vec2(s.width/3*2,s.height) };
116 draw->drawPolygon(points, sizeof(points)/sizeof(points[0]), Color4F(1.0f,0.0f,0.0f,0.5f), 4, Color4F(0.0f,0.0f,1.0f,0.5f));
117
118 // star poly (triggers buggs)
119 {
120 const float o=80;
121 const float w=20;
122 const float h=50;
123 Vec2 star[] = {
124 Vec2(o+w,o-h), Vec2(o+w*2, o), // lower spike
125 Vec2(o + w*2 + h, o+w ), Vec2(o + w*2, o+w*2), // right spike
126 // {o +w, o+w*2+h}, {o,o+w*2}, // top spike
127 // {o -h, o+w}, {o,o}, // left spike
128 };
129
130 draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1.0f,0.0f,0.0f,0.5f), 1, Color4F(0.0f,0.0f,1.0f,1.0f));
131 }
132
133 // star poly (doesn't trigger bug... order is important un tesselation is supported.
134 {
135 const float o=180;
136 const float w=20;
137 const float h=50;
138 Vec2 star[] = {
139 Vec2(o,o), Vec2(o+w,o-h), Vec2(o+w*2, o), // lower spike
140 Vec2(o + w*2 + h, o+w ), Vec2(o + w*2, o+w*2), // right spike
141 Vec2(o +w, o+w*2+h), Vec2(o,o+w*2), // top spike
142 Vec2(o -h, o+w), // left spike
143 };
144
145 draw->drawPolygon(star, sizeof(star)/sizeof(star[0]), Color4F(1.0f,0.0f,0.0f,0.5f), 1, Color4F(0.0f,0.0f,1.0f,1.0f));
146 }
147
148 //draw a solid polygon
149 Vec2 vertices3[] = {Vec2(60.0f,160.0f), Vec2(70.0f,190.0f), Vec2(100.0f,190.0f), Vec2(90.0f,160.0f)};
150 draw->drawSolidPoly( vertices3, 4, Color4F(1.0f,1.0f,0.0f,1.0f) );
151
152 //draw a solid rectangle
153 draw->drawSolidRect(Vec2(10.0f,10.0f), Vec2(20.0f,20.0f), Color4F(1.0f,1.0f,0.0f,1.0f));
154
155 //draw a solid circle
156 draw->drawSolidCircle( VisibleRect::center() + Vec2(140.0f,0.0f), 40, CC_DEGREES_TO_RADIANS(90), 50, 2.0f, 2.0f, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
157
158 // Draw segment
159 draw->drawSegment(Vec2(20.0f,s.height), Vec2(20.0f,s.height/2), 10, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
160
161 draw->drawSegment(Vec2(10.0f,s.height/2), Vec2(s.width/2, s.height/2), 40, Color4F(1.0f, 0.0f, 1.0f, 0.5f));
162
163 // Draw triangle
164 draw->drawTriangle(Vec2(10.0f, 10.0f), Vec2(70.0f, 30.0f), Vec2(100.0f, 140.0f), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5f));
165
166 for (int i = 0; i < 100; i++) {
167 draw->drawPoint(Vec2(i*7.0f, 5.0f), (float)i/5+1, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1.0f));
168 }
169
170 auto draw1 = DrawNode::create();
171 this->addChild(draw1, 10);
172 draw1->setLineWidth(4);
173 draw1->drawLine(Vec2(0.0f, s.height), Vec2(s.width, s.height - 20), Color4F::YELLOW);
174 draw1->drawLine(Vec2(0.0f, 0.0f), Vec2(s.width, s.height - 20), Color4F::YELLOW);
175
176 draw->runAction(RepeatForever::create(Sequence::create(FadeIn::create(1.2),FadeOut::create(1.2), NULL)));
177 draw1->runAction(RepeatForever::create(Sequence::create(FadeIn::create(1.2),FadeOut::create(1.2), NULL)));
178}
static cocos2d::Vec2 center()
Definition: VisibleRect.cpp:69
static cocos2d::Vec2 right()
Definition: VisibleRect.cpp:51

引用了 VisibleRect::center() , 以及 VisibleRect::right().

+ 函数调用图:

成员函数说明

◆ CREATE_FUNC()

DrawNodeTest::CREATE_FUNC ( DrawNodeTest  )

◆ subtitle()

string DrawNodeTest::subtitle ( ) const
overridevirtual

重载 TestCase .

在文件 DrawPrimitivesTest.cpp185 行定义.

186{
187 return "Testing DrawNode - batched draws. Concave polygons are BROKEN";
188}

◆ title()

string DrawNodeTest::title ( ) const
overridevirtual

重载 DrawPrimitivesBaseTest .

在文件 DrawPrimitivesTest.cpp180 行定义.

181{
182 return "Test DrawNode";
183}

该类的文档由以下文件生成: