scrolling for touchpad fix

This commit is contained in:
RandomityGuy 2023-05-28 01:04:49 +05:30
parent e058f28865
commit 27a8f8f18b
4 changed files with 14 additions and 3 deletions

View file

@ -4,5 +4,9 @@
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<false/> <false/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict> </dict>
</plist> </plist>

View file

@ -49,6 +49,8 @@ class MarbleGame {
var consoleShown:Bool = false; var consoleShown:Bool = false;
var console:ConsoleDlg; var console:ConsoleDlg;
var _mouseWheelDelta:Float;
public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) { public function new(scene2d:h2d.Scene, scene:h3d.scene.Scene) {
Console.log("Initializing the game..."); Console.log("Initializing the game...");
canvas = new Canvas(scene2d, cast this); canvas = new Canvas(scene2d, cast this);
@ -169,6 +171,9 @@ class MarbleGame {
Window.getInstance().removeEventTarget(@:privateAccess Key.onEvent); Window.getInstance().removeEventTarget(@:privateAccess Key.onEvent);
#end #end
scene2d.addEventListener(e -> {
_mouseWheelDelta = e.wheelDelta;
});
} }
public function update(dt:Float) { public function update(dt:Float) {
@ -207,7 +212,8 @@ class MarbleGame {
} }
var mouseState:MouseState = { var mouseState:MouseState = {
position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY) position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY),
wheel: _mouseWheelDelta
} }
ProfilerUI.measure("canvasUpdate"); ProfilerUI.measure("canvasUpdate");
canvas.update(dt, mouseState); canvas.update(dt, mouseState);

View file

@ -33,6 +33,7 @@ enum VertSizing {
typedef MouseState = { typedef MouseState = {
var position:Vector; var position:Vector;
var ?button:Int; var ?button:Int;
var ?wheel:Float;
} }
@:publicFields @:publicFields

View file

@ -242,14 +242,14 @@ class GuiScrollCtrl extends GuiControl {
} }
public override function update(dt:Float, mouseState:MouseState) { public override function update(dt:Float, mouseState:MouseState) {
if (Key.isPressed(Key.MOUSE_WHEEL_DOWN)) { if (Key.isPressed(Key.MOUSE_WHEEL_DOWN) && Math.abs(mouseState.wheel) >= 1) {
var renderRect = this.getRenderRectangle(); var renderRect = this.getRenderRectangle();
var scrollBarYSize = renderRect.extent.y * renderRect.extent.y / (maxScrollY * Settings.uiScale); var scrollBarYSize = renderRect.extent.y * renderRect.extent.y / (maxScrollY * Settings.uiScale);
this.scrollY += scrollBarYSize / 10; this.scrollY += scrollBarYSize / 10;
deltaY = scrollBarYSize / 10; deltaY = scrollBarYSize / 10;
this.updateScrollVisual(); this.updateScrollVisual();
} }
if (Key.isPressed(Key.MOUSE_WHEEL_UP)) { if (Key.isPressed(Key.MOUSE_WHEEL_UP) && Math.abs(mouseState.wheel) >= 1) {
var renderRect = this.getRenderRectangle(); var renderRect = this.getRenderRectangle();
var scrollBarYSize = renderRect.extent.y * renderRect.extent.y / (maxScrollY * Settings.uiScale); var scrollBarYSize = renderRect.extent.y * renderRect.extent.y / (maxScrollY * Settings.uiScale);
this.scrollY -= scrollBarYSize / 10; this.scrollY -= scrollBarYSize / 10;