blob: 04f34840e1821be5a510a230993789bbfb95d438 [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;
22 bitmap->setConfig(SkBitmap::kARGB_8888_Config, W, H);
23 bitmap->allocPixels();
24
25 SkCanvas canvas(*bitmap);
26 canvas.drawColor(SK_ColorRED);
27 SkPaint paint;
28 paint.setColor(SK_ColorBLUE);
29 canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint);
30}
31
32class WritePixelsView : public SampleView {
33 SkPath fPath;
34public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000035 WritePixelsView() {}
36
reed@google.comceff2872011-07-27 18:21:37 +000037protected:
38 // overrides from SkEventSink
39 virtual bool onQuery(SkEvent* evt) {
40 if (SampleCode::TitleQ(*evt)) {
41 SampleCode::TitleR(evt, "WritePixels");
42 return true;
43 }
44 return this->INHERITED::onQuery(evt);
45 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000046
reed@google.comceff2872011-07-27 18:21:37 +000047 virtual void onDrawContent(SkCanvas* canvas) {
48 SkBitmap bitmap;
49 create_bitmap(&bitmap);
50 int x = bitmap.width() / 2;
51 int y = bitmap.height() / 2;
rmistry@google.comae933ce2012-08-23 18:19:56 +000052
reed@google.comceff2872011-07-27 18:21:37 +000053 SkBitmap subset;
54 bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y));
55
56 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
57
58 canvas->writePixels(bitmap, 0, 0);
59 canvas->writePixels(subset, 0, 0);
60 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000061
reed@google.comceff2872011-07-27 18:21:37 +000062private:
63 typedef SampleView INHERITED;
64};
65
66//////////////////////////////////////////////////////////////////////////////
67
68static SkView* MyFactory() { return new WritePixelsView; }
69static SkViewRegister reg(MyFactory);