Skip to content
Permalink
Browse files

updated events, event handlers, window class, demo.

  • Loading branch information...
ShchAlexander committed Nov 28, 2018
1 parent c5c23f5 commit 1c7dd27b3a5f275e7c83feca5cd5e386c9b4566b
Showing with 428 additions and 268 deletions.
  1. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemCharEvent.java
  2. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemCharModsEvent.java
  3. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemCursorEnterEvent.java
  4. +3 −3 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemCursorPosEvent.java
  5. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemDropEvent.java
  6. +17 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemEvent.java
  7. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemFramebufferSizeEvent.java
  8. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemKeyEvent.java
  9. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemMouseClickEvent.java
  10. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemScrollEvent.java
  11. +3 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowCloseEvent.java
  12. +1 −1 ...nd.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowContentScaleEvent.java
  13. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowFocusEvent.java
  14. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowIconifyEvent.java
  15. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowMaximizeEvent.java
  16. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowPosEvent.java
  17. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowRefreshEvent.java
  18. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemWindowSizeEvent.java
  19. +13 −0 ...e/src/main/java/com/spinyowl/spinygui/backend/core/event/handler/SystemCursorPosEventHandler.java
  20. +44 −0 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/handler/SystemEventHandlers.java
  21. +1 −1 ...src/main/java/com/spinyowl/spinygui/backend/core/event/handler/SystemWindowCloseEventHandler.java
  22. +89 −0 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/handler/util/SehUtil.java
  23. +1 −12 ...src/main/java/com/spinyowl/spinygui/backend/core/event/processor/DefaultSystemEventProcessor.java
  24. +0 −1 backend.glfwutil/src/main/java/com/spinyowl/spinygui/backend/glfwutil/callback/DefaultCallback.java
  25. +2 −96 backend.opengl32/src/main/java/com/spinyowl/spinygui/backend/opengl32/api/WindowOpenGL32.java
  26. +1 −1 ...rc/main/java/com/spinyowl/spinygui/backend/opengl32/service/SpinyGuiOpenGL32ClipboardService.java
  27. +1 −1 .../src/main/java/com/spinyowl/spinygui/backend/opengl32/service/SpinyGuiOpenGL32MonitorService.java
  28. +4 −4 ...src/main/java/com/spinyowl/spinygui/backend/opengl32/service/SpinyGuiOpenGL32ServiceProvider.java
  29. +69 −32 ...2/src/main/java/com/spinyowl/spinygui/backend/opengl32/service/SpinyGuiOpenGL32WindowService.java
  30. +9 −9 ...rc/main/java/com/spinyowl/spinygui/backend/opengl32/service/internal/SpinyGuiOpenGL32Service.java
  31. +11 −2 ...n/java/com/spinyowl/spinygui/backend/opengl32/service/internal/SpinyGuiOpenGL32ServiceThread.java
  32. +3 −0 core/build.gradle
  33. +1 −1 core/src/main/java/com/spinyowl/spinygui/core/api/Monitor.java
  34. +44 −26 core/src/main/java/com/spinyowl/spinygui/core/api/Window.java
  35. +31 −35 core/src/main/java/com/spinyowl/spinygui/core/component/base/Component.java
  36. +7 −4 core/src/main/java/com/spinyowl/spinygui/core/component/intersection/RectangleIntersection.java
  37. +0 −15 core/src/main/java/com/spinyowl/spinygui/core/service/WindowService.java
  38. 0 core/src/main/java/com/spinyowl/spinygui/core/system/.gitkeep
  39. +7 −0 core/src/main/java/com/spinyowl/spinygui/core/system/render/Renderer.java
  40. +1 −1 core/src/main/java/com/spinyowl/spinygui/core/{ → system}/service/ClipboardService.java
  41. +1 −1 core/src/main/java/com/spinyowl/spinygui/core/{ → system}/service/MonitorService.java
  42. +8 −0 core/src/main/java/com/spinyowl/spinygui/core/system/service/RendererFactoryService.java
  43. +1 −3 core/src/main/java/com/spinyowl/spinygui/core/{ → system}/service/ServiceHolder.java
  44. +33 −0 core/src/main/java/com/spinyowl/spinygui/core/system/service/WindowService.java
  45. +4 −2 core/src/main/java/module-info.java
  46. +1 −1 demo.integrated/src/main/java/com/spinyowl/spinygui/demo/SingleClassExample.java
  47. +1 −0 demo.simple/src/main/java/com/spinyowl/spinygui/demo/Main.java
  48. +1 −0 spinygui/build.gradle
  49. +1 −0 spinygui/src/main/java/module-info.java
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemCharEvent implements SystemEvent {
public class SystemCharEvent extends SystemEvent {

public final long window;
public final int codePoint;
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemCharModsEvent implements SystemEvent {
public class SystemCharModsEvent extends SystemEvent {

public final long window;
public final int codePoint;
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemCursorEnterEvent implements SystemEvent {
public class SystemCursorEnterEvent extends SystemEvent {

public final long window;
public final boolean entered;
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemCursorPosEvent implements SystemEvent {
public class SystemCursorPosEvent extends SystemEvent {

public final long window;
public final double posX;
@@ -15,8 +15,8 @@ public SystemCursorPosEvent(long window, double posX, double posY) {
this.window = window;
this.posX = posX;
this.posY = posY;
fx = (float) posX;
fy = (float) posY;
this.fx = (float) posX;
this.fy = (float) posY;
}

@Override
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemDropEvent implements SystemEvent {
public class SystemDropEvent extends SystemEvent {

public final long window;
public final String[] strings;
@@ -1,8 +1,24 @@
package com.spinyowl.spinygui.backend.core.event;

import com.spinyowl.spinygui.backend.core.event.handler.SystemEventHandler;
import com.spinyowl.spinygui.backend.core.event.handler.SystemEventHandlers;

/**
* Marker interface that defines tree of system events.
*/
public interface SystemEvent {
public abstract class SystemEvent {

private final SystemEventHandler eventHandler;

public SystemEvent(SystemEventHandler systemEventHandler) {
this.eventHandler = systemEventHandler;
}

public SystemEvent() {
this.eventHandler = SystemEventHandlers.getHandler(getClass());
}

public SystemEventHandler getEventHandler() {
return eventHandler;
}
}
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemFramebufferSizeEvent implements SystemEvent {
public class SystemFramebufferSizeEvent extends SystemEvent {

public final long window;
public final int width;
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemKeyEvent implements SystemEvent {
public class SystemKeyEvent extends SystemEvent {

public final long window;
public final int key;
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemMouseClickEvent implements SystemEvent {
public class SystemMouseClickEvent extends SystemEvent {

public final long window;
public final int button;
@@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class SystemScrollEvent implements SystemEvent {
public class SystemScrollEvent extends SystemEvent {

public final long window;
public final double offsetX;
@@ -1,12 +1,14 @@
package com.spinyowl.spinygui.backend.core.event;

import com.spinyowl.spinygui.backend.core.event.handler.SystemEventHandlers;
import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowCloseEvent implements SystemEvent {
public class SystemWindowCloseEvent extends SystemEvent {

public final long window;

public SystemWindowCloseEvent(long window) {
super(SystemEventHandlers.getSystemWindowCloseEventHandler());
this.window = window;
}

@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowContentScaleEvent implements SystemEvent {
public class SystemWindowContentScaleEvent extends SystemEvent {
public final long window;
public final float scaleX;
public final float scaleY;
@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowFocusEvent implements SystemEvent {
public class SystemWindowFocusEvent extends SystemEvent {

public final long window;
public final boolean focused;
@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowIconifyEvent implements SystemEvent {
public class SystemWindowIconifyEvent extends SystemEvent {

public final long window;
public final boolean iconified;
@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowMaximizeEvent implements SystemEvent {
public class SystemWindowMaximizeEvent extends SystemEvent {
public final long window;
public final boolean maximized;

@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowPosEvent implements SystemEvent {
public class SystemWindowPosEvent extends SystemEvent {

public final long window;
public final int posX;
@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowRefreshEvent implements SystemEvent {
public class SystemWindowRefreshEvent extends SystemEvent {

public final long window;

@@ -2,7 +2,7 @@

import org.apache.commons.lang3.builder.ToStringBuilder;

public class SystemWindowSizeEvent implements SystemEvent {
public class SystemWindowSizeEvent extends SystemEvent {

public final long window;
public final int width;
@@ -0,0 +1,13 @@
package com.spinyowl.spinygui.backend.core.event.handler;

import com.spinyowl.spinygui.backend.core.event.SystemCursorPosEvent;
import com.spinyowl.spinygui.core.system.service.ServiceHolder;

public class SystemCursorPosEventHandler implements SystemEventHandler<SystemCursorPosEvent> {
@Override
public void handle(SystemCursorPosEvent event) {
// ServiceHolder.


}
}
@@ -0,0 +1,44 @@
package com.spinyowl.spinygui.backend.core.event.handler;

import com.spinyowl.spinygui.backend.core.event.SystemEvent;
import com.spinyowl.spinygui.backend.core.event.SystemWindowCloseEvent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public final class SystemEventHandlers {

public static final SystemEventHandler<SystemWindowCloseEvent> DEFAULT_SYSTEM_WINDOW_CLOSE_EVENT_HANDLER = new SystemWindowCloseEventHandler();
private static SystemEventHandler<SystemWindowCloseEvent> systemWindowCloseEventHandler = DEFAULT_SYSTEM_WINDOW_CLOSE_EVENT_HANDLER;

private static Map<Class<? extends SystemEvent>, SystemEventHandler> eventHandlerMap = new ConcurrentHashMap<>();

static {
setHandler(SystemWindowCloseEvent.class, systemWindowCloseEventHandler);
}

private SystemEventHandlers() {
}

public static <T extends SystemEvent, H extends SystemEventHandler<T>> void setHandler(Class<T> clazz, H handler) {
eventHandlerMap.put(clazz, handler);
}

public static <T extends SystemEvent> SystemEventHandler<T> getHandler(Class<T> clazz) {
return (SystemEventHandler<T>) eventHandlerMap.get(clazz);
}

public static SystemEventHandler<SystemWindowCloseEvent> getSystemWindowCloseEventHandler() {
return systemWindowCloseEventHandler;
}

public static void setSystemWindowCloseEventHandler(SystemEventHandler<SystemWindowCloseEvent> systemWindowCloseEventHandler) {
if (systemWindowCloseEventHandler != null) {
SystemEventHandlers.systemWindowCloseEventHandler = systemWindowCloseEventHandler;
} else {
SystemEventHandlers.systemWindowCloseEventHandler = DEFAULT_SYSTEM_WINDOW_CLOSE_EVENT_HANDLER;
}
setHandler(SystemWindowCloseEvent.class, SystemEventHandlers.systemWindowCloseEventHandler);
}

}
@@ -3,7 +3,7 @@
import com.spinyowl.spinygui.backend.core.event.SystemWindowCloseEvent;
import com.spinyowl.spinygui.core.event.WindowCloseEvent;
import com.spinyowl.spinygui.core.event.processor.EventProcessor;
import com.spinyowl.spinygui.core.service.ServiceHolder;
import com.spinyowl.spinygui.core.system.service.ServiceHolder;

public class SystemWindowCloseEventHandler implements SystemEventHandler<SystemWindowCloseEvent> {
@Override
@@ -0,0 +1,89 @@
package com.spinyowl.spinygui.backend.core.event.handler.util;

import com.spinyowl.spinygui.core.component.base.Component;
import com.spinyowl.spinygui.core.component.base.Container;

import java.util.ArrayList;
import java.util.List;

public final class SehUtil {

private SehUtil() {
}

/**
* Used to find target component for provided layer and vector. Target means top component which intersected by provided point(vector).
*
* @param container root container to search.
* @param x x point coordinates to search.
* @param y y point coordinates to search.
* @return top component from layer intersected by vector.
*/
public static Component getTargetComponent(Container container, final float x, final float y) {
Component target = container;
List<Component> childComponents = container.getChildComponents();
for (Component child : childComponents) {
target = recursiveTargetComponentSearch(child, target, x, y);
}
return target;
}

/**
* Used to search target component (under point) in component. Target means top component which intersected by provided point(vector).
*
* @param component source component to search target.
* @param target current target.
* @param x x point coordinates to search.
* @param y y point coordinates to search.
* @return the top visible component under point.
*/
private static Component recursiveTargetComponentSearch(Component component, Component target, final float x, final float y) {
Component newtarget = target;
if (isaTarget(component, x, y)) {
newtarget = component;
List<Component> childComponents = component.getChildComponents();
for (Component child : childComponents) {
newtarget = recursiveTargetComponentSearch(child, newtarget, x, y);
}
}
return newtarget;
}


/**
* Used to search all components (under point) in component.
*
* @param container root container to search.
* @param x x point coordinates to search.
* @param y y point coordinates to search.
* @return all top visible components in layer under point(vector).
*/
public static List<Component> getTargetComponentList(Container container, final float x, final float y) {
List<Component> targetList = new ArrayList<>();
recursiveTargetComponentListSearch(container, targetList, x, y);
return targetList;
}


/**
* Used to search all components (under point) in component. New located target component will be added to target list.
*
* @param component source component to search target.
* @param targetList current target list.
* @param x x point coordinates to search.
* @param y y point coordinates to search.
*/
public static void recursiveTargetComponentListSearch(Component component, List<Component> targetList, final float x, final float y) {
if (isaTarget(component, x, y)) {
targetList.add(component);
List<Component> childComponents = component.getChildComponents();
for (Component child : childComponents) {
recursiveTargetComponentListSearch(child, targetList, x, y);
}
}
}

private static boolean isaTarget(Component component, float x, float y) {
return component.isVisible() && component.getIntersection().intersects(component, x, y);
}
}
@@ -14,11 +14,6 @@
public class DefaultSystemEventProcessor extends SystemEventProcessor {

private Queue<SystemEvent> eventQueue = new LinkedBlockingQueue<>();
private Map<Class<? extends SystemEvent>, SystemEventHandler<? extends SystemEvent>> eventHandlerMap = new ConcurrentHashMap<>();

{
setHandler(SystemWindowCloseEvent.class, new SystemWindowCloseEventHandler());
}

@Override
public void pushEvent(SystemEvent event) {
@@ -36,18 +31,12 @@ public void processEvents() {


private void processEvent(SystemEvent event) {
SystemEventHandler handler = getHandler(event.getClass());
SystemEventHandler handler = event.getEventHandler();
if (handler != null) {
System.out.println("PROCESS EVENT: " + event);
handler.handle(event);
}
}

public <T extends SystemEvent, H extends SystemEventHandler<T>> void setHandler(Class<T> clazz, H handler) {
eventHandlerMap.put(clazz, handler);
}

public <T extends SystemEvent, H extends SystemEventHandler<T>> H getHandler(Class<T> clazz) {
return (H) eventHandlerMap.get(clazz);
}
}
@@ -2,7 +2,6 @@

import com.spinyowl.spinygui.backend.core.event.*;
import com.spinyowl.spinygui.backend.core.event.processor.SystemEventProcessor;
import com.spinyowl.spinygui.core.service.ServiceHolder;
import org.lwjgl.PointerBuffer;
import org.lwjgl.glfw.*;

Oops, something went wrong.

0 comments on commit 1c7dd27

Please sign in to comment.
You can’t perform that action at this time.