1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
TestView.h
Simple subclass of NSView.
Copyright (C) 1996 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: June 1996
This file is part of the GNUstep GUI X/RAW Backend.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <AppKit/AppKit.h>
#include "TestView.h"
@interface FlippedView : NSView
@end
@implementation FlippedView
- (BOOL) isFlipped
{
return YES;
}
- (void)drawRect:(NSRect)rect
{
[[NSColor redColor] set];
NSRectFill ([self bounds]);
}
@end
@interface UnflippedView : NSView
@end
@implementation UnflippedView
- (BOOL) isFlipped
{
return NO;
}
- (void)drawRect:(NSRect)rect
{
[[NSColor greenColor] set];
NSRectFill ([self bounds]);
}
@end
@implementation TestView
// Class methods
// Instance methods
- (BOOL)isFlipped
{
return NO;
}
- (void)drawRect:(NSRect)rect
{
static BOOL beenHere = NO;
NSFont *f;
NSColor *c = [NSColor greenColor];
NSColor *blue = [NSColor blueColor];
NSColor *y = [NSColor yellowColor];
NSColor *orange = [NSColor orangeColor];
static NSView *fv;
static NSView *uv;
NSRectClip (rect);
[orange set];
NSRectFill ([self bounds]);
NSDrawGroove (NSMakeRect (10, 10, 100, 200),
NSMakeRect (10, 10, 100, 200));
if (beenHere == NO)
{
beenHere = YES;
fv = [[FlippedView alloc] initWithFrame: NSMakeRect(15,15,20,20)];
[self addSubview: fv];
uv = [[UnflippedView alloc] initWithFrame: NSMakeRect(45,15,20,20)];
[self addSubview: uv];
}
[c set];
// Text
f = [NSFont boldSystemFontOfSize: 24];
[f set];
PSmoveto(15, 20);
PSshow("Bold system font.");
f = [NSFont systemFontOfSize: 24];
[f set];
PSmoveto(15, 50);
PSshow("System font.");
f = [NSFont userFixedPitchFontOfSize: 24];
[f set];
PSmoveto(15, 100);
PSshow("User fixed pitch font.");
f = [NSFont userFontOfSize: 24];
[f set];
PSmoveto(15, 150);
PSshow("User font.");
// Absolute Lines
[blue set];
PSnewpath ();
PSmoveto (400, 400);
PSlineto (420, 400);
PSlineto (440, 380);
PSlineto (440, 360);
PSlineto (420, 340);
PSlineto (400, 340);
PSlineto (380, 360);
PSlineto (380, 380);
PSclosepath ();
PSfill ();
// Relative Lines
[y set];
PSnewpath ();
PSmoveto (400, 200);
PSrlineto (20, 0);
PSrlineto (20, -20);
PSrlineto (0, -20);
PSrlineto (-20, -20);
PSrlineto (-20, 0);
PSrlineto (-20, 20);
PSrlineto (0, 20);
PSclosepath ();
PSstroke ();
PSinitclip ();
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint location = [theEvent locationInWindow];
NSPoint p = [self convertPoint:location fromView:nil];
NSClipView* clipView = [self superview];
NSRect rect;
NSLog (@"mouse down at (%2.2f, %2.2f), window location (%2.2f, %2.2f)",
p.x, p.y,
location.x, location.y);
rect = [clipView bounds];
NSLog (@"clip view bounds = ((%f, %f) (%f, %f))",
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
rect = [self bounds];
NSLog (@"self bounds = ((%f, %f) (%f, %f))\n",
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
@end
|