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