aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/SampleApp.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-11 21:42:12 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-11-11 21:42:12 +0000
commitf03bb566e25ace918f8fdda3cb8426626a00894c (patch)
tree6955fcccb33cdc4a3bb9a38a269351f98342ce24 /samplecode/SampleApp.cpp
parent83ab49556ffc83fd3b2c1142db264362d21e6b19 (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 'samplecode/SampleApp.cpp')
-rw-r--r--samplecode/SampleApp.cpp99
1 files changed, 46 insertions, 53 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 35a822a279..ffe56b104d 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -751,50 +751,13 @@ void SampleWindow::draw(SkCanvas* canvas) {
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, &center);
- 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 @@ void SampleWindow::changeZoomLevel(float delta) {
} else {
fZoomScale = SK_Scalar1;
}
+ this->updateMatrix();
+}
+void SampleWindow::updateMatrix(){
+ SkMatrix m;
+ m.reset();
+ if (fZoomLevel) {
+ SkPoint center;
+ //m = this->getLocalMatrix();//.invert(&m);
+ m.mapXY(fZoomCenterX, fZoomCenterY, &center);
+ 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 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
}
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 @@ SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y) {
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 @@ bool SampleWindow::onClick(Click* click) {
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;