diff options
author | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-09 11:00:06 +0000 |
---|---|---|
committer | randomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64> | 2012-01-09 11:00:06 +0000 |
commit | e1cf0babff63e670e0d550b4072c22649a117fa7 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/osx/Grid.m | |
parent | 49393f6f445deb37e55a81798f88242e3e99d7a0 (diff) |
Re-make trunk
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@364 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'src/osx/Grid.m')
-rw-r--r-- | src/osx/Grid.m | 152 |
1 files changed, 0 insertions, 152 deletions
diff --git a/src/osx/Grid.m b/src/osx/Grid.m deleted file mode 100644 index 3e412a3..0000000 --- a/src/osx/Grid.m +++ /dev/null @@ -1,152 +0,0 @@ -// -// Grid.m -// TikZiT -// -// Copyright 2010 Aleks Kissinger. All rights reserved. -// -// -// This file is part of TikZiT. -// -// TikZiT is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// TikZiT is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with TikZiT. If not, see <http://www.gnu.org/licenses/>. -// - -#import "Grid.h" - - -@implementation Grid - -@synthesize size; - -- (id)initWithSpacing:(float)spacing - subdivisions:(int)subs - transformer:(Transformer*)t -{ - [super init]; - gridX = spacing; - gridY = spacing; - subdivisions = subs; - size.width = 0; - size.height = 0; - transformer = t; - return self; -} - -+ (Grid*)gridWithSpacing:(float)spacing - subdivisions:(int)subs - transformer:(Transformer*)t -{ - return [[Grid alloc] initWithSpacing:spacing - subdivisions:subs - transformer:t]; -} - -- (float)gridX { - return gridX; -} - -- (float)gridY { - return gridY; -} - -- (int)subdivisions { - return subdivisions; -} - -- (void)setSubdivisions:(int)subs { - subdivisions = subs; -} - -- (NSPoint)snapScreenPoint:(NSPoint)p { - NSPoint snap; - - float gridCellX = [transformer scaleToScreen:gridX] / (float)subdivisions; - float gridCellY = [transformer scaleToScreen:gridY] / (float)subdivisions; - - // snap along grid lines, relative to the origin - snap.x = floor(((p.x-[transformer origin].x)/gridCellX)+0.5)*gridCellX + [transformer origin].x; - snap.y = floor(((p.y-[transformer origin].y)/gridCellY)+0.5)*gridCellY + [transformer origin].y; - return snap; -} - --(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context -{ - CGContextSaveGState(context); - - CGContextSetShouldAntialias(context, NO); - - float x,y; - float grX = [transformer scaleToScreen:gridX]; - float grY = [transformer scaleToScreen:gridY]; - - float gridCellX = grX / (float)subdivisions; - float gridCellY = grY / (float)subdivisions; - - for (x = [transformer origin].x + gridCellX; x < size.width; x += gridCellX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (x = [transformer origin].x - gridCellX; x > 0; x -= gridCellX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (y = [transformer origin].y + gridCellY; y < size.height; y += gridCellY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - for (y = [transformer origin].y - gridCellY; y > 0; y -= gridCellY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - CGContextSetRGBStrokeColor(context, 0.9, 0.9, 1, 1); - CGContextStrokePath(context); - - for (x = [transformer origin].x + grX; x < size.width; x += grX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (x = [transformer origin].x - grX; x > 0; x -= grX) { - CGContextMoveToPoint(context, x, 0); - CGContextAddLineToPoint(context, x, size.height); - } - - for (y = [transformer origin].y + grY; y < size.height; y += grY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - for (y = [transformer origin].y + grY; y > 0; y -= grY) { - CGContextMoveToPoint(context, 0, y); - CGContextAddLineToPoint(context, size.width, y); - } - - CGContextSetRGBStrokeColor(context, 0.8, 0.8, 0.9, 1); - CGContextStrokePath(context); - - CGContextMoveToPoint(context, [transformer origin].x, 0); - CGContextAddLineToPoint(context, [transformer origin].x, size.height); - CGContextMoveToPoint(context, 0, [transformer origin].y); - CGContextAddLineToPoint(context, size.width, [transformer origin].y); - - CGContextSetRGBStrokeColor(context, 0.6, 0.6, 0.7, 1); - CGContextStrokePath(context); - - CGContextRestoreGState(context); -} - -@end |