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