| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(0.1f, SK_ScalarPI
*0.5f, | 73 fXform[currIndex] = SkRSXform::MakeFromRadians(2.0f, 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(0.5f, SK_ScalarPI*0.5f, | 81 fXform[currIndex] = SkRSXform::MakeFromRadians(2.0f, 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 Loading... |
| 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 paint.setColor(SK_ColorBLACK); | 150 canvas->drawText(outString.c_str(), outString.size(), 100.f, 100.f, pain
t); |
| 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); | |
| 154 | 151 |
| 155 this->inval(nullptr); | 152 this->inval(nullptr); |
| 156 } | 153 } |
| 157 | 154 |
| 158 #if 0 | 155 #if 0 |
| 159 // TODO: switch over to use this for our animation | 156 // TODO: switch over to use this for our animation |
| 160 bool onAnimate(const SkAnimTimer& timer) override { | 157 bool onAnimate(const SkAnimTimer& timer) override { |
| 161 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); | 158 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); |
| 162 fAnimatingDrawable->setSweep(angle); | 159 fAnimatingDrawable->setSweep(angle); |
| 163 return true; | 160 return true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 176 int fCurrentTime; | 173 int fCurrentTime; |
| 177 | 174 |
| 178 | 175 |
| 179 typedef SampleView INHERITED; | 176 typedef SampleView INHERITED; |
| 180 }; | 177 }; |
| 181 | 178 |
| 182 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
| 183 | 180 |
| 184 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); ) | 181 DEF_SAMPLE( return new DrawShipView("DrawShip", draw_atlas); ) |
| 185 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); ) | 182 DEF_SAMPLE( return new DrawShipView("DrawShipSim", draw_atlas_sim); ) |
| OLD | NEW |