[Vm-dev] [commit][3693] minor revisions to point x/y rounding

commits at squeakvm.org commits at squeakvm.org
Tue May 3 22:17:48 UTC 2016


Revision: 3693
Author:   johnmci
Date:     2016-05-03 15:17:47 -0700 (Tue, 03 May 2016)
Log Message:
-----------
minor revisions to point x/y rounding

Modified Paths:
--------------
    branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m

Modified: branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m
===================================================================
--- branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m	2016-05-02 05:12:46 UTC (rev 3692)
+++ branches/Cog/platforms/iOS/vm/OSX/sqSqueakOSXApplication+events.m	2016-05-03 22:17:47 UTC (rev 3693)
@@ -15,10 +15,10 @@
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:
-
+ 
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.
-
+ 
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -27,7 +27,7 @@
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
-
+ 
  The end-user documentation included with the redistribution, if any, must include the following acknowledgment: 
  "This product includes software developed by Corporate Smalltalk Consulting Ltd (http://www.smalltalkconsulting.com) 
  and its contributors", in the same place and form as other third-party acknowledgments. 
@@ -51,7 +51,7 @@
  bits. (The Mac shift and caps lock keys are both mapped to the single
  Squeak shift bit).  This was true for squeak upto 3.0.7. Then in 3.0.8 we 
  decided to not map the cap lock key to shift
-
+ 
  Mac bits: <control><option><caps lock><shift><command>
  ST bits:  <command><option><control><shift>
  */
@@ -108,7 +108,7 @@
 
 - (void) pumpRunLoopEventSendAndSignal:(BOOL)signal {
     NSEvent *event;
-
+    
     while ((event = [NSApp
                         nextEventMatchingMask:NSAnyEventMask
                         untilDate:nil 
@@ -133,16 +133,16 @@
 	 using the runloop, but if you just run the runloop on the main thread,
 	 events won't get processed. You have to explicitly run this in order
 	 to get them to be processed.
-
+	 
 	 Note that using the default runloop mode with this is generally a bad
 	 idea. By running in the default mode you allow *everything* else to
 	 run, which means that some other code might decide that *it* wants an
 	 inner event loop as well. If you then want to quit before that other
 	 code has finished, tough cookies. Much better to control things more
 	 tightly by using a different runloop mode.
-
+	 
 	 */
-
+	
 }
 
 - (void ) processAsOldEventOrComplexEvent: (id) event placeIn: (sqInputEvent *) evt {
@@ -166,17 +166,17 @@
 	NSInteger	i;
 	NSRange picker;
 	NSUInteger totaLength;
-
+	
 	evt.type = EventTypeKeyboard;
-	evt.timeStamp = ioMSecs();
+	evt.timeStamp =  ioMSecs();
 	picker.location = 0;
 	picker.length = 1;
 	totaLength = [unicodeString length];
 	for (i=0;i < totaLength;i++) {
-
-
+		
+		
 		unicode = [unicodeString characterAtIndex: i];
-
+		
 		if (mainView.lastSeenKeyBoardStrokeDetails) {
 			evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: mainView.lastSeenKeyBoardStrokeDetails.modifierFlags];
 			evt.charCode = mainView.lastSeenKeyBoardStrokeDetails.keyCode;
@@ -184,32 +184,32 @@
 			evt.modifiers = 0;
 			evt.charCode = 0;
 		}
-
+		
 		if ((evt.modifiers & CommandKeyBit) && (evt.modifiers & ShiftKeyBit)) {  /* command and shift */
             if ((unicode >= 97) && (unicode <= 122)) {
 				/* convert ascii code of command-shift-letter to upper case */
 				unicode = unicode - 32;
             }
 		}
-
+		
 		NSString *lookupString = AUTORELEASEOBJ([[NSString alloc] initWithCharacters: &unicode length: 1]);
 		[lookupString getBytes: &macRomanCharacter maxLength: 1 usedLength: NULL encoding: NSMacOSRomanStringEncoding
 					   options: 0 range: picker remainingRange: NULL];
-
+		
 		evt.pressCode = EventKeyDown;
 		unsigned short keyCodeRemembered = evt.charCode;
 		evt.utf32Code = 0;
 		evt.reserved1 = 0;
-		evt.windowIndex = mainView.windowLogic.windowIndex;
+		evt.windowIndex =   mainView.windowLogic.windowIndex;
 		[self pushEventToQueue: (sqInputEvent *)&evt];
-
+		
 		evt.charCode =	macRomanCharacter;
 		evt.pressCode = EventKeyChar;
 		evt.modifiers = evt.modifiers;		
 		evt.utf32Code = unicode;
-
+		
 		[self pushEventToQueue: (sqInputEvent *) &evt];
-
+		
 		if (i > 1 || !mainView.lastSeenKeyBoardStrokeDetails) {
 			evt.pressCode = EventKeyUp;
 			evt.charCode = keyCodeRemembered;
@@ -217,16 +217,16 @@
 			[self pushEventToQueue: (sqInputEvent *) &evt];
 		}
 	}
-
+	
 	interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
 
 }
 
 - (void) recordKeyDownEvent:(NSEvent *)theEvent fromView: (sqSqueakOSXOpenGLView *) aView {
 	sqKeyboardEvent evt;
-
+	
 	evt.type = EventTypeKeyboard;
-	evt.timeStamp = ioMSecs();
+	evt.timeStamp =  ioMSecs();
 	evt.charCode =	[theEvent keyCode];
 	evt.pressCode = EventKeyDown;
 	evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: [theEvent modifierFlags]];
@@ -240,15 +240,15 @@
 
 - (void) recordKeyUpEvent:(NSEvent *)theEvent fromView: (sqSqueakOSXOpenGLView *) aView {
 	sqKeyboardEvent evt;
-
+	
 	evt.type = EventTypeKeyboard;
-	evt.timeStamp = ioMSecs();
+	evt.timeStamp =  ioMSecs();
 	evt.charCode =	[theEvent keyCode];
 	evt.pressCode = EventKeyUp;
 	evt.modifiers = [self translateCocoaModifiersToSqueakModifiers: [theEvent modifierFlags]];
 	evt.utf32Code = 0;
 	evt.reserved1 = 0;
-	evt.windowIndex = aView.windowLogic.windowIndex;
+	evt.windowIndex =  aView.windowLogic.windowIndex;
 	[self pushEventToQueue: (sqInputEvent *) &evt];
 
 	interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
@@ -256,15 +256,15 @@
 
 - (void) recordMouseEvent:(NSEvent *)theEvent fromView: (sqSqueakOSXOpenGLView *) aView{
 	sqMouseEvent evt;
-
+	
 	evt.type = EventTypeMouse;
 	evt.timeStamp = ioMSecs();
-
+	
 	NSPoint local_point = [aView convertPoint: [theEvent locationInWindow] fromView:nil];
-
-	evt.x = local_point.x; 
-	evt.y = local_point.y;
-
+	
+	evt.x =  lrintf((float)local_point.x);
+	evt.y =  lrintf((float)local_point.y);
+	
 	int buttonAndModifiers = [self mapMouseAndModifierStateToSqueakBits: theEvent];
 	evt.buttons = buttonAndModifiers & 0x07;
 	evt.modifiers = buttonAndModifiers >> 3;
@@ -273,28 +273,28 @@
 #else
 	evt.reserved1 = 0;
 #endif 
-	evt.windowIndex = aView.windowLogic.windowIndex;
-
+	evt.windowIndex =  aView.windowLogic.windowIndex;
+	
 	[self pushEventToQueue:(sqInputEvent *) &evt];
-//NSLog(@"mouse hit x %i y %i buttons %i mods %i",evt.x,evt.y,evt.buttons,evt.modifiers);
+    //NSLog(@"mouse hit x %i y %i buttons %i mods %i",evt.x,evt.y,evt.buttons,evt.modifiers);
 	interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
 }
-
+						   
 - (void) recordWheelEvent:(NSEvent *) theEvent fromView: (sqSqueakOSXOpenGLView *) aView{
-
+		
 	[self recordMouseEvent: theEvent fromView: aView];
 	CGFloat x = [theEvent deltaX];
 	CGFloat y = [theEvent deltaY];
 
 	if (x != 0.0f) {
-		[self fakeMouseWheelKeyboardEventsKeyCode: (x < 0 ? 124 : 123) ascii: (x < 0 ? 29 : 28) windowIndex:  aView.windowLogic.windowIndex];
+		[self fakeMouseWheelKeyboardEventsKeyCode: (x < 0 ? 124 : 123) ascii: (x < 0 ? 29 : 28) windowIndex:   aView.windowLogic.windowIndex];
 	}
 	if (y != 0.0f) {
-		[self fakeMouseWheelKeyboardEventsKeyCode: (y < 0 ? 125 : 126) ascii: (y < 0 ? 31 : 30) windowIndex: aView.windowLogic.windowIndex];
+		[self fakeMouseWheelKeyboardEventsKeyCode: (y < 0 ? 125 : 126) ascii: (y < 0 ? 31 : 30) windowIndex:  aView.windowLogic.windowIndex];
 	}
 }
-
-- (void) fakeMouseWheelKeyboardEventsKeyCode: (int) keyCode ascii: (int) ascii windowIndex: (sqInt) windowIndex {
+		  
+- (void) fakeMouseWheelKeyboardEventsKeyCode: (int) keyCode ascii: (int) ascii windowIndex: (int) windowIndex {
 	sqKeyboardEvent evt;
 
 	evt.type = EventTypeKeyboard;
@@ -311,12 +311,12 @@
 	evt.charCode = ascii;
 	evt.utf32Code = ascii;
 	[self pushEventToQueue:(sqInputEvent *) &evt];
-
+	
 	evt.pressCode = EventKeyUp;
 	evt.charCode =	keyCode;
 	evt.utf32Code = 0;
 	[self pushEventToQueue:(sqInputEvent *) &evt];
-
+	
 }
 
 - (int) translateCocoaModifiersToSqueakModifiers: (NSUInteger) modifiers {
@@ -337,23 +337,23 @@
 	if (modifiers & NSCommandKeyMask)
 		keyBoardModifiers |= cmdKey;
 	return keyBoardModifiers;
-
+		
 }
-
+		
 - (int) mapMouseAndModifierStateToSqueakBits: (NSEvent *) event {
 	/* On a two- or three-button mouse, the left button is normally considered primary and the 
 	 right button secondary, 
 	 but left-handed users can reverse these settings as a matter of preference. 
 	 The middle button on a three-button mouse is always the tertiary button. '
-
+	 
 	 But mapping assumes 1,2,3  red, yellow, blue
 	 */
-
+	
 	NSInteger stButtons,modifier,mappedButton;
 	NSInteger mouseButton=0;
-
+	
 	static NSInteger buttonStateBits[4] = {0,0,0,0};
-
+	
 	stButtons = buttonState;
 	NSUInteger keyBoardCarbonModifiers = [self translateCocoaModifiersToCarbonModifiers: [event modifierFlags]];
 	NSInteger whatHappened = [event type];
@@ -366,9 +366,9 @@
 			mouseButton = 2;
 		if (!mouseButton)
 			mouseButton = [event buttonNumber] + 1; //buttonNumber seems to count from 0.
-
+		
 		if (mouseButton > 0 && mouseButton < 4) {
-
+			
 			modifier = 0;
 			if (keyBoardCarbonModifiers & cmdKey  )
 				modifier = 1;
@@ -376,7 +376,7 @@
 				modifier = 2;
 			if (keyBoardCarbonModifiers & controlKey)
 				modifier = 3;
-
+			
 			if (browserActiveAndDrawingContextOkAndNOTInFullScreenMode())
 				mappedButton = [(sqSqueakOSXInfoPlistInterface *) self.infoPlistInterfaceLogic getSqueakBrowserMouseMappingsAt: modifier by: mouseButton];
 			else
@@ -390,35 +390,36 @@
 			stButtons |= mappedButton == 3 ? (buttonStateBits[mappedButton] ? BlueButtonBit : 0)  : 0;
 		}
 	}
-
+	
 	// button state: low three bits are mouse buttons; next 8 bits are modifier bits
-	buttonState = (modifierMap[((keyBoardCarbonModifiers & 0xFFFF) >> 8)] << 3) | (stButtons & 0x7);
+	buttonState =  (modifierMap[((keyBoardCarbonModifiers & 0xFFFF) >> 8)] << 3) | (stButtons & 0x7);
 	return buttonState;
 }
 
-- (void) recordDragEvent:(int)dragType numberOfFiles:(int)numFiles where:(NSPoint)point windowIndex:(sqInt)windowIndex view:(NSView *)aView{
+- (void) recordDragEvent:(int)dragType numberOfFiles:(int)numFiles where:(NSPoint)point windowIndex:(sqInt)windowIndex view:(NSView *)aView
+{
 	sqDragDropFilesEvent evt;
-
+	
     NSPoint local_point = [aView convertPoint:point fromView:nil];
-
+    
 	evt.type= EventTypeDragDropFiles;
 	evt.timeStamp= ioMSecs();
 	evt.dragType= dragType;
-	evt.x = local_point.x; 
-	evt.y = local_point.y;
+	evt.x = lrintf(local_point.x);
+	evt.y = lrintf(local_point.y);
 	evt.modifiers= (buttonState >> 3);
 	evt.numFiles= numFiles;
-	evt.windowIndex = windowIndex;
+	evt.windowIndex =  windowIndex;
 	[self pushEventToQueue: (sqInputEvent *) &evt];
-
+	
 	interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
 }
 
 - (void) recordWindowEvent: (int) windowType window: (NSWIndow *) window {
 	sqWindowEvent evt;
-
+	
 	evt.type= EventTypeWindow;
-	evt.timeStamp= ioMSecs();
+	evt.timeStamp=  ioMSecs();
 	evt.action= windowType;
 	evt.value1 =  0;
 	evt.value2 =  0;
@@ -426,7 +427,7 @@
 	evt.value4 =  0;
 	evt.windowIndex = windowIndexFromHandle((wHandleType)window);
 	[self pushEventToQueue: (sqInputEvent *) &evt];
-
+	
 	interpreterProxy->signalSemaphoreWithIndex(gDelegateApp.squeakApplication.inputSemaphoreIndex);
 }
 



More information about the Vm-dev mailing list