OLD | NEW |
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 30 matching lines...) Expand all Loading... |
41 canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex
[i].y()), paint, | 41 canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex
[i].y()), paint, |
42 SkCanvas::kFast_SrcRectConstraint); | 42 SkCanvas::kFast_SrcRectConstraint); |
43 canvas->restore(); | 43 canvas->restore(); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 class DrawShipView : public SampleView { | 48 class DrawShipView : public SampleView { |
49 public: | 49 public: |
50 DrawShipView(const char name[], DrawAtlasProc proc) : fName(name), fProc(pro
c) { | 50 DrawShipView(const char name[], DrawAtlasProc proc) : fName(name), fProc(pro
c) { |
51 fAtlas.reset(GetResourceAsImage("ship.png")); | 51 fAtlas = GetResourceAsImage("ship.png"); |
52 if (!fAtlas) { | 52 if (!fAtlas) { |
53 SkDebugf("\nCould not decode file ship.png. Falling back to penguin
mode.\n"); | 53 SkDebugf("\nCould not decode file ship.png. Falling back to penguin
mode.\n"); |
54 fAtlas.reset(GetResourceAsImage("baby_tux.png")); | 54 fAtlas = GetResourceAsImage("baby_tux.png"); |
55 if (!fAtlas) { | 55 if (!fAtlas) { |
56 SkDebugf("\nCould not decode file baby_tux.png. Did you forget" | 56 SkDebugf("\nCould not decode file baby_tux.png. Did you forget" |
57 " to set the resourcePath?\n"); | 57 " to set the resourcePath?\n"); |
58 return; | 58 return; |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 SkScalar anchorX = fAtlas->width()*0.5f; | 62 SkScalar anchorX = fAtlas->width()*0.5f; |
63 SkScalar anchorY = fAtlas->height()*0.5f; | 63 SkScalar anchorY = fAtlas->height()*0.5f; |
64 int currIndex = 0; | 64 int currIndex = 0; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
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.get(), fXform, fTex, nullptr, kGrid*kGrid+1, nullpt
r, &paint); |
150 paint.setColor(SK_ColorBLACK); | 150 paint.setColor(SK_ColorBLACK); |
151 canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint); | 151 canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint); |
152 paint.setColor(SK_ColorWHITE); | 152 paint.setColor(SK_ColorWHITE); |
153 canvas->drawText(outString.c_str(), outString.size(), 5, 15, paint); | 153 canvas->drawText(outString.c_str(), outString.size(), 5, 15, paint); |
154 | 154 |
155 this->inval(nullptr); | 155 this->inval(nullptr); |
156 } | 156 } |
157 | 157 |
158 #if 0 | 158 #if 0 |
159 // TODO: switch over to use this for our animation | 159 // TODO: switch over to use this for our animation |
160 bool onAnimate(const SkAnimTimer& timer) override { | 160 bool onAnimate(const SkAnimTimer& timer) override { |
161 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); | 161 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); |
162 fAnimatingDrawable->setSweep(angle); | 162 fAnimatingDrawable->setSweep(angle); |
163 return true; | 163 return true; |
164 } | 164 } |
165 #endif | 165 #endif |
166 | 166 |
167 private: | 167 private: |
168 const char* fName; | 168 const char* fName; |
169 DrawAtlasProc fProc; | 169 DrawAtlasProc fProc; |
170 | 170 |
171 SkAutoTUnref<SkImage> fAtlas; | 171 sk_sp<SkImage> fAtlas; |
172 SkRSXform fXform[kGrid*kGrid+1]; | 172 SkRSXform fXform[kGrid*kGrid+1]; |
173 SkRect fTex[kGrid*kGrid+1]; | 173 SkRect fTex[kGrid*kGrid+1]; |
174 WallTimer fTimer; | 174 WallTimer fTimer; |
175 float fTimes[32]; | 175 float fTimes[32]; |
176 int fCurrentTime; | 176 int fCurrentTime; |
177 | 177 |
178 | 178 |
179 typedef SampleView INHERITED; | 179 typedef SampleView INHERITED; |
180 }; | 180 }; |
181 | 181 |
182 ////////////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////////////// |
183 | 183 |
184 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); ) | 184 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); ) |
185 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); ) | 185 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); ) |
OLD | NEW |