Permalink
Browse files

GridView

  • Loading branch information...
1 parent 6318cfe commit c7ced8044f2399499fc25f5d38cb4749fe75a814 @takuma104 committed Apr 6, 2010
Showing with 173 additions and 21 deletions.
  1. +11 −0 GridView.h
  2. +92 −0 GridView.m
  3. +10 −0 NTouches.xcodeproj/project.pbxproj
  4. +6 −1 Shared/MainViewController.m
  5. +30 −6 iPad/MainWindow_Pad.xib
  6. +24 −14 iPhone/MainWindow_Phone.xib
View
@@ -0,0 +1,11 @@
+#import <UIKit/UIKit.h>
+#import <QuartzCore/QuartzCore.h>
+
+@interface GridView : UIView {
+// double lastUpdate;
+// CALayer *gridLayer;
+}
+
+- (void)updateGrid;
+
+@end
View
@@ -0,0 +1,92 @@
+#import "GridView.h"
+/*
+@interface Grid : NSObject
+{
+ GridView *gridView;
+}
+
+@property (readwrite, assign) GridView *gridView;
+
+@end
+
+@implementation Grid
+
+@synthesize gridView;
+
+- (void)drawLayer:(CALayer *)l inContext:(CGContextRef)context {
+ CGContextSetLineWidth(context, 1.f);
+ const CGFloat col = 55.f/255.f;
+ CGContextSetRGBStrokeColor(context, col, col, col, 1.f);
+ CGFloat width = gridView.bounds.size.width;
+ CGFloat height = gridView.bounds.size.height;
+ for (UIView *v in gridView.subviews) {
+ if ([v isKindOfClass:[UIImageView class]]) {
+ CGPoint pt = v.center;
+ CGPoint pts[4];
+ pts[0] = CGPointMake(0, pt.y+0.5f);
+ pts[1] = CGPointMake(width, pt.y+0.5f);
+ pts[2] = CGPointMake(pt.x+0.5f, 0.f);
+ pts[3] = CGPointMake(pt.x+0.5f, height);
+ CGContextStrokeLineSegments(context, pts, 4);
+ }
+ }
+}
+
+@end
+*/
+
+@implementation GridView
+
+/*- (id)initWithFrame:(CGRect)f {
+ if ((self = [super initWithFrame:f])) {
+
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSCoder *)aDecoder {
+ if ((self = [super initWithCoder:aDecoder])) {
+ Grid *g = [[[Grid alloc] init] autorelease];
+ g.gridView = self;
+ gridLayer = [[CALayer layer] retain];
+ gridLayer.delegate = g;
+ gridLayer.bounds = self.bounds;
+ gridLayer.position = self.center;
+ [self.layer addSublayer:gridLayer];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [gridLayer release];
+ [super dealloc];
+}
+*/
+
+
+- (void)drawRect:(CGRect)rect {
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGContextSetLineWidth(context, 1.f);
+ const CGFloat col = 55.f/255.f;
+ CGContextSetRGBStrokeColor(context, col, col, col, 1.f);
+ CGFloat width = self.bounds.size.width;
+ CGFloat height = self.bounds.size.height;
+ for (UIView *v in self.subviews) {
+ if ([v isKindOfClass:[UIImageView class]]) {
+ CGPoint pt = v.center;
+ CGPoint pts[4];
+ pts[0] = CGPointMake(0, pt.y+0.5f);
+ pts[1] = CGPointMake(width, pt.y+0.5f);
+ pts[2] = CGPointMake(pt.x+0.5f, 0.f);
+ pts[3] = CGPointMake(pt.x+0.5f, height);
+ CGContextStrokeLineSegments(context, pts, 4);
+ }
+ }
+}
+
+- (void)updateGrid {
+ [super setNeedsDisplay];
+// [gridLayer setNeedsDisplay];
+}
+
+@end
@@ -21,6 +21,8 @@
F19016FF116BB3A6002ED641 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = F19016FA116BB3A6002ED641 /* Default.png */; };
F1901700116BB3A6002ED641 /* icon72x72.png in Resources */ = {isa = PBXBuildFile; fileRef = F19016FB116BB3A6002ED641 /* icon72x72.png */; };
F1901701116BB3A6002ED641 /* touch.png in Resources */ = {isa = PBXBuildFile; fileRef = F19016FC116BB3A6002ED641 /* touch.png */; };
+ F1901852116BC487002ED641 /* GridView.m in Sources */ = {isa = PBXBuildFile; fileRef = F1901851116BC487002ED641 /* GridView.m */; };
+ F1901917116BCCBD002ED641 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1901916116BCCBD002ED641 /* QuartzCore.framework */; };
F1AF123E116B85CB0041D976 /* UIView+FadeInOut.m in Sources */ = {isa = PBXBuildFile; fileRef = F1AF123D116B85CB0041D976 /* UIView+FadeInOut.m */; };
/* End PBXBuildFile section */
@@ -45,6 +47,9 @@
F19016FA116BB3A6002ED641 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
F19016FB116BB3A6002ED641 /* icon72x72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon72x72.png; sourceTree = "<group>"; };
F19016FC116BB3A6002ED641 /* touch.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = touch.png; sourceTree = "<group>"; };
+ F1901850116BC487002ED641 /* GridView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridView.h; sourceTree = "<group>"; };
+ F1901851116BC487002ED641 /* GridView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GridView.m; sourceTree = "<group>"; };
+ F1901916116BCCBD002ED641 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
F1AF123C116B85CB0041D976 /* UIView+FadeInOut.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIView+FadeInOut.h"; path = "Shared/UIView+FadeInOut.h"; sourceTree = "<group>"; };
F1AF123D116B85CB0041D976 /* UIView+FadeInOut.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIView+FadeInOut.m"; path = "Shared/UIView+FadeInOut.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -57,6 +62,7 @@
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */,
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */,
288765FD0DF74451002DB57D /* CoreGraphics.framework in Frameworks */,
+ F1901917116BCCBD002ED641 /* QuartzCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -99,6 +105,8 @@
F110DA49116B7A01004C5C30 /* MainViewController.m */,
F1AF123C116B85CB0041D976 /* UIView+FadeInOut.h */,
F1AF123D116B85CB0041D976 /* UIView+FadeInOut.m */,
+ F1901850116BC487002ED641 /* GridView.h */,
+ F1901851116BC487002ED641 /* GridView.m */,
);
name = Shared;
sourceTree = "<group>";
@@ -129,6 +137,7 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
+ F1901916116BCCBD002ED641 /* QuartzCore.framework */,
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
288765FC0DF74451002DB57D /* CoreGraphics.framework */,
@@ -212,6 +221,7 @@
2860E32E111B888700E27156 /* AppDelegate_Pad.m in Sources */,
F110DA4A116B7A01004C5C30 /* MainViewController.m in Sources */,
F1AF123E116B85CB0041D976 /* UIView+FadeInOut.m in Sources */,
+ F1901852116BC487002ED641 /* GridView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1,5 +1,6 @@
#import "MainViewController.h"
#import "UIView+FadeInOut.h"
+#import "GridView.h"
@implementation MainViewController
@@ -39,6 +40,7 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
[self updateTouchCount];
+ [(GridView*)self.view updateGrid];
}
@@ -54,8 +56,10 @@ - (UIView*)viewForTouch:(UITouch*)touch {
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {
UIView *v = [self viewForTouch:t];
- v.center = [t locationInView:self.view];
+ CGPoint pt = [t locationInView:self.view];
+ v.center = pt;
}
+ [(GridView*)self.view updateGrid];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -66,6 +70,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
[self updateTouchCount];
+ [(GridView*)self.view updateGrid];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="11"/>
+ <integer value="10"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -56,7 +56,7 @@
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<bool key="IBUIResizesToFullScreen">YES</bool>
</object>
- <object class="IBUIImageView" id="987634314">
+ <object class="IBUIImageView" id="991637070">
<nil key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<string key="NSFrameSize">{768, 1024}</string>
@@ -67,7 +67,7 @@
<string key="NSResourceName">Default-Portrait.png</string>
</object>
</object>
- <object class="IBUIImageView" id="1059595214">
+ <object class="IBUIImageView" id="807011477">
<nil key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<string key="NSFrameSize">{1024, 768}</string>
@@ -258,12 +258,12 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">16</int>
- <reference key="object" ref="1059595214"/>
+ <reference key="object" ref="807011477"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">17</int>
- <reference key="object" ref="987634314"/>
+ <reference key="object" ref="991637070"/>
<reference key="parent" ref="0"/>
</object>
</object>
@@ -277,6 +277,7 @@
<string>10.CustomClassName</string>
<string>10.IBEditorWindowLastContentRect</string>
<string>10.IBPluginDependency</string>
+ <string>11.CustomClassName</string>
<string>11.IBPluginDependency</string>
<string>12.IBPluginDependency</string>
<string>13.IBPluginDependency</string>
@@ -294,8 +295,9 @@
<string>UIApplication</string>
<string>UIResponder</string>
<string>MainViewController</string>
- <string>{{386, 67}, {597, 618}}</string>
+ <string>{{386, 45}, {783, 711}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>GridView</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -360,6 +362,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">GridView</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">GridView.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">MainViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
@@ -483,6 +493,20 @@
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">QuartzCore.framework/Headers/CAAnimation.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">QuartzCore.framework/Headers/CALayer.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIAccessibility.h</string>
</object>
</object>
Oops, something went wrong.

0 comments on commit c7ced80

Please sign in to comment.