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
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp
index 5b15439..fc1ddfb 100644
--- a/src/views/SkView.cpp
+++ b/src/views/SkView.cpp
@@ -15,7 +15,7 @@
fWidth = fHeight = 0;
fLoc.set(0, 0);
fParent = fFirstChild = fNextSibling = fPrevSibling = NULL;
-
+ fMatrix.setIdentity();
fContainsFocus = 0;
}
@@ -82,7 +82,7 @@
{
this->inval(NULL);
fLoc.set(x, y);
- this->inval(NULL);
+ this->inval(NULL);
}
}
@@ -92,6 +92,13 @@
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 @@
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 @@
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 @@
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);
}
}