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

Side by Side Diff: samplecode/SampleShip.cpp

Issue 1410663005: Add text animation sample; tweak DrawShip sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Correct fix for CrOS Created 5 years, 1 month 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/SampleApp.cpp ('k') | src/gpu/GrTest.cpp » ('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 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 #include "SkAnimTimer.h" 10 #include "SkAnimTimer.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 SkScalar anchorY = fAtlas->height()*0.5f; 63 SkScalar anchorY = fAtlas->height()*0.5f;
64 int currIndex = 0; 64 int currIndex = 0;
65 for (int x = 0; x < kGrid; x++) { 65 for (int x = 0; x < kGrid; x++) {
66 for (int y = 0; y < kGrid; y++) { 66 for (int y = 0; y < kGrid; y++) {
67 float xPos = (x / (kGrid - 1.0f)) * kWidth; 67 float xPos = (x / (kGrid - 1.0f)) * kWidth;
68 float yPos = (y / (kGrid - 1.0f)) * kWidth; 68 float yPos = (y / (kGrid - 1.0f)) * kWidth;
69 69
70 fTex[currIndex] = SkRect::MakeLTRB(0.0f, 0.0f, 70 fTex[currIndex] = SkRect::MakeLTRB(0.0f, 0.0f,
71 SkIntToScalar(fAtlas->width() ), 71 SkIntToScalar(fAtlas->width() ),
72 SkIntToScalar(fAtlas->height( ))); 72 SkIntToScalar(fAtlas->height( )));
73 fXform[currIndex] = SkRSXform::MakeFromRadians(2.0f, SK_ScalarPI *0.5f, 73 fXform[currIndex] = SkRSXform::MakeFromRadians(0.1f, SK_ScalarPI *0.5f,
74 xPos, yPos, ancho rX, anchorY); 74 xPos, yPos, ancho rX, anchorY);
75 currIndex++; 75 currIndex++;
76 } 76 }
77 } 77 }
78 fTex[currIndex] = SkRect::MakeLTRB(0.0f, 0.0f, 78 fTex[currIndex] = SkRect::MakeLTRB(0.0f, 0.0f,
79 SkIntToScalar(fAtlas->width()), 79 SkIntToScalar(fAtlas->width()),
80 SkIntToScalar(fAtlas->height())); 80 SkIntToScalar(fAtlas->height()));
81 fXform[currIndex] = SkRSXform::MakeFromRadians(2.0f, SK_ScalarPI*0.5f, 81 fXform[currIndex] = SkRSXform::MakeFromRadians(0.5f, SK_ScalarPI*0.5f,
82 kWidth*0.5f, kHeight*0.5f , anchorX, anchorY); 82 kWidth*0.5f, kHeight*0.5f , anchorX, anchorY);
83 83
84 fCurrentTime = 0; 84 fCurrentTime = 0;
85 fTimer.start(); 85 fTimer.start();
86 } 86 }
87 87
88 ~DrawShipView() override {} 88 ~DrawShipView() override {}
89 89
90 protected: 90 protected:
91 // overrides from SkEventSink 91 // overrides from SkEventSink
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 fXform[i].fSCos = kCosDiff*c - kSinDiff*s; 140 fXform[i].fSCos = kCosDiff*c - kSinDiff*s;
141 fXform[i].fSSin = kSinDiff*c + kCosDiff*s; 141 fXform[i].fSSin = kSinDiff*c + kCosDiff*s;
142 142
143 dx -= fXform[i].fSCos*anchorX - fXform[i].fSSin*anchorY; 143 dx -= fXform[i].fSCos*anchorX - fXform[i].fSSin*anchorY;
144 dy -= fXform[i].fSSin*anchorX + fXform[i].fSCos*anchorY; 144 dy -= fXform[i].fSSin*anchorX + fXform[i].fSCos*anchorY;
145 fXform[i].fTx += dx; 145 fXform[i].fTx += dx;
146 fXform[i].fTy += dy; 146 fXform[i].fTy += dy;
147 } 147 }
148 148
149 fProc(canvas, fAtlas, fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &pa int); 149 fProc(canvas, fAtlas, fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &pa int);
150 canvas->drawText(outString.c_str(), outString.size(), 100.f, 100.f, pain t); 150 paint.setColor(SK_ColorBLACK);
151 canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint);
152 paint.setColor(SK_ColorWHITE);
153 canvas->drawText(outString.c_str(), outString.size(), 5, 15, paint);
151 154
152 this->inval(nullptr); 155 this->inval(nullptr);
153 } 156 }
154 157
155 #if 0 158 #if 0
156 // TODO: switch over to use this for our animation 159 // TODO: switch over to use this for our animation
157 bool onAnimate(const SkAnimTimer& timer) override { 160 bool onAnimate(const SkAnimTimer& timer) override {
158 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); 161 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360));
159 fAnimatingDrawable->setSweep(angle); 162 fAnimatingDrawable->setSweep(angle);
160 return true; 163 return true;
(...skipping 12 matching lines...) Expand all
173 int fCurrentTime; 176 int fCurrentTime;
174 177
175 178
176 typedef SampleView INHERITED; 179 typedef SampleView INHERITED;
177 }; 180 };
178 181
179 ////////////////////////////////////////////////////////////////////////////// 182 //////////////////////////////////////////////////////////////////////////////
180 183
181 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); ) 184 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); )
182 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); ) 185 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); )
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/gpu/GrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698