/* Views.m Main View class Copyright (C) 2003 Marko Riedel Author: Marko Riedel Date: 5 July 2003 This program 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 2 of the License, or (at your option) any later version. This program 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 this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA */ #include "Views.h" #include #include #include #include #include #include #include void shadow(float x, float y, float r) { PSsetlinewidth(2.0); int angle; for(angle=132; angle<492; angle+=6){ float gray = (angle < 312 ? 0.9-(float)(angle-132)/180.0*0.8 : 0.1+(float)(angle-312)/180.0*0.8); PSsetgray(gray); PSarc(x, y, r, angle, angle+6); PSstroke(); } } void shadow2(float x, float y, float r) { PSsetlinewidth(2.0); int angle; for(angle=312; angle<672; angle+=6){ float gray = (angle < 492 ? 0.9-(float)(angle-312)/180.0*0.8 : 0.1+(float)(angle-492)/180.0*0.8); PSsetgray(gray); PSarc(x, y, r, angle, angle+6); PSstroke(); } } void tile(NSRect rect) { NSRectEdge sides[] = { NSMinXEdge, NSMaxXEdge, NSMinYEdge, NSMaxYEdge, NSMinXEdge, NSMaxXEdge, NSMinYEdge, NSMaxYEdge}; float grays[] = { NSWhite, NSBlack, NSBlack, NSWhite, NSWhite, NSBlack, NSBlack, NSWhite}; NSDrawTiledRects(rect, rect, sides, grays, 8); } @implementation Result - initAtPoint:(NSPoint)aPoint { NSRect frame; frame.origin = aPoint; frame.size.width = frame.size.height = PEGDIMENSION; [super initWithFrame:frame]; black = white = 0; return self; } - getBlack:(int *)bptr andWhite:(int *)wptr; { *bptr = black; *wptr = white; return self; } - setBlack:(int)bval andWhite:(int)wval { black = bval; white = wval; [self setNeedsDisplay:YES]; return self; } - (void)drawRect:(NSRect)aRect { tile([self bounds]); int index; for(index=0; index<4; index++){ float x = PEGDIMENSION/4+(index%2)*PEGDIMENSION/2, y = PEGDIMENSION/4+(index/2)*PEGDIMENSION/2; NSColor *col = (index)sender { NSPasteboard *pb; NSDragOperation sourceDragMask; if(active==NO){ return NSDragOperationNone; } sourceDragMask = [sender draggingSourceOperationMask]; pb = [sender draggingPasteboard]; if([[pb types] indexOfObject:NSColorPboardType]!=NSNotFound){ if(sourceDragMask & NSDragOperationCopy){ NSColor *col = [NSColor colorFromPasteboard:pb], *rgb; float ccomps[4]; rgb = [col colorUsingColorSpaceName:NSDeviceRGBColorSpace]; [rgb getRed:ccomps green:ccomps+1 blue:ccomps+2 alpha:ccomps+3]; if((ccomps[0]==0.0 || ccomps[0]==1.0) && (ccomps[1]==0.0 || ccomps[1]==1.0) && (ccomps[2]==0.0 || ccomps[2]==1.0) && ccomps[3]==1.0){ float s = ccomps[0]+ccomps[1]+ccomps[2]; if(s==1.0 || s==2.0){ return NSDragOperationCopy; } } } } return NSDragOperationNone; } - (BOOL)performDragOperation:(id )sender { NSPasteboard *pb = [sender draggingPasteboard]; NSColor *rgb; rgb = [[NSColor colorFromPasteboard:pb] colorUsingColorSpaceName:NSDeviceRGBColorSpace]; [self setColor:rgb]; return YES; } - (BOOL)prepareForDragOperation:(id )sender { return YES; } @end