fixed strumline drop down with different zooms

This commit is contained in:
TheZoroForce240
2024-08-03 16:48:29 +01:00
parent 00dde96956
commit 7914603009
2 changed files with 25 additions and 1 deletions
+21
View File
@@ -37,6 +37,7 @@ import haxe.io.Path;
import haxe.xml.Access;
import lime.utils.Assets;
import openfl.geom.ColorTransform;
import flixel.math.FlxPoint;
using StringTools;
@@ -846,6 +847,26 @@ class CoolUtil
return angle - diff;
}
/**
* Returns the screen position of an object, while taking the camera zoom into account.
*
* @param object Any `FlxObject`
* @param camera The desired "screen" coordinate space. If `null`, `FlxG.camera` is used.
* @param result Optional arg for the returning point
* @return The screen position of the object.
*/
public static function worldToScreenPosition(object:FlxObject, ?camera:FlxCamera, ?result:FlxPoint) {
if (result == null)
result = FlxPoint.get();
if (camera == null)
camera = FlxG.camera;
result.set(object.x, object.y);
result.x = (((result.x - camera.scroll.x * object.scrollFactor.x) * camera.zoom) - ((camera.width * 0.5) * (camera.zoom - camera.initialZoom)));
result.y = (((result.y - camera.scroll.y * object.scrollFactor.y) * camera.zoom) - ((camera.height * 0.5) * (camera.zoom - camera.initialZoom)));
return result;
}
public static function sortAlphabetically(array:Array<String>, ?lowercase:Bool=false) {
array.sort(function(a1, a2):Int {
if(lowercase) {
@@ -203,6 +203,9 @@ class CharterStrumlineOptions extends UITopMenuButton {
contextMenu.insert(1+Charter.waveformHandler.waveformList.length, null);
super.openContextMenu();
var cam = Charter.instance.charterCamera;
var point = CoolUtil.worldToScreenPosition(this, cam);
curMenu = UIState.state.openContextMenu(contextMenu, null, point.x, point.y + (bHeight*cam.zoom), Std.int(bWidth * cam.zoom));
point.put();
}
}