blob: 5919084d9cd4412564975eb14bcd979ce5b70131 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkCanvas.h"
4#include "SkGradientShader.h"
5#include "SkGraphics.h"
6#include "SkImageDecoder.h"
7#include "SkPath.h"
8#include "SkPorterDuff.h"
9#include "SkRegion.h"
10#include "SkShader.h"
11#include "SkUtils.h"
12#include "SkXfermode.h"
13#include "SkShaderExtras.h"
14#include "SkColorPriv.h"
15#include "SkColorFilter.h"
16#include "SkTime.h"
17#include "SkTypeface.h"
18
19#include "SkImageRef.h"
20#include "SkOSFile.h"
21#include "SkStream.h"
22
23#define SPECIFIC_IMAGE "/skimages/main.gif"
24
25class BitmapRectView : public SkView {
26public:
27 SkBitmap fBitmap;
28 int fCurrX, fCurrY;
29
30 BitmapRectView() {
31 SkImageDecoder::DecodeFile(SPECIFIC_IMAGE, &fBitmap);
32 fCurrX = fCurrY = 0;
33 }
34
35protected:
36 // overrides from SkEventSink
37 virtual bool onQuery(SkEvent* evt)
38 {
39 if (SampleCode::TitleQ(*evt))
40 {
41 SkString str("BitmapRect: ");
42 str.append(SPECIFIC_IMAGE);
43 SampleCode::TitleR(evt, str.c_str());
44 return true;
45 }
46 return this->INHERITED::onQuery(evt);
47 }
48
49 void drawBG(SkCanvas* canvas)
50 {
51 canvas->drawColor(SK_ColorGRAY);
52 }
53
54 virtual void onDraw(SkCanvas* canvas)
55 {
56 this->drawBG(canvas);
57
58 canvas->drawBitmap(fBitmap, 0, 0, NULL);
59
60 SkIRect subset;
61 const int SRC_WIDTH = 16;
62 const int SRC_HEIGHT = 16;
63
64 subset.set(0, 0, SRC_WIDTH, SRC_HEIGHT);
65 subset.offset(fCurrX, fCurrY);
66
67 SkDebugf("---- src x=%d y=%d\n", subset.fLeft, subset.fTop);
68
69 SkRect dst0, dst1;
70 SkScalar y = SkIntToScalar(fBitmap.height() + 16);
71
72 dst0.set(SkIntToScalar(50), y,
73 SkIntToScalar(50+SRC_WIDTH),
74 y + SkIntToScalar(SRC_HEIGHT));
75 dst1 = dst0;
76 dst1.offset(SkIntToScalar(200), 0);
77 dst1.fRight = dst1.fLeft + 8 * dst0.width();
78 dst1.fBottom = dst1.fTop + 8 * dst0.height();
79
80 canvas->drawBitmapRect(fBitmap, &subset, dst0, NULL);
81 canvas->drawBitmapRect(fBitmap, &subset, dst1, NULL);
82
83 SkPaint paint;
84 paint.setColor(0x88FF0000);
85 canvas->drawRect(dst0, paint);
86 paint.setColor(0x880000FF);
87 canvas->drawRect(dst1, paint);
88 }
89
90 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y)
91 {
92 return new Click(this);
93 }
94
95 virtual bool onClick(Click* click)
96 {
97 fCurrX = click->fICurr.fX;
98 fCurrY = click->fICurr.fY;
99 this->inval(NULL);
100 return true;
101 }
102
103private:
104 typedef SkView INHERITED;
105};
106
107//////////////////////////////////////////////////////////////////////////////
108
109static SkView* MyFactory() { return new BitmapRectView; }
110static SkViewRegister reg(MyFactory);
111