pushing latest changes
This commit is contained in:
		
							parent
							
								
									867733cdfc
								
							
						
					
					
						commit
						afa3215abd
					
				@ -30,7 +30,7 @@ public class NewInputTest {
 | 
				
			|||||||
		Window window = manager.builder().title("Testing Engine").build();
 | 
							Window window = manager.builder().title("Testing Engine").build();
 | 
				
			||||||
		window.visible(true);
 | 
							window.visible(true);
 | 
				
			||||||
		//TODO implement window close requests
 | 
							//TODO implement window close requests
 | 
				
			||||||
		while(true) {
 | 
							while(!window.shouldClose()) {
 | 
				
			||||||
			GLFW.glfwPollEvents();
 | 
								GLFW.glfwPollEvents();
 | 
				
			||||||
			window.beginFrame();
 | 
								window.beginFrame();
 | 
				
			||||||
			window.handleInput();
 | 
								window.handleInput();
 | 
				
			||||||
@ -38,5 +38,7 @@ public class NewInputTest {
 | 
				
			|||||||
			try { Thread.sleep(100); }
 | 
								try { Thread.sleep(100); }
 | 
				
			||||||
			catch(InterruptedException e) { e.printStackTrace(); }
 | 
								catch(InterruptedException e) { e.printStackTrace(); }
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							window.destroy();
 | 
				
			||||||
 | 
							manager.destroy();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,15 +1,72 @@
 | 
				
			|||||||
package speiger.src.coreengine.rendering.gui.animation;
 | 
					package speiger.src.coreengine.rendering.gui.animation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import speiger.src.collections.objects.functions.consumer.ObjectFloatConsumer;
 | 
				
			||||||
 | 
					import speiger.src.collections.objects.maps.impl.misc.LinkedEnum2ObjectMap;
 | 
				
			||||||
 | 
					import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap;
 | 
				
			||||||
 | 
					import speiger.src.collections.objects.maps.interfaces.Object2ObjectMap.Entry;
 | 
				
			||||||
 | 
					import speiger.src.collections.objects.utils.maps.Object2ObjectMaps;
 | 
				
			||||||
 | 
					import speiger.src.coreengine.rendering.gui.components.base.GuiComponent;
 | 
				
			||||||
 | 
					import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GuiAnimation {
 | 
					public class GuiAnimation {
 | 
				
			||||||
 | 
						Object2ObjectMap<Target, IAction> actions;
 | 
				
			||||||
 | 
						float duration;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static class Builder {
 | 
						private GuiAnimation(Object2ObjectMap<Target, IAction> actions, float duration) {
 | 
				
			||||||
		
 | 
							this.actions = actions;
 | 
				
			||||||
 | 
							this.duration = duration;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static interface IAction {
 | 
						public Builder copy() { return new Builder(this); }
 | 
				
			||||||
 | 
						public static Builder of() { return new Builder(); }
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public float duration() { return duration; }
 | 
				
			||||||
 | 
						public void apply(GuiComponent owner, float progress) {
 | 
				
			||||||
 | 
							for(Entry<Target, IAction> entry : Object2ObjectMaps.fastIterable(actions)) {
 | 
				
			||||||
 | 
								IAction action = entry.getValue();
 | 
				
			||||||
 | 
								action.apply(entry.getKey(), Math.min(progress, action.duration()));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public static class Builder {
 | 
				
			||||||
 | 
							Object2ObjectMap<Target, IAction> actions = new LinkedEnum2ObjectMap<>(Target.class);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							private Builder() {}
 | 
				
			||||||
 | 
							private Builder(GuiAnimation owner) {
 | 
				
			||||||
 | 
								this.actions.putAll(owner.actions);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public Builder add(Target target, IAction action) {
 | 
				
			||||||
 | 
								this.actions.put(target, Objects.requireNonNull(action));
 | 
				
			||||||
 | 
								return this;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public GuiAnimation build() {
 | 
				
			||||||
 | 
								float duration = 0F;
 | 
				
			||||||
 | 
								for(IAction action : actions.values()) {
 | 
				
			||||||
 | 
									duration = Math.max(duration, action.duration());
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								return new GuiAnimation(actions, duration);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public static enum Target {
 | 
						public static enum Target {
 | 
				
			||||||
		X, Y, WIDTH, HEIGHT, SCALE, VISIBILITY
 | 
							X(IGuiBox::setX),
 | 
				
			||||||
 | 
							Y(IGuiBox::setY),
 | 
				
			||||||
 | 
							WIDTH(IGuiBox::setWidth),
 | 
				
			||||||
 | 
							HEIGHT(IGuiBox::setHeight),
 | 
				
			||||||
 | 
							SCALE(IGuiBox::setScale);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							ObjectFloatConsumer<IGuiBox> consumer;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							private Target(ObjectFloatConsumer<IGuiBox> consumer) {
 | 
				
			||||||
 | 
								this.consumer = consumer;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public void set(GuiComponent component, float value) {
 | 
				
			||||||
 | 
								consumer.accept(component.getBox(), value);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					package speiger.src.coreengine.rendering.gui.animation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import speiger.src.coreengine.rendering.gui.animation.GuiAnimation.Target;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface IAction {
 | 
				
			||||||
 | 
						public float duration();
 | 
				
			||||||
 | 
						public void apply(Target target, float progress);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -143,15 +143,12 @@ public class Window {
 | 
				
			|||||||
		if(flags.isFlagSet(WINDOW_CHANGE)) updateViewport();
 | 
							if(flags.isFlagSet(WINDOW_CHANGE)) updateViewport();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public void handleInput() {
 | 
						public void handleInput() { manager.processDevices(id); }
 | 
				
			||||||
		manager.processDevices(id);
 | 
						public boolean shouldClose() { return flags.isFlagSet(CLOSE) || GLFW.glfwWindowShouldClose(id); }
 | 
				
			||||||
	}
 | 
						public void finishFrame() { GLFW.glfwSwapBuffers(id); }
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	public void finishFrame() {
 | 
					 | 
				
			||||||
		GLFW.glfwSwapBuffers(id);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public void destroy() {
 | 
						public void destroy() {
 | 
				
			||||||
 | 
							manager.removeWindow(id);
 | 
				
			||||||
		for(int i = 0,m=listeners.size();i<m;i++) {
 | 
							for(int i = 0,m=listeners.size();i<m;i++) {
 | 
				
			||||||
			listeners.get(i).onChanged(this, Reason.CLOSING);
 | 
								listeners.get(i).onChanged(this, Reason.CLOSING);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,8 @@
 | 
				
			|||||||
package speiger.src.coreengine.rendering.input.window;
 | 
					package speiger.src.coreengine.rendering.input.window;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Iterator;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Objects;
 | 
					import java.util.Objects;
 | 
				
			||||||
import java.util.function.Consumer;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.lwjgl.glfw.GLFW;
 | 
					import org.lwjgl.glfw.GLFW;
 | 
				
			||||||
import org.lwjgl.system.Callback;
 | 
					import org.lwjgl.system.Callback;
 | 
				
			||||||
@ -79,6 +79,16 @@ public class WindowManager {
 | 
				
			|||||||
		windows.put(prev.id(), prev);
 | 
							windows.put(prev.id(), prev);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						void removeWindow(long id) {
 | 
				
			||||||
 | 
							Window window = windows.remove(id);
 | 
				
			||||||
 | 
							if(window == null) return;
 | 
				
			||||||
 | 
							if(window == activeWindow) activeWindow = null;
 | 
				
			||||||
 | 
							if(window == primaryWindow) {
 | 
				
			||||||
 | 
								Iterator<Window> iter = windows.values().iterator();
 | 
				
			||||||
 | 
								primaryWindow = iter.hasNext() ? iter.next() : null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	void updateFocus(Window window, boolean focus) {
 | 
						void updateFocus(Window window, boolean focus) {
 | 
				
			||||||
		if(focus) this.activeWindow = window;
 | 
							if(focus) this.activeWindow = window;
 | 
				
			||||||
		else if(activeWindow == window) activeWindow = null;
 | 
							else if(activeWindow == window) activeWindow = null;
 | 
				
			||||||
@ -152,7 +162,6 @@ public class WindowManager {
 | 
				
			|||||||
		boolean floating;
 | 
							boolean floating;
 | 
				
			||||||
		boolean borderless;
 | 
							boolean borderless;
 | 
				
			||||||
		boolean center = true;
 | 
							boolean center = true;
 | 
				
			||||||
		Consumer<Window> carrierThread;
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		private WindowBuilder(WindowManager manager) {
 | 
							private WindowBuilder(WindowManager manager) {
 | 
				
			||||||
			this.manager = manager;
 | 
								this.manager = manager;
 | 
				
			||||||
@ -240,11 +249,6 @@ public class WindowManager {
 | 
				
			|||||||
			return this;
 | 
								return this;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
		public WindowBuilder carrierThread(Consumer<Window> run) {
 | 
					 | 
				
			||||||
			carrierThread = run;
 | 
					 | 
				
			||||||
			return this;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		public Window build() {
 | 
							public Window build() {
 | 
				
			||||||
			return manager.create(this);
 | 
								return manager.create(this);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -86,7 +86,6 @@ public class EventBus
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public void post(Event event) {
 | 
						public void post(Event event) {
 | 
				
			||||||
		Consumer<Event>[] listeners = getListeners(event.getClass()).getListeners();
 | 
							Consumer<Event>[] listeners = getListeners(event.getClass()).getListeners();
 | 
				
			||||||
		System.out.println("Event: "+event);
 | 
					 | 
				
			||||||
		if(listeners.length <= 0) return;
 | 
							if(listeners.length <= 0) return;
 | 
				
			||||||
		int index = 0;
 | 
							int index = 0;
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user