Skip to content

Commit

Permalink
Separate event types
Browse files Browse the repository at this point in the history
Separate events into input and output types.

Affects: #46
  • Loading branch information
io7m committed Dec 8, 2023
1 parent 91a3faf commit 6028711
Show file tree
Hide file tree
Showing 65 changed files with 308 additions and 443 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.jsycamore.api.events;

import com.io7m.jsycamore.api.keyboard.SyKeyEventType;
import com.io7m.jsycamore.api.mouse.SyMouseEventType;

/**
* The type of events that the system accepts as input.
*/

public sealed interface SyEventInputType
extends SyEventType
permits SyKeyEventType,
SyMouseEventType
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.jsycamore.api.events;

import com.io7m.jsycamore.api.menus.SyMenuEventType;
import com.io7m.jsycamore.api.windows.SyWindowEventType;

/**
* The type of events that the system produces as output.
*/

public sealed interface SyEventOutputType
extends SyEventType
permits SyMenuEventType,
SyWindowEventType
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public interface SyEventReceiverType
* @return A value indicating if the event was understood and consumed
*/

SyEventConsumed eventSend(SyEventType event);
SyEventConsumed eventSend(SyEventInputType event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@

package com.io7m.jsycamore.api.events;

import com.io7m.jsycamore.api.keyboard.SyKeyEventType;
import com.io7m.jsycamore.api.menus.SyMenuEventType;
import com.io7m.jsycamore.api.mouse.SyMouseEventType;
import com.io7m.jsycamore.api.windows.SyWindowEventType;

/**
* The base type of events used by the UI.
*/

public sealed interface SyEventType
permits SyKeyEventType,
SyMenuEventType,
SyMouseEventType,
SyWindowEventType
permits SyEventInputType,
SyEventOutputType
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package com.io7m.jsycamore.api.keyboard;

import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;

/**
* The type of key events.
*/

public sealed interface SyKeyEventType
extends SyEventType
extends SyEventInputType
permits SyKeyEventModifierPressed,
SyKeyEventModifierReleased,
SyKeyEventPressed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package com.io7m.jsycamore.api.menus;

import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventOutputType;

/**
* The type of events relating to menus.
*/

public sealed interface SyMenuEventType
extends SyEventType
extends SyEventOutputType
permits SyMenuClosed,
SyMenuOpened
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package com.io7m.jsycamore.api.mouse;

import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;

/**
* The base type of mouse events.
*/

public sealed interface SyMouseEventType extends SyEventType
public sealed interface SyMouseEventType
extends SyEventInputType
permits SyMouseEventOnHeld,
SyMouseEventOnNoLongerOver,
SyMouseEventOnOver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package com.io7m.jsycamore.api.windows;

import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventOutputType;

/**
* The type of events relating to windows.
*/

public sealed interface SyWindowEventType
extends SyEventType
extends SyEventOutputType
permits SyWindowBecameInvisible,
SyWindowBecameVisible,
SyWindowClosed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.io7m.jsycamore.api.components.SyComponentReadableType;
import com.io7m.jsycamore.api.components.SyComponentType;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnNoLongerOver;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnOver;
import com.io7m.jsycamore.api.screens.SyScreenType;
Expand Down Expand Up @@ -253,15 +253,15 @@ public final Optional<SyWindowReadableType> windowReadable()

@Override
public final SyEventConsumed eventSend(
final SyEventType event)
final SyEventInputType event)
{
/*
* Only deliver the event to this component if it is active.
*/

SyEventConsumed consumed = EVENT_CONSUMED;
if (this.isActive()) {
consumed = this.onEvent(event);
consumed = this.onEventInput(event);
}

/*
Expand Down Expand Up @@ -301,7 +301,7 @@ public final SyEventConsumed eventSend(
* @return {@code true} if the event has been consumed
*/

protected abstract SyEventConsumed onEvent(SyEventType event);
protected abstract SyEventConsumed onEventInput(SyEventInputType event);

@Override
public final Optional<SyComponentType> componentForWindowRelative(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.io7m.jattribute.core.AttributeType;
import com.io7m.jsycamore.api.components.SyImageViewType;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.screens.SyScreenType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

Expand Down Expand Up @@ -68,8 +68,8 @@ public SyImageView(final SyScreenType inScreen)
}

@Override
protected SyEventConsumed onEvent(
final SyEventType event)
protected SyEventConsumed onEventInput(
final SyEventInputType event)
{
return EVENT_NOT_CONSUMED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.io7m.jsycamore.api.components.SyContainerType;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.screens.SyScreenType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

Expand All @@ -43,8 +43,8 @@ protected SyLayoutAbstract(
}

@Override
protected final SyEventConsumed onEvent(
final SyEventType event)
protected final SyEventConsumed onEventInput(
final SyEventInputType event)
{
return EVENT_NOT_CONSUMED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.io7m.jregions.core.parameterized.sizes.PAreaSizeI;
import com.io7m.jsycamore.api.components.SyConstraints;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.layout.SyLayoutContextType;
import com.io7m.jsycamore.api.menus.SyMenuItemAtomType;
import com.io7m.jsycamore.api.menus.SyMenuItemSeparatorType;
Expand Down Expand Up @@ -234,8 +234,8 @@ public List<SyMenuItemType> items()
}

@Override
protected SyEventConsumed onEvent(
final SyEventType event)
protected SyEventConsumed onEventInput(
final SyEventInputType event)
{
return EVENT_NOT_CONSUMED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
import com.io7m.jsycamore.api.components.SyConstraints;
import com.io7m.jsycamore.api.components.SyTextViewType;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.keyboard.SyKeyEventType;
import com.io7m.jsycamore.api.layout.SyLayoutContextType;
import com.io7m.jsycamore.api.menus.SyMenuBarItemType;
import com.io7m.jsycamore.api.menus.SyMenuBarType;
import com.io7m.jsycamore.api.menus.SyMenuSelected;
import com.io7m.jsycamore.api.menus.SyMenuType;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnHeld;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnNoLongerOver;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnOver;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnPressed;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnReleased;
import com.io7m.jsycamore.api.screens.SyScreenType;
import com.io7m.jsycamore.api.spaces.SySpaceParentRelativeType;
import com.io7m.jsycamore.api.spaces.SySpaceViewportType;
Expand Down Expand Up @@ -99,8 +103,8 @@ public SyMenuBar(final SyScreenType inScreen)
}

@Override
protected SyEventConsumed onEvent(
final SyEventType event)
protected SyEventConsumed onEventInput(
final SyEventInputType event)
{
return EVENT_NOT_CONSUMED;
}
Expand Down Expand Up @@ -247,8 +251,8 @@ public PAreaSizeI<SySpaceParentRelativeType> layout(
}

@Override
protected SyEventConsumed onEvent(
final SyEventType event)
protected SyEventConsumed onEventInput(
final SyEventInputType event)
{
return switch (event) {
case final SyMouseEventOnPressed e -> {
Expand All @@ -264,9 +268,10 @@ protected SyEventConsumed onEvent(
}
yield EVENT_NOT_CONSUMED;
}
default -> {
yield EVENT_NOT_CONSUMED;
}
case final SyKeyEventType e -> EVENT_NOT_CONSUMED;
case final SyMouseEventOnHeld e -> EVENT_NOT_CONSUMED;
case final SyMouseEventOnNoLongerOver e -> EVENT_NOT_CONSUMED;
case final SyMouseEventOnReleased e -> EVENT_NOT_CONSUMED;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.io7m.jsycamore.components.standard;

import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.screens.SyScreenType;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

Expand Down Expand Up @@ -67,8 +67,8 @@ public List<SyThemeClassNameType> themeClassesDefaultForComponent()
}

@Override
protected SyEventConsumed onEvent(
final SyEventType event)
protected SyEventConsumed onEventInput(
final SyEventInputType event)
{
return EVENT_NOT_CONSUMED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.io7m.jsycamore.api.components.SyButtonWithTextType;
import com.io7m.jsycamore.api.components.SyTextViewType;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.screens.SyScreenType;
import com.io7m.jsycamore.api.text.SyText;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;
Expand Down Expand Up @@ -224,7 +224,7 @@ public static SyButtonBuilderType buttonBuilder(

@Override
protected SyEventConsumed onOtherEvent(
final SyEventType event)
final SyEventInputType event)
{
return EVENT_NOT_CONSUMED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.io7m.jsycamore.api.components.SyButtonType;
import com.io7m.jsycamore.api.events.SyEventConsumed;
import com.io7m.jsycamore.api.events.SyEventType;
import com.io7m.jsycamore.api.events.SyEventInputType;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnHeld;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnPressed;
import com.io7m.jsycamore.api.mouse.SyMouseEventOnReleased;
Expand Down Expand Up @@ -72,8 +72,8 @@ public final void setOnClickListener(
}

@Override
protected final SyEventConsumed onEvent(
final SyEventType event)
protected final SyEventConsumed onEventInput(
final SyEventInputType event)
{
if (event instanceof final SyMouseEventType mouseEvent) {
return this.onMouseEvent(mouseEvent);
Expand All @@ -96,7 +96,7 @@ public final boolean isPressed()
* @return {@code true} if the event has been consumed
*/

protected abstract SyEventConsumed onOtherEvent(SyEventType event);
protected abstract SyEventConsumed onOtherEvent(SyEventInputType event);

private SyEventConsumed onMouseEvent(
final SyMouseEventType event)
Expand Down

0 comments on commit 6028711

Please sign in to comment.