Update tiledImage to use the new function of the drawer

This commit is contained in:
Philip Giuliani 2015-04-09 19:57:55 +02:00
parent 1a230d8b9f
commit 5958c50d62

View File

@ -1158,36 +1158,25 @@ function drawTiles( tiledImage, lastDrawn ) {
viewport, viewport,
position, position,
tileSource, tileSource,
needsRestore = false; contextSaved = false;
// TODO: Move this function
var boxToDrawerRectangle = function( box ) {
var topLeft = tiledImage.viewport.pixelFromPoint(box.getTopLeft(), true);
var size = tiledImage.viewport.deltaPixelsFromPoints(box.getSize(), true);
return new $.Rect(
topLeft.x * $.pixelDensityRatio,
topLeft.y * $.pixelDensityRatio,
size.x * $.pixelDensityRatio,
size.y * $.pixelDensityRatio
);
};
if ( tiledImage._clip ) { if ( tiledImage._clip ) {
tiledImage._drawer.saveContext(); tiledImage._drawer.saveContext();
var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true); contextSaved = true;
var clipRect = boxToDrawerRectangle(box);
var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true);
var clipRect = tiledImage._drawer.viewportToDrawerRectangle(box);
tiledImage._drawer.setClip(clipRect); tiledImage._drawer.setClip(clipRect);
needsRestore = true;
} }
if ( tiledImage.placeholderFillStyle && lastDrawn.length === 0 ) { if ( tiledImage.placeholderFillStyle && lastDrawn.length === 0 ) {
tiledImage._drawer.saveContext(); if ( !contextSaved ) {
var placeholderRect = boxToDrawerRectangle( tiledImage.getBounds(true) ); tiledImage._drawer.saveContext();
contextSaved = true;
}
var placeholderRect = tiledImage._drawer.viewportToDrawerRectangle(tiledImage.getBounds(true));
tiledImage._drawer.drawPlaceholder(placeholderRect, tiledImage.placeholderFillStyle); tiledImage._drawer.drawPlaceholder(placeholderRect, tiledImage.placeholderFillStyle);
needsRestore = true;
} }
for ( i = lastDrawn.length - 1; i >= 0; i-- ) { for ( i = lastDrawn.length - 1; i >= 0; i-- ) {
@ -1222,7 +1211,7 @@ function drawTiles( tiledImage, lastDrawn ) {
} }
} }
if ( needsRestore ) { if ( contextSaved ) {
tiledImage._drawer.restoreContext(); tiledImage._drawer.restoreContext();
} }
} }