blob: f7829eaada5bdd17745ab87238a68d470daf1954 [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@google.comceff2872011-07-27 18:21:37 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkCornerPathEffect.h"
12#include "SkCullPoints.h"
13#include "SkGradientShader.h"
14#include "SkPath.h"
15#include "SkRegion.h"
16#include "SkShader.h"
17#include "SkUtils.h"
18
19static void create_bitmap(SkBitmap* bitmap) {
20 const int W = 100;
21 const int H = 100;
commit-bot@chromium.orga8c18312014-02-17 02:55:57 +000022 bitmap->allocN32Pixels(W, H);
reed@google.comceff2872011-07-27 18:21:37 +000023
24 SkCanvas canvas(*bitmap);
25 canvas.drawColor(SK_ColorRED);
26 SkPaint paint;
27 paint.setColor(SK_ColorBLUE);
28 canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
29}
30
31class WritePixelsView : public SampleView {
32 SkPath fPath;
33public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000034 WritePixelsView() {}
35
reed@google.comceff2872011-07-27 18:21:37 +000036protected:
37 // overrides from SkEventSink
38 virtual bool onQuery(SkEvent* evt) {
39 if (SampleCode::TitleQ(*evt)) {
40 SampleCode::TitleR(evt, "WritePixels");
41 return true;
42 }
43 return this->INHERITED::onQuery(evt);
44 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000045
reed@google.comceff2872011-07-27 18:21:37 +000046 virtual void onDrawContent(SkCanvas* canvas) {
47 SkBitmap bitmap;
48 create_bitmap(&bitmap);
49 int x = bitmap.width() / 2;
50 int y = bitmap.height() / 2;
rmistry@google.comae933ce2012-08-23 18:19:56 +000051
reed@google.comceff2872011-07-27 18:21:37 +000052 SkBitmap subset;
53 bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
54
55 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
56
57 canvas->writePixels(bitmap, 0, 0);
58 canvas->writePixels(subset, 0, 0);
59 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000060
reed@google.comceff2872011-07-27 18:21:37 +000061private:
62 typedef SampleView INHERITED;
63};
64
65//////////////////////////////////////////////////////////////////////////////
66
67static SkView* MyFactory() { return new WritePixelsView; }
68static SkViewRegister reg(MyFactory);