소스 검색

Make Mac use TextInput Event.

fodinabor 9 년 전
부모
커밋
d1ad2ea38b
3개의 변경된 파일19개의 추가작업 그리고 24개의 파일을 삭제
  1. 1 1
      include/polycode/core/PolyCocoaCore.h
  2. 5 2
      src/core/PolyCocoaCore.mm
  3. 13 21
      src/view/osx/PolycodeView.mm

+ 1 - 1
include/polycode/core/PolyCocoaCore.h

@@ -65,7 +65,7 @@ namespace Polycode {
 		TouchInfo touch;
 		
 		PolyKEY keyCode;
-		wchar_t unicodeChar;
+        String text;
 		
 		char mouseButton;
 		

+ 5 - 2
src/core/PolyCocoaCore.mm

@@ -494,10 +494,10 @@ void CocoaCore::checkEvents() {
 						break;
 					case InputEvent::EVENT_KEYDOWN:
 						if(!checkSpecialKeyEvents(event.keyCode))
-							input->setKeyState(event.keyCode, event.unicodeChar, true, getTicks());
+							input->setKeyState(event.keyCode, true, getTicks());
 						break;
 					case InputEvent::EVENT_KEYUP:
-						input->setKeyState(event.keyCode, event.unicodeChar, false, getTicks());
+						input->setKeyState(event.keyCode, false, getTicks());
                     break;
                     case InputEvent::EVENT_TOUCHES_BEGAN:
                         input->touchesBegan(event.touch, event.touches, getTicks());
@@ -508,6 +508,9 @@ void CocoaCore::checkEvents() {
                     case InputEvent::EVENT_TOUCHES_MOVED:
                         input->touchesMoved(event.touch, event.touches, getTicks());
                     break;
+					case InputEvent::EVENT_TEXTINPUT:
+						input->textInput(event.text);
+					break;
 				}
 				break;
 				case CocoaEvent::FOCUS_EVENT:

+ 13 - 21
src/view/osx/PolycodeView.mm

@@ -682,7 +682,6 @@
 			// Don't care otherwise
 			break;
 	}
-	newEvent.unicodeChar = 0;
 	
 	
 	core->cocoaEvents.push_back(newEvent);	
@@ -700,19 +699,20 @@
 	newEvent.eventGroup = CocoaEvent::INPUT_EVENT;
 	newEvent.eventCode = InputEvent::EVENT_KEYDOWN;
 	newEvent.keyCode = keymap[[theEvent keyCode]];	
-	
-	NSString *chars = [theEvent characters];
-	NSUInteger numChars = [chars length];
-	
-//	NSLog(@"CHARS: %@", [chars characterAtIndex:0]);
-	if(numChars > 0) {
-		newEvent.unicodeChar = [chars characterAtIndex:0];
-	} else {
-		newEvent.unicodeChar = 0;
+    core->cocoaEvents.push_back(newEvent);
+    
+    CocoaEvent textEvent;
+    textEvent.eventGroup = CocoaEvent::INPUT_EVENT;
+    textEvent.eventCode = InputEvent::EVENT_TEXTINPUT;
+    
+    NSString *chars = [theEvent characters];
+    NSUInteger numChars = [chars length];
+	textEvent.text = [chars UTF8String];
+	if(numChars > 0 && !((unsigned char) textEvent.text[0] < ' ' || textEvent.text[0] == 127) && textEvent.text[0] > 0) {
+		core->cocoaEvents.push_back(textEvent);
 	}
 	
-	core->cocoaEvents.push_back(newEvent);	
-	core->unlockMutex(core->eventMutex);	
+	core->unlockMutex(core->eventMutex);
 	
 }
 
@@ -726,15 +726,7 @@
 	newEvent.eventGroup = CocoaEvent::INPUT_EVENT;
 	newEvent.eventCode = InputEvent::EVENT_KEYUP;
 	newEvent.keyCode = keymap[[theEvent keyCode]];
-	
-	NSString *chars = [theEvent characters];
-	NSUInteger numChars = [chars length];
-	
-	if(numChars > 0)
-		newEvent.unicodeChar = [chars characterAtIndex:0];
-	else
-		newEvent.unicodeChar = 0;
-	
+    
 	core->cocoaEvents.push_back(newEvent);	
 	core->unlockMutex(core->eventMutex);		
 }