Skip to content

Commit

Permalink
Flixel 5.9.0 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Jul 10, 2024
1 parent cdeb0de commit 28c997f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
23 changes: 17 additions & 6 deletions flixel/addons/display/FlxExtendedMouseSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class FlxExtendedMouseSprite extends FlxSprite
* Returns how many vertical pixels the mouse pointer is inside this sprite from the top left corner. Returns -1 if outside.
*/
public var mouseY(get, never):Int;
var viewX(get, never):Int;
var viewY(get, never):Int;
#end

var _snapOnDrag:Bool = false;
Expand Down Expand Up @@ -549,14 +551,14 @@ class FlxExtendedMouseSprite extends FlxSprite
if (_allowHorizontalDrag)
{
#if FLX_MOUSE
x = Math.floor(FlxG.mouse.screenX + scrollFactor.x * (FlxG.mouse.x - FlxG.mouse.screenX)) - _dragOffsetX;
x = Math.floor(viewX + scrollFactor.x * (FlxG.mouse.x - viewX)) - _dragOffsetX;
#end
}

if (_allowVerticalDrag)
{
#if FLX_MOUSE
y = Math.floor(FlxG.mouse.screenY + scrollFactor.y * (FlxG.mouse.y - FlxG.mouse.screenY)) - _dragOffsetY;
y = Math.floor(viewY + scrollFactor.y * (FlxG.mouse.y - viewY)) - _dragOffsetY;
#end
}

Expand Down Expand Up @@ -657,8 +659,8 @@ class FlxExtendedMouseSprite extends FlxSprite
#if FLX_MOUSE
if (_dragFromPoint == false)
{
_dragOffsetX = Math.floor(FlxG.mouse.screenX + scrollFactor.x * (FlxG.mouse.x - FlxG.mouse.screenX) - x);
_dragOffsetY = Math.floor(FlxG.mouse.screenY + scrollFactor.y * (FlxG.mouse.y - FlxG.mouse.screenY) - y);
_dragOffsetX = Math.floor(viewX + scrollFactor.x * (FlxG.mouse.x - viewX) - x);
_dragOffsetY = Math.floor(viewY + scrollFactor.y * (FlxG.mouse.y - viewY) - y);
}
else
{
Expand Down Expand Up @@ -828,8 +830,8 @@ class FlxExtendedMouseSprite extends FlxSprite
#if FLX_MOUSE
function get_mouseOver():Bool
{
return FlxMath.pointInCoordinates(Math.floor(FlxG.mouse.screenX + scrollFactor.x * (FlxG.mouse.x - FlxG.mouse.screenX)),
Math.floor(FlxG.mouse.screenY + scrollFactor.y * (FlxG.mouse.y - FlxG.mouse.screenY)), Math.floor(x), Math.floor(y), Math.floor(width),
return FlxMath.pointInCoordinates(Math.floor(viewX + scrollFactor.x * (FlxG.mouse.x - viewX)),
Math.floor(viewY + scrollFactor.y * (FlxG.mouse.y - viewY)), Math.floor(x), Math.floor(y), Math.floor(width),
Math.floor(height));
}

Expand All @@ -852,6 +854,15 @@ class FlxExtendedMouseSprite extends FlxSprite

return -1;
}
inline function get_viewX():Int
{
return #if (flixel < version("5.9.0")) FlxG.mouse.screenX #else FlxG.mouse.viewX #end;
}

inline function get_viewY():Int
{
return #if (flixel < version("5.9.0")) FlxG.mouse.screenY #else FlxG.mouse.viewY #end;
}
#end

inline function get_rect():FlxRect
Expand Down
14 changes: 10 additions & 4 deletions flixel/addons/ui/FlxSlider.hx
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,17 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon
override public function update(elapsed:Float):Void
{
// Clicking and sound logic
#if (flixel >= "5.7.0")
#if (flixel >= version("5.7.0"))
final camera = getCameras()[0];// else use this.camera
#end
final mouse = FlxG.mouse.getScreenPosition(camera);
if (FlxMath.pointInFlxRect(mouse.x, mouse.y, _bounds))
#if (flixel >= version("5.9.0"))
final viewX = FlxG.mouse.viewX;
final viewY = FlxG.mouse.viewY;
#else
final viewX = FlxG.mouse.screenX;
final viewY = FlxG.mouse.screenY;
#end
if (FlxMath.pointInFlxRect(viewX, viewY, _bounds))
{
if (hoverAlpha != 1)
{
Expand All @@ -293,7 +299,7 @@ class FlxSlider extends #if (flixel < "5.7.0") FlxSpriteGroup #else FlxSpriteCon

if (FlxG.mouse.pressed)
{
handle.x = FlxG.mouse.screenX;
handle.x = viewX;
updateValue();

#if FLX_SOUND_SYSTEM
Expand Down

0 comments on commit 28c997f

Please sign in to comment.