Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/HaxeFlixel/flixel into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Nov 21, 2023
2 parents ecdc994 + c234196 commit 98eade7
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions flixel/input/mouse/FlxMouse.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
* sits at the right "height". Not used on flash with the native cursor API.
*/
public var cursorContainer(default, null):Sprite;

/**
* The current cursor bitmap, if there is one. To set, use the `load` function.
*/
public var cursor(default, null):Null<Bitmap>;

/**
* Used to toggle the visiblity of the mouse cursor - works on both
Expand Down Expand Up @@ -192,11 +197,8 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
var _rightButton:FlxMouseButton;
#end

/**
* This is just a reference to the current cursor image, if there is one.
*/
var _cursor:Bitmap = null;

@:deprecated("_cursor is deprecated, use the new, public cursor, instead")
var _cursor(get, set):Bitmap;
var _cursorBitmapData:BitmapData;
var _wheelUsed:Bool = false;
var _visibleWhenFocusLost:Bool = true;
Expand Down Expand Up @@ -244,9 +246,9 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
public function load(?Graphic:Dynamic, Scale:Float = 1, XOffset:Int = 0, YOffset:Int = 0):Void
{
#if !FLX_NATIVE_CURSOR
if (_cursor != null)
if (cursor != null)
{
FlxDestroyUtil.removeChild(cursorContainer, _cursor);
FlxDestroyUtil.removeChild(cursorContainer, cursor);
}
#end

Expand All @@ -257,25 +259,25 @@ class FlxMouse extends FlxPointer implements IFlxInputManager

if ((Graphic is Class))
{
_cursor = Type.createInstance(Graphic, []);
cursor = Type.createInstance(Graphic, []);
}
else if ((Graphic is BitmapData))
{
_cursor = new Bitmap(cast Graphic);
cursor = new Bitmap(cast Graphic);
}
else if ((Graphic is String))
{
_cursor = new Bitmap(FlxAssets.getBitmapData(Graphic));
cursor = new Bitmap(FlxAssets.getBitmapData(Graphic));
}
else
{
_cursor = new Bitmap(new GraphicCursor(0, 0));
cursor = new Bitmap(new GraphicCursor(0, 0));
}

_cursor.x = XOffset;
_cursor.y = YOffset;
_cursor.scaleX = Scale;
_cursor.scaleY = Scale;
cursor.x = XOffset;
cursor.y = YOffset;
cursor.scaleX = Scale;
cursor.scaleY = Scale;

#if FLX_NATIVE_CURSOR
if (XOffset < 0 || YOffset < 0)
Expand All @@ -288,8 +290,8 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
throw "Negative scale isn't supported for native cursors.";
}

var scaledWidth:Int = Std.int(Scale * _cursor.bitmapData.width);
var scaledHeight:Int = Std.int(Scale * _cursor.bitmapData.height);
var scaledWidth:Int = Std.int(Scale * cursor.bitmapData.width);
var scaledHeight:Int = Std.int(Scale * cursor.bitmapData.height);

var bitmapWidth:Int = scaledWidth + XOffset;
var bitmapHeight:Int = scaledHeight + YOffset;
Expand All @@ -301,10 +303,10 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
_matrix.scale(Scale, Scale);
_matrix.translate(XOffset, YOffset);
}
cursorBitmap.draw(_cursor.bitmapData, _matrix);
cursorBitmap.draw(cursor.bitmapData, _matrix);
setSimpleNativeCursorData(_cursorDefaultName, cursorBitmap);
#else
cursorContainer.addChild(_cursor);
cursorContainer.addChild(cursor);
#end
}

Expand All @@ -314,15 +316,15 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
*/
public function unload():Void
{
if (_cursor != null)
if (cursor != null)
{
if (cursorContainer.visible)
{
load();
}
else
{
_cursor = FlxDestroyUtil.removeChild(cursorContainer, _cursor);
cursor = FlxDestroyUtil.removeChild(cursorContainer, cursor);
}
}
}
Expand Down Expand Up @@ -419,7 +421,7 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
}

cursorContainer = null;
_cursor = null;
cursor = null;

#if FLX_NATIVE_CURSOR
_matrix = null;
Expand Down Expand Up @@ -693,7 +695,7 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
}
else
{
if (_cursor == null)
if (cursor == null)
load();

#if FLX_NATIVE_CURSOR
Expand Down Expand Up @@ -756,5 +758,15 @@ class FlxMouse extends FlxPointer implements IFlxInputManager
_globalScreenY = record.y;
updatePositions();
}

inline function get__cursor()
{
return cursor;
}

inline function set__cursor(value:Bitmap)
{
return cursor = value;
}
}
#end

0 comments on commit 98eade7

Please sign in to comment.