mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-02-23 14:41:02 +00:00
37 lines
1.1 KiB
Haxe
37 lines
1.1 KiB
Haxe
package gui;
|
|
|
|
import h2d.Scene;
|
|
import hxd.snd.Channel;
|
|
import hxd.res.Sound;
|
|
import hxd.Key;
|
|
import gui.GuiControl.MouseState;
|
|
import src.Util;
|
|
import src.Settings;
|
|
|
|
class GuiSlider extends GuiImage {
|
|
public var sliderValue:Float = 0;
|
|
|
|
public var slidingSound:Channel;
|
|
public var enabled:Bool = true;
|
|
|
|
public override function update(dt:Float, mouseState:MouseState) {
|
|
var renderRect = getRenderRectangle();
|
|
if (renderRect.inRect(mouseState.position) && enabled) {
|
|
if (Key.isDown(Key.MOUSE_LEFT)) {
|
|
sliderValue = (mouseState.position.x - renderRect.position.x - bmp.width / 2) / renderRect.extent.x;
|
|
sliderValue = Util.clamp(sliderValue, 0, 1);
|
|
|
|
if (this.pressedAction != null)
|
|
this.pressedAction(new GuiEvent(this));
|
|
|
|
if (slidingSound != null)
|
|
slidingSound.pause = false;
|
|
}
|
|
} else if (slidingSound != null)
|
|
slidingSound.pause = true;
|
|
this.bmp.x = renderRect.position.x + renderRect.extent.x * sliderValue;
|
|
this.bmp.x = Util.clamp(this.bmp.x, renderRect.position.x, renderRect.position.x + renderRect.extent.x - bmp.width / 2);
|
|
this.bmp.width = this.bmp.tile.width * Settings.uiScale;
|
|
super.update(dt, mouseState);
|
|
}
|
|
}
|