From 5fd9243fd6b82aa3f2a2fae7c62310e77ab7b6d3 Mon Sep 17 00:00:00 2001 From: "mike@reedtribe.org" Date: Thu, 5 May 2011 01:59:48 +0000 Subject: switch to inheriting from SampleView git-svn-id: http://skia.googlecode.com/svn/trunk@1249 2bbb7eff-a529-9590-31e7-b0007b416f81 --- samplecode/SampleAll.cpp | 131 ++++++++++++++-------------------------- samplecode/SampleAvoid.cpp | 8 +-- samplecode/SampleCamera.cpp | 23 ++----- samplecode/SampleCircle.cpp | 35 +---------- samplecode/SampleEffects.cpp | 14 ++--- samplecode/SampleFuzz.cpp | 9 +-- samplecode/SampleHairline.cpp | 14 +---- samplecode/SampleLayerMask.cpp | 16 ++--- samplecode/SampleMipMap.cpp | 12 +--- samplecode/SamplePatch.cpp | 14 ++--- samplecode/SamplePicture.cpp | 14 +---- samplecode/SampleRegion.cpp | 109 ++++++--------------------------- samplecode/SampleShaders.cpp | 27 +++------ samplecode/SampleStrokeText.cpp | 17 ++---- samplecode/SampleTextAlpha.cpp | 12 +--- samplecode/SampleUnitMapper.cpp | 12 +--- 16 files changed, 122 insertions(+), 345 deletions(-) (limited to 'samplecode') diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp index f57bf385e6..75d1a317ca 100644 --- a/samplecode/SampleAll.cpp +++ b/samplecode/SampleAll.cpp @@ -31,8 +31,7 @@ #include -static inline SkPMColor rgb2gray(SkPMColor c) -{ +static inline SkPMColor rgb2gray(SkPMColor c) { unsigned r = SkGetPackedR32(c); unsigned g = SkGetPackedG32(c); unsigned b = SkGetPackedB32(c); @@ -44,8 +43,7 @@ static inline SkPMColor rgb2gray(SkPMColor c) class SkGrayScaleColorFilter : public SkColorFilter { public: - virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) - { + virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) { for (int i = 0; i < count; i++) result[i] = rgb2gray(src[i]); } @@ -53,16 +51,15 @@ public: class SkChannelMaskColorFilter : public SkColorFilter { public: - SkChannelMaskColorFilter(U8CPU redMask, U8CPU greenMask, U8CPU blueMask) - { + SkChannelMaskColorFilter(U8CPU redMask, U8CPU greenMask, U8CPU blueMask) { fMask = SkPackARGB32(0xFF, redMask, greenMask, blueMask); } - virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) - { + virtual void filterSpan(const SkPMColor src[], int count, SkPMColor result[]) { SkPMColor mask = fMask; - for (int i = 0; i < count; i++) + for (int i = 0; i < count; i++) { result[i] = src[i] & mask; + } } private: @@ -71,8 +68,7 @@ private: /////////////////////////////////////////////////////////// -static void r0(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r0(SkLayerRasterizer* rast, SkPaint& p) { p.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3), SkBlurMaskFilter::kNormal_BlurStyle))->unref(); rast->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); @@ -88,8 +84,7 @@ static void r0(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r1(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r1(SkLayerRasterizer* rast, SkPaint& p) { rast->addLayer(p); p.setAlpha(0x40); @@ -99,8 +94,7 @@ static void r1(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r2(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r2(SkLayerRasterizer* rast, SkPaint& p) { p.setStyle(SkPaint::kStrokeAndFill_Style); p.setStrokeWidth(SK_Scalar1*4); rast->addLayer(p); @@ -111,8 +105,7 @@ static void r2(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r3(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r3(SkLayerRasterizer* rast, SkPaint& p) { p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1*3); rast->addLayer(p); @@ -123,8 +116,7 @@ static void r3(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r4(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r4(SkLayerRasterizer* rast, SkPaint& p) { p.setAlpha(0x60); rast->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); @@ -136,8 +128,7 @@ static void r4(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r5(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r5(SkLayerRasterizer* rast, SkPaint& p) { rast->addLayer(p); p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref(); @@ -145,8 +136,7 @@ static void r5(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r6(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r6(SkLayerRasterizer* rast, SkPaint& p) { rast->addLayer(p); p.setAntiAlias(false); @@ -162,8 +152,7 @@ public: Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix) : Sk2DPathEffect(matrix), fRadius(radius) {} - virtual void flatten(SkFlattenableWriteBuffer& buffer) - { + virtual void flatten(SkFlattenableWriteBuffer& buffer) { this->INHERITED::flatten(buffer); buffer.writeScalar(fRadius); @@ -171,28 +160,24 @@ public: virtual Factory getFactory() { return CreateProc; } protected: - virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) - { + virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) { dst->addCircle(loc.fX, loc.fY, fRadius); } - Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) - { + Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) { fRadius = buffer.readScalar(); } private: SkScalar fRadius; - static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) - { + static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { return new Dot2DPathEffect(buffer); } typedef Sk2DPathEffect INHERITED; }; -static void r7(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r7(SkLayerRasterizer* rast, SkPaint& p) { SkMatrix lattice; lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); lattice.postSkew(SK_Scalar1/3, 0, 0, 0); @@ -200,8 +185,7 @@ static void r7(SkLayerRasterizer* rast, SkPaint& p) rast->addLayer(p); } -static void r8(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r8(SkLayerRasterizer* rast, SkPaint& p) { rast->addLayer(p); SkMatrix lattice; @@ -223,10 +207,8 @@ public: Line2DPathEffect(SkScalar width, const SkMatrix& matrix) : Sk2DPathEffect(matrix), fWidth(width) {} - virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) - { - if (this->INHERITED::filterPath(dst, src, width)) - { + virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) { + if (this->INHERITED::filterPath(dst, src, width)) { *width = fWidth; return true; } @@ -234,16 +216,13 @@ public: } virtual Factory getFactory() { return CreateProc; } - virtual void flatten(SkFlattenableWriteBuffer& buffer) - { + virtual void flatten(SkFlattenableWriteBuffer& buffer) { this->INHERITED::flatten(buffer); buffer.writeScalar(fWidth); } protected: - virtual void nextSpan(int u, int v, int ucount, SkPath* dst) - { - if (ucount > 1) - { + virtual void nextSpan(int u, int v, int ucount, SkPath* dst) { + if (ucount > 1) { SkPoint src[2], dstP[2]; src[0].set(SkIntToScalar(u) + SK_ScalarHalf, @@ -257,8 +236,7 @@ protected: } } - Line2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) - { + Line2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) { fWidth = buffer.readScalar(); } @@ -270,8 +248,7 @@ private: typedef Sk2DPathEffect INHERITED; }; -static void r9(SkLayerRasterizer* rast, SkPaint& p) -{ +static void r9(SkLayerRasterizer* rast, SkPaint& p) { rast->addLayer(p); SkMatrix lattice; @@ -304,8 +281,7 @@ static const struct { { 0xFFFFFF, 0x000000 } // identity case }; -static unsigned color_dist16(uint16_t a, uint16_t b) -{ +static unsigned color_dist16(uint16_t a, uint16_t b) { unsigned dr = SkAbs32(SkPacked16ToR32(a) - SkPacked16ToR32(b)); unsigned dg = SkAbs32(SkPacked16ToG32(a) - SkPacked16ToG32(b)); unsigned db = SkAbs32(SkPacked16ToB32(a) - SkPacked16ToB32(b)); @@ -313,8 +289,7 @@ static unsigned color_dist16(uint16_t a, uint16_t b) return SkMax32(dr, SkMax32(dg, db)); } -static unsigned scale_dist(unsigned dist, unsigned scale) -{ +static unsigned scale_dist(unsigned dist, unsigned scale) { dist >>= 6; dist = (dist << 2) | dist; dist = (dist << 4) | dist; @@ -323,11 +298,9 @@ static unsigned scale_dist(unsigned dist, unsigned scale) // return SkAlphaMul(dist, scale); } -static void apply_shader(SkPaint* paint, int index) -{ +static void apply_shader(SkPaint* paint, int index) { raster_proc proc = gRastProcs[index]; - if (proc) - { + if (proc) { SkPaint p; SkLayerRasterizer* rast = new SkLayerRasterizer; @@ -343,29 +316,25 @@ static void apply_shader(SkPaint* paint, int index) #endif } -class DemoView : public SkView { +class DemoView : public SampleView { public: DemoView() {} protected: // overrides from SkEventSink - virtual bool onQuery(SkEvent* evt) - { - if (SampleCode::TitleQ(*evt)) - { + virtual bool onQuery(SkEvent* evt) { + if (SampleCode::TitleQ(*evt)) { SampleCode::TitleR(evt, "Demo"); return true; } return this->INHERITED::onQuery(evt); } - virtual bool onClick(Click* click) - { + virtual bool onClick(Click* click) { return this->INHERITED::onClick(click); } - void makePath(SkPath& path) - { + void makePath(SkPath& path) { path.addCircle(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(20), SkPath::kCCW_Direction); for (int index = 0; index < 10; index++) { @@ -383,9 +352,7 @@ protected: path.close(); } - virtual void onDraw(SkCanvas* canvas) - { - canvas->drawColor(SK_ColorWHITE); + virtual void onDrawContent(SkCanvas* canvas) { canvas->save(); drawPicture(canvas, 0); canvas->restore(); @@ -413,8 +380,7 @@ protected: } } - void drawPicture(SkCanvas* canvas, int spriteOffset) - { + void drawPicture(SkCanvas* canvas, int spriteOffset) { SkMatrix matrix; matrix.reset(); SkPaint paint; SkPath path; @@ -619,15 +585,13 @@ protected: SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { */ - virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) - { + virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { fClickPt.set(x, y); this->inval(NULL); return this->INHERITED::onFindClickHandler(x, y); } - SkPathEffect* pathEffectTest() - { + SkPathEffect* pathEffectTest() { static const int gXY[] = { 1, 0, 0, -1, 2, -1, 3, 0, 2, 1, 0, 1 }; SkScalar gPhase = 0; SkPath path; @@ -646,8 +610,7 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { return result; } - SkPathEffect* pathEffectTest2() // unsure this works (has no visible effect) - { + SkPathEffect* pathEffectTest2() { // unsure this works (has no visible effect) SkPathEffect* outer = new SkStrokePathEffect(SkIntToScalar(4), SkPaint::kStroke_Style, SkPaint::kMiter_Join, SkPaint::kButt_Cap); static const SkScalar intervals[] = {SkIntToScalar(1), SkIntToScalar(2), @@ -660,8 +623,7 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { return result; } - SkShader* shaderTest() - { + SkShader* shaderTest() { SkPoint pts[] = {0, 0, SkIntToScalar(100), 0 }; SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, @@ -684,14 +646,12 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { SkImageDecoder::DecodeFile("/Users/caryclark/Desktop/05psp04.gif", &fTx); } - void drawRaster(SkCanvas* canvas) - { + void drawRaster(SkCanvas* canvas) { for (int index = 0; index < SK_ARRAY_COUNT(gRastProcs); index++) drawOneRaster(canvas); } - void drawOneRaster(SkCanvas* canvas) - { + void drawOneRaster(SkCanvas* canvas) { canvas->save(); SkScalar x = SkIntToScalar(20); @@ -705,8 +665,7 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { SkString str("GOOGLE"); - for (int i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) - { + for (int i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) { apply_shader(&paint, i); // paint.setMaskFilter(NULL); @@ -746,7 +705,7 @@ SkCornerPathEffect.h:28:class SkCornerPathEffect : public SkPathEffect { private: SkPoint fClickPt; SkBitmap fBug, fTb, fTx; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleAvoid.cpp b/samplecode/SampleAvoid.cpp index faeee20696..95363505cb 100644 --- a/samplecode/SampleAvoid.cpp +++ b/samplecode/SampleAvoid.cpp @@ -6,7 +6,7 @@ /////////////////////////////////////////////////////////////////////////////// -class AvoidView : public SkView { +class AvoidView : public SampleView { SkShader* fShader; enum { @@ -44,9 +44,7 @@ protected: return this->INHERITED::onQuery(evt); } - virtual void onDraw(SkCanvas* canvas) { - canvas->drawColor(SK_ColorWHITE); - + virtual void onDrawContent(SkCanvas* canvas) { SkPaint paint; SkRect r = { 0, 0, SkIntToScalar(W), SkIntToScalar(H) }; @@ -88,7 +86,7 @@ protected: } private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleCamera.cpp b/samplecode/SampleCamera.cpp index 66cb4e7f74..2db396889d 100644 --- a/samplecode/SampleCamera.cpp +++ b/samplecode/SampleCamera.cpp @@ -11,7 +11,7 @@ #include "SkRandom.h" #include "SkImageDecoder.h" -class CameraView : public SkView { +class CameraView : public SampleView { SkTDArray fShaders; int fShaderIndex; bool fFrontFace; @@ -40,6 +40,7 @@ public: break; } } + this->setBGColor(0xFFDDDDDD); } virtual ~CameraView() { @@ -57,13 +58,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(0xFFDDDDDD); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { canvas->translate(this->width()/2, this->height()/2); Sk3DView view; @@ -72,8 +67,6 @@ protected: view.applyToCanvas(canvas); SkPaint paint; - SkScalar rad = SkIntToScalar(50); - SkScalar dim = rad*2; if (fShaders.count() > 0) { bool frontFace = view.dotWithNormal(0, 0, SK_Scalar1) < 0; if (frontFace != fFrontFace) { @@ -83,16 +76,8 @@ protected: paint.setAntiAlias(true); paint.setShader(fShaders[fShaderIndex]); -#if 0 - canvas->drawCircle(0, 0, rad, paint); - canvas->drawCircle(-dim, -dim, rad, paint); - canvas->drawCircle(-dim, dim, rad, paint); - canvas->drawCircle( dim, -dim, rad, paint); - canvas->drawCircle( dim, dim, rad, paint); -#else SkRect r = { -150, -150, 150, 150 }; canvas->drawRoundRect(r, 30, 30, paint); -#endif } fRY += SampleCode::GetAnimSecondsDelta() * 90; @@ -104,7 +89,7 @@ protected: private: SkScalar fRX, fRY, fRZ; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleCircle.cpp b/samplecode/SampleCircle.cpp index 1f9957d3e6..2abc28de3e 100644 --- a/samplecode/SampleCircle.cpp +++ b/samplecode/SampleCircle.cpp @@ -17,7 +17,7 @@ static void test_circlebounds(SkCanvas* canvas) { #endif } -class CircleView : public SkView { +class CircleView : public SampleView { public: static const SkScalar ANIM_DX; static const SkScalar ANIM_DY; @@ -39,10 +39,6 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(SK_ColorWHITE); - } - void circle(SkCanvas* canvas, int width, bool aa) { SkPaint paint; @@ -95,9 +91,7 @@ protected: canvas->translate(px, py); } - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); @@ -114,34 +108,11 @@ protected: canvas->translate(-SK_Scalar1, 0); canvas->drawPath(path, paint); } - - if (false) { - test_circlebounds(canvas); - - SkScalar dx = SkIntToScalar(32); - SkScalar dy = SkIntToScalar(32); - - canvas->translate(dx + fDX, dy + fDY); - drawSix(canvas, dx, dy); - - canvas->translate(dx, 0); - canvas->translate(SK_ScalarHalf, SK_ScalarHalf); - drawSix(canvas, dx, dy); - - fDX += ANIM_DX; - fDY += ANIM_DY; - fRAD += ANIM_RAD; - fN += 1; - if (fN > 40) { - fN = 3; - } - this->inval(NULL); - } } private: int fN; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; const SkScalar CircleView::ANIM_DX(SK_Scalar1 / 67); diff --git a/samplecode/SampleEffects.cpp b/samplecode/SampleEffects.cpp index 97853c3c6b..158a89f5d9 100644 --- a/samplecode/SampleEffects.cpp +++ b/samplecode/SampleEffects.cpp @@ -65,7 +65,7 @@ const PaintProc gPaintProcs[] = { /////////////////////////////////////////////////////////////////////////////// -class EffectsView : public SkView { +class EffectsView : public SampleView { public: SkPath fPath; SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; @@ -96,6 +96,8 @@ public: SkColorMatrix cm; cm.setRotate(SkColorMatrix::kG_Axis, 180); cm.setIdentity(); + + this->setBGColor(0xFFDDDDDD); } protected: @@ -108,13 +110,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(0xFFDDDDDD); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { canvas->scale(3, 3); canvas->translate(10, 30); for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { @@ -124,7 +120,7 @@ protected: } private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleFuzz.cpp b/samplecode/SampleFuzz.cpp index 9be3c81204..5c41886b8b 100644 --- a/samplecode/SampleFuzz.cpp +++ b/samplecode/SampleFuzz.cpp @@ -326,9 +326,11 @@ static void do_fuzz(SkCanvas* canvas) { ////////////////////////////////////////////////////////////////////////////// -class FuzzView : public SkView { +class FuzzView : public SampleView { public: - FuzzView() {} + FuzzView() { + this->setBGColor(0xFFDDDDDD); + } protected: // overrides from SkEventSink @@ -344,9 +346,8 @@ protected: canvas->drawColor(0xFFDDDDDD); } - virtual void onDraw(SkCanvas* canvas) { + virtual void onDrawContent(SkCanvas* canvas) { SkIRect r = canvas->getTotalClip().getBounds(); - this->drawBG(canvas); do_fuzz(canvas); this->inval(NULL); } diff --git a/samplecode/SampleHairline.cpp b/samplecode/SampleHairline.cpp index 6c2fc437df..ab5ac8ce97 100644 --- a/samplecode/SampleHairline.cpp +++ b/samplecode/SampleHairline.cpp @@ -180,7 +180,7 @@ static int cycle_hairproc_index(int index) { return (index + 1) % SK_ARRAY_COUNT(gProcs); } -class HairlineView : public SkView { +class HairlineView : public SampleView { SkMSec fNow; int fProcIndex; bool fDoAA; @@ -209,17 +209,9 @@ protected: canvas->drawBitmap(b1, SkIntToScalar(b0.width()), 0, NULL); } - void drawBG(SkCanvas* canvas) { -// canvas->drawColor(0xFFDDDDDD); - canvas->drawColor(SK_ColorWHITE); - // canvas->drawColor(SK_ColorBLACK); - } - int fCounter; - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { gRand.setSeed(fNow); if (false) { @@ -269,7 +261,7 @@ protected: private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleLayerMask.cpp b/samplecode/SampleLayerMask.cpp index 51a021b71a..9bd00ae5af 100644 --- a/samplecode/SampleLayerMask.cpp +++ b/samplecode/SampleLayerMask.cpp @@ -5,9 +5,11 @@ /////////////////////////////////////////////////////////////////////////////// -class LayerMaskView : public SkView { +class LayerMaskView : public SampleView { public: - LayerMaskView() {} + LayerMaskView() { + this->setBGColor(0xFFDDDDDD); + } protected: // overrides from SkEventSink @@ -46,13 +48,7 @@ protected: } } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(0xFFDDDDDD); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { SkRect r; r.set(SkIntToScalar(20), SkIntToScalar(20), SkIntToScalar(120), SkIntToScalar(120)); canvas->saveLayer(&r, NULL, SkCanvas::kARGB_ClipLayer_SaveFlag); @@ -62,7 +58,7 @@ protected: } private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleMipMap.cpp b/samplecode/SampleMipMap.cpp index fd3f5cf437..3d9515691e 100644 --- a/samplecode/SampleMipMap.cpp +++ b/samplecode/SampleMipMap.cpp @@ -28,7 +28,7 @@ static SkBitmap createBitmap(int n) { return bitmap; } -class MipMapView : public SkView { +class MipMapView : public SampleView { SkBitmap fBitmap; enum { N = 64 @@ -79,13 +79,7 @@ protected: } } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(SK_ColorWHITE); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); canvas->scale(1.00000001f, 0.9999999f); @@ -139,7 +133,7 @@ protected: private: int fWidth; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SamplePatch.cpp b/samplecode/SamplePatch.cpp index 4203391c18..0bfaa5aa22 100644 --- a/samplecode/SamplePatch.cpp +++ b/samplecode/SamplePatch.cpp @@ -221,7 +221,7 @@ static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv, patch->draw(canvas, paint, 10, 10, true, true); } -class PatchView : public SkView { +class PatchView : public SampleView { SkShader* fShader0; SkShader* fShader1; SkIPoint fSize0, fSize1; @@ -250,6 +250,8 @@ public: fPts[9].set(S*0, T*4); fPts[10].set(S*0, T*3); fPts[11].set(S*0, T*2); + + this->setBGColor(SK_ColorGRAY); } virtual ~PatchView() { @@ -269,13 +271,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(SK_ColorGRAY); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { SkPaint paint; paint.setDither(true); paint.setFilterBitmap(true); @@ -335,7 +331,7 @@ protected: } private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp index 00a9d2e5cb..d7b6b229f4 100644 --- a/samplecode/SamplePicture.cpp +++ b/samplecode/SamplePicture.cpp @@ -109,7 +109,7 @@ static void drawCircle(SkCanvas* canvas, int r, SkColor color) { paint); } -class PictureView : public SkView { +class PictureView : public SampleView { SkBitmap fBitmap; public: PictureView() { @@ -155,12 +155,6 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { -// canvas->drawColor(0xFFDDDDDD); - canvas->drawColor(SK_ColorWHITE); - // canvas->drawColor(SK_ColorBLACK); - } - void drawSomething(SkCanvas* canvas) { SkPaint paint; @@ -186,9 +180,7 @@ protected: } - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { drawSomething(canvas); SkPicture* pict = new SkPicture; @@ -252,7 +244,7 @@ private: SkPicture* fPicture; SkPicture* fSubPicture; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleRegion.cpp b/samplecode/SampleRegion.cpp index 8777050b14..272c722993 100644 --- a/samplecode/SampleRegion.cpp +++ b/samplecode/SampleRegion.cpp @@ -86,18 +86,17 @@ static void paint_rgn(SkCanvas* canvas, const SkRegion& rgn, } } -class RegionView : public SkView { +class RegionView : public SampleView { public: - RegionView() - { + RegionView() { fBase.set(100, 100, 150, 150); fRect = fBase; fRect.inset(5, 5); fRect.offset(25, 25); + this->setBGColor(0xFFDDDDDD); } - void build_rgn(SkRegion* rgn, SkRegion::Op op) - { + void build_rgn(SkRegion* rgn, SkRegion::Op op) { rgn->setRect(fBase); SkIRect r = fBase; r.offset(75, 20); @@ -108,18 +107,15 @@ public: protected: // overrides from SkEventSink - virtual bool onQuery(SkEvent* evt) - { - if (SampleCode::TitleQ(*evt)) - { + virtual bool onQuery(SkEvent* evt) { + if (SampleCode::TitleQ(*evt)) { SampleCode::TitleR(evt, "Regions"); return true; } return this->INHERITED::onQuery(evt); } - void drawOrig(SkCanvas* canvas, bool bg) - { + void drawOrig(SkCanvas* canvas, bool bg) { SkRect r; SkPaint paint; @@ -133,8 +129,7 @@ protected: canvas->drawRect(r, paint); } - void drawRgnOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) - { + void drawRgnOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) { SkRegion rgn; this->build_rgn(&rgn, op); @@ -176,8 +171,7 @@ protected: paint_rgn(canvas, rgn, paint); } - void drawPathOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) - { + void drawPathOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) { SkRegion rgn; SkPath path; @@ -196,68 +190,7 @@ protected: canvas->drawPath(path, paint); } - void drawBG(SkCanvas* canvas) - { - canvas->drawColor(0xFFDDDDDD); - return; - -#if 0 - SkColorTable ct; - SkPMColor colors[] = { SK_ColorRED, SK_ColorBLUE }; - ct.setColors(colors, 2); - ct.setFlags(ct.getFlags() | SkColorTable::kColorsAreOpaque_Flag); - - SkBitmap bm; - bm.setConfig(SkBitmap::kIndex8_Config, 20, 20, 21); - bm.setColorTable(&ct); - bm.allocPixels(); - sk_memset16((uint16_t*)bm.getAddr8(0, 0), 0x0001, bm.rowBytes() * bm.height() / 2); -#endif -#if 0 - SkBitmap bm; - bm.setConfig(SkBitmap::kRGB_565_Config, 20, 20, 42); - bm.allocPixels(); - sk_memset32((uint32_t*)bm.getAddr16(0, 0), 0x0000FFFF, bm.rowBytes() * bm.height() / 4); -#endif -#if 1 - SkBitmap bm; - bm.setConfig(SkBitmap::kARGB_8888_Config, 20, 20); - bm.allocPixels(); - sk_memset32((uint32_t*)bm.getAddr32(0, 0), 0xFFDDDDDD, bm.rowBytes() * bm.height() / 4); -#endif - - SkPaint paint; - -// SkShader* shader = SkShader::CreateBitmapShader(bm, false, SkPaint::kBilinear_FilterType, SkShader::kRepeat_TileMode); - SkPoint pts[] = { 0, 0, SkIntToScalar(100), SkIntToScalar(0) }; - SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; - SkShader* shader = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kMirror_TileMode); - paint.setShader(shader)->unref(); - - canvas->drawPaint(paint); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - - if (false) { - SkPaint paint; - paint.setAntiAlias(true); - SkBitmap bm; - bm.setConfig(SkBitmap::kA8_Config, 100, 100); - bm.allocPixels(); - bm.eraseColor(0); - SkCanvas c(bm); - c.drawCircle(50, 50, 50, paint); - - paint.setColor(SK_ColorBLUE); - canvas->drawBitmap(bm, 0, 0, &paint); - canvas->scale(SK_Scalar1/2, SK_Scalar1/2); - paint.setColor(SK_ColorRED); - canvas->drawBitmap(bm, 0, 0, &paint); - return; - } - + virtual void onDrawContent(SkCanvas* canvas) { #ifdef SK_DEBUG if (true) { SkRegion a, b, c; @@ -302,31 +235,25 @@ protected: canvas->translate(0, SkIntToScalar(200)); - for (int op = 0; op < SK_ARRAY_COUNT(gOps); op++) - { + for (int op = 0; op < SK_ARRAY_COUNT(gOps); op++) { canvas->drawText(gOps[op].fName, strlen(gOps[op].fName), SkIntToScalar(75), SkIntToScalar(50), textPaint); this->drawRgnOped(canvas, gOps[op].fOp, gOps[op].fColor); - if (true) - { - canvas->save(); - canvas->translate(0, SkIntToScalar(200)); - this->drawPathOped(canvas, gOps[op].fOp, gOps[op].fColor); - canvas->restore(); - } + canvas->save(); + canvas->translate(0, SkIntToScalar(200)); + this->drawPathOped(canvas, gOps[op].fOp, gOps[op].fColor); + canvas->restore(); canvas->translate(SkIntToScalar(200), 0); } } - virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) - { + virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { return fRect.contains(SkScalarRound(x), SkScalarRound(y)) ? new Click(this) : NULL; } - virtual bool onClick(Click* click) - { + virtual bool onClick(Click* click) { fRect.offset(click->fICurr.fX - click->fIPrev.fX, click->fICurr.fY - click->fIPrev.fY); this->inval(NULL); @@ -336,7 +263,7 @@ protected: private: SkIRect fBase, fRect; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleShaders.cpp b/samplecode/SampleShaders.cpp index 86c8b17e82..c1bb0fda21 100644 --- a/samplecode/SampleShaders.cpp +++ b/samplecode/SampleShaders.cpp @@ -40,13 +40,12 @@ static SkShader* make_bitmapfade(const SkBitmap& bm) return shader; } -class ShaderView : public SkView { +class ShaderView : public SampleView { public: SkShader* fShader; SkBitmap fBitmap; - ShaderView() - { + ShaderView() { SkImageDecoder::DecodeFile("/skimages/logo.gif", &fBitmap); SkPoint pts[2]; @@ -71,8 +70,7 @@ public: shaderB->unref(); mode->unref(); } - virtual ~ShaderView() - { + virtual ~ShaderView() { SkSafeUnref(fShader); } @@ -86,16 +84,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) - { -// canvas->drawColor(0xFFDDDDDD); - canvas->drawColor(SK_ColorWHITE); - } - - virtual void onDraw(SkCanvas* canvas) - { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { canvas->drawBitmap(fBitmap, 0, 0); canvas->translate(SkIntToScalar(20), SkIntToScalar(120)); @@ -125,19 +114,17 @@ protected: canvas->drawRect(r, paint); } - virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) - { + virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { this->inval(NULL); return this->INHERITED::onFindClickHandler(x, y); } - virtual bool onClick(Click* click) - { + virtual bool onClick(Click* click) { return this->INHERITED::onClick(click); } private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleStrokeText.cpp b/samplecode/SampleStrokeText.cpp index e75bb54ca2..bcb9e4fca0 100644 --- a/samplecode/SampleStrokeText.cpp +++ b/samplecode/SampleStrokeText.cpp @@ -98,10 +98,12 @@ static void lettersToBitmap2(SkBitmap* dst, const char chars[], canvas.drawPath(path, paint); } -class StrokeTextView : public SkView { +class StrokeTextView : public SampleView { bool fAA; public: - StrokeTextView() : fAA(false) {} + StrokeTextView() : fAA(false) { + this->setBGColor(0xFFCC8844); + } protected: // overrides from SkEventSink @@ -113,14 +115,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(0xFF333333); - canvas->drawColor(0xFFCC8844); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { SkBitmap bm; SkPaint paint; @@ -135,7 +130,7 @@ protected: private: - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleTextAlpha.cpp b/samplecode/SampleTextAlpha.cpp index b23af51b0d..ccfed68e6d 100644 --- a/samplecode/SampleTextAlpha.cpp +++ b/samplecode/SampleTextAlpha.cpp @@ -35,7 +35,7 @@ static void check_for_nonwhite(const SkBitmap& bm, int alpha) { } } -class TextAlphaView : public SkView { +class TextAlphaView : public SampleView { public: TextAlphaView() { fByte = 0xFF; @@ -52,13 +52,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(SK_ColorWHITE); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { const char* str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; SkPaint paint; SkScalar x = SkIntToScalar(10); @@ -110,7 +104,7 @@ protected: private: int fByte; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/samplecode/SampleUnitMapper.cpp b/samplecode/SampleUnitMapper.cpp index e045d965ee..b20aece316 100644 --- a/samplecode/SampleUnitMapper.cpp +++ b/samplecode/SampleUnitMapper.cpp @@ -27,7 +27,7 @@ static void set_scalar(SkStaticTextView* view, SkScalar value) { view->setText(str); } -class UnitMapperView : public SkView { +class UnitMapperView : public SampleView { SkPoint fPts[4]; SkMatrix fMatrix; SkStaticTextView* fViews[4]; @@ -73,13 +73,7 @@ protected: return this->INHERITED::onQuery(evt); } - void drawBG(SkCanvas* canvas) { - canvas->drawColor(SK_ColorWHITE); - } - - virtual void onDraw(SkCanvas* canvas) { - this->drawBG(canvas); - + virtual void onDrawContent(SkCanvas* canvas) { SkPaint paint; paint.setAntiAlias(true); paint.setColor(0xFF8888FF); @@ -153,7 +147,7 @@ protected: private: int fDragIndex; - typedef SkView INHERITED; + typedef SampleView INHERITED; }; ////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3