Skip to content

Commit

Permalink
Huge code refactoring cross modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SpinyOwl committed Feb 25, 2019
1 parent 5801543 commit 8a3c628
Show file tree
Hide file tree
Showing 25 changed files with 238 additions and 115 deletions.
Expand Up @@ -8,17 +8,30 @@
*/
public abstract class SystemEvent {

private final SystemEventHandler eventHandler;
private SystemEventHandler eventHandler;

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

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

public SystemEventHandler getEventHandler() {
public static <T extends SystemEvent> void setEventHandler(T event, SystemEventHandler<? extends T> eventHandler) {
event.setEventHandler(SystemEventHandlers.getHandler(event.getClass()));
}

public static <T extends SystemEvent> SystemEventHandler<T> getEventHandler(T event) {
return event.getEventHandler();
}

final SystemEventHandler getEventHandler() {
return eventHandler;
}

final <T extends SystemEvent> void setEventHandler(SystemEventHandler<? extends T> eventHandler) {
this.eventHandler = eventHandler;
}

}
@@ -1,7 +1,6 @@
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
Expand Down
@@ -1,17 +1,13 @@
package com.spinyowl.spinygui.backend.core.event.processor;

import com.spinyowl.spinygui.backend.core.event.SystemEvent;
import com.spinyowl.spinygui.backend.core.event.SystemWindowCloseEvent;
import com.spinyowl.spinygui.backend.core.event.handler.SystemEventHandler;
import com.spinyowl.spinygui.backend.core.event.handler.SystemWindowCloseEventHandler;

import java.util.ArrayList;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

public class DefaultSystemEventProcessor extends SystemEventProcessor {
public class DefaultSystemEventProcessor implements SystemEventProcessor {

private Queue<SystemEvent> eventQueue = new LinkedBlockingQueue<>();

Expand All @@ -31,9 +27,8 @@ public void processEvents() {


private void processEvent(SystemEvent event) {
SystemEventHandler handler = event.getEventHandler();
SystemEventHandler<SystemEvent> handler = SystemEvent.getEventHandler(event);
if (handler != null) {
System.out.println("PROCESS EVENT: " + event);
handler.handle(event);
}
}
Expand Down
Expand Up @@ -2,29 +2,18 @@

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

public abstract class SystemEventProcessor {

public static SystemEventProcessor getInstance() {
return SEPH.INSTANCE;
}

public static void setInstance(SystemEventProcessor instance) {
if (instance != null) SEPH.INSTANCE = instance;
}
public interface SystemEventProcessor {

/**
* Used to process system event.
*/
public abstract void processEvents();
void processEvents();

/**
* Used to push system event to processing queue.
*
* @param event event to push.
*/
public abstract void pushEvent(SystemEvent event);
void pushEvent(SystemEvent event);

private static final class SEPH {
private static SystemEventProcessor INSTANCE = new DefaultSystemEventProcessor();
}
}
@@ -0,0 +1,18 @@
package com.spinyowl.spinygui.backend.core.event.processor;

public final class SystemEventProcessorProvider {
private SystemEventProcessorProvider() {
}

public static SystemEventProcessor getSystemEventProcessor() {
return SEPPH.systemEventProcessor;
}

public static void setSystemEventProcessor(SystemEventProcessor systemEventProcessor) {
SystemEventProcessorProvider.SEPPH.systemEventProcessor = systemEventProcessor;
}

private static final class SEPPH {
private static SystemEventProcessor systemEventProcessor = new DefaultSystemEventProcessor();
}
}
@@ -1,7 +1,7 @@
package com.spinyowl.spinygui.backend.core.renderer;

import com.spinyowl.spinygui.backend.core.context.Context;
import com.spinyowl.spinygui.core.component.Frame;
import com.spinyowl.spinygui.core.api.Frame;

public interface Renderer {

Expand Down
@@ -0,0 +1,18 @@
package com.spinyowl.spinygui.backend.core.renderer;

public final class RendererProvider {
private static Renderer renderer;

private RendererProvider() {
}

public static Renderer getRenderer() {
return renderer;
}

public static void setRenderer(Renderer renderer) {
if (renderer != null) {
RendererProvider.renderer = renderer;
}
}
}
@@ -1,7 +1,7 @@
package com.spinyowl.spinygui.backend.glfwutil.callback;

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

Expand All @@ -16,7 +16,7 @@ private DefaultCallback() {
* @return the GLFWWindowSizeCallback.
*/
public static GLFWWindowSizeCallbackI createWindowSizeCallback() {
return (window, width, height) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowSizeEvent(window, width, height));
return (window, width, height) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowSizeEvent(window, width, height));
}

/**
Expand All @@ -25,7 +25,7 @@ public static GLFWWindowSizeCallbackI createWindowSizeCallback() {
* @return the GLFWWindowRefreshCallback.
*/
public static GLFWWindowRefreshCallbackI createWindowRefreshCallback() {
return window -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowRefreshEvent(window));
return window -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowRefreshEvent(window));
}

/**
Expand All @@ -34,7 +34,7 @@ public static GLFWWindowRefreshCallbackI createWindowRefreshCallback() {
* @return the GLFWWindowPosCallback.
*/
public static GLFWWindowPosCallbackI createWindowPosCallback() {
return (window, xpos, ypos) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowPosEvent(window, xpos, ypos));
return (window, xpos, ypos) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowPosEvent(window, xpos, ypos));
}

/**
Expand All @@ -43,7 +43,7 @@ public static GLFWWindowPosCallbackI createWindowPosCallback() {
* @return the GLFWWindowIconifyCallback.
*/
public static GLFWWindowIconifyCallbackI createWindowIconifyCallback() {
return (window, iconified) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowIconifyEvent(window, iconified));
return (window, iconified) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowIconifyEvent(window, iconified));
}

/**
Expand All @@ -52,7 +52,7 @@ public static GLFWWindowIconifyCallbackI createWindowIconifyCallback() {
* @return the GLFWWindowFocusCallback.
*/
public static GLFWWindowFocusCallbackI createWindowFocusCallback() {
return (window, focused) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowFocusEvent(window, focused));
return (window, focused) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowFocusEvent(window, focused));
}

/**
Expand All @@ -61,7 +61,7 @@ public static GLFWWindowFocusCallbackI createWindowFocusCallback() {
* @return the GLFWWindowCloseCallback.
*/
public static GLFWWindowCloseCallbackI createWindowCloseCallback() {
return (window) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowCloseEvent(window));
return window -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowCloseEvent(window));
}

/**
Expand All @@ -70,7 +70,7 @@ public static GLFWWindowCloseCallbackI createWindowCloseCallback() {
* @return the GLFWCursorPosCallback.
*/
public static GLFWCursorPosCallbackI createCursorPosCallback() {
return (window, xpos, ypos) -> SystemEventProcessor.getInstance().pushEvent(new SystemCursorPosEvent(window, xpos, ypos));
return (window, xpos, ypos) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemCursorPosEvent(window, xpos, ypos));
}

/**
Expand All @@ -79,7 +79,7 @@ public static GLFWCursorPosCallbackI createCursorPosCallback() {
* @return the GLFWMouseButtonCallback.
*/
public static GLFWMouseButtonCallbackI createMouseButtonCallback() {
return (window, button, action, mods) -> SystemEventProcessor.getInstance().pushEvent(new SystemMouseClickEvent(window, button, action, mods));
return (window, button, action, mods) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemMouseClickEvent(window, button, action, mods));
}

/**
Expand All @@ -88,7 +88,7 @@ public static GLFWMouseButtonCallbackI createMouseButtonCallback() {
* @return the GLFWFramebufferSizeCallback.
*/
public static GLFWFramebufferSizeCallbackI createFramebufferSizeCallback() {
return (window, width, height) -> SystemEventProcessor.getInstance().pushEvent(new SystemFramebufferSizeEvent(window, width, height));
return (window, width, height) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemFramebufferSizeEvent(window, width, height));
}

/**
Expand All @@ -97,7 +97,7 @@ public static GLFWFramebufferSizeCallbackI createFramebufferSizeCallback() {
* @return the GLFWCursorEnterCallback.
*/
public static GLFWCursorEnterCallbackI createCursorEnterCallback() {
return (window, entered) -> SystemEventProcessor.getInstance().pushEvent(new SystemCursorEnterEvent(window, entered));
return (window, entered) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemCursorEnterEvent(window, entered));
}

/**
Expand All @@ -106,7 +106,7 @@ public static GLFWCursorEnterCallbackI createCursorEnterCallback() {
* @return the GLFWCharModsCallback.
*/
public static GLFWCharModsCallbackI createCharModsCallback() {
return (window, codepoint, mods) -> SystemEventProcessor.getInstance().pushEvent(new SystemCharModsEvent(window, codepoint, mods));
return (window, codepoint, mods) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemCharModsEvent(window, codepoint, mods));
}

/**
Expand All @@ -115,7 +115,7 @@ public static GLFWCharModsCallbackI createCharModsCallback() {
* @return the GLFWScrollCallback.
*/
public static GLFWScrollCallbackI createScrollCallback() {
return (window, xoffset, yoffset) -> SystemEventProcessor.getInstance().pushEvent(new SystemScrollEvent(window, xoffset, yoffset));
return (window, xoffset, yoffset) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemScrollEvent(window, xoffset, yoffset));
}

/**
Expand All @@ -124,7 +124,7 @@ public static GLFWScrollCallbackI createScrollCallback() {
* @return the GLFWKeyCallback.
*/
public static GLFWKeyCallbackI createKeyCallback() {
return (window, key, scancode, action, mods) -> SystemEventProcessor.getInstance().pushEvent(new SystemKeyEvent(window, key, scancode, action, mods));
return (window, key, scancode, action, mods) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemKeyEvent(window, key, scancode, action, mods));
}

/**
Expand All @@ -139,7 +139,7 @@ public static GLFWDropCallbackI createDropCallback() {
for (int i = 0; i < count; i++) {
strings[i] = pb.getStringUTF8(i);
}
SystemEventProcessor.getInstance().pushEvent(new SystemDropEvent(window, strings));
SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemDropEvent(window, strings));
};
}

Expand All @@ -149,7 +149,7 @@ public static GLFWDropCallbackI createDropCallback() {
* @return the GLFWCharCallback.
*/
public static GLFWCharCallbackI createCharCallback() {
return (window, codepoint) -> SystemEventProcessor.getInstance().pushEvent(new SystemCharEvent(window, codepoint));
return (window, codepoint) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemCharEvent(window, codepoint));
}

/**
Expand All @@ -158,7 +158,7 @@ public static GLFWCharCallbackI createCharCallback() {
* @return the GLFWWindowContentScaleCallbackI.
*/
public static GLFWWindowContentScaleCallbackI createWindowContentScaleCallback() {
return (window, xscale, yscale) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowContentScaleEvent(window, xscale, yscale));
return (window, xscale, yscale) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowContentScaleEvent(window, xscale, yscale));
}

/**
Expand All @@ -167,6 +167,6 @@ public static GLFWWindowContentScaleCallbackI createWindowContentScaleCallback()
* @return the GLFWWindowMaximizeCallbackI.
*/
public static GLFWWindowMaximizeCallbackI createWindowMaximizeCallback() {
return (window, maximized) -> SystemEventProcessor.getInstance().pushEvent(new SystemWindowMaximizeEvent(window, maximized));
return (window, maximized) -> SystemEventProcessorProvider.getSystemEventProcessor().pushEvent(new SystemWindowMaximizeEvent(window, maximized));
}
}
Expand Up @@ -10,7 +10,7 @@
* Base implementation of {@link IChainCallback} based on {@link CopyOnWriteArrayList}
*/
public abstract class AbstractChainCallback<T extends CallbackI> implements IChainCallback<T> {
protected List<T> callbackChain = new CopyOnWriteArrayList<T>();
protected final List<T> callbackChain = new CopyOnWriteArrayList<>();

/**
* Returns <tt>true</tt> if this chain contains no callbacks.
Expand Down
@@ -1,7 +1,6 @@
package com.spinyowl.spinygui.backend.opengl32.api;

import com.spinyowl.spinygui.backend.glfwutil.callback.CallbackKeeper;
import com.spinyowl.spinygui.backend.opengl32.service.SpinyGuiOpenGL32WindowService;
import com.spinyowl.spinygui.core.api.Monitor;
import com.spinyowl.spinygui.core.api.Window;
import com.spinyowl.spinygui.core.component.base.Component;
Expand Down
@@ -0,0 +1,22 @@
package com.spinyowl.spinygui.backend.opengl32.renderer;

import com.spinyowl.spinygui.backend.core.context.Context;
import com.spinyowl.spinygui.backend.core.renderer.Renderer;
import com.spinyowl.spinygui.core.api.Frame;

public class NvgRenderer implements Renderer {
@Override
public void initialize() {

}

@Override
public void render(Frame f, Context c) {

}

@Override
public void destroy() {

}
}

0 comments on commit 8a3c628

Please sign in to comment.