From 8e276cf1d62479906a2a550a4e9af72ee2231906 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Mon, 7 Feb 2011 17:25:45 -0800 Subject: [PATCH] make factory icons a fixed height --- src/EntitySidebarImg.as | 29 ++++++++++++++++++++++++----- src/Factory.as | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/EntitySidebarImg.as b/src/EntitySidebarImg.as index bffec2e..0a47cfc 100644 --- a/src/EntitySidebarImg.as +++ b/src/EntitySidebarImg.as @@ -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 diff --git a/src/Factory.as b/src/Factory.as index a7add19..73b770f 100644 --- a/src/Factory.as +++ b/src/Factory.as @@ -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; }