Search in sources :

Example 1 with SliderChangeValueEvent

use of com.spinyowl.legui.component.event.slider.SliderChangeValueEvent in project legui by SpinyOwl.

the class SliderMouseDragEventListener method process.

@Override
public void process(MouseDragEvent event) {
    Slider slider = (Slider) event.getTargetComponent();
    if (!Mouse.MouseButton.MOUSE_BUTTON_LEFT.isPressed()) {
        return;
    }
    // calculate new value
    float value = SliderHelper.determineSliderValue(slider, Mouse.getCursorPosition());
    // set value & push event
    float oldValue = slider.getValue();
    slider.setValue(value);
    EventProcessorProvider.getInstance().pushEvent(new SliderChangeValueEvent(slider, event.getContext(), event.getFrame(), oldValue, slider.getValue()));
}
Also used : Slider(com.spinyowl.legui.component.Slider) SliderChangeValueEvent(com.spinyowl.legui.component.event.slider.SliderChangeValueEvent)

Example 2 with SliderChangeValueEvent

use of com.spinyowl.legui.component.event.slider.SliderChangeValueEvent in project legui by SpinyOwl.

the class SliderMouseClickEventListener method process.

@Override
public void process(MouseClickEvent event) {
    if (!event.getButton().equals(Mouse.MouseButton.MOUSE_BUTTON_LEFT) || event.getAction() != MouseClickEvent.MouseClickAction.PRESS) {
        return;
    }
    Slider slider = (Slider) event.getTargetComponent();
    // calculate new value
    float value = SliderHelper.determineSliderValue(slider, Mouse.getCursorPosition());
    // set value & push event
    float oldValue = slider.getValue();
    slider.setValue(value);
    EventProcessorProvider.getInstance().pushEvent(new SliderChangeValueEvent(slider, event.getContext(), event.getFrame(), oldValue, slider.getValue()));
}
Also used : Slider(com.spinyowl.legui.component.Slider) SliderChangeValueEvent(com.spinyowl.legui.component.event.slider.SliderChangeValueEvent)

Example 3 with SliderChangeValueEvent

use of com.spinyowl.legui.component.event.slider.SliderChangeValueEvent in project legui by SpinyOwl.

the class SliderScrollEventListener method process.

@Override
public void process(ScrollEvent event) {
    Slider slider = (Slider) event.getTargetComponent();
    float oldValue = slider.getValue();
    float newValue = oldValue;
    // respect step size
    if (slider.getStepSize() > 0f) {
        newValue = newValue + slider.getStepSize() * (float) event.getYoffset();
    } else {
        newValue = newValue + (float) event.getYoffset();
    }
    // check for min/max values
    if (newValue > slider.getMaxValue()) {
        newValue = slider.getMaxValue();
    }
    if (newValue < slider.getMinValue()) {
        newValue = slider.getMinValue();
    }
    // set value & push event
    slider.setValue(newValue);
    EventProcessorProvider.getInstance().pushEvent(new SliderChangeValueEvent(slider, event.getContext(), event.getFrame(), oldValue, newValue));
}
Also used : Slider(com.spinyowl.legui.component.Slider) SliderChangeValueEvent(com.spinyowl.legui.component.event.slider.SliderChangeValueEvent)

Aggregations

Slider (com.spinyowl.legui.component.Slider)3 SliderChangeValueEvent (com.spinyowl.legui.component.event.slider.SliderChangeValueEvent)3