Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Classes/StripChartRulerView.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (show annotations) (download)
Sun Dec 17 04:05:28 2017 UTC (6 years, 3 months ago) by toshinagata1964
File size: 2785 byte(s)
Xcode project is updated so that ppc/i386 universal binary can be built (as before)
1 //
2 // StripChartRulerView.m
3 // Created by Toshi Nagata on Sun Jan 26 2003.
4 //
5 /*
6 Copyright (c) 2003-2016 Toshi Nagata. All rights reserved.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 */
17
18 #import "StripChartRulerView.h"
19 #import "StripChartView.h"
20 #import "MDHeaders.h"
21
22 @implementation StripChartRulerView
23
24 - (id)initWithFrame:(NSRect)frame {
25 self = [super initWithFrame:frame];
26 if (self) {
27 }
28 return self;
29 }
30
31 - (void)dealloc
32 {
33 [super dealloc];
34 }
35
36 - (void)drawRect:(NSRect)aRect
37 {
38 NSRect frame, bounds, visibleRect;
39 NSFont *font;
40 NSDictionary *attr;
41 float grid;
42 float minValue, maxValue;
43 // float visibleMinValue, visibleMaxValue, visibleRange, aRange;
44 // int i;
45 // int min, max;
46 float ascender, descender, x, y, yval;
47 NSString *str;
48 frame = [self frame];
49 bounds = [self bounds];
50 visibleRect = [(NSClipView *)[self superview] documentVisibleRect];
51 x = frame.size.width - 0.5f;
52 [NSBezierPath strokeLineFromPoint: NSMakePoint(x, 0) toPoint: NSMakePoint(x, bounds.size.height)];
53 minValue = [(StripChartView *)[self clientView] minValue];
54 maxValue = [(StripChartView *)[self clientView] maxValue];
55 grid = [(StripChartView *)[self clientView] horizontalGridInterval];
56 font = [[self class] rulerLabelFont];
57 ascender = [font ascender];
58 descender = [font descender];
59 attr = [NSDictionary dictionaryWithObjectsAndKeys: font, NSFontAttributeName, nil];
60 for (yval = minValue; yval <= maxValue + 1.01; yval += grid) {
61 y = (float)floor(yval * bounds.size.height / (maxValue - minValue));
62 x = frame.size.width - 4.0f;
63 if (y > 0.0f && y < bounds.size.height)
64 [NSBezierPath strokeLineFromPoint: NSMakePoint(x, y + 0.5f) toPoint: NSMakePoint(x + 4.0f, y + 0.5f)];
65 y -= (float)floor((ascender - descender) / 2);
66 if (y > aRect.origin.y + aRect.size.height + 1
67 || y < aRect.origin.y - (ascender - descender) - 1)
68 continue;
69 if (y > bounds.size.height - (ascender - descender))
70 y = bounds.size.height - (ascender - descender);
71 if (y < 0)
72 y = 0;
73 str = [NSString stringWithFormat: @"%g", (yval >= maxValue - 0.01 ? maxValue : yval)];
74 // x = frame.size.width - 4.0f - [font widthOfString: str];
75 x = frame.size.width - 4.0f - [str sizeWithAttributes:[NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]].width;
76 [str drawAtPoint: NSMakePoint(x, y) withAttributes: attr];
77 }
78 [super drawRect:aRect];
79 }
80
81 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26