浏览代码

Added some emscripten hacks; docs...

Mark Sibly 9 年之前
父节点
当前提交
2f89c95764
共有 2 个文件被更改,包括 34 次插入11 次删除
  1. 24 10
      modules/mojo/input/keyboard.monkey2
  2. 10 1
      modules/mojo/input/mouse.monkey2

+ 24 - 10
modules/mojo/input/keyboard.monkey2

@@ -16,21 +16,24 @@ Global bbKeyInfos:bbKeyInfo Ptr
 
 Public
 
-#rem monkeydoc Global Keyboard device.
-#end
-Global Keyboard:=New KeyboardDevice
+#rem monkeydoc Application keyboard device instance.
 
-#rem monkeydoc The KeyboardDevice class.
+#end
+Const Keyboard:=New KeyboardDevice
 
-The KeyboardDevice can be accessed via the [[Keyboard]] global variable.
+#rem monkeydoc The KeyboardDevice singleton class.
 
-Note that all methods can also be used with 'raw' keys. 
+All method that take a `key` parameter can also be used with 'raw' keys.
 
 A raw key represents the physical location of a key on US keyboards. For example, `Key.Q|Key.Raw` indicates the key at the top left of the
 'qwerty' keys regardless of the current keyboard layout.
 
 Please see the [[Key]] enum for more information on raw keys.
 
+To access the keyboard device, use the global [[Keyboard]] constant.
+
+The keyboard device should only used after a new [[app.AppInstance]] is created.
+
 #end
 Class KeyboardDevice Extends InputDevice
 
@@ -61,8 +64,12 @@ Class KeyboardDevice Extends InputDevice
 	#end
 	Method TranslateKey:Key( key:Key )
 		If key & Key.Raw
+#If __TARGET__="emscripten"
+			Return key & ~Key.Raw
+#Else
 			Local keyCode:=SDL_GetKeyFromScancode( Cast<SDL_Scancode>( _raw2scan[ key & ~Key.Raw ] ) )
 			Return KeyCodeToKey( keyCode )
+#Endif
 		Else
 			Local scanCode:=_key2scan[key]
 			Return _scan2raw[scanCode]
@@ -189,9 +196,15 @@ Class KeyboardDevice Extends InputDevice
 			Local key:=KeyCodeToKey( keyCode )
 			
 			_names[key]=name
-			_key2scan[key]=SDL_GetScancodeFromKey( Cast<SDL_Keycode>( keyCode ) )
 			_raw2scan[key]=scanCode
 			_scan2raw[scanCode]=key | Key.Raw
+#If __TARGET__="emscripten"
+			_key2scan[key]=scanCode
+#Else
+			_key2scan[key]=SDL_GetScancodeFromKey( Cast<SDL_Keycode>( keyCode ) )
+#Endif
+			_scan2key[_key2scan[key]]=scanCode
+			
 			
 			p=p+1
 		Wend
@@ -209,9 +222,10 @@ Class KeyboardDevice Extends InputDevice
 	Field _pressed:=New Bool[512]
 	Field _released:=New Bool[512]
 	Field _names:=New String[512]
-	Field _key2scan:=New Int[512]
-	Field _raw2scan:=New Int[512]
-	Field _scan2raw:=New Key[512]
+	Field _raw2scan:=New Int[512]	'no translate
+	Field _scan2raw:=New Key[512]	'no translate
+	Field _key2scan:=New Int[512]	'translate
+	Field _scan2key:=New Int[512]	'translate
 	
 	Method New()
 	End

+ 10 - 1
modules/mojo/input/mouse.monkey2

@@ -1,7 +1,9 @@
 
 Namespace mojo.input
 
-Global Mouse:=New MouseDevice
+#rem monkeydoc Application mouse device instance.
+#end
+Const Mouse:=New MouseDevice
 
 #rem monkeydoc Mouse buttons.
 
@@ -19,6 +21,13 @@ Enum MouseButton
 	Right=3
 End
 
+#rem monkeydoc The MouseDevice singleton class.
+
+To access the mouse device, use the [[Mouse]] constant.
+
+The mouse device should only used after a new [[app.AppInstance]] is created.
+
+#end
 Class MouseDevice Extends InputDevice
 
 	#rem monkeydoc @hidden