Can load image with only 1 unit, for scaled pasting.

This commit is contained in:
Devine Lu Linvega 2016-11-15 09:27:42 -08:00
parent 17c5f08da8
commit 896d4c0254
2 changed files with 5 additions and 1 deletions

BIN
media/demo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

View File

@ -24,6 +24,10 @@ function File()
height = cmd.rect().height; height = cmd.rect().height;
position.normalize(cmd.rect()); position.normalize(cmd.rect());
} }
// Scale with only 1 unit
width = isNaN(width) && height > 0 ? (height*base_image.naturalWidth)/base_image.naturalHeight : width;
height = isNaN(height) && width > 0 ? (width*base_image.naturalHeight)/base_image.naturalWidth : height;
ronin.canvas.context().drawImage(base_image, position.x, position.y, width, height); ronin.canvas.context().drawImage(base_image, position.x, position.y, width, height);
} }
} }
@ -46,7 +50,7 @@ function File()
{ {
var hint_path = (cmd.path() ? "Path "+cmd.path()+" " : ""); var hint_path = (cmd.path() ? "Path "+cmd.path()+" " : "");
var hint_position = (cmd.position() ? "Position "+cmd.position().x+","+cmd.position().y+" " : ""); var hint_position = (cmd.position() ? "Position "+cmd.position().x+","+cmd.position().y+" " : "");
var hint_rect = (cmd.rect() ? "Size "+cmd.rect().width+"px by "+cmd.rect().height+"px " : ""); var hint_rect = (cmd.rect() ? "Size "+cmd.rect().width+" by "+cmd.rect().height+" " : "");
return "File: "+hint_path+hint_position+hint_rect; return "File: "+hint_path+hint_position+hint_rect;
} }