[Gridflow-cvs] [svn] commit: r5133 - in /trunk: ChangeLog TODO src/quartz.m

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Wed Mar 17 21:26:54 EDT 2010


Author: pboivin
Date: Wed Mar 17 21:26:52 2010
New Revision: 5133

Log:
add [#io.quartz] position (compatible with [#io.x11]'s)

Modified:
    trunk/ChangeLog
    trunk/TODO
    trunk/src/quartz.m

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog (original)
+++ trunk/ChangeLog Wed Mar 17 21:26:52 2010
@@ -7,6 +7,7 @@
  * small fixes to colouring of [display] and [#see]
  * added [gf/selector] [gf/getcwd] [gf/find_file]
  * OSX: print real error messages instead of error #-43, etc.
+ * OSX: [#io.quartz] reports position
  * [#in]: lookup file in -path and the dir of the patch containing [#in]
 
 version 0.9.7 (2010.02.26):

Modified: trunk/TODO
==============================================================================
--- trunk/TODO (original)
+++ trunk/TODO Wed Mar 17 21:26:52 2010
@@ -6,7 +6,8 @@
 0.9.8 assigned to Patrick:
 [ ] [#io.quicktimecamera] contrast, brightness, hue, saturation, colour, etc.
 [ ] [#io.quicktimecamera] minsize, size, maxsize
-[ ] [#io.quartz] position/keypress/keyrelease
+[x] [#io.quartz] position
+[ ] [#io.quartz] keypress/keyrelease
 [ ] [#io.quartz] setcursor/hidecursor
 [ ] [#io.quartz] fullscreen mode
 [ ] [#io.quicktime out] grid, codec, quality.

Modified: trunk/src/quartz.m
==============================================================================
--- trunk/src/quartz.m (original)
+++ trunk/src/quartz.m Wed Mar 17 21:26:52 2010
@@ -45,7 +45,6 @@
 - (int) imageWidth;
 - (uint8 *) imageData;
 - (int) imageDataSize;
-- (void) mouseMoved: (NSEvent *)theEvent;
 - (BOOL) acceptsFirstResponder;
 @end
 
@@ -96,9 +95,6 @@
 	return self;
 }
 
-- (void) mouseMoved: (NSEvent *)theEvent {    /// doesn't work...
-	post("mouseMoved");	
-}
 - (BOOL) acceptsFirstResponder {return YES;}
 
 @end
@@ -124,6 +120,7 @@
 	NSWindow *window;
 	NSWindowController *wc;
 	GFView *widget; /* GridFlow's Cocoa widget */
+	NSPoint mouse_lastpos;
 	int mouse_state;
 	t_clock *clock;
 	\constructor (t_symbol *mode) {
@@ -142,13 +139,14 @@
 		clock = clock_new(this,(t_method)FormatQuartz_call);
 		clock_delay(clock,0);
 		[window makeFirstResponder: widget];
-		[window setAcceptsMouseMovedEvents: YES];
 		//post("mainWindow = %08lx",(long)[NSApp mainWindow]);
 		//post(" keyWindow = %08lx",(long)[NSApp keyWindow]);
 		NSColor *color = [NSColor clearColor];
 		[window setBackgroundColor: color];
 		_0_move(0,0,0,0);
 		mouse_state = 0;
+		mouse_lastpos.x = 0;
+		mouse_lastpos.y = 0;
 	}
 	~FormatQuartz () {
 		clock_unset(clock);
@@ -172,48 +170,56 @@
 	SETFLOAT(a+1,x);
 	SETFLOAT(a+2,state);
 	outlet_anything(outlets[0],gensym("position"),COUNT(a),a);
+	this->mouse_lastpos.y = y;
+	this->mouse_lastpos.x = x;
 }
 
 static NSDate *distantFuture, *distantPast;
+
+#define VALIDATE_MOUSEEVENT  if ((p.y >= 0 && p.y <= [this->widget imageHeight]) && \
+                                 (p.x >= 0 && p.x <= [this->widget imageWidth])) wasMouseEvent = YES
 
 void FormatQuartz::call() {
 	BOOL wasMouseEvent = NO;
-	NSPoint p;
-	NSEvent *e = [NSApp nextEventMatchingMask: NSAnyEventMask | NSMouseMovedMask
+	NSPoint p, *l=&this->mouse_lastpos;
+	NSEvent *e = [NSApp nextEventMatchingMask: NSAnyEventMask
 		// untilDate: distantFuture // blocking
-		untilDate: distantPast // nonblocking
+		untilDate: distantPast      // nonblocking
 		inMode: NSDefaultRunLoopMode
 		dequeue: YES];
+		
+	p = [this->window mouseLocationOutsideOfEventStream];
+	p.y = [this->widget imageHeight] - p.y;
+	if (p.y != l->y || p.x != l->x) // mouse moved
+		VALIDATE_MOUSEEVENT;    // inside our window ?
 	if (e) {
-		NSLog(@"%@", e);
+		//NSLog(@"%@", e);
 		[NSApp sendEvent: e];
-		p = [this->window mouseLocationOutsideOfEventStream];
-		
 		switch ([e type]) {
 		case NSLeftMouseDown:
-			this->mouse_state += 256;  wasMouseEvent = YES; break;
+			this->mouse_state += 256;  VALIDATE_MOUSEEVENT; break;
 		case NSLeftMouseUp:
-			this->mouse_state -= 256;  wasMouseEvent = YES; break;
+			this->mouse_state -= 256;  VALIDATE_MOUSEEVENT; break;
 		case NSOtherMouseDown:
-			this->mouse_state += 512;  wasMouseEvent = YES; break;
+			this->mouse_state += 512;  VALIDATE_MOUSEEVENT; break;
 		case NSOtherMouseUp:
-			this->mouse_state -= 512;  wasMouseEvent = YES; break;
+			this->mouse_state -= 512;  VALIDATE_MOUSEEVENT; break;
 		case NSRightMouseDown:
-			this->mouse_state += 1024; wasMouseEvent = YES; break;
+			this->mouse_state += 1024; VALIDATE_MOUSEEVENT; break;
 		case NSRightMouseUp:
-			this->mouse_state -= 1024; wasMouseEvent = YES; break;
+			this->mouse_state -= 1024; VALIDATE_MOUSEEVENT; break;
 		case NSLeftMouseDragged:
 		case NSRightMouseDragged:
 		case NSOtherMouseDragged:
-			wasMouseEvent = YES; break;
+			wasMouseEvent = YES; break; // don't VALIDATE_MOUSEEVENT for when dragging outside the window
 		}
-		int img_h = [this->widget imageHeight];
-		if (wasMouseEvent) report_pointer(img_h - (int)p.y, (int)p.x, this->mouse_state);
-	}
+	}
+	if (wasMouseEvent) report_pointer((int)p.y, (int)p.x, this->mouse_state);
 	[NSApp updateWindows];
 	[this->window flushWindowIfNeeded];
 	clock_delay(clock,20);
 }
+
 void FormatQuartz_call(FormatQuartz *self) {self->call();}
 
 template <class T, class S>



More information about the Gridflow-cvs mailing list