mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-19 09:37:50 -05:00
95 lines
2.7 KiB
ActionScript
95 lines
2.7 KiB
ActionScript
package gui
|
|
{
|
|
import flash.display.BitmapData;
|
|
import flash.display.DisplayObject;
|
|
import flash.display.Sprite;
|
|
import flash.geom.Point;
|
|
import flash.geom.Rectangle;
|
|
import flash.ui.Mouse;
|
|
import flash.ui.MouseCursor;
|
|
import flash.ui.MouseCursorData;
|
|
|
|
public class CursorManager extends Sprite
|
|
{
|
|
|
|
private static var _customCursor:Sprite;
|
|
|
|
private static var _mcd:MouseCursorData;
|
|
|
|
private static var _previousCursor:String;
|
|
|
|
public static const CUSTOM_CURSOR:String = "custom_cursor";
|
|
|
|
public static const DEFAULT_I_CURSOR:String = "ibeam";
|
|
|
|
public static const DEFAULT_CURSOR:String = "Default_Cursor";
|
|
|
|
public function CursorManager()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function init() : void
|
|
{
|
|
_customCursor = GETDEFINITIONBYNAME("Cursor");
|
|
_mcd = new MouseCursorData();
|
|
}
|
|
|
|
public static function changeDefaultMouse() : void
|
|
{
|
|
var v:Vector.<BitmapData> = new Vector.<BitmapData>();
|
|
v[0] = convertToBitmapData(_customCursor);
|
|
_mcd.data = v;
|
|
_mcd.hotSpot = new Point(5,0.5);
|
|
Mouse.registerCursor("custom_cursor",_mcd);
|
|
Mouse.cursor = "custom_cursor";
|
|
}
|
|
|
|
public static function switchToCursor(cursorName:String) : void
|
|
{
|
|
var vec:Vector.<BitmapData> = new Vector.<BitmapData>();
|
|
switch(cursorName)
|
|
{
|
|
case CUSTOM_CURSOR:
|
|
vec[0] = convertToBitmapData(_customCursor);
|
|
_mcd.hotSpot = new Point(5,0.5);
|
|
_mcd.data = vec;
|
|
Mouse.registerCursor("custom_cursor",_mcd);
|
|
Mouse.cursor = "custom_cursor";
|
|
break;
|
|
case DEFAULT_I_CURSOR:
|
|
Mouse.cursor = MouseCursor.IBEAM;
|
|
break;
|
|
case DEFAULT_CURSOR:
|
|
Mouse.unregisterCursor("custom_cursor");
|
|
_previousCursor = "";
|
|
}
|
|
}
|
|
|
|
public static function showICursor(show:Boolean) : void
|
|
{
|
|
if(Mouse.cursor != "auto")
|
|
{
|
|
if(show)
|
|
{
|
|
_previousCursor = Mouse.cursor;
|
|
switchToCursor(DEFAULT_I_CURSOR);
|
|
}
|
|
else
|
|
{
|
|
switchToCursor(_previousCursor);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static function convertToBitmapData(dis:DisplayObject) : BitmapData
|
|
{
|
|
var bounds:Rectangle = new Rectangle(0,0,19,24);
|
|
var bitmap:BitmapData = new BitmapData(19,24,true,0);
|
|
bitmap.draw(dis);
|
|
return bitmap;
|
|
}
|
|
}
|
|
}
|
|
|