Просмотр исходного кода

Add custom cursor support to JS target (#425)

Pavel Alexandrov 7 лет назад
Родитель
Сommit
bbc99b8893
3 измененных файлов с 13 добавлено и 4 удалено
  1. 4 0
      hxd/Cursor.hx
  2. 9 1
      hxd/System.js.hx
  3. 0 3
      samples/Cursor.hx

+ 4 - 0
hxd/Cursor.hx

@@ -24,6 +24,8 @@ class CustomCursor {
 	static var UID = 0;
 	var name : String;
 	var alloc : flash.ui.MouseCursorData;
+	#elseif js
+	var alloc : Array<String>;
 	#else
 	var alloc : Dynamic;
 	#end
@@ -49,6 +51,8 @@ class CustomCursor {
 			flash.ui.Mouse.unregisterCursor(name);
 			#elseif hldx
 			alloc.destroy();
+			#elseif js
+			// alloc set to null below.
 			#else
 			throw "TODO";
 			#end

+ 9 - 1
hxd/System.js.hx

@@ -67,7 +67,15 @@ class System {
 			case Move: "move";
 			case TextInput: "text";
 			case Hide: "none";
-			case Custom(_): throw "Custom cursor not supported";
+			case Custom(cur):
+				if ( cur.alloc == null ) {
+					if ( cur.frames.length > 1 ) throw "Animated cursor not supported";
+					cur.alloc = new Array();
+					for ( frame in cur.frames ) {
+						cur.alloc.push("url(\"" + frame.toNative().canvas.toDataURL("image/png") + "\") " + cur.offsetX + " " + cur.offsetY + ", default");
+					}
+				}
+				cur.alloc[0];
 			};
 		}
 	}

+ 0 - 3
samples/Cursor.hx

@@ -24,9 +24,6 @@ class Cursor extends hxd.App {
 			i.backgroundColor = Std.random(0x1000000) | 0xFF000000;
 
 			var supported = true;
-			#if js
-			if( c.match(Custom(_)) ) supported = false;
-			#end
 
 			if( !supported ) {
 				tf.textColor = 0xFF0000;