make factory icons a fixed height

This commit is contained in:
Jeremy Penner 2011-02-07 17:25:45 -08:00
parent c6c09e50ff
commit 8e276cf1d6
2 changed files with 25 additions and 6 deletions

View file

@ -14,19 +14,38 @@ package
public class EntitySidebarImg extends EntitySidebar
{
protected var img: Image;
public function EntitySidebarImg(sidebar: Sidebar, bmp:*)
protected var h: Number;
public function EntitySidebarImg(sidebar: Sidebar, bmp:*, h:Number = -1)
{
img = new Image(bmp);
img.scale = sidebar.width / img.width;
super(sidebar, img.scaledHeight, img);
this.h = h;
SetScale(sidebar);
super(sidebar, h < 0 ? img.scaledHeight : h, img);
}
private function SetScale(sidebar: Sidebar)
{
var scale:Number = sidebar.width / img.width;
if (h >= 0)
{
var hscale:Number = h / img.height;
if (hscale < scale)
{
img.x = (sidebar.width - (img.width * hscale)) / 2;
scale = hscale;
}
else
{
img.y = (h - (img.height * scale)) / 2;
}
}
img.scale = scale;
}
public function OnImgReload(bmp:BitmapData, file:File): void
{
var imgNew:Image = new Image(bmp);
imgNew.scale = sidebar.width / imgNew.width;
imgNew.alpha = img.alpha;
img = imgNew;
SetScale(sidebar);
graphic = img;
}
override public function Fade(pct:Number):void

View file

@ -21,7 +21,7 @@ package
private var filewatcher: FileWatcher;
public function Factory(sidebar: Sidebar, urpf: String, bmp:BitmapData)
{
super(sidebar, bmp);
super(sidebar, bmp, sidebar.width);
this.bmp = bmp;
this.urpf = urpf;
}