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