blob: 912567d06bb97e16b305d02f39cdecfca45e494c [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@google.comceff2872011-07-27 18:21:37 +00007#include "SampleCode.h"
8#include "SkView.h"
9#include "SkCanvas.h"
10#include "SkCornerPathEffect.h"
reed@google.comceff2872011-07-27 18:21:37 +000011#include "SkGradientShader.h"
12#include "SkPath.h"
13#include "SkRegion.h"
14#include "SkShader.h"
15#include "SkUtils.h"
16
17static void create_bitmap(SkBitmap* bitmap) {
18 const int W = 100;
19 const int H = 100;
commit-bot@chromium.orga8c18312014-02-17 02:55:57 +000020 bitmap->allocN32Pixels(W, H);
reed@google.comceff2872011-07-27 18:21:37 +000021
22 SkCanvas canvas(*bitmap);
23 canvas.drawColor(SK_ColorRED);
24 SkPaint paint;
25 paint.setColor(SK_ColorBLUE);
26 canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
27}
28
29class WritePixelsView : public SampleView {
30 SkPath fPath;
31public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000032 WritePixelsView() {}
33
reed@google.comceff2872011-07-27 18:21:37 +000034protected:
35 // overrides from SkEventSink
36 virtual bool onQuery(SkEvent* evt) {
37 if (SampleCode::TitleQ(*evt)) {
38 SampleCode::TitleR(evt, "WritePixels");
39 return true;
40 }
41 return this->INHERITED::onQuery(evt);
42 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000043
reed@google.comceff2872011-07-27 18:21:37 +000044 virtual void onDrawContent(SkCanvas* canvas) {
45 SkBitmap bitmap;
46 create_bitmap(&bitmap);
47 int x = bitmap.width() / 2;
48 int y = bitmap.height() / 2;
rmistry@google.comae933ce2012-08-23 18:19:56 +000049
reed@google.comceff2872011-07-27 18:21:37 +000050 SkBitmap subset;
51 bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
52
53 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
54
55 canvas->writePixels(bitmap, 0, 0);
56 canvas->writePixels(subset, 0, 0);
57 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000058
reed@google.comceff2872011-07-27 18:21:37 +000059private:
60 typedef SampleView INHERITED;
61};
62
63//////////////////////////////////////////////////////////////////////////////
64
65static SkView* MyFactory() { return new WritePixelsView; }
66static SkViewRegister reg(MyFactory);