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);
}
}
}
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());
}
}
}
Aggregations