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