blob: 862d935b2e60ce19dc8889eec40ac398204c6ff4 [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 */
reed@android.comf5493692009-07-22 19:21:01 +00007#include "SampleCode.h"
8#include "SkView.h"
9#include "SkCanvas.h"
10#include "SkDevice.h"
11#include "SkPaint.h"
12#include "SkShader.h"
13
14class LCDView : public SkView {
15public:
16 LCDView() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000017
reed@android.comf5493692009-07-22 19:21:01 +000018protected:
19 // overrides from SkEventSink
20 virtual bool onQuery(SkEvent* evt) {
21 if (SampleCode::TitleQ(*evt)) {
22 SampleCode::TitleR(evt, "LCD Text");
23 return true;
24 }
25 return this->INHERITED::onQuery(evt);
26 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000027
reed@android.comf5493692009-07-22 19:21:01 +000028 void drawBG(SkCanvas* canvas) {
29 canvas->drawColor(SK_ColorWHITE);
30 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000031
reed@android.comf5493692009-07-22 19:21:01 +000032 virtual void onDraw(SkCanvas* canvas) {
33 this->drawBG(canvas);
34
35 SkPaint paint;
36 paint.setAntiAlias(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000037
reed@android.comf5493692009-07-22 19:21:01 +000038 SkScalar textSize = SkIntToScalar(6);
39 SkScalar delta = SK_Scalar1;
40 const char* text = "HHHamburgefonts iii";
41 size_t len = strlen(text);
42 SkScalar x0 = SkIntToScalar(10);
43 SkScalar x1 = SkIntToScalar(310);
44 SkScalar y = SkIntToScalar(20);
45
46 for (int i = 0; i < 20; i++) {
47 paint.setTextSize(textSize);
48 textSize += delta;
rmistry@google.comae933ce2012-08-23 18:19:56 +000049
reed@android.comf5493692009-07-22 19:21:01 +000050 paint.setLCDRenderText(false);
51 canvas->drawText(text, len, x0, y, paint);
52 paint.setLCDRenderText(true);
53 canvas->drawText(text, len, x1, y, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +000054
reed@android.comf5493692009-07-22 19:21:01 +000055 y += paint.getFontSpacing();
56 }
57 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000058
reed@android.comf5493692009-07-22 19:21:01 +000059private:
60 typedef SkView INHERITED;
61};
62
63//////////////////////////////////////////////////////////////////////////////
64
65static SkView* MyFactory() { return new LCDView; }
66static SkViewRegister reg(MyFactory);