skia2/samplecode/SampleNinePatch.cpp
reed@android.com c4cae85752 add BlitRow procs for 32->32, to allow for neon and other optimizations.
call these new procs in (nearly) all the places we had inlined loops before.
In once instance (blitter_argb32::blitAntiH) we get different results by a
  tiny bit. The new code is more accurate, and exactly inline with all of the
  other like-minded blits, so I think the change is good going forward.



git-svn-id: http://skia.googlecode.com/svn/trunk@366 2bbb7eff-a529-9590-31e7-b0007b416f81
2009-09-23 15:06:10 +00:00

75 lines
1.8 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);
fX = SkIntToScalar(fBM.width());
fY = 0;
}
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);
}
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
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(fX, fY);
SkNinePatch::DrawNine(canvas, dst, fBM, margins);
}
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
fX = x / 1.5f;
fY = y / 1.5f;
this->inval(NULL);
return this->INHERITED::onFindClickHandler(x, y);
}
private:
SkScalar fX, fY;
typedef SkView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new NinePatchView; }
static SkViewRegister reg(MyFactory);