diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index dc59ea4bf..908f70b11 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -157,17 +157,27 @@ class Image { public function clone ():Image { - var image = new Image (buffer.clone (), offsetX, offsetY, width, height, null, type); - - if (image.type == CANVAS && image.buffer.data != null && image.buffer.__srcCanvas == null) { + if (buffer != null) { - ImageCanvasUtil.convertToCanvas (image); + if (type == CANVAS && buffer.__srcImage == null) { + + ImageCanvasUtil.convertToCanvas (this); + ImageCanvasUtil.sync (this); + buffer.data = null; + buffer.__srcImageData = null; + + } + + var image = new Image (buffer.clone (), offsetX, offsetY, width, height, null, type); + image.dirty = dirty; + return image; + + } else { + + return new Image (null, offsetX, offsetY, width, height, null, type); } - image.dirty = dirty; - return image; - } @@ -710,6 +720,37 @@ class Image { } + public function scroll (x:Int, y:Int):Void { + + if (buffer == null) return; + + switch (type) { + + case CANVAS: + + ImageCanvasUtil.scroll (this, x, y); + + case DATA: + + //#if (js && html5) + //ImageCanvasUtil.convertToData (this); + //#end + + //ImageDataUtil.scroll (this, x, y); + + copyPixels (this, rect, new Vector2 (x, y)); + + case FLASH: + + buffer.__srcBitmapData.scroll (x + offsetX, y + offsetX); + + default: + + } + + } + + public function setPixel (x:Int, y:Int, color:Int, format:PixelFormat = null):Void { if (buffer == null || x < 0 || y < 0 || x >= width || y >= height) return; diff --git a/lime/graphics/utils/ImageCanvasUtil.hx b/lime/graphics/utils/ImageCanvasUtil.hx index ebdf81721..7fb286321 100644 --- a/lime/graphics/utils/ImageCanvasUtil.hx +++ b/lime/graphics/utils/ImageCanvasUtil.hx @@ -297,6 +297,19 @@ class ImageCanvasUtil { } + public static function scroll (image:Image, x:Int, y:Int):Void { + + if ((x % image.width == 0) && (y % image.height == 0)) return; + + convertToCanvas (image); + sync (image); + + image.buffer.__srcContext.clearRect (x, y, image.width, image.height); + image.buffer.__srcContext.drawImage (image.buffer.__srcCanvas, x, y); + + } + + public static function setPixel (image:Image, x:Int, y:Int, color:Int, format:PixelFormat):Void { convertToCanvas (image);