Allow randomise to work with different drawing strategies

This commit is contained in:
nigel 2002-12-18 11:53:11 +00:00
parent bfbeb17a96
commit 470adec0e6
2 changed files with 31 additions and 31 deletions

View File

@ -30,18 +30,19 @@
@interface EmulatorView : NSView @interface EmulatorView : NSView
{ {
#ifdef CGIMAGEREF #ifdef CGIMAGEREF
CGImageRef bitmap; CGImageRef cgImgRep;
#endif #endif
#ifdef NSBITMAP #ifdef NSBITMAP
NSBitmapImageRep *bitmap; NSBitmapImageRep *bitmap;
#endif #endif
#ifdef CGDRAWBITMAP #ifdef CGDRAWBITMAP
void *bitmap; void *bitmap;
short bps, spp, bpp; short bps, spp, bpp;
int bytesPerRow; int bytesPerRow;
BOOL isPlanar, hasAlpha; BOOL isPlanar, hasAlpha;
#endif #endif
float numBytes;
short x, y; short x, y;
BOOL drawView, // Set when the bitmap is all set up BOOL drawView, // Set when the bitmap is all set up

View File

@ -49,21 +49,9 @@
drawView = NO; // Disable drawing until later drawView = NO; // Disable drawing until later
fullScreen = NO; fullScreen = NO;
#ifdef SAVE_GSTATE
[self allocateGState];
#endif
return self; return self;
} }
- (void) dealloc
{
#ifdef SAVE_GSTATE
[self releaseGState];
#endif
[super dealloc];
}
// Mouse click in this window. If window is not active, // Mouse click in this window. If window is not active,
// should the click be passed to this view? // should the click be passed to this view?
- (BOOL) acceptsFirstMouse: (NSEvent *) event - (BOOL) acceptsFirstMouse: (NSEvent *) event
@ -163,7 +151,7 @@ static int prevFlags;
[bitmap draw]; [bitmap draw];
#endif #endif
#ifdef CGIMAGEREF #ifdef CGIMAGEREF
cgDrawInto([self bounds], bitmap); cgDrawInto([self bounds], cgImgRep);
#endif #endif
#ifdef CGDRAWBITMAP #ifdef CGDRAWBITMAP
[self CGDrawBitmap]; [self CGDrawBitmap];
@ -196,13 +184,15 @@ static int prevFlags;
imageHeight: (short) height imageHeight: (short) height
{ {
bitmap = theBitmap; bitmap = theBitmap;
numBytes = [theBitmap bytesPerRow] * height;
#endif #endif
#ifdef CGIMAGEREF #ifdef CGIMAGEREF
- (void) readyToDraw: (CGImageRef) image - (void) readyToDraw: (CGImageRef) image
imageWidth: (short) width imageWidth: (short) width
imageHeight: (short) height imageHeight: (short) height
{ {
bitmap = image; cgImgRep = image;
numBytes = CGImageGetBytesPerRow(image);
#endif #endif
#ifdef CGDRAWBITMAP #ifdef CGDRAWBITMAP
- (void) readyToDraw: (void *) theBitmap - (void) readyToDraw: (void *) theBitmap
@ -222,6 +212,7 @@ static int prevFlags;
bytesPerRow = bpr; bytesPerRow = bpr;
isPlanar = planar; isPlanar = planar;
hasAlpha = alpha; hasAlpha = alpha;
numBytes = bpr * height;
#endif #endif
x = width, y = height; x = width, y = height;
drawView = YES; drawView = YES;
@ -370,16 +361,22 @@ static NSPoint mouse; // Previous/current mouse location
ADBMouseUp(0); ADBMouseUp(0);
} }
#if DEBUG #if DEBUG && ! defined(CGIMAGEREF)
- (void) randomise // Draw some coloured snow in the bitmap - (void) randomise // Draw some coloured snow in the bitmap
{ {
unsigned char *pixel; unsigned char *data,
*pixel;
#ifdef CGDRAWBITMAP
data = bitmap;
#endif
#ifdef NSBITMAP
data = [bitmap bitmapData];
#endif
for ( int i = 0; i < 1000; ++i ) for ( int i = 0; i < 1000; ++i )
{ {
pixel = [bitmap bitmapData] pixel = data + (int) (numBytes * rand() / RAND_MAX);
+ (int) (1.0 * [bitmap bytesPerRow] * 342 //[bitmap height]
* rand() / RAND_MAX);
*pixel = (unsigned char) (256.0 * rand() / RAND_MAX); *pixel = (unsigned char) (256.0 * rand() / RAND_MAX);
} }
} }
@ -392,7 +389,9 @@ static NSPoint mouse; // Previous/current mouse location
#if DEBUG #if DEBUG
NSLog(@"In drawRect"); NSLog(@"In drawRect");
//[self randomise]; # ifndef CGIMAGEREF
[self randomise];
# endif
#endif #endif
#ifdef NSBITMAP #ifdef NSBITMAP
@ -400,7 +399,7 @@ static NSPoint mouse; // Previous/current mouse location
[bitmap draw]; [bitmap draw];
#endif #endif
#ifdef CGIMAGEREF #ifdef CGIMAGEREF
cgDrawInto(rect, bitmap); cgDrawInto(rect, cgImgRep);
#endif #endif
#ifdef CGDRAWBITMAP #ifdef CGDRAWBITMAP
[self CGDrawBitmap]; [self CGDrawBitmap];
@ -416,8 +415,8 @@ extern "C" void CGDrawBitmap(...);
- (void) CGDrawBitmap - (void) CGDrawBitmap
{ {
CGContextRef cgContext = [[NSGraphicsContext currentContext] CGContextRef cgContext = (CGContextRef) [[NSGraphicsContext currentContext]
graphicsPort]; graphicsPort];
NSRect rect = [self bounds]; NSRect rect = [self bounds];
CGRect cgRect = { CGRect cgRect = {
{rect.origin.x, rect.origin.y}, {rect.origin.x, rect.origin.y},
@ -427,7 +426,7 @@ extern "C" void CGDrawBitmap(...);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextSetShouldAntialias(cgContext, NO); // Seems to have no effect? // CGContextSetShouldAntialias(cgContext, NO); // Seems to have no effect?
CGDrawBitmap(cgContext, cgRect, x, y, bps, spp, bpp, CGDrawBitmap(cgContext, cgRect, x, y, bps, spp, bpp,
bytesPerRow, isPlanar, hasAlpha, colourSpace, &bitmap); bytesPerRow, isPlanar, hasAlpha, colourSpace, &bitmap);
@ -436,18 +435,18 @@ extern "C" void CGDrawBitmap(...);
#ifdef CGIMAGEREF #ifdef CGIMAGEREF
void void
cgDrawInto(NSRect rect, CGImageRef bitmap) cgDrawInto(NSRect rect, CGImageRef cgImgRep)
{ {
CGContextRef cgContext = [[NSGraphicsContext currentContext] CGContextRef cgContext = (CGContextRef) [[NSGraphicsContext currentContext]
graphicsPort]; graphicsPort];
CGRect cgRect = { CGRect cgRect = {
{rect.origin.x, rect.origin.y}, {rect.origin.x, rect.origin.y},
{rect.size.width, rect.size.height} {rect.size.width, rect.size.height}
}; };
CGContextSetShouldAntialias(cgContext, NO); // Seems to have no effect? // CGContextSetShouldAntialias(cgContext, NO); // Seems to have no effect?
CGContextDrawImage(cgContext, cgRect, bitmap); CGContextDrawImage(cgContext, cgRect, cgImgRep);
} }
#endif #endif