reed@android.com | f549369 | 2009-07-22 19:21:01 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
| 4 | #include "SkDevice.h" |
| 5 | #include "SkPaint.h" |
| 6 | #include "SkShader.h" |
| 7 | |
| 8 | class LCDView : public SkView { |
| 9 | public: |
| 10 | LCDView() {} |
| 11 | |
| 12 | protected: |
| 13 | // overrides from SkEventSink |
| 14 | virtual bool onQuery(SkEvent* evt) { |
| 15 | if (SampleCode::TitleQ(*evt)) { |
| 16 | SampleCode::TitleR(evt, "LCD Text"); |
| 17 | return true; |
| 18 | } |
| 19 | return this->INHERITED::onQuery(evt); |
| 20 | } |
| 21 | |
| 22 | void drawBG(SkCanvas* canvas) { |
| 23 | canvas->drawColor(SK_ColorWHITE); |
| 24 | } |
| 25 | |
| 26 | virtual void onDraw(SkCanvas* canvas) { |
| 27 | this->drawBG(canvas); |
| 28 | |
| 29 | SkPaint paint; |
| 30 | paint.setAntiAlias(true); |
| 31 | |
| 32 | SkScalar textSize = SkIntToScalar(6); |
| 33 | SkScalar delta = SK_Scalar1; |
| 34 | const char* text = "HHHamburgefonts iii"; |
| 35 | size_t len = strlen(text); |
| 36 | SkScalar x0 = SkIntToScalar(10); |
| 37 | SkScalar x1 = SkIntToScalar(310); |
| 38 | SkScalar y = SkIntToScalar(20); |
| 39 | |
| 40 | for (int i = 0; i < 20; i++) { |
| 41 | paint.setTextSize(textSize); |
| 42 | textSize += delta; |
| 43 | |
| 44 | paint.setLCDRenderText(false); |
| 45 | canvas->drawText(text, len, x0, y, paint); |
| 46 | paint.setLCDRenderText(true); |
| 47 | canvas->drawText(text, len, x1, y, paint); |
| 48 | |
| 49 | y += paint.getFontSpacing(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | typedef SkView INHERITED; |
| 55 | }; |
| 56 | |
| 57 | ////////////////////////////////////////////////////////////////////////////// |
| 58 | |
| 59 | static SkView* MyFactory() { return new LCDView; } |
| 60 | static SkViewRegister reg(MyFactory); |
| 61 | |