Search in sources :

Example 1 with ChangeSizeEvent

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

the class WidgetResizeButtonDragListener method process.

/**
 * Used to handle {@link MouseDragEvent}.
 *
 * @param event event to handle.
 */
@Override
public void process(MouseDragEvent event) {
    Vector2f delta = event.getDelta();
    Vector2f cursorPositionPrev = Mouse.getCursorPositionPrev();
    Vector2f cursorPosition = Mouse.getCursorPosition();
    float xx = widget.getSize().x + delta.x;
    float yy = widget.getSize().y + delta.y;
    Vector2f deltaSize = new Vector2f();
    Length minWidthU = widget.getStyle().getMinWidth();
    if (minWidthU == null) {
        minWidthU = pixel(1f);
    }
    Length minHeightU = widget.getStyle().getMinHeight();
    if (minHeightU == null) {
        minHeightU = pixel(widget.getTitleContainer().getSize().y);
    }
    Length maxWidthU = widget.getStyle().getMaxWidth();
    Length maxHeightU = widget.getStyle().getMaxHeight();
    Float minWidth = StyleUtilities.getFloatLength(minWidthU, widget.getParent().getSize().x);
    Float minHeight = StyleUtilities.getFloatLength(minHeightU, widget.getParent().getSize().y);
    Float maxWidth = StyleUtilities.getFloatLength(maxWidthU, widget.getParent().getSize().x);
    Float maxHeight = StyleUtilities.getFloatLength(maxHeightU, widget.getParent().getSize().y);
    if ((delta.x < 0 && (cursorPositionPrev.x <= resizeButton.getAbsolutePosition().x + resizeButton.getSize().x || cursorPosition.x <= resizeButton.getAbsolutePosition().x + resizeButton.getSize().x)) || ((delta.x > 0 && (cursorPositionPrev.x >= resizeButton.getAbsolutePosition().x || cursorPosition.x >= resizeButton.getAbsolutePosition().x)))) {
        if (xx >= minWidth && (maxWidth == null || xx <= maxWidth)) {
            deltaSize.x = delta.x;
        }
    }
    if ((delta.y < 0 && (cursorPositionPrev.y <= resizeButton.getAbsolutePosition().y + resizeButton.getSize().y || cursorPosition.y <= resizeButton.getAbsolutePosition().y + resizeButton.getSize().y)) || ((delta.y > 0 && (cursorPositionPrev.y >= resizeButton.getAbsolutePosition().y || cursorPosition.y >= resizeButton.getAbsolutePosition().y)))) {
        if (yy >= minHeight && (maxHeight == null || yy <= maxHeight)) {
            deltaSize.y = delta.y;
        }
    }
    Vector2f oldSize = new Vector2f(widget.getSize());
    widget.getSize().add(deltaSize);
    Vector2f newSize = widget.getSize();
    if (!oldSize.equals(newSize, THRESHOLD)) {
        EventProcessorProvider.getInstance().pushEvent(new ChangeSizeEvent(widget, event.getContext(), event.getFrame(), oldSize, newSize));
    }
}
Also used : Length(com.spinyowl.legui.style.length.Length) Vector2f(org.joml.Vector2f) ChangeSizeEvent(com.spinyowl.legui.component.event.component.ChangeSizeEvent)

Aggregations

ChangeSizeEvent (com.spinyowl.legui.component.event.component.ChangeSizeEvent)1 Length (com.spinyowl.legui.style.length.Length)1 Vector2f (org.joml.Vector2f)1