blob: 22aaba6262c5c289d4cd9e0040cc4a4d242603fc [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 Wagnerb2c4ea62018-08-08 11:36:17 -04007#include "Sample.h"
reed@android.comf5493692009-07-22 19:21:01 +00008#include "SkCanvas.h"
reed@android.comf5493692009-07-22 19:21:01 +00009#include "SkPaint.h"
10#include "SkShader.h"
11
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040012class LCDView : public Sample {
reed@android.comf5493692009-07-22 19:21:01 +000013public:
14 LCDView() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000015
reed@android.comf5493692009-07-22 19:21:01 +000016protected:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040017 bool onQuery(Sample::Event* evt) override {
18 if (Sample::TitleQ(*evt)) {
19 Sample::TitleR(evt, "LCD Text");
reed@android.comf5493692009-07-22 19:21:01 +000020 return true;
21 }
22 return this->INHERITED::onQuery(evt);
23 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000024
reed@android.comf5493692009-07-22 19:21:01 +000025 void drawBG(SkCanvas* canvas) {
26 canvas->drawColor(SK_ColorWHITE);
27 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000028
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040029 void onDrawContent(SkCanvas* canvas) override {
reed@android.comf5493692009-07-22 19:21:01 +000030 this->drawBG(canvas);
31
32 SkPaint paint;
33 paint.setAntiAlias(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000034
reed@android.comf5493692009-07-22 19:21:01 +000035 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.comae933ce2012-08-23 18:19:56 +000046
reed@android.comf5493692009-07-22 19:21:01 +000047 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.comae933ce2012-08-23 18:19:56 +000051
reed@android.comf5493692009-07-22 19:21:01 +000052 y += paint.getFontSpacing();
53 }
54 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000055
reed@android.comf5493692009-07-22 19:21:01 +000056private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040057 typedef Sample INHERITED;
reed@android.comf5493692009-07-22 19:21:01 +000058};
59
60//////////////////////////////////////////////////////////////////////////////
61
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040062DEF_SAMPLE( return new LCDView(); )