Skip to content
Permalink
Browse files

Huge code refactoring cross modules

  • Loading branch information...
ShchAlexander committed Feb 25, 2019
1 parent 5801543 commit 8a3c628449cf43f658e9c6e6df7f602d900146ee
Showing with 238 additions and 115 deletions.
  1. +16 −3 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/event/SystemEvent.java
  2. +0 −1 ...e/src/main/java/com/spinyowl/spinygui/backend/core/event/handler/SystemCursorPosEventHandler.java
  3. +2 −7 ...src/main/java/com/spinyowl/spinygui/backend/core/event/processor/DefaultSystemEventProcessor.java
  4. +3 −14 ...d.core/src/main/java/com/spinyowl/spinygui/backend/core/event/processor/SystemEventProcessor.java
  5. +18 −0 ...rc/main/java/com/spinyowl/spinygui/backend/core/event/processor/SystemEventProcessorProvider.java
  6. +1 −1 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/renderer/Renderer.java
  7. +18 −0 backend.core/src/main/java/com/spinyowl/spinygui/backend/core/renderer/RendererProvider.java
  8. +18 −18 backend.glfwutil/src/main/java/com/spinyowl/spinygui/backend/glfwutil/callback/DefaultCallback.java
  9. +1 −1 ...il/src/main/java/com/spinyowl/spinygui/backend/glfwutil/callback/chain/AbstractChainCallback.java
  10. +0 −1 backend.opengl32/src/main/java/com/spinyowl/spinygui/backend/opengl32/api/WindowOpenGL32.java
  11. +22 −0 backend.opengl32/src/main/java/com/spinyowl/spinygui/backend/opengl32/renderer/NvgRenderer.java
  12. +36 −11 ...2/src/main/java/com/spinyowl/spinygui/backend/opengl32/service/SpinyGuiOpenGL32WindowService.java
  13. +2 −2 ...rc/main/java/com/spinyowl/spinygui/backend/opengl32/service/internal/SpinyGuiOpenGL32Service.java
  14. +15 −10 ...n/java/com/spinyowl/spinygui/backend/opengl32/service/internal/SpinyGuiOpenGL32ServiceThread.java
  15. +15 −0 build.gradle
  16. +31 −18 core/src/main/java/com/spinyowl/spinygui/core/Configuration.java
  17. +17 −0 core/src/main/java/com/spinyowl/spinygui/core/api/Frame.java
  18. +7 −10 core/src/main/java/com/spinyowl/spinygui/core/api/Window.java
  19. +0 −4 core/src/main/java/com/spinyowl/spinygui/core/component/Frame.java
  20. +0 −1 core/src/main/java/com/spinyowl/spinygui/core/component/intersection/RectangleIntersection.java
  21. +2 −2 core/src/main/java/com/spinyowl/spinygui/core/converter/dom/ComponentMarshaller.java
  22. +7 −7 core/src/main/java/com/spinyowl/spinygui/core/system/service/ServiceHolder.java
  23. +4 −1 core/src/main/java/com/spinyowl/spinygui/core/system/service/WindowService.java
  24. +2 −2 demo.integrated/src/main/java/com/spinyowl/spinygui/demo/SingleClassExample.java
  25. +1 −1 gradle/wrapper/gradle-wrapper.properties
@@ -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
@@ -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<>();

@@ -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);
}
}
@@ -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 {

@@ -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.*;

@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
};
}

@@ -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));
}

/**
@@ -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));
}

/**
@@ -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));
}
}
@@ -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.
@@ -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;
@@ -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() {

}
}
Oops, something went wrong.

0 comments on commit 8a3c628

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