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
|
#import "Controller.h"
@interface TestView : NSView
{
@public
BOOL isFlipped;
}
@end
@interface CopyBitsView : NSView
{
@public
BOOL isFlipped;
}
@end
@implementation TestView
#ifdef GNUSTEP
- (BOOL) isFlipped
{
return _rFlags.flipped_view;
}
#else
- (BOOL) isFlipped
{
return isFlipped;
}
#endif
- (void) drawRect: (NSRect)aRect
{
NSImage *appImg = [[NSImage imageNamed: @"GNUstep"] copy];
/*[appImg setScalesWhenResized: YES];
[appImg setSize: NSMakeSize(200, 200)];
[appImg setScalesWhenResized: NO];*/
NSSize imgSize = [appImg size];
NSAffineTransform *xform = [NSAffineTransform transform];
/*if ([self isFlipped] == NO)
{
[xform translateXBy: 0 yBy: [self frame].size.height];
[xform scaleXBy: 1.0 yBy: -1.0];
[xform concat];
}*/
[xform rotateByDegrees: 15];
[xform concat];
NSLog(@"Image data flipped: %d", [appImg isFlipped]);
[appImg drawInRect: NSMakeRect(0, 50, 200, 200)
fromRect: NSMakeRect(0, 0, imgSize.width, imgSize.height)
operation: NSCompositeSourceOver
fraction: 0.5];
id imgCell = [[NSImageCell alloc] initImageCell: appImg];
[imgCell drawWithFrame: NSMakeRect(150, 50, 25, 25) inView: self];
[[NSColor redColor] set];
NSRectFill(NSMakeRect(50, 0, 50, 50));
[appImg setScalesWhenResized: YES];
[appImg setSize: NSMakeSize(48, 48)];
[appImg compositeToPoint: NSMakePoint(100, 50)
operation: NSCompositeSourceOver];
[appImg dissolveToPoint: NSMakePoint(150, 50)
fraction: 0.5];
[[NSColor colorWithPatternImage: appImg] set];
NSRectFill(NSMakeRect(150, 100, 100, 150));
/*if ([self isFlipped] == NO)
{
[xform invert];
[xform concat];
}*/
[xform invert];
[xform concat];
}
- (BOOL) canDraw
{
return YES;
}
@end
@implementation CopyBitsView
#ifdef GNUSTEP
- (BOOL) isFlipped
{
return _rFlags.flipped_view;
}
#else
- (BOOL) isFlipped
{
return isFlipped;
}
#endif
- (void) drawRect: (NSRect)aRect
{
NSAffineTransform *flip = [NSAffineTransform transform];
NSAffineTransform *xform = [NSAffineTransform transform];
/*[flip translateXBy: 0 yBy: [self frame].size.height];
[flip scaleXBy: 1.0 yBy: -1.0];
[flip concat];*/
[[NSColor redColor] set];
NSRectFill(NSMakeRect(0, 0, 50, 50));
NSRectFill(NSMakeRect(50, 50, 30, 30));
// FIXME: NSCopyBits doesn't draw at the right location with a rotation
[xform rotateByDegrees: 25];
[xform concat];
NSRect copyRect = NSMakeRect(0, 0, 80, 80);
NSLog(@"Copy bits");
NSCopyBits([self gState], copyRect, NSMakePoint(130, 0));
NSImage *appImg = [[NSImage imageNamed: @"GNUstep"] copy];
[appImg compositeToPoint: NSMakePoint(130, 0)
operation: NSCompositeSourceOver];
[xform invert];
[xform concat];
[[NSColor blackColor] setStroke];
[NSBezierPath strokeRect: copyRect];
[NSBezierPath strokeRect: NSMakeRect(100, 0, 80, 80)];
[NSBezierPath strokeRect: [self bounds]];
/*[flip invert];
[flip concat];*/
}
@end
@implementation Controller
- (void) awakeFromNib
{
TestView *view1 = [[TestView alloc] initWithFrame: NSMakeRect(0, 0, 200, 200)];
TestView *view2 = [[TestView alloc] initWithFrame: NSMakeRect(200, 0, 200, 200)];
CopyBitsView *view3 = [[CopyBitsView alloc] initWithFrame: NSMakeRect(200, 200, 200, 150)];
#ifdef GNUSTEP
view1->_rFlags.flipped_view = YES;
[view1 _rebuildCoordinates];
//view3->_rFlags.flipped_view = YES;
//[view3 _rebuildCoordinates];
#else
view1->isFlipped = YES;
//view3->isFlipped = YES;
#endif
[[window contentView] addSubview: view1];
[[window contentView] addSubview: view2];
[[window contentView] addSubview: view3];
}
@end
|