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/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 35a822a..ffe56b1 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -751,50 +751,13 @@
gAnimTimePrev = gAnimTime;
gAnimTime = SkTime::GetMSecs();
}
-
- SkScalar cx = fZoomCenterX;
- SkScalar cy = fZoomCenterY;
-
- if (fZoomLevel) {
- SkMatrix m;
- SkPoint center;
- m = canvas->getTotalMatrix();//.invert(&m);
- m.mapXY(cx, cy, ¢er);
- cx = center.fX;
- cy = center.fY;
-
- m.setTranslate(-cx, -cy);
- m.postScale(fZoomScale, fZoomScale);
- m.postTranslate(cx, cy);
-
- canvas->concat(m);
- }
-
- if (fFlipAxis) {
- SkMatrix m;
- m.setTranslate(cx, cy);
- if (fFlipAxis & kFlipAxis_X) {
- m.preScale(-SK_Scalar1, SK_Scalar1);
- }
- if (fFlipAxis & kFlipAxis_Y) {
- m.preScale(SK_Scalar1, -SK_Scalar1);
- }
- m.preTranslate(-cx, -cy);
- canvas->concat(m);
- }
- // Apply any gesture matrix
- if (true) {
- const SkMatrix& localM = fGesture.localM();
- if (localM.getType() & SkMatrix::kScale_Mask) {
- canvas->setExternalMatrix(&localM);
- }
- canvas->concat(localM);
- canvas->concat(fGesture.globalM());
-
- if (fGesture.isActive()) {
- this->inval(NULL);
- }
+ const SkMatrix& localM = fGesture.localM();
+ if (localM.getType() & SkMatrix::kScale_Mask) {
+ canvas->setExternalMatrix(&localM);
+ }
+ if (fGesture.isActive()) {
+ this->updateMatrix();
}
if (fNClip) {
@@ -1224,12 +1187,44 @@
} else {
fZoomScale = SK_Scalar1;
}
-
- this->updateTitle();
-
- this->inval(NULL);
+ this->updateMatrix();
}
+void SampleWindow::updateMatrix(){
+ SkMatrix m;
+ m.reset();
+ if (fZoomLevel) {
+ SkPoint center;
+ //m = this->getLocalMatrix();//.invert(&m);
+ m.mapXY(fZoomCenterX, fZoomCenterY, ¢er);
+ SkScalar cx = center.fX;
+ SkScalar cy = center.fY;
+
+ m.setTranslate(-cx, -cy);
+ m.postScale(fZoomScale, fZoomScale);
+ m.postTranslate(cx, cy);
+ }
+
+ if (fFlipAxis) {
+ m.preTranslate(fZoomCenterX, fZoomCenterY);
+ if (fFlipAxis & kFlipAxis_X) {
+ m.preScale(-SK_Scalar1, SK_Scalar1);
+ }
+ if (fFlipAxis & kFlipAxis_Y) {
+ m.preScale(SK_Scalar1, -SK_Scalar1);
+ }
+ m.preTranslate(-fZoomCenterX, -fZoomCenterY);
+ //canvas->concat(m);
+ }
+ // Apply any gesture matrix
+ m.preConcat(fGesture.localM());
+ m.preConcat(fGesture.globalM());
+
+ this->setLocalMatrix(m);
+
+ this->updateTitle();
+ this->inval(NULL);
+}
bool SampleWindow::previousSample() {
fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count();
this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(),
@@ -1331,14 +1326,12 @@
}
if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) {
fFlipAxis ^= kFlipAxis_X;
- this->updateTitle();
- this->inval(NULL);
+ this->updateMatrix();
return true;
}
if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) {
fFlipAxis ^= kFlipAxis_Y;
- this->updateTitle();
- this->inval(NULL);
+ this->updateMatrix();
return true;
}
if (SkOSMenu::FindAction(evt,"Save to PDF")) {
@@ -1619,8 +1612,8 @@
bool SampleWindow::onClick(Click* click) {
if (GestureClick::IsGesture(click)) {
- float x = SkScalarToFloat(click->fCurr.fX);
- float y = SkScalarToFloat(click->fCurr.fY);
+ float x = click->fICurr.fX;
+ float y = click->fICurr.fY;
switch (click->fState) {
case SkView::Click::kDown_State:
@@ -1628,11 +1621,11 @@
break;
case SkView::Click::kMoved_State:
fGesture.touchMoved(click->fOwner, x, y);
- this->inval(NULL);
+ this->updateMatrix();
break;
case SkView::Click::kUp_State:
fGesture.touchEnd(click->fOwner);
- this->inval(NULL);
+ this->updateMatrix();
break;
}
return true;