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 SimpleView : public SampleView { |
| 6 | public: |
| 7 | SimpleView() { |
| 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, "Box Gradient"); |
| 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 x,y; |
| 30 | x = 10; |
| 31 | y = 10; |
| 32 | |
| 33 | r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100)); |
| 34 | for (int i = 0; i < 256; ++i) { |
| 35 | canvas->translate(1, 1); |
| 36 | paint.setColor(0xFF000000 + i * 0x00010000); |
| 37 | canvas->drawRect(r, paint); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | typedef SampleView INHERITED; |
| 43 | }; |
| 44 | |
| 45 | ////////////////////////////////////////////////////////////////////////////// |
| 46 | |
| 47 | static SkView* MyFactory() { return new SimpleView; } |
| 48 | static SkViewRegister reg(MyFactory); |