1/*
2 Project: Graphos
3 GRObjectControlPoint.m
4
5 Copyright (C) 2007-2013 GNUstep Application Project
6
7 Author: Ing. Riccardo Mottola
8
9 Created: 2007-11-18
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 <AppKit/NSColor.h>
27#import <AppKit/NSGraphics.h>
28
29#import "GRObjectControlPoint.h"
30
31
32@implementation GRObjectControlPoint
33
34- (id)initAtPoint:(NSPoint)aPoint zoomFactor:(CGFloat)zf
35{
36    self = [super init];
37    if(self)
38    {
39        center = aPoint;
40        centerRect = NSMakeRect(aPoint.x-3, aPoint.y-3, 6, 6);
41        isSelect = NO;
42        zmFactor = zf;
43    }
44    return self;
45}
46
47- (id)copyWithZone:(NSZone *)zone
48{
49    GRObjectControlPoint *objCopy;
50
51    objCopy = [[[self class] allocWithZone:zone] init];
52    objCopy->isActiveHandle = isActiveHandle;
53    objCopy->isSelect = isSelect;
54    objCopy->center = NSMakePoint (center.x, center.y);
55    objCopy->centerRect = NSMakeRect (centerRect.origin.x, centerRect.origin.y, centerRect.size.width, centerRect.size.height);
56    objCopy->zmFactor = zmFactor;
57
58    return objCopy;
59}
60
61
62- (void)moveToPoint:(NSPoint)p
63{
64  center.x = p.x;
65  center.y = p.y;
66  centerRect = NSMakeRect(center.x-3, center.y-3, 6, 6);
67}
68
69- (void)drawControlAsSelected: (BOOL)sel
70{
71  NSPoint centerZ;
72  NSRect centerRectZ;
73  NSRect innerRectZ;
74
75  centerZ.x = center.x * zmFactor;
76  centerZ.y = center.y * zmFactor;
77  centerRectZ = NSMakeRect(centerZ.x-3, centerZ.y-3, 6, 6);
78  innerRectZ = NSMakeRect(centerZ.x-2, centerZ.y-2, 4, 4);
79
80  [[NSColor blackColor] set];
81  NSRectFill(centerRectZ);
82
83  if (sel)
84    {
85      [[NSColor whiteColor] set];
86      NSRectFill(innerRectZ);
87    }
88}
89
90- (void)drawControl
91{
92  [self drawControlAsSelected:isSelect];
93}
94
95- (void)setZoomFactor:(CGFloat)f
96{
97  //  center.x = center.x / zmFactor * f;
98  //  center.y = center.y / zmFactor * f;
99  //  centerRect = NSMakeRect(center.x-3, center.y-3, 6, 6);
100  zmFactor = f;
101}
102
103- (NSPoint)center
104{
105    return center;
106}
107
108- (NSRect)centerRect
109{
110  return centerRect;
111}
112
113- (void)select
114{
115    isSelect = YES;
116}
117
118- (void)unselect
119{
120    isSelect = NO;
121}
122
123- (BOOL)isSelect
124{
125    return isSelect;
126}
127
128- (BOOL)isActiveHandle
129{
130    return isActiveHandle;
131}
132
133
134@end
135