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