From 490dab57801114c622e0dd983f77d68a8c72bc5c Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Mon, 8 May 2006 21:31:24 +0000 Subject: [PATCH] Added an ImageUtil with some basic utility functions. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4099 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/media/image/ImageUtil.as | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/as/com/threerings/media/image/ImageUtil.as diff --git a/src/as/com/threerings/media/image/ImageUtil.as b/src/as/com/threerings/media/image/ImageUtil.as new file mode 100644 index 000000000..8518671d1 --- /dev/null +++ b/src/as/com/threerings/media/image/ImageUtil.as @@ -0,0 +1,46 @@ +package com.threerings.media.image { + +import flash.display.BitmapData; +import flash.display.DisplayObject; +import flash.display.Shape; +import flash.display.TextField; + +import flash.text.TextLineMetrics; + +/** + * Image and Bitmap related utility functions. + */ +public class ImageUtil +{ + /** + * Create a Shape that will display an error message of the specified + * dimensions. + */ + public static function createErrorImage (width :int, height :int) :Shape + { + var shape :Shape = new Shape(); + shape.graphics.beginBitmapFill(createErrorBitmap(), null, true); + shape.graphics.drawRect(0, 0, width, height); + shape.graphics.endFill(); + return shape; + } + + /** + * Create a minimally-sized "error" BitmapData. + */ + public static function createErrorBitmap () :BitmapData + { + var txt :TextField = new TextField(); + txt.text = "Error"; + var metrics :TextLineMetrics = txt.getLineMetrics(0); + var data :BitmapData = new BitmapData( + metrics.width + ERROR_PADDING, metrics.height + ERROR_PADDING, + false, 0xFF4040); + data.draw(txt); + return data; + } + + /** The amount to pad error messages by. */ + private static const ERROR_PADDING :int = 5; +} +}