1/* 2 Project: Graphos 3 GRCircleEditor.m 4 5 Copyright (C) 2009-2013 GNUstep Application Project 6 7 Author: Ing. Riccardo Mottola 8 9 Created: 2009-12-27 10 11 This application is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public 13 License as published by the Free Software Foundation; either 14 version 2 of the License, or (at your option) any later version. 15 16 This application is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 Library General Public License for more details. 20 21 You should have received a copy of the GNU General Public 22 License along with this library; if not, write to the Free 23 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 */ 25 26#import "GRCircleEditor.h" 27#import "GRDocView.h" 28#import "GRFunctions.h" 29 30 31@implementation GRCircleEditor 32 33- (id)initEditor:(GRDrawableObject *)anObject 34{ 35 self = [super initEditor:anObject]; 36 if(self != nil) 37 { 38 } 39 return self; 40} 41 42- (NSPoint)constrainControlPoint:(NSPoint)p 43{ 44 NSPoint pos; 45 CGFloat w, h; 46 NSPoint retP; 47 48 retP = p; 49 pos = [(GRCircle *)object position]; 50 w = pos.x-p.x; 51 h = pos.y-p.y; 52 53 if (w < h) 54 retP.y = pos.y+w; 55 else 56 retP.x = pos.x+h; 57 58 return retP; 59} 60 61- (NSPoint)moveControlAtPoint:(NSPoint)p 62{ 63 GRObjectControlPoint *cp; 64 NSEvent *event; 65 NSPoint pp; 66 CGFloat zFactor; 67 BOOL found = NO; 68 69 pp = NSZeroPoint; 70 zFactor = [object zoomFactor]; 71 cp = [(GRCircle *)object startControlPoint]; 72 if (pointInRect([cp centerRect], p)) 73 { 74 [self selectForEditing]; 75 [(GRPathObject *)object setCurrentPoint:cp]; 76 [cp select]; 77 found = YES; 78 } 79 cp = [(GRCircle *)object endControlPoint]; 80 if (pointInRect([cp centerRect], p)) 81 { 82 [self selectForEditing]; 83 [(GRPathObject *)object setCurrentPoint:cp]; 84 [cp select]; 85 found = YES; 86 } 87 88 if(!found) 89 return p; 90 91 event = [[[object view] window] nextEventMatchingMask: 92 NSLeftMouseUpMask | NSLeftMouseDraggedMask]; 93 if([event type] == NSLeftMouseDragged) 94 { 95 [[object view] verifyModifiersOfEvent: event]; 96 do 97 { 98 pp = [event locationInWindow]; 99 pp = [[object view] convertPoint: pp fromView: nil]; 100 pp = GRpointDeZoom(pp, zFactor); 101 if([[object view] shiftclick]) 102 pp = [self constrainControlPoint:pp]; 103 104 [[(GRPathObject *)object currentPoint] moveToPoint: pp]; 105 [(GRPathObject *)object remakePath]; 106 107 [[object view] setNeedsDisplay: YES]; 108 event = [[[object view] window] nextEventMatchingMask: 109 NSLeftMouseUpMask | NSLeftMouseDraggedMask]; 110 [[object view] verifyModifiersOfEvent: event]; 111 } while([event type] != NSLeftMouseUp); 112 } 113 114 return pp; 115} 116 117 118- (void)draw 119{ 120 if(![object visible]) 121 return; 122 123 if([self isGroupSelected]) 124 { 125 [[(GRCircle *)object startControlPoint] drawControlAsSelected:NO]; 126 [[(GRCircle *)object endControlPoint] drawControlAsSelected:NO]; 127 } 128 129 if([self isEditSelected]) 130 { 131 NSBezierPath *bzp; 132 133 bzp = [NSBezierPath bezierPath]; 134 [bzp appendBezierPathWithRect:[(GRCircle *)object bounds]]; 135 [bzp setLineWidth:0.5]; 136 [[NSColor grayColor] set]; 137 [bzp stroke]; 138 139 [[(GRCircle *)object startControlPoint] drawControl]; 140 [[(GRCircle *)object endControlPoint] drawControl]; 141 } 142} 143 144@end 145