diff options
author | 2011-11-11 21:42:12 +0000 | |
---|---|---|
committer | 2011-11-11 21:42:12 +0000 | |
commit | f03bb566e25ace918f8fdda3cb8426626a00894c (patch) | |
tree | 6955fcccb33cdc4a3bb9a38a269351f98342ce24 /src | |
parent | 83ab49556ffc83fd3b2c1142db264362d21e6b19 (diff) |
land http://codereview.appspot.com/5244058/ - add matrix to SkView
git-svn-id: http://skia.googlecode.com/svn/trunk@2670 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/views/SkView.cpp | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp index 5b154392e8..fc1ddfbfc5 100644 --- a/src/views/SkView.cpp +++ b/src/views/SkView.cpp @@ -15,7 +15,7 @@ SkView::SkView(uint32_t flags) : fFlags(SkToU8(flags)) fWidth = fHeight = 0; fLoc.set(0, 0); fParent = fFirstChild = fNextSibling = fPrevSibling = NULL; - + fMatrix.setIdentity(); fContainsFocus = 0; } @@ -82,7 +82,7 @@ void SkView::setLoc(SkScalar x, SkScalar y) { this->inval(NULL); fLoc.set(x, y); - this->inval(NULL); + this->inval(NULL); } } @@ -92,6 +92,13 @@ void SkView::offset(SkScalar dx, SkScalar dy) this->setLoc(fLoc.fX + dx, fLoc.fY + dy); } +void SkView::setLocalMatrix(const SkMatrix& matrix) +{ + this->inval(NULL); + fMatrix = matrix; + this->inval(NULL); +} + void SkView::draw(SkCanvas* canvas) { if (fWidth && fHeight && this->isVisible()) @@ -108,8 +115,10 @@ void SkView::draw(SkCanvas* canvas) if (this->isClipToBounds()) { canvas->clipRect(r); } - canvas->translate(fLoc.fX, fLoc.fY); - + + canvas->translate(fLoc.fX, fLoc.fY); + canvas->concat(fMatrix); + if (fParent) { fParent->beforeChild(this, canvas); } @@ -369,11 +378,14 @@ SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y) if (this->onSendClickToChildren(x, y)) { F2BIter iter(this); SkView* child; - + while ((child = iter.next()) != NULL) { - Click* click = child->findClickHandler(x - child->fLoc.fX, - y - child->fLoc.fY); + SkPoint p; + child->globalToLocal(x, y, &p); + + Click* click = child->findClickHandler(p.fX, p.fY); + if (click) { return click; } @@ -594,20 +606,30 @@ void SkView::detachAllChildren() fFirstChild->detachFromParent_NoLayout(); } +void SkView::localToGlobal(SkMatrix* matrix) const +{ + if (matrix) { + matrix->reset(); + const SkView* view = this; + while (view) + { + matrix->preConcat(view->getLocalMatrix()); + matrix->preTranslate(-view->fLoc.fX, -view->fLoc.fY); + view = view->fParent; + } + } +} void SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const { SkASSERT(this); - if (local) { - const SkView* view = this; - while (view) - { - x -= view->fLoc.fX; - y -= view->fLoc.fY; - view = view->fParent; - } - local->set(x, y); + SkMatrix m; + this->localToGlobal(&m); + SkPoint p; + m.invert(&m); + m.mapXY(x, y, &p); + local->set(p.fX, p.fY); } } |