Permalink
Browse files

Draw stroke everywhere!

  • Loading branch information...
1 parent 30bceff commit d130d64eba6f388b03d9c0ee0b53e07b6c003f29 @dabaopku committed Feb 11, 2012
View
@@ -1,162 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.050000190734863">
- <data>
- <int key="IBDocument.SystemTarget">1060</int>
- <string key="IBDocument.SystemVersion">10A216</string>
- <string key="IBDocument.InterfaceBuilderVersion">708</string>
- <string key="IBDocument.AppKitVersion">994.4</string>
- <string key="IBDocument.HIToolboxVersion">404.00</string>
- <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
- <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="NS.object.0">708</string>
- </object>
- <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="NSArray" key="IBDocument.PluginDependencies">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- </object>
- <object class="NSMutableDictionary" key="IBDocument.Metadata">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- </object>
- <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSCustomObject" id="1001">
- <string key="NSClassName">NSObject</string>
- </object>
- <object class="NSCustomObject" id="1003">
- <string key="NSClassName">FirstResponder</string>
- </object>
- <object class="NSCustomObject" id="1004">
- <string key="NSClassName">NSApplication</string>
- </object>
- <object class="NSWindowTemplate" id="1005">
- <int key="NSWindowStyleMask">15</int>
- <int key="NSWindowBacking">2</int>
- <string key="NSWindowRect">{{196, 240}, {480, 270}}</string>
- <int key="NSWTFlags">544735232</int>
- <string key="NSWindowTitle">Window</string>
- <string key="NSWindowClass">NSWindow</string>
- <nil key="NSViewClass"/>
- <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
- <object class="NSView" key="NSWindowView" id="1006">
- <nil key="NSNextResponder"/>
- <int key="NSvFlags">256</int>
- <string key="NSFrameSize">{480, 270}</string>
- </object>
- <string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
- <string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
- </object>
- </object>
- <object class="IBObjectContainer" key="IBDocument.Objects">
- <object class="NSMutableArray" key="connectionRecords">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="IBMutableOrderedSet" key="objectRecords">
- <object class="NSArray" key="orderedObjects">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBObjectRecord">
- <int key="objectID">0</int>
- <object class="NSArray" key="object" id="1002">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <reference key="children" ref="1000"/>
- <nil key="parent"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">-2</int>
- <reference key="object" ref="1001"/>
- <reference key="parent" ref="1002"/>
- <string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">-1</int>
- <reference key="object" ref="1003"/>
- <reference key="parent" ref="1002"/>
- <string key="objectName">First Responder</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">-3</int>
- <reference key="object" ref="1004"/>
- <reference key="parent" ref="1002"/>
- <string key="objectName">Application</string>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">1</int>
- <reference key="object" ref="1005"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="1006"/>
- </object>
- <reference key="parent" ref="1002"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">2</int>
- <reference key="object" ref="1006"/>
- <reference key="parent" ref="1005"/>
- </object>
- </object>
- </object>
- <object class="NSMutableDictionary" key="flattenedProperties">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>-1.IBPluginDependency</string>
- <string>-2.IBPluginDependency</string>
- <string>-3.IBPluginDependency</string>
- <string>1.IBPluginDependency</string>
- <string>1.IBWindowTemplateEditedContentRect</string>
- <string>1.NSWindowTemplate.visibleAtLaunch</string>
- <string>1.WindowOrigin</string>
- <string>1.editorWindowContentRectSynchronizationRect</string>
- <string>2.IBPluginDependency</string>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{357, 418}, {480, 270}}</string>
- <integer value="1"/>
- <string>{196, 240}</string>
- <string>{{357, 418}, {480, 270}}</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- </object>
- </object>
- <object class="NSMutableDictionary" key="unlocalizedProperties">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- </object>
- <nil key="activeLocalization"/>
- <object class="NSMutableDictionary" key="localizations">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- </object>
- <nil key="sourceID"/>
- <int key="maxID">2</int>
- </object>
- <object class="IBClassDescriber" key="IBDocument.Classes"/>
- <int key="IBDocument.localizationMode">0</int>
- <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
- <nil key="IBDocument.LastKnownRelativeProjectPath"/>
- <int key="IBDocument.defaultPropertyAccessControl">3</int>
- </data>
-</archive>
@@ -25,7 +25,7 @@
E772DBF314E4424100A06FA8 /* testAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E772DBF214E4424100A06FA8 /* testAppDelegate.m */; };
E772DBF614E4424100A06FA8 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = E772DBF414E4424100A06FA8 /* MainMenu.xib */; };
E772DBF914E4424100A06FE6 /* Gesture.mm in Sources */ = {isa = PBXBuildFile; fileRef = E772DBF914E4424100A06FE5 /* Gesture.mm */; };
- E78E667814E6CBC700C7BDC3 /* DrawStrokeWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = E78E667714E6CBC700C7BDC3 /* DrawStrokeWindow.xib */; };
+ E7C4ED6F14E6DF6D006444E0 /* DrawStrokeView.m in Sources */ = {isa = PBXBuildFile; fileRef = E7C4ED6E14E6DF6D006444E0 /* DrawStrokeView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -69,7 +69,8 @@
E772DBF514E4424100A06FA8 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
E772DBF914E4424100A06FE5 /* Gesture.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Gesture.mm; sourceTree = "<group>"; };
E772DBF914E4424100A06FE7 /* Gesture.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Gesture.hh; sourceTree = "<group>"; };
- E78E667714E6CBC700C7BDC3 /* DrawStrokeWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DrawStrokeWindow.xib; sourceTree = "<group>"; };
+ E7C4ED6D14E6DF6D006444E0 /* DrawStrokeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawStrokeView.h; sourceTree = "<group>"; };
+ E7C4ED6E14E6DF6D006444E0 /* DrawStrokeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DrawStrokeView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -95,7 +96,6 @@
E750792514E2E70F00964C83 = {
isa = PBXGroup;
children = (
- E78E667714E6CBC700C7BDC3 /* DrawStrokeWindow.xib */,
E750793A14E2E70F00964C83 /* iStroke */,
E772DBE514E4424100A06FA8 /* test */,
E750793314E2E70F00964C83 /* Frameworks */,
@@ -134,22 +134,10 @@
E750793A14E2E70F00964C83 /* iStroke */ = {
isa = PBXGroup;
children = (
- E772DBF914E4424100A06FE5 /* Gesture.mm */,
- E772DBF914E4424100A06FE7 /* Gesture.hh */,
- E7727A1814E4544A00935AE7 /* Application.h */,
- E7727A1914E4544A00935AE7 /* Application.m */,
- E719195914E2F70C00193FDB /* EventListener.h */,
- E719195A14E2F70C00193FDB /* EventListener.mm */,
- E750796314E2EE3200964C86 /* ProcessHooker.h */,
- E750796314E2EE3200964C84 /* ProcessHooker.m */,
- E750794614E2E70F00964C83 /* iStrokeAppDelegate.hh */,
- E750794714E2E70F00964C83 /* iStrokeAppDelegate.mm */,
- E750794914E2E70F00964C83 /* MainMenu.xib */,
+ E7C4ED7014E6DFF5006444E0 /* Interface */,
+ E7C4ED7114E6E00D006444E0 /* Gesture */,
+ E7C4ED7214E6E021006444E0 /* Event */,
E750793B14E2E70F00964C83 /* Supporting Files */,
- E7727A1514E4541E00935AE7 /* ApplicationManager.h */,
- E7727A1614E4541E00935AE7 /* ApplicationManager.m */,
- E7727A1B14E4546B00935AE7 /* Stroke.hh */,
- E7727A1C14E4546C00935AE7 /* Stroke.mm */,
);
path = iStroke;
sourceTree = "<group>";
@@ -189,6 +177,44 @@
name = "Supporting Files";
sourceTree = "<group>";
};
+ E7C4ED7014E6DFF5006444E0 /* Interface */ = {
+ isa = PBXGroup;
+ children = (
+ E7C4ED6D14E6DF6D006444E0 /* DrawStrokeView.h */,
+ E7C4ED6E14E6DF6D006444E0 /* DrawStrokeView.m */,
+ E750794614E2E70F00964C83 /* iStrokeAppDelegate.hh */,
+ E750794714E2E70F00964C83 /* iStrokeAppDelegate.mm */,
+ E750794914E2E70F00964C83 /* MainMenu.xib */,
+ );
+ name = Interface;
+ sourceTree = "<group>";
+ };
+ E7C4ED7114E6E00D006444E0 /* Gesture */ = {
+ isa = PBXGroup;
+ children = (
+ E772DBF914E4424100A06FE5 /* Gesture.mm */,
+ E772DBF914E4424100A06FE7 /* Gesture.hh */,
+ E7727A1B14E4546B00935AE7 /* Stroke.hh */,
+ E7727A1C14E4546C00935AE7 /* Stroke.mm */,
+ );
+ name = Gesture;
+ sourceTree = "<group>";
+ };
+ E7C4ED7214E6E021006444E0 /* Event */ = {
+ isa = PBXGroup;
+ children = (
+ E7727A1514E4541E00935AE7 /* ApplicationManager.h */,
+ E7727A1614E4541E00935AE7 /* ApplicationManager.m */,
+ E7727A1814E4544A00935AE7 /* Application.h */,
+ E7727A1914E4544A00935AE7 /* Application.m */,
+ E719195914E2F70C00193FDB /* EventListener.h */,
+ E719195A14E2F70C00193FDB /* EventListener.mm */,
+ E750796314E2EE3200964C86 /* ProcessHooker.h */,
+ E750796314E2EE3200964C84 /* ProcessHooker.m */,
+ );
+ name = Event;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -261,7 +287,6 @@
E750793F14E2E70F00964C83 /* InfoPlist.strings in Resources */,
E750794514E2E70F00964C83 /* Credits.rtf in Resources */,
E750794B14E2E70F00964C83 /* MainMenu.xib in Resources */,
- E78E667814E6CBC700C7BDC3 /* DrawStrokeWindow.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -290,6 +315,7 @@
E7727A1A14E4544A00935AE7 /* Application.m in Sources */,
E7727A1D14E4546C00935AE7 /* Stroke.mm in Sources */,
E772DBF914E4424100A06FE6 /* Gesture.mm in Sources */,
+ E7C4ED6F14E6DF6D006444E0 /* DrawStrokeView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -0,0 +1,20 @@
+//
+// DrawStrokeView.h
+// iStroke
+//
+// Created by dabao on 12-2-12.
+// Copyright 2012年 PKU. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface DrawStrokeView : NSView {
+@private
+ NSMutableArray *strokePoint;
+}
+
+-(void) addPoint:(int)x :(int)y;
+-(void) clear;
+
+@end
View
@@ -0,0 +1,66 @@
+//
+// DrawStrokeView.m
+// iStroke
+//
+// Created by dabao on 12-2-12.
+// Copyright 2012年 PKU. All rights reserved.
+//
+
+#import "DrawStrokeView.h"
+
+@implementation DrawStrokeView
+
+- (id)initWithFrame:(NSRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ [self awakeFromNib];
+ }
+
+ return self;
+}
+
+-(void)awakeFromNib
+{
+ strokePoint=[[NSMutableArray alloc]init];
+}
+- (void)dealloc
+{
+ [super dealloc];
+}
+
+-(BOOL) isFlipped
+{
+ return YES;
+}
+
+- (void)drawRect:(NSRect)dirtyRect
+{
+ if([strokePoint count]<8)
+ return;
+
+ NSGraphicsContext *context=[NSGraphicsContext currentContext];
+ CGContextRef contextRef = (CGContextRef) [context graphicsPort];
+
+ CGContextSetRGBStrokeColor(contextRef, 1, 0, 0, 1);
+
+ CGContextBeginPath(contextRef);
+ CGContextMoveToPoint(contextRef,[[strokePoint objectAtIndex:0] intValue],[[strokePoint objectAtIndex:1] intValue]);
+ CGContextSetLineWidth(contextRef, 4);
+
+ for (NSUInteger i=1,n=[strokePoint count]/2; i<n; ++i) {
+ CGContextAddLineToPoint(contextRef,[[strokePoint objectAtIndex:2*i] intValue],[[strokePoint objectAtIndex:2*i+1] intValue]);
+ }
+ CGContextDrawPath(contextRef,kCGPathStroke);
+}
+
+-(void) addPoint:(int)x :(int)y
+{
+ [strokePoint addObject:[[NSNumber alloc] initWithInt:x]];
+ [strokePoint addObject:[[NSNumber alloc] initWithInt:y]];
+}
+-(void)clear
+{
+ [strokePoint removeAllObjects];
+}
+@end
View
@@ -69,6 +69,7 @@ - (CGEventRef)callback:(CGEventTapProxy)proxy :(CGEventType)type :(CGEventRef)ev
if (state==kListen) {
if (type==maskDown) {
trackNum=0;
+ CGEventSetType(event, kCGEventNull);
}
if (type==maskUp) {
if (trackNum>5) {
@@ -82,10 +83,7 @@ - (CGEventRef)callback:(CGEventTapProxy)proxy :(CGEventType)type :(CGEventRef)ev
iStrokeAppDelegate *app = [[NSApplication sharedApplication] delegate];
CGPoint pos=CGEventGetLocation(event);
[app addPoint:pos.x :pos.y];
- }
- CGEventSetType(event, kCGEventNull);
- return event;
-
+ }
}
return event;
}
View
@@ -32,7 +32,8 @@
void Stroke::addPoint(double x, double y)
{
- assert(capacity>n);
+ if(capacity<=n)
+ return;
p[n].x=x;
p[n].y=y;
n++;
Oops, something went wrong.

0 comments on commit d130d64

Please sign in to comment.