From: reed@android.com Date: Wed, 24 Feb 2010 02:01:23 +0000 (+0000) Subject: add DEBUG_LAYER_BOUNDS option to show layer bounds X-Git-Tag: submit/tizen/20180928.044319~19248 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2bd703b3163fe1da3ea55f6459c5e162f32cce12;p=platform%2Fupstream%2FlibSkiaSharp.git add DEBUG_LAYER_BOUNDS option to show layer bounds git-svn-id: http://skia.googlecode.com/svn/trunk@509 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/samplecode/SampleSkLayer.cpp b/samplecode/SampleSkLayer.cpp index 42f0a60498..a5278dcd2d 100644 --- a/samplecode/SampleSkLayer.cpp +++ b/samplecode/SampleSkLayer.cpp @@ -32,8 +32,8 @@ private: public: SkLayerView() { - static const int W = 640; - static const int H = 480; + static const int W = 600; + static const int H = 440; static const struct { int fWidth; int fHeight; @@ -47,7 +47,7 @@ public: { 120, 80, SK_ColorMAGENTA, W - 120, H - 80 }, }; - fRootLayer = new SkLayer; + fRootLayer = new TestLayer(0xFFDDDDDD); fRootLayer->setSize(W, H); for (size_t i = 0; i < SK_ARRAY_COUNT(gData); i++) { SkLayer* child = new TestLayer(gData[i].fColor); @@ -55,6 +55,18 @@ public: child->setPosition(gData[i].fPosX, gData[i].fPosY); fRootLayer->addChild(child)->unref(); } + + SkLayer* child = new TestLayer(0xFFDD8844); + child->setSize(120, 80); + child->setPosition(fRootLayer->getWidth()/2 - child->getWidth()/2, + fRootLayer->getHeight()/2 - child->getHeight()/2); + child->setAnchorPoint(SK_ScalarHalf, SK_ScalarHalf); + { + SkMatrix m; + m.setRotate(SkIntToScalar(30)); + child->setMatrix(m); + } + fRootLayer->addChild(child)->unref(); } virtual ~SkLayerView() { @@ -72,8 +84,9 @@ protected: } void drawBG(SkCanvas* canvas) { - canvas->drawColor(0xFFDDDDDD); + canvas->drawColor(SK_ColorWHITE); + canvas->translate(20, 20); fRootLayer->draw(canvas); } diff --git a/src/utils/SkLayer.cpp b/src/utils/SkLayer.cpp index 603cdd1eb8..759f826d96 100644 --- a/src/utils/SkLayer.cpp +++ b/src/utils/SkLayer.cpp @@ -1,11 +1,13 @@ #include "SkLayer.h" #include "SkCanvas.h" +//#define DEBUG_LAYER_BOUNDS + SkLayer::SkLayer() { - m_opacity = 1; + m_opacity = SK_Scalar1; m_size.set(0, 0); m_position.set(0, 0); - m_anchorPoint.set(0.5, 0.5); + m_anchorPoint.set(SK_ScalarHalf, SK_ScalarHalf); fMatrix.reset(); fChildrenMatrix.reset(); @@ -102,6 +104,20 @@ void SkLayer::draw(SkCanvas* canvas, SkScalar opacity) { this->onDraw(canvas, opacity); +#ifdef DEBUG_LAYER_BOUNDS + { + SkRect r = SkRect::MakeSize(this->getSize()); + SkPaint p; + p.setAntiAlias(true); + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(SkIntToScalar(2)); + p.setColor(0xFFFF44DD); + canvas->drawRect(r, p); + canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, p); + canvas->drawLine(r.fLeft, r.fBottom, r.fRight, r.fTop, p); + } +#endif + int count = this->countChildren(); if (count > 0) { canvas->concat(this->getChildrenMatrix());