0b9e2dbf2f
bugs when drawing stretched bitmaps (like ninepatch) at nasty scale factors like 1.5 (where the inverse matrix steps 0.333333, 1.0, 1.666667, etc.) git-svn-id: http://skia.googlecode.com/svn/trunk@354 2bbb7eff-a529-9590-31e7-b0007b416f81
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#include "SampleCode.h"
|
|
#include "SkView.h"
|
|
#include "SkCanvas.h"
|
|
#include "SkImageDecoder.h"
|
|
#include "SkNinePatch.h"
|
|
#include "SkPaint.h"
|
|
#include "SkUnPreMultiply.h"
|
|
|
|
class NinePatchView : public SkView {
|
|
public:
|
|
SkBitmap fBM;
|
|
|
|
NinePatchView() {
|
|
SkImageDecoder::DecodeFile("/skimages/folder_background.9.png", &fBM);
|
|
|
|
// trim off the edge guide-lines
|
|
SkBitmap tmp;
|
|
SkIRect r;
|
|
r.set(1, 1, fBM.width() - 1, fBM.height() - 1);
|
|
fBM.extractSubset(&tmp, r);
|
|
fBM.swap(tmp);
|
|
}
|
|
|
|
protected:
|
|
// overrides from SkEventSink
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
SampleCode::TitleR(evt, "NinePatch");
|
|
return true;
|
|
}
|
|
return this->INHERITED::onQuery(evt);
|
|
}
|
|
|
|
void drawBG(SkCanvas* canvas) {
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
|
|
canvas->scale(1.5f, 1.5f);
|
|
|
|
canvas->drawBitmap(fBM, 0, 0);
|
|
|
|
SkIRect margins;
|
|
SkRect dst;
|
|
int d = 25;
|
|
|
|
margins.set(d, d, d, d);
|
|
dst.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
|
|
dst.offset(SkIntToScalar(fBM.width()), 0);
|
|
dst.offset(SkIntToScalar(2), SkIntToScalar(2));
|
|
|
|
SkNinePatch::DrawNine(canvas, dst, fBM, margins);
|
|
}
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
this->drawBG(canvas);
|
|
}
|
|
|
|
private:
|
|
typedef SkView INHERITED;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
static SkView* MyFactory() { return new NinePatchView; }
|
|
static SkViewRegister reg(MyFactory);
|
|
|