00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "LLShapes.h"
00010
00011
00012 @implementation LLShapes
00013
00014 static NSBezierPath *line = nil;
00015
00016 - (id) init {
00017 self = [super init];
00018 if (self != nil) {
00019 line = [[NSBezierPath alloc] init];
00020 }
00021 return self;
00022 }
00023
00024 - (NSRect) rectWithHeight:(int)height width:(int)width centerPoint:(NSPoint)centerGravity {
00025
00026 NSRect result;
00027
00028 result.size.width = width;
00029 result.size.height = height;
00030 result.origin.x = centerGravity.x - width / 2;
00031 result.origin.y = centerGravity.y - height / 2;
00032
00033 return result;
00034 }
00035
00036 - (void)drawTriangleNotchUpInRect:(NSRect)rect {
00037
00038
00039 NSPoint left = rect.origin;
00040 left.y += rect.size.height;
00041
00042 NSPoint right = left;
00043 right.x += rect.size.width;
00044
00045 NSPoint mid = rect.origin;
00046 mid.x += rect.size.width/2;
00047
00048
00049 [line removeAllPoints];
00050 [line moveToPoint:left];
00051 [line lineToPoint:right];
00052 [line lineToPoint:mid];
00053 [line lineToPoint:left];
00054 [line closePath];
00055 [line stroke];
00056 }
00057
00058 - (void)drawTriangleNotchDownInRect:(NSRect)rect {
00059
00060
00061 NSPoint left = rect.origin;
00062
00063 NSPoint right = rect.origin;
00064 right.x += rect.size.width;
00065
00066 NSPoint mid = rect.origin;
00067 mid.x += rect.size.width/2;
00068 mid.y += rect.size.height;
00069
00070
00071 [line removeAllPoints];
00072 [line moveToPoint:left];
00073 [line lineToPoint:right];
00074 [line lineToPoint:mid];
00075 [line lineToPoint:left];
00076 [line closePath];
00077 [line stroke];
00078 }
00079
00080 - (void) drawCircleInRect:(NSRect) rect {
00081
00082 [line removeAllPoints];
00083 [line appendBezierPathWithOvalInRect:rect];
00084 [line stroke];
00085 }
00086
00087 - (void) drawSpaceShipInRect:(NSRect) rect {
00088
00089 [line removeAllPoints];
00090
00091
00092 NSPoint p;
00093 NSRect r;
00094
00095
00096 p.x = rect.origin.x + rect.size.width / 2;
00097
00098 p.y = rect.origin.y + rect.size.height / 4;
00099
00100 [line appendBezierPathWithArcWithCenter:p radius:(rect.size.height / 4)
00101 startAngle:0 endAngle:360];
00102
00103
00104 r.origin.x = rect.origin.x;
00105 r.origin.y = rect.origin.y + rect.size.height / 2;
00106 r.size.width = rect.size.width / 5;
00107 r.size.height = rect.size.height / 2;
00108
00109 [line appendBezierPathWithRect:r];
00110
00111 r.origin.x += 4 * r.size.width;
00112 [line appendBezierPathWithRect:r];
00113
00114
00115
00116 r.origin.x -= 2 * r.size.width;
00117 r.origin.y -= (rect.size.width / 5);
00118 [line appendBezierPathWithRect:r];
00119
00120 r = rect;
00121 r.size.height = (rect.size.width / 5);
00122 r.origin.y += (rect.size.height - 2*r.size.height);
00123 [line appendBezierPathWithRect:r];
00124
00125
00126 [line fill];
00127 }
00128
00129 - (void) drawDoubleCircleInRect:(NSRect) rect {
00130
00131 [line removeAllPoints];
00132 [line setWindingRule:NSEvenOddWindingRule];
00133 [line appendBezierPathWithOvalInRect:rect];
00134 [line appendBezierPathWithOvalInRect:NSInsetRect(rect, 5, 5)];
00135 [line stroke];
00136
00137 [line setWindingRule:[NSBezierPath defaultWindingRule]];
00138 }
00139
00140 - (NSRect) createRectAroundOrigin:(NSRect)Rect {
00141 NSRect result = Rect;
00142 result.origin.x = -(result.size.width/2);
00143 result.origin.y = -(result.size.height/2);
00144 return result;
00145 }
00146
00147 - (NSPoint) centreOfRect:(NSRect)Rect {
00148 NSPoint result = Rect.origin;
00149 result.x += Rect.size.width/2;
00150 result.y += Rect.size.height/2;
00151 return result;
00152 }
00153
00154 @end