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