yangsu@google.com | 4c295a3 | 2011-06-01 16:11:58 +0000 | [diff] [blame^] | 1 | #include "SampleCode.h" |
| 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
| 4 | |
| 5 | class SpiralView : public SampleView { |
| 6 | public: |
| 7 | SpiralView() { |
| 8 | this->setBGColor(0xFFDDDDDD); |
| 9 | } |
| 10 | |
| 11 | protected: |
| 12 | // overrides from SkEventSink |
| 13 | virtual bool onQuery(SkEvent* evt) { |
| 14 | if (SampleCode::TitleQ(*evt)) { |
| 15 | SampleCode::TitleR(evt, "Spiral"); |
| 16 | return true; |
| 17 | } |
| 18 | return this->INHERITED::onQuery(evt); |
| 19 | } |
| 20 | |
| 21 | virtual void onDrawContent(SkCanvas* canvas) { |
| 22 | SkPaint paint; |
| 23 | paint.setAntiAlias(true); |
| 24 | paint.setStyle(SkPaint::kStroke_Style); |
| 25 | paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3))); |
| 26 | paint.setStyle(SkPaint::kFill_Style); |
| 27 | |
| 28 | SkRect r; |
| 29 | SkScalar l,t,x,y; |
| 30 | l = SampleCode::GetAnimScalar(SkIntToScalar(10), |
| 31 | SkIntToScalar(400)); |
| 32 | t = SampleCode::GetAnimScalar(SkIntToScalar(5), |
| 33 | SkIntToScalar(200)); |
| 34 | |
| 35 | canvas->translate(320,240); |
| 36 | for (int i = 0; i < 35; i++) { |
| 37 | paint.setColor(0xFFF00FF0 - i * 0x04000000); |
| 38 | SkScalar step = SK_ScalarPI / (55 - i); |
| 39 | SkScalar angle = t * step; |
| 40 | x = (20 + SkIntToScalar(i) * 5) * SkScalarSinCos(angle, &y); |
| 41 | y *= (20 + SkIntToScalar(i) * 5); |
| 42 | r.set(x, y, x + SkIntToScalar(10), y + SkIntToScalar(10)); |
| 43 | canvas->drawRect(r, paint); |
| 44 | } |
| 45 | |
| 46 | this->inval(NULL); |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | typedef SampleView INHERITED; |
| 51 | }; |
| 52 | |
| 53 | ////////////////////////////////////////////////////////////////////////////// |
| 54 | |
| 55 | static SkView* MyFactory() { return new SpiralView; } |
| 56 | static SkViewRegister reg(MyFactory); |