/* ResultGraph.m - Result graph class for Popup.app Copyright (C) 2004 Rob Burns March,12 2004 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 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 the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ #include "ResultGraph.h" @implementation ResultGraph - (void) dealloc { RELEASE(passColor); RELEASE(failColor); [super dealloc]; } - (id) initWithFrame: (NSRect) aFrame { if( (self = [super initWithFrame: aFrame]) ) { passColor = RETAIN([NSColor colorWithCalibratedRed: 0.2 green: 0.8 blue: 0.2 alpha: 1.0]); failColor = RETAIN([NSColor colorWithCalibratedRed: 0.8 green: 0.2 blue: 0.2 alpha: 1.0]); pass = 0; fail = 0; return self; } return nil; } - (void) setPassValue: (int)aValue { pass = aValue; } - (void) setFailValue: (int)aValue { fail = aValue; } - (void) drawRect: (NSRect)aRect { NSBezierPath *passBar; NSBezierPath *failBar; NSBezierPath *passFrame; NSBezierPath *failFrame; int space = 4; double barHeight = (aRect.size.height - (4 * space)) / 2; double maxLength = aRect.size.width; NSPoint passOrigin = {0,barHeight + space * 2.5}; NSPoint failOrigin = {0, 2}; double passLength = (pass!=0 ? (((double)pass/((double)pass + (double)fail)) * maxLength) : 0); double failLength = (fail!=0 ? (((double)fail/((double)pass + (double)fail)) * maxLength) : 0); passBar = [NSBezierPath bezierPathWithRect: NSMakeRect(passOrigin.x, passOrigin.y, passLength, barHeight)]; [passColor set]; [passBar fill]; failBar = [NSBezierPath bezierPathWithRect: NSMakeRect(failOrigin.x, failOrigin.y, failLength, barHeight)]; [failColor set]; [failBar fill]; if( pass > 0 || fail > 0 ) { passFrame = [NSBezierPath bezierPathWithRect: NSMakeRect(passOrigin.x, passOrigin.y, maxLength, barHeight)]; [[NSColor blackColor] set]; [passFrame stroke]; failFrame = [NSBezierPath bezierPathWithRect: NSMakeRect(failOrigin.x, failOrigin.y, maxLength, barHeight)]; [[NSColor blackColor] set]; [failFrame stroke]; } } @end