blob: 7136448c8c792cd30ed09eaa5340704f2b754d22 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.comf5493692009-07-22 19:21:01 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkDevice.h"
12#include "SkPaint.h"
13#include "SkShader.h"
14
15class LCDView : public SkView {
16public:
17 LCDView() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000018
reed@android.comf5493692009-07-22 19:21:01 +000019protected:
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.comae933ce2012-08-23 18:19:56 +000028
reed@android.comf5493692009-07-22 19:21:01 +000029 void drawBG(SkCanvas* canvas) {
30 canvas->drawColor(SK_ColorWHITE);
31 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000032
reed@android.comf5493692009-07-22 19:21:01 +000033 virtual void onDraw(SkCanvas* canvas) {
34 this->drawBG(canvas);
35
36 SkPaint paint;
37 paint.setAntiAlias(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +000038
reed@android.comf5493692009-07-22 19:21:01 +000039 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.comae933ce2012-08-23 18:19:56 +000050
reed@android.comf5493692009-07-22 19:21:01 +000051 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.comae933ce2012-08-23 18:19:56 +000055
reed@android.comf5493692009-07-22 19:21:01 +000056 y += paint.getFontSpacing();
57 }
58 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000059
reed@android.comf5493692009-07-22 19:21:01 +000060private:
61 typedef SkView INHERITED;
62};
63
64//////////////////////////////////////////////////////////////////////////////
65
66static SkView* MyFactory() { return new LCDView; }
67static SkViewRegister reg(MyFactory);
68