Search in sources :

Example 1 with CursorEnterEvent

use of com.spinyowl.legui.event.CursorEnterEvent in project legui by SpinyOwl.

the class CursorPosEventHandler method preHandle.

/**
 * Pre-handles {@link SystemCursorPosEvent} event.
 *
 * @param event   event which should be pre-processed.
 * @param frame   target frame for event.
 * @param context context
 */
protected void preHandle(SystemCursorPosEvent event, Frame frame, Context context) {
    Vector2f cursorPosition = new Vector2f(event.fx, event.fy);
    Mouse.setCursorPositionPrev(new Vector2f(Mouse.getCursorPosition()));
    Mouse.setCursorPosition(cursorPosition);
    List<Layer> allLayers = frame.getAllLayers();
    Collections.reverse(allLayers);
    Component targetComponent = null;
    for (Layer layer : allLayers) {
        if (!layer.isEventReceivable() || !layer.isVisible() || !layer.isEnabled()) {
            continue;
        }
        targetComponent = SehUtil.getTargetComponent(layer, cursorPosition);
        if (targetComponent != null || !layer.isEventPassable()) {
            break;
        }
    }
    Component prevTarget = context.getMouseTargetGui();
    context.setMouseTargetGui(targetComponent);
    if (targetComponent != prevTarget) {
        if (targetComponent != null) {
            targetComponent.setHovered(true);
            Vector2f curPosInComponent = targetComponent.getAbsolutePosition().sub(cursorPosition).negate();
            CursorEnterEvent enterEvent = new CursorEnterEvent(targetComponent, context, frame, true, curPosInComponent, cursorPosition);
            EventProcessorProvider.getInstance().pushEvent(enterEvent);
        }
        if (prevTarget != null) {
            Vector2f curPosInPrevTarget = prevTarget.getAbsolutePosition().sub(cursorPosition).negate();
            CursorEnterEvent exitEvent = new CursorEnterEvent(prevTarget, context, frame, false, curPosInPrevTarget, cursorPosition);
            EventProcessorProvider.getInstance().pushEvent(exitEvent);
            prevTarget.setHovered(false);
        }
    }
}
Also used : Vector2f(org.joml.Vector2f) CursorEnterEvent(com.spinyowl.legui.event.CursorEnterEvent) Component(com.spinyowl.legui.component.Component) Layer(com.spinyowl.legui.component.Layer)

Example 2 with CursorEnterEvent

use of com.spinyowl.legui.event.CursorEnterEvent in project legui by SpinyOwl.

the class SplitPanelSeparatorListenerDelegate method process.

/**
 * Used to handle specific event.
 *
 * @param event event to handle.
 */
@Override
public void process(Event event) {
    if (!event.getTargetComponent().equals(splitPanel.getSeparator())) {
        return;
    }
    if (event instanceof MouseClickEvent) {
        MouseClickEvent e = (MouseClickEvent) event;
        if (e.getAction() == PRESS) {
            dragging = true;
        }
        if (e.getAction() == RELEASE) {
            dragging = false;
            CursorServiceProvider.getInstance().setCursor(Cursor.ARROW, e.getContext());
        }
    }
    if (event instanceof CursorEnterEvent) {
        CursorEnterEvent e = (CursorEnterEvent) event;
        Orientation orientation = splitPanel.getOrientation();
        if (e.isEntered() && orientation == HORIZONTAL) {
            CursorServiceProvider.getInstance().setCursor(Cursor.H_RESIZE, e.getContext());
        } else if (e.isEntered() && orientation != HORIZONTAL) {
            CursorServiceProvider.getInstance().setCursor(Cursor.V_RESIZE, e.getContext());
        } else if (!dragging) {
            CursorServiceProvider.getInstance().setCursor(Cursor.ARROW, e.getContext());
        }
    }
}
Also used : CursorEnterEvent(com.spinyowl.legui.event.CursorEnterEvent) Orientation(com.spinyowl.legui.component.optional.Orientation) MouseClickEvent(com.spinyowl.legui.event.MouseClickEvent)

Aggregations

CursorEnterEvent (com.spinyowl.legui.event.CursorEnterEvent)2 Component (com.spinyowl.legui.component.Component)1 Layer (com.spinyowl.legui.component.Layer)1 Orientation (com.spinyowl.legui.component.optional.Orientation)1 MouseClickEvent (com.spinyowl.legui.event.MouseClickEvent)1 Vector2f (org.joml.Vector2f)1