Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: samplecode/SampleAnimator.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleAll.cpp ('k') | samplecode/SampleApp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 22 matching lines...) Expand all
33 virtual void onDraw(SkCanvas*); 33 virtual void onDraw(SkCanvas*);
34 virtual bool onQuery(SkEvent* evt); 34 virtual bool onQuery(SkEvent* evt);
35 35
36 private: 36 private:
37 SkString fBaseURI; 37 SkString fBaseURI;
38 SkAnimator* fAnimator; 38 SkAnimator* fAnimator;
39 39
40 typedef SkView INHERITED; 40 typedef SkView INHERITED;
41 }; 41 };
42 42
43 SkAnimatorView::SkAnimatorView() : fAnimator(NULL) {} 43 SkAnimatorView::SkAnimatorView() : fAnimator(nullptr) {}
44 44
45 SkAnimatorView::~SkAnimatorView() { 45 SkAnimatorView::~SkAnimatorView() {
46 delete fAnimator; 46 delete fAnimator;
47 } 47 }
48 48
49 void SkAnimatorView::setURIBase(const char dir[]) { 49 void SkAnimatorView::setURIBase(const char dir[]) {
50 fBaseURI.set(dir); 50 fBaseURI.set(dir);
51 } 51 }
52 52
53 bool SkAnimatorView::decodeFile(const char path[]) { 53 bool SkAnimatorView::decodeFile(const char path[]) {
54 SkAutoTDelete<SkStream> is(SkStream::NewFromFile(path)); 54 SkAutoTDelete<SkStream> is(SkStream::NewFromFile(path));
55 return is.get() != NULL && this->decodeStream(is); 55 return is.get() != nullptr && this->decodeStream(is);
56 } 56 }
57 57
58 bool SkAnimatorView::decodeMemory(const void* buffer, size_t size) { 58 bool SkAnimatorView::decodeMemory(const void* buffer, size_t size) {
59 SkMemoryStream is(buffer, size); 59 SkMemoryStream is(buffer, size);
60 return this->decodeStream(&is); 60 return this->decodeStream(&is);
61 } 61 }
62 62
63 static const SkDOMNode* find_nodeID(const SkDOM& dom, 63 static const SkDOMNode* find_nodeID(const SkDOM& dom,
64 const SkDOMNode* node, const char name[]) { 64 const SkDOMNode* node, const char name[]) {
65 if (NULL == node) { 65 if (nullptr == node) {
66 node = dom.getRootNode(); 66 node = dom.getRootNode();
67 } 67 }
68 do { 68 do {
69 const char* idval = dom.findAttr(node, "id"); 69 const char* idval = dom.findAttr(node, "id");
70 if (idval && !strcmp(idval, name)) { 70 if (idval && !strcmp(idval, name)) {
71 return node; 71 return node;
72 } 72 }
73 const SkDOMNode* child = dom.getFirstChild(node); 73 const SkDOMNode* child = dom.getFirstChild(node);
74 if (child) { 74 if (child) {
75 const SkDOMNode* found = find_nodeID(dom, child, name); 75 const SkDOMNode* found = find_nodeID(dom, child, name);
76 if (found) { 76 if (found) {
77 return found; 77 return found;
78 } 78 }
79 } 79 }
80 } while ((node = dom.getNextSibling(node)) != NULL); 80 } while ((node = dom.getNextSibling(node)) != nullptr);
81 return NULL; 81 return nullptr;
82 } 82 }
83 83
84 bool SkAnimatorView::decodeStream(SkStream* stream) { 84 bool SkAnimatorView::decodeStream(SkStream* stream) {
85 delete fAnimator; 85 delete fAnimator;
86 fAnimator = new SkAnimator; 86 fAnimator = new SkAnimator;
87 fAnimator->setURIBase(fBaseURI.c_str()); 87 fAnimator->setURIBase(fBaseURI.c_str());
88 #if 0 88 #if 0
89 if (!fAnimator->decodeStream(stream)) { 89 if (!fAnimator->decodeStream(stream)) {
90 delete fAnimator; 90 delete fAnimator;
91 fAnimator = NULL; 91 fAnimator = nullptr;
92 return false; 92 return false;
93 } 93 }
94 #else 94 #else
95 size_t len = stream->getLength(); 95 size_t len = stream->getLength();
96 char* text = (char*)sk_malloc_throw(len); 96 char* text = (char*)sk_malloc_throw(len);
97 stream->read(text, len); 97 stream->read(text, len);
98 SkDOM dom; 98 SkDOM dom;
99 const SkDOM::Node* root = dom.build(text, len); 99 const SkDOM::Node* root = dom.build(text, len);
100 if (NULL == root) { 100 if (nullptr == root) {
101 return false; 101 return false;
102 } 102 }
103 if (!fAnimator->decodeDOM(dom, root)) { 103 if (!fAnimator->decodeDOM(dom, root)) {
104 delete fAnimator; 104 delete fAnimator;
105 fAnimator = NULL; 105 fAnimator = nullptr;
106 return false; 106 return false;
107 } 107 }
108 for (int i = 0; i <= 10; i++) { 108 for (int i = 0; i <= 10; i++) {
109 SkString name("glyph"); 109 SkString name("glyph");
110 name.appendS32(i); 110 name.appendS32(i);
111 const SkDOM::Node* node = find_nodeID(dom, NULL, name.c_str()); 111 const SkDOM::Node* node = find_nodeID(dom, nullptr, name.c_str());
112 SkASSERT(node); 112 SkASSERT(node);
113 SkRect r; 113 SkRect r;
114 dom.findScalar(node, "left", &r.fLeft); 114 dom.findScalar(node, "left", &r.fLeft);
115 dom.findScalar(node, "top", &r.fTop); 115 dom.findScalar(node, "top", &r.fTop);
116 dom.findScalar(node, "width", &r.fRight); r.fRight += r.fLeft; 116 dom.findScalar(node, "width", &r.fRight); r.fRight += r.fLeft;
117 dom.findScalar(node, "height", &r.fBottom); r.fBottom += r.fTop; 117 dom.findScalar(node, "height", &r.fBottom); r.fBottom += r.fTop;
118 SkDebugf("--- %s [%g %g %g %g]\n", name.c_str(), 118 SkDebugf("--- %s [%g %g %g %g]\n", name.c_str(),
119 r.fLeft, r.fTop, r.fRight, r.fBottom); 119 r.fLeft, r.fTop, r.fRight, r.fBottom);
120 } 120 }
121 #endif 121 #endif
(...skipping 12 matching lines...) Expand all
134 canvas->scale(0.5, 0.5); 134 canvas->scale(0.5, 0.5);
135 fAnimator->draw(canvas, 0); 135 fAnimator->draw(canvas, 0);
136 canvas->restore(); 136 canvas->restore();
137 137
138 canvas->save(); 138 canvas->save();
139 canvas->translate(190, 40); 139 canvas->translate(190, 40);
140 canvas->scale(0.25, 0.25); 140 canvas->scale(0.25, 0.25);
141 fAnimator->draw(canvas, 0); 141 fAnimator->draw(canvas, 0);
142 canvas->restore(); 142 canvas->restore();
143 143
144 this->inval(NULL); 144 this->inval(nullptr);
145 #endif 145 #endif
146 } 146 }
147 } 147 }
148 148
149 bool SkAnimatorView::onQuery(SkEvent* evt) { 149 bool SkAnimatorView::onQuery(SkEvent* evt) {
150 if (SampleCode::TitleQ(*evt)) { 150 if (SampleCode::TitleQ(*evt)) {
151 SampleCode::TitleR(evt, "Animator"); 151 SampleCode::TitleR(evt, "Animator");
152 return true; 152 return true;
153 } 153 }
154 return this->INHERITED::onQuery(evt); 154 return this->INHERITED::onQuery(evt);
155 } 155 }
156 156
157 ////////////////////////////////////////////////////////////////////////////// 157 //////////////////////////////////////////////////////////////////////////////
158 158
159 static SkView* MyFactory() { 159 static SkView* MyFactory() {
160 SkAnimatorView* av = new SkAnimatorView; 160 SkAnimatorView* av = new SkAnimatorView;
161 // av->decodeFile("/skimages/test.xml"); 161 // av->decodeFile("/skimages/test.xml");
162 #if 0 162 #if 0
163 av->setURIBase("/skia/trunk/animations/"); 163 av->setURIBase("/skia/trunk/animations/");
164 av->decodeFile("/skia/trunk/animations/checkbox.xml"); 164 av->decodeFile("/skia/trunk/animations/checkbox.xml");
165 #else 165 #else
166 av->setURIBase("/"); 166 av->setURIBase("/");
167 av->decodeFile("/testanim.txt"); 167 av->decodeFile("/testanim.txt");
168 #endif 168 #endif
169 return av; 169 return av;
170 } 170 }
171 171
172 static SkViewRegister reg(MyFactory); 172 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleAll.cpp ('k') | samplecode/SampleApp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698