Explorar o código

touch events in HL (#485)

Josu Igoa %!s(int64=6) %!d(string=hai) anos
pai
achega
8a2a8187d6
Modificáronse 2 ficheiros con 20 adicións e 6 borrados
  1. 17 3
      hxd/System.hl.hx
  2. 3 3
      hxd/Window.hl.hx

+ 17 - 3
hxd/System.hl.hx

@@ -27,7 +27,7 @@ class System {
 	public static var width(get,never) : Int;
 	public static var height(get, never) : Int;
 	public static var lang(get, never) : String;
-	public static var platform(get, never) : Platform;
+	public static var platform(get, null) : Platform;
 	public static var screenDPI(get,never) : Float;
 	public static var setCursor = setNativeCursor;
 	public static var allowTimeout(get, set) : Bool;
@@ -253,7 +253,12 @@ class System {
 		return switch( s ) {
 		#if !usesys
 		case IsWindowed:
-			return true;
+			platform == PC;
+		case IsMobile:
+			platform == IOS || platform == Android;
+		case IsTouch:
+			// TODO: check PC touch screens?
+			platform == IOS || platform == Android;
 		#end
 		default:
 			return false;
@@ -293,7 +298,16 @@ class System {
 	#elseif hlsdl
 	static function get_width() : Int return sdl.Sdl.getScreenWidth();
 	static function get_height() : Int return sdl.Sdl.getScreenHeight();
-	static function get_platform() : Platform return PC; // TODO : Xbox ?
+	static function get_platform() : Platform {
+		if (platform == null)
+			platform = switch Sys.systemName() {
+						case 'Windows' | 'Linux'| 'Mac': PC;
+						case 'iOS' | 'tvOS': IOS;
+						case 'Android': Android;
+						default: PC;
+					}
+		return platform;
+	}
 	#else
 	static function get_width() : Int return 800;
 	static function get_height() : Int return 600;

+ 3 - 3
hxd/Window.hl.hx

@@ -174,7 +174,7 @@ class Window {
 				event(new Event(EOut));
 			default:
 			}
-		case MouseDown:
+		case MouseDown if (!hxd.System.getValue(IsTouch)):
 			curMouseX = e.mouseX;
 			curMouseY = e.mouseY;
 			eh = new Event(EPush, e.mouseX, e.mouseY);
@@ -185,7 +185,7 @@ class Window {
 			case 2: 1;
 			case x: x;
 			}
-		case MouseUp:
+		case MouseUp if (!hxd.System.getValue(IsTouch)):
 			curMouseX = e.mouseX;
 			curMouseY = e.mouseY;
 			eh = new Event(ERelease, e.mouseX, e.mouseY);
@@ -195,7 +195,7 @@ class Window {
 			case 2: 1;
 			case x: x;
 			};
-		case MouseMove:
+		case MouseMove if (!hxd.System.getValue(IsTouch)):
 			curMouseX = e.mouseX;
 			curMouseY = e.mouseY;
 			eh = new Event(EMove, e.mouseX, e.mouseY);