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