Fix canvas Image clone, add image.scroll
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user