1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-16 03:43:36 +00:00
Funkin/source/funkin/util/MouseUtil.hx

49 lines
1.4 KiB
Haxe
Raw Normal View History

package funkin.util;
import flixel.math.FlxPoint;
/**
* Utility functions related to the mouse.
*/
class MouseUtil
{
static var oldCamPos:FlxPoint = new FlxPoint();
static var oldMousePos:FlxPoint = new FlxPoint();
/**
* Used to be for general camera middle click dragging, now generalized for any click and drag type shit!
* Listen I don't make the rules here
* @param target what you want to be dragged, defaults to CAMERA SCROLL
* @param jusPres the "justPressed", should be a button of some sort
* @param pressed the "pressed", which should be the same button as `jusPres`
*/
public static function mouseCamDrag(?target:FlxPoint, ?jusPres:Bool, ?pressed:Bool):Void
{
if (target == null) target = FlxG.camera.scroll;
if (jusPres == null) jusPres = FlxG.mouse.justPressedMiddle;
if (pressed == null) pressed = FlxG.mouse.pressedMiddle;
if (jusPres)
{
oldCamPos.set(target.x, target.y);
oldMousePos.set(FlxG.mouse.screenX, FlxG.mouse.screenY);
}
if (pressed)
{
target.x = oldCamPos.x - (FlxG.mouse.screenX - oldMousePos.x);
target.y = oldCamPos.y - (FlxG.mouse.screenY - oldMousePos.y);
}
}
2024-03-17 02:20:22 +00:00
/**
* Increment the zoom level of the current camera by the mouse wheel scroll value.
*/
public static function mouseWheelZoom():Void
{
if (FlxG.mouse.wheel != 0) FlxG.camera.zoom += FlxG.mouse.wheel * (0.1 * FlxG.camera.zoom);
}
}