فهرست منبع

try at multidriver / multiwindow support on hl (partial)

Nicolas Cannasse 1 سال پیش
والد
کامیت
a95df40381
3فایلهای تغییر یافته به همراه55 افزوده شده و 7 حذف شده
  1. 1 1
      h3d/impl/Driver.hx
  2. 5 3
      hxd/System.hl.hx
  3. 49 3
      hxd/Window.hl.hx

+ 1 - 1
h3d/impl/Driver.hx

@@ -10,7 +10,7 @@ typedef Texture = { t : js.html.webgl.Texture, width : Int, height : Int, intern
 typedef Query = {};
 #elseif hlsdl
 typedef GPUBuffer = sdl.GL.Buffer;
-typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int, bias : Float, startMip : Int };
+typedef Texture = { t : sdl.GL.Texture, width : Int, height : Int, internalFmt : Int, pixelFmt : Int, bits : Int, bind : Int, bias : Float, startMip : Int #if multidriver, driver : Driver #end };
 typedef Query = { q : sdl.GL.Query, kind : QueryKind };
 #elseif usegl
 typedef GPUBuffer = haxe.GLTypes.Buffer;

+ 5 - 3
hxd/System.hl.hx

@@ -61,13 +61,13 @@ class System {
 	static function mainLoop() : Bool {
 		// process events
 		#if usesys
-		if( !haxe.System.emitEvents(@:privateAccess hxd.Window.inst.event) )
+		if( !haxe.System.emitEvents(@:privateAccess hxd.Window.dispatchEvent) )
 			return false;
 		#elseif hldx
-		if( !dx.Loop.processEvents(@:privateAccess hxd.Window.inst.onEvent) )
+		if( !dx.Loop.processEvents(@:privateAccess hxd.Window.dispatchEvent) )
 			return false;
 		#elseif hlsdl
-		if( !sdl.Sdl.processEvents(@:privateAccess hxd.Window.inst.onEvent) )
+		if( !sdl.Sdl.processEvents(@:privateAccess hxd.Window.dispatchEvent) )
 			return false;
 		#end
 
@@ -166,7 +166,9 @@ class System {
 			if( check_reload() ) onReload();
 			#end
 		}
+		#if !multidriver
 		Sys.exit(0);
+		#end
 	}
 
 	#if hot_reload

+ 49 - 3
hxd/Window.hl.hx

@@ -39,11 +39,14 @@ private class NativeDroppedFile extends hxd.DropFileEvent.DroppedFile {
 //@:coreApi
 class Window {
 
+	static var WINDOWS : Array<Window> = [];
+
 	var resizeEvents : List<Void -> Void>;
 	var eventTargets : List<Event -> Void>;
 	var dropTargets : List<DropFileEvent -> Void>;
 	var dropFiles : Array<hxd.DropFileEvent.DroppedFile>;
 
+	public var id : Int;
 	public var width(get, never) : Int;
 	public var height(get, never) : Int;
 	public var mouseX(get, never) : Int;
@@ -113,6 +116,10 @@ class Window {
 		final dxFlags = if (!fixed) dx.Window.RESIZABLE else 0;
 		window = new dx.Window(title, width, height, dx.Window.CW_USEDEFAULT, dx.Window.CW_USEDEFAULT, dxFlags);
 		#end
+		WINDOWS.push(this);
+		#if (hlsdl && multidriver)
+		id = window.id;
+		#end
 	}
 
 	public dynamic function onClose() : Bool {
@@ -123,6 +130,12 @@ class Window {
 		return null;
 	}
 
+	public function close() {
+		#if hlsdl
+		window.destroy();
+		#end
+	}
+
 	public function event( e : hxd.Event ) : Void {
 		for( et in eventTargets )
 			et(e);
@@ -305,7 +318,7 @@ class Window {
 
 		startMouseX = curMouseX;
 		startMouseY = curMouseY;
-		
+
 		return mouseMode = v;
 	}
 
@@ -363,6 +376,8 @@ class Window {
 				event(new Event(EOver));
 			case Leave:
 				event(new Event(EOut));
+			case Close:
+				return onCloseEvent();
 			default:
 			}
 		case MouseDown if (!hxd.System.getValue(IsTouch)):
@@ -474,7 +489,7 @@ class Window {
 			#end
 			eh = new Event(ERelease, e.mouseX, e.mouseY);
 			eh.touchId = e.fingerId;
-		
+
 		#elseif hldx
 		case KeyDown:
 			eh = new Event(EKeyDown);
@@ -516,13 +531,24 @@ class Window {
 			dropFiles = null;
 		#end
 		case Quit:
-			return onClose();
+			return onCloseEvent();
 		default:
 		}
 		if( eh != null ) event(eh);
 		return true;
 	}
 
+	function onCloseEvent() {
+		var ret = onClose();
+		if( ret ) {
+			close();
+			WINDOWS.remove(this);
+			if( WINDOWS.length == 0 )
+				Sys.exit(0);
+		}
+		return ret;
+	}
+
 	static function initChars() : Void {
 
 		inline function addKey(sdl, keyCode) {
@@ -801,8 +827,28 @@ class Window {
 		return "";
 	}
 
+	public function setCurrent() {
+		inst = this;
+		#if hlsdl
+		window.renderTo();
+		#end
+	}
+
 	static var inst : Window = null;
 	public static function getInstance() : Window {
 		return inst;
 	}
+
+	static function dispatchEvent( e ) {
+		#if multidriver
+		if( false ) @:privateAccess WINDOWS[0].onEvent(e); // typing
+		for( w in WINDOWS )
+			if( e.value == w.id )
+				return w.onEvent(e);
+		return true;
+		#else
+		return inst.onEvent(e);
+		#end
+	}
+
 }