2022-11-08 16:32:00 -05:00
|
|
|
package funkin.input;
|
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
import haxe.ui.backend.flixel.CursorHelper;
|
2022-11-08 16:32:00 -05:00
|
|
|
import openfl.utils.Assets;
|
|
|
|
import lime.app.Future;
|
|
|
|
import openfl.display.BitmapData;
|
|
|
|
|
2023-09-12 18:37:59 -04:00
|
|
|
@:nullSafety
|
2022-11-08 16:32:00 -05:00
|
|
|
class Cursor
|
|
|
|
{
|
2023-09-12 18:37:59 -04:00
|
|
|
/**
|
|
|
|
* The current cursor mode.
|
|
|
|
* Set this value to change the cursor graphic.
|
|
|
|
*/
|
|
|
|
public static var cursorMode(default, set):Null<CursorMode> = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the cursor.
|
|
|
|
*/
|
|
|
|
public static inline function show():Void
|
|
|
|
{
|
|
|
|
FlxG.mouse.visible = true;
|
|
|
|
// Reset the cursor mode.
|
|
|
|
Cursor.cursorMode = Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the cursor.
|
|
|
|
*/
|
|
|
|
public static inline function hide():Void
|
|
|
|
{
|
|
|
|
FlxG.mouse.visible = false;
|
|
|
|
// Reset the cursor mode.
|
|
|
|
Cursor.cursorMode = null;
|
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_DEFAULT_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-default.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorDefault:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_CROSS_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-cross.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorCross:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_ERASER_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-eraser.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorEraser:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_GRABBING_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-grabbing.png",
|
|
|
|
scale: 1.0,
|
2023-09-12 18:37:59 -04:00
|
|
|
offsetX: -8,
|
2023-01-22 22:25:45 -05:00
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorGrabbing:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_HOURGLASS_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-hourglass.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorHourglass:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_POINTER_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-pointer.png",
|
|
|
|
scale: 1.0,
|
2023-09-12 18:37:59 -04:00
|
|
|
offsetX: -8,
|
2023-01-22 22:25:45 -05:00
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorPointer:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_TEXT_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-text.png",
|
2023-09-12 18:37:59 -04:00
|
|
|
scale: 0.2,
|
2023-01-22 22:25:45 -05:00
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorText:Null<BitmapData> = null;
|
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_TEXT_VERTICAL_PARAMS:CursorParams =
|
2023-09-12 18:37:59 -04:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-text-vertical.png",
|
|
|
|
scale: 0.2,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
|
|
|
static var assetCursorTextVertical:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_ZOOM_IN_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-zoom-in.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorZoomIn:Null<BitmapData> = null;
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_ZOOM_OUT_PARAMS:CursorParams =
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-zoom-out.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: 0,
|
|
|
|
offsetY: 0,
|
|
|
|
};
|
2023-09-12 18:37:59 -04:00
|
|
|
static var assetCursorZoomOut:Null<BitmapData> = null;
|
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_CROSSHAIR_PARAMS:CursorParams =
|
2023-09-12 18:37:59 -04:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-crosshair.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: -16,
|
|
|
|
offsetY: -16,
|
|
|
|
};
|
|
|
|
static var assetCursorCrosshair:Null<BitmapData> = null;
|
|
|
|
|
2023-10-31 14:43:01 -04:00
|
|
|
public static final CURSOR_CELL_PARAMS:CursorParams =
|
2023-09-12 18:37:59 -04:00
|
|
|
{
|
|
|
|
graphic: "assets/images/cursor/cursor-cell.png",
|
|
|
|
scale: 1.0,
|
|
|
|
offsetX: -16,
|
|
|
|
offsetY: -16,
|
|
|
|
};
|
|
|
|
static var assetCursorCell:Null<BitmapData> = null;
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-09-12 18:37:59 -04:00
|
|
|
// DESIRED CURSOR: Resize NS (vertical)
|
|
|
|
// DESIRED CURSOR: Resize EW (horizontal)
|
|
|
|
// DESIRED CURSOR: Resize NESW (diagonal)
|
|
|
|
// DESIRED CURSOR: Resize NWSE (diagonal)
|
|
|
|
// DESIRED CURSOR: Help (Cursor with question mark)
|
|
|
|
// DESIRED CURSOR: Menu (Cursor with menu icon)
|
|
|
|
|
|
|
|
static function set_cursorMode(value:Null<CursorMode>):Null<CursorMode>
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-09-12 18:37:59 -04:00
|
|
|
if (value != null && cursorMode != value)
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
cursorMode = value;
|
|
|
|
setCursorGraphic(cursorMode);
|
|
|
|
}
|
|
|
|
return cursorMode;
|
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-09-12 18:37:59 -04:00
|
|
|
/**
|
|
|
|
* Synchronous.
|
|
|
|
*/
|
|
|
|
static function setCursorGraphic(?value:CursorMode = null):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
2023-09-12 18:37:59 -04:00
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
FlxG.mouse.unload();
|
|
|
|
return;
|
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-09-12 18:37:59 -04:00
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case Default:
|
|
|
|
if (assetCursorDefault == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_DEFAULT_PARAMS.graphic);
|
|
|
|
assetCursorDefault = bitmapData;
|
|
|
|
applyCursorParams(assetCursorDefault, CURSOR_DEFAULT_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorDefault, CURSOR_DEFAULT_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Cross:
|
|
|
|
if (assetCursorCross == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_CROSS_PARAMS.graphic);
|
|
|
|
assetCursorCross = bitmapData;
|
|
|
|
applyCursorParams(assetCursorCross, CURSOR_CROSS_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorCross, CURSOR_CROSS_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Eraser:
|
|
|
|
if (assetCursorEraser == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_ERASER_PARAMS.graphic);
|
|
|
|
assetCursorEraser = bitmapData;
|
|
|
|
applyCursorParams(assetCursorEraser, CURSOR_ERASER_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorEraser, CURSOR_ERASER_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Grabbing:
|
|
|
|
if (assetCursorGrabbing == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_GRABBING_PARAMS.graphic);
|
|
|
|
assetCursorGrabbing = bitmapData;
|
|
|
|
applyCursorParams(assetCursorGrabbing, CURSOR_GRABBING_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorGrabbing, CURSOR_GRABBING_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Hourglass:
|
|
|
|
if (assetCursorHourglass == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_HOURGLASS_PARAMS.graphic);
|
|
|
|
assetCursorHourglass = bitmapData;
|
|
|
|
applyCursorParams(assetCursorHourglass, CURSOR_HOURGLASS_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorHourglass, CURSOR_HOURGLASS_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Pointer:
|
|
|
|
if (assetCursorPointer == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_POINTER_PARAMS.graphic);
|
|
|
|
assetCursorPointer = bitmapData;
|
|
|
|
applyCursorParams(assetCursorPointer, CURSOR_POINTER_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorPointer, CURSOR_POINTER_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Text:
|
|
|
|
if (assetCursorText == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_TEXT_PARAMS.graphic);
|
|
|
|
assetCursorText = bitmapData;
|
|
|
|
applyCursorParams(assetCursorText, CURSOR_TEXT_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorText, CURSOR_TEXT_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case ZoomIn:
|
|
|
|
if (assetCursorZoomIn == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_ZOOM_IN_PARAMS.graphic);
|
|
|
|
assetCursorZoomIn = bitmapData;
|
|
|
|
applyCursorParams(assetCursorZoomIn, CURSOR_ZOOM_IN_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorZoomIn, CURSOR_ZOOM_IN_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case ZoomOut:
|
|
|
|
if (assetCursorZoomOut == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_ZOOM_OUT_PARAMS.graphic);
|
|
|
|
assetCursorZoomOut = bitmapData;
|
|
|
|
applyCursorParams(assetCursorZoomOut, CURSOR_ZOOM_OUT_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorZoomOut, CURSOR_ZOOM_OUT_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Crosshair:
|
|
|
|
if (assetCursorCrosshair == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_CROSSHAIR_PARAMS.graphic);
|
|
|
|
assetCursorCrosshair = bitmapData;
|
|
|
|
applyCursorParams(assetCursorCrosshair, CURSOR_CROSSHAIR_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorCrosshair, CURSOR_CROSSHAIR_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Cell:
|
|
|
|
if (assetCursorCell == null)
|
|
|
|
{
|
|
|
|
var bitmapData:BitmapData = Assets.getBitmapData(CURSOR_CELL_PARAMS.graphic);
|
|
|
|
assetCursorCell = bitmapData;
|
|
|
|
applyCursorParams(assetCursorCell, CURSOR_CELL_PARAMS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorCell, CURSOR_CELL_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
setCursorGraphic(null);
|
|
|
|
}
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-09-12 18:37:59 -04:00
|
|
|
/**
|
|
|
|
* Asynchronous.
|
|
|
|
*/
|
|
|
|
static function loadCursorGraphic(?value:CursorMode = null):Void
|
2023-01-22 22:25:45 -05:00
|
|
|
{
|
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
FlxG.mouse.unload();
|
|
|
|
return;
|
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case Default:
|
|
|
|
if (assetCursorDefault == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_DEFAULT_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorDefault = bitmapData;
|
|
|
|
applyCursorParams(assetCursorDefault, CURSOR_DEFAULT_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Default));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorDefault, CURSOR_DEFAULT_PARAMS);
|
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case Cross:
|
|
|
|
if (assetCursorCross == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_CROSS_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorCross = bitmapData;
|
|
|
|
applyCursorParams(assetCursorCross, CURSOR_CROSS_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Cross));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorCross, CURSOR_CROSS_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case Eraser:
|
|
|
|
if (assetCursorEraser == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_ERASER_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorEraser = bitmapData;
|
|
|
|
applyCursorParams(assetCursorEraser, CURSOR_ERASER_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Eraser));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorEraser, CURSOR_ERASER_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case Grabbing:
|
|
|
|
if (assetCursorGrabbing == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_GRABBING_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorGrabbing = bitmapData;
|
|
|
|
applyCursorParams(assetCursorGrabbing, CURSOR_GRABBING_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Grabbing));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorGrabbing, CURSOR_GRABBING_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case Hourglass:
|
|
|
|
if (assetCursorHourglass == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_HOURGLASS_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorHourglass = bitmapData;
|
|
|
|
applyCursorParams(assetCursorHourglass, CURSOR_HOURGLASS_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Hourglass));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorHourglass, CURSOR_HOURGLASS_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case Pointer:
|
|
|
|
if (assetCursorPointer == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_POINTER_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorPointer = bitmapData;
|
|
|
|
applyCursorParams(assetCursorPointer, CURSOR_POINTER_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Pointer));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorPointer, CURSOR_POINTER_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case Text:
|
|
|
|
if (assetCursorText == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_TEXT_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorText = bitmapData;
|
|
|
|
applyCursorParams(assetCursorText, CURSOR_TEXT_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(Text));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorText, CURSOR_TEXT_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case ZoomIn:
|
|
|
|
if (assetCursorZoomIn == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_ZOOM_IN_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorZoomIn = bitmapData;
|
|
|
|
applyCursorParams(assetCursorZoomIn, CURSOR_ZOOM_IN_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(ZoomIn));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorZoomIn, CURSOR_ZOOM_IN_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
case ZoomOut:
|
|
|
|
if (assetCursorZoomOut == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_ZOOM_OUT_PARAMS.graphic);
|
2023-06-08 16:30:45 -04:00
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
2023-01-22 22:25:45 -05:00
|
|
|
assetCursorZoomOut = bitmapData;
|
|
|
|
applyCursorParams(assetCursorZoomOut, CURSOR_ZOOM_OUT_PARAMS);
|
|
|
|
});
|
2023-09-12 18:37:59 -04:00
|
|
|
future.onError(onCursorError.bind(ZoomOut));
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorZoomOut, CURSOR_ZOOM_OUT_PARAMS);
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-09-12 18:37:59 -04:00
|
|
|
case Crosshair:
|
|
|
|
if (assetCursorCrosshair == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_CROSSHAIR_PARAMS.graphic);
|
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
|
|
|
assetCursorCrosshair = bitmapData;
|
|
|
|
applyCursorParams(assetCursorCrosshair, CURSOR_CROSSHAIR_PARAMS);
|
|
|
|
});
|
|
|
|
future.onError(onCursorError.bind(Crosshair));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorCrosshair, CURSOR_CROSSHAIR_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
case Cell:
|
|
|
|
if (assetCursorCell == null)
|
|
|
|
{
|
|
|
|
var future:Future<BitmapData> = Assets.loadBitmapData(CURSOR_CELL_PARAMS.graphic);
|
|
|
|
future.onComplete(function(bitmapData:BitmapData) {
|
|
|
|
assetCursorCell = bitmapData;
|
|
|
|
applyCursorParams(assetCursorCell, CURSOR_CELL_PARAMS);
|
|
|
|
});
|
|
|
|
future.onError(onCursorError.bind(Cell));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
applyCursorParams(assetCursorCell, CURSOR_CELL_PARAMS);
|
|
|
|
}
|
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
default:
|
2023-09-12 18:37:59 -04:00
|
|
|
loadCursorGraphic(null);
|
2023-01-22 22:25:45 -05:00
|
|
|
}
|
|
|
|
}
|
2022-11-08 17:28:09 -05:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
static inline function applyCursorParams(graphic:BitmapData, params:CursorParams):Void
|
|
|
|
{
|
|
|
|
FlxG.mouse.load(graphic, params.scale, params.offsetX, params.offsetY);
|
|
|
|
}
|
2023-09-12 18:37:59 -04:00
|
|
|
|
|
|
|
static function onCursorError(cursorMode:CursorMode, error:String):Void
|
|
|
|
{
|
|
|
|
trace("Failed to load cursor graphic for cursor mode " + cursorMode + ": " + error);
|
|
|
|
}
|
2023-10-31 14:43:01 -04:00
|
|
|
|
|
|
|
public static function registerHaxeUICursors():Void
|
|
|
|
{
|
|
|
|
CursorHelper.useCustomCursors = true;
|
|
|
|
registerHaxeUICursor('default', CURSOR_DEFAULT_PARAMS);
|
|
|
|
registerHaxeUICursor('cross', CURSOR_CROSS_PARAMS);
|
|
|
|
registerHaxeUICursor('eraser', CURSOR_ERASER_PARAMS);
|
|
|
|
registerHaxeUICursor('grabbing', CURSOR_GRABBING_PARAMS);
|
|
|
|
registerHaxeUICursor('hourglass', CURSOR_HOURGLASS_PARAMS);
|
|
|
|
registerHaxeUICursor('pointer', CURSOR_POINTER_PARAMS);
|
|
|
|
registerHaxeUICursor('text', CURSOR_TEXT_PARAMS);
|
|
|
|
registerHaxeUICursor('text-vertical', CURSOR_TEXT_VERTICAL_PARAMS);
|
|
|
|
registerHaxeUICursor('zoom-in', CURSOR_ZOOM_IN_PARAMS);
|
|
|
|
registerHaxeUICursor('zoom-out', CURSOR_ZOOM_OUT_PARAMS);
|
|
|
|
registerHaxeUICursor('crosshair', CURSOR_CROSSHAIR_PARAMS);
|
|
|
|
registerHaxeUICursor('cell', CURSOR_CELL_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function registerHaxeUICursor(id:String, params:CursorParams):Void
|
|
|
|
{
|
|
|
|
CursorHelper.registerCursor(id, params.graphic, params.scale, params.offsetX, params.offsetY);
|
|
|
|
}
|
2022-11-08 16:32:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
|
|
|
|
enum CursorMode
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
Default;
|
|
|
|
Cross;
|
|
|
|
Eraser;
|
|
|
|
Grabbing;
|
|
|
|
Hourglass;
|
|
|
|
Pointer;
|
|
|
|
Text;
|
|
|
|
ZoomIn;
|
|
|
|
ZoomOut;
|
2023-09-12 18:37:59 -04:00
|
|
|
Crosshair;
|
|
|
|
Cell;
|
2022-11-08 17:28:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static data describing how a cursor should be rendered.
|
|
|
|
*/
|
|
|
|
typedef CursorParams =
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
graphic:String,
|
|
|
|
scale:Float,
|
|
|
|
offsetX:Int,
|
|
|
|
offsetY:Int,
|
2022-11-08 16:32:00 -05:00
|
|
|
}
|