Skip to content

Commit

Permalink
Merge pull request #32 from Sword352/master
Browse files Browse the repository at this point in the history
Better way to load mouse graphics and add `mouseLoadFunction` to dynamically be able to change the way to load them
  • Loading branch information
ianharrigan authored Dec 23, 2023
2 parents 1bc0401 + cb504c6 commit 7a517d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions haxe/ui/backend/ScreenImpl.hx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class ScreenImpl extends ScreenBase {
_cursor = cursor;
if (CursorHelper.hasCursor(_cursor)) {
var cursorInfo = CursorHelper.registeredCursors.get(_cursor);
FlxG.mouse.load(new FlxSprite().loadGraphic(cursorInfo.graphic).pixels, cursorInfo.scale, cursorInfo.offsetX, cursorInfo.offsetY);
FlxG.mouse.load(CursorHelper.mouseLoadFunction(cursorInfo.graphic), cursorInfo.scale, cursorInfo.offsetX, cursorInfo.offsetY);
} else if (openfl.Assets.exists(_cursor)) {
FlxG.mouse.load(new FlxSprite().loadGraphic(_cursor).pixels, 1, offsetX, offsetY);
FlxG.mouse.load(CursorHelper.mouseLoadFunction(_cursor), 1, offsetX, offsetY);
} else {
FlxG.mouse.load(null);
}
Expand Down
12 changes: 11 additions & 1 deletion haxe/ui/backend/flixel/CursorHelper.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package haxe.ui.backend.flixel;

import openfl.display.BitmapData;

class CursorHelper {
public static var useCustomCursors:Bool = true;
public static var registeredCursors:Map<String, CursorInfo> = new Map<String, CursorInfo>();

public static var mouseLoadFunction(default, set):String->BitmapData = (bmd) -> openfl.Assets.getBitmapData(bmd);
static function set_mouseLoadFunction(v:String->BitmapData):String->BitmapData {
if (v == null)
return mouseLoadFunction;

return mouseLoadFunction = v;
}

public static function registerCursor(name:String, graphic:String, scale:Float = 1, offsetX:Int = 0, offsetY:Int = 0) {
registeredCursors.set(name, {
name: name,
Expand Down Expand Up @@ -46,4 +56,4 @@ private typedef CursorInfo = {
var scale:Float;
var offsetX:Int;
var offsetY:Int;
}
}

0 comments on commit 7a517d5

Please sign in to comment.