fHintingState = 0;
fFilterQualityIndex = 0;
fFlipAxis = 0;
- fScrollTestX = fScrollTestY = 0;
fMouseX = fMouseY = 0;
fFatBitsScale = 8;
fZoomLevel = 0;
fZoomScale = SK_Scalar1;
+ fOffset = { 0, 0 };
fMagnify = false;
if (kNo_Tiling == fTilingMode) {
this->INHERITED::draw(canvas); // no looping or surfaces needed
} else {
- const int w = SkScalarRoundToInt(tile.width());
- const int h = SkScalarRoundToInt(tile.height());
- SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
+ const SkScalar w = SkScalarCeilToScalar(tile.width());
+ const SkScalar h = SkScalarCeilToScalar(tile.height());
+ SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarTruncToInt(w), SkScalarTruncToInt(h));
SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
SkCanvas* tileCanvas = surface->getCanvas();
- for (SkScalar y = 0; y < height(); y += tile.height()) {
- for (SkScalar x = 0; x < width(); x += tile.width()) {
+ for (SkScalar y = 0; y < height(); y += h) {
+ for (SkScalar x = 0; x < width(); x += w) {
SkAutoCanvasRestore acr(tileCanvas, true);
tileCanvas->translate(-x, -y);
tileCanvas->clear(0);
}
}
+void SampleWindow::changeOffset(SkVector delta) {
+ fOffset += delta;
+ this->updateMatrix();
+}
+
void SampleWindow::changeZoomLevel(float delta) {
fZoomLevel += delta;
if (fZoomLevel > 0) {
void SampleWindow::updateMatrix(){
SkMatrix m;
m.reset();
+
if (fZoomLevel) {
SkPoint center;
//m = this->getLocalMatrix();//.invert(&m);
m.postTranslate(cx, cy);
}
+ m.postTranslate(fOffset.fX, fOffset.fY);
+
if (fFlipAxis) {
m.preTranslate(fZoomCenterX, fZoomCenterY);
if (fFlipAxis & kFlipAxis_X) {
}
if (0xFF != dx && 0xFF != dy) {
- if ((dx | dy) == 0) {
- fScrollTestX = fScrollTestY = 0;
- } else {
- fScrollTestX += dx;
- fScrollTestY += dy;
- }
- this->inval(nullptr);
+ this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f)});
return true;
}
}
}
}
+
+ int dx = 0xFF;
+ int dy = 0xFF;
+
switch (key) {
case kRight_SkKey:
if (this->nextSample()) {
case kBack_SkKey:
this->showOverview();
return true;
+
+ case k5_SkKey: dx = 0; dy = 0; break;
+ case k8_SkKey: dx = 0; dy = -1; break;
+ case k6_SkKey: dx = 1; dy = 0; break;
+ case k2_SkKey: dx = 0; dy = 1; break;
+ case k4_SkKey: dx = -1; dy = 0; break;
+ case k7_SkKey: dx = -1; dy = -1; break;
+ case k9_SkKey: dx = 1; dy = -1; break;
+ case k3_SkKey: dx = 1; dy = 1; break;
+ case k1_SkKey: dx = -1; dy = 1; break;
+
default:
break;
}
+
+ if (0xFF != dx && 0xFF != dy) {
+ this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f)});
+ return true;
+ }
+
return this->INHERITED::onHandleKey(key);
}
title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr);
title.prepend(gHintingStates[fHintingState].label);
+ if (fOffset.fX || fOffset.fY) {
+ title.prependf("(%.2f, %.2f) ", SkScalarToFloat(fOffset.fX), SkScalarToFloat(fOffset.fY));
+ }
if (fZoomLevel) {
title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
}