blob: 8aec99265ac08727425a0acf2ba903f4934f660f [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 */
yangsu@google.com4c295a32011-06-01 16:11:58 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11
12class SimpleView : public SampleView {
13public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000014 SimpleView() {
yangsu@google.com4c295a32011-06-01 16:11:58 +000015 this->setBGColor(0xFFDDDDDD);
rmistry@google.comae933ce2012-08-23 18:19:56 +000016 }
17
yangsu@google.com4c295a32011-06-01 16:11:58 +000018protected:
19 // overrides from SkEventSink
20 virtual bool onQuery(SkEvent* evt) {
21 if (SampleCode::TitleQ(*evt)) {
22 SampleCode::TitleR(evt, "Box Gradient");
23 return true;
24 }
25 return this->INHERITED::onQuery(evt);
26 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000027
yangsu@google.com4c295a32011-06-01 16:11:58 +000028 virtual void onDrawContent(SkCanvas* canvas) {
29 SkPaint paint;
30 paint.setAntiAlias(true);
31 paint.setStyle(SkPaint::kStroke_Style);
32 paint.setStrokeWidth(SkScalarHalf(SkIntToScalar(3)));
33 paint.setStyle(SkPaint::kFill_Style);
rmistry@google.comae933ce2012-08-23 18:19:56 +000034
yangsu@google.com4c295a32011-06-01 16:11:58 +000035 SkRect r;
36 SkScalar x,y;
37 x = 10;
38 y = 10;
39
40 r.set(x, y, x + SkIntToScalar(100), y + SkIntToScalar(100));
41 for (int i = 0; i < 256; ++i) {
42 canvas->translate(1, 1);
43 paint.setColor(0xFF000000 + i * 0x00010000);
44 canvas->drawRect(r, paint);
45 }
46 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000047
yangsu@google.com4c295a32011-06-01 16:11:58 +000048private:
49 typedef SampleView INHERITED;
50};
51
52//////////////////////////////////////////////////////////////////////////////
53
54static SkView* MyFactory() { return new SimpleView; }
rmistry@google.combda03db2012-08-14 20:27:54 +000055static SkViewRegister reg(MyFactory);