aboutsummaryrefslogtreecommitdiffstats
path: root/src/views/SkView.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/views/SkView.cpp')
-rw-r--r--src/views/SkView.cpp72
1 files changed, 51 insertions, 21 deletions
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp
index 1cd6339..fc1ddfb 100644
--- a/src/views/SkView.cpp
+++ b/src/views/SkView.cpp
@@ -1,3 +1,10 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
#include "SkView.h"
#include "SkCanvas.h"
@@ -8,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;
}
@@ -75,7 +82,7 @@ void SkView::setLoc(SkScalar x, SkScalar y)
{
this->inval(NULL);
fLoc.set(x, y);
- this->inval(NULL);
+ this->inval(NULL);
}
}
@@ -85,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())
@@ -101,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);
}
@@ -296,10 +312,11 @@ void SkView::onFocusChange(bool gainFocusP)
SkView::Click::Click(SkView* target)
{
- SkASSERT(target);
- fTargetID = target->getSinkID();
- fType = NULL;
- fWeOwnTheType = false;
+ SkASSERT(target);
+ fTargetID = target->getSinkID();
+ fType = NULL;
+ fWeOwnTheType = false;
+ fOwner = NULL;
}
SkView::Click::~Click()
@@ -355,17 +372,20 @@ void SkView::Click::copyType(const char type[])
SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y)
{
if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) {
- return false;
+ return NULL;
}
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;
}
@@ -586,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);
}
}