diff -ru ./Colormap.h ../../../swarm-1.1/src/tkobjc/Colormap.h --- ./Colormap.h Thu Mar 12 13:55:01 1998 +++ ../../../swarm-1.1/src/tkobjc/Colormap.h Tue May 12 11:45:43 1998 @@ -32,6 +32,7 @@ @public PixelValue map[MAXCOLORS]; BOOL isSet[MAXCOLORS]; + XColor xcolors[MAXCOLORS]; X11Colormap cmap; } @@ -43,5 +44,6 @@ - (PixelValue)white; - (PixelValue)black; - (BOOL)colorIsSet: (Color)c; +-(XColor *) xColorValue: (Color) c; @end diff -ru ./Colormap.m ../../../swarm-1.1/src/tkobjc/Colormap.m --- ./Colormap.m Thu Mar 12 13:55:01 1998 +++ ../../../swarm-1.1/src/tkobjc/Colormap.m Tue May 12 12:48:00 1998 @@ -51,6 +51,15 @@ } } +-(XColor *) xColorValue: (Color) c { + if ([self colorIsSet: c]) + return &(xcolors[c]); + else { + [InvalidArgument raiseEvent: "attempted to access unset color %d\n", c]; + return 0; + } +} + // set a new colormap entry to something. Error if it's already set. // we should do something to see if the colour already has been allocated // in our colourmap. If it has, then we should somehow persuade the client @@ -89,6 +98,10 @@ return NO; } map[c] = xc.pixel; + + // (nelson) make a copy of the XColor structure into the array. + // Is this a good idea? Is it necessary? + xcolors[c] = xc; return YES; } } diff -ru ./ZoomRaster.h ../../../swarm-1.1/src/tkobjc/ZoomRaster.h --- ./ZoomRaster.h Sat Jan 24 15:37:57 1998 +++ ../../../swarm-1.1/src/tkobjc/ZoomRaster.h Tue May 12 11:41:21 1998 @@ -12,6 +12,8 @@ { unsigned zoomFactor; unsigned logicalWidth, logicalHeight; + + Color * buffer; } - increaseZoom; @@ -19,5 +21,6 @@ - (unsigned)getZoomFactor; - setZoomFactor: (unsigned)z; - handleConfigureWidth: (unsigned)newWidth Height: (unsigned)newHeight; +-writeSelfToFile: (char *) f; @end diff -ru ./ZoomRaster.m ../../../swarm-1.1/src/tkobjc/ZoomRaster.m --- ./ZoomRaster.m Wed May 6 15:06:21 1998 +++ ../../../swarm-1.1/src/tkobjc/ZoomRaster.m Tue May 12 12:38:40 1998 @@ -8,6 +8,8 @@ #import #import +#define bufferAt(x,y) (buffer[(y)*logicalWidth + (x)]) + @implementation ZoomRaster - (unsigned)getWidth @@ -41,6 +43,10 @@ [parent getWidgetName], [self getObjcName], "%w", "%h"]; + + // no buffer to start + buffer = 0; + return self; } @@ -113,7 +119,8 @@ [self setZoomFactor: newZoom]; return self; } - + +#import // override setWidth to set it for them according to zoom factor. - setWidth: (unsigned)newWidth Height: (unsigned)newHeight { @@ -122,6 +129,11 @@ [super setWidth: newWidth * zoomFactor Height: newHeight * zoomFactor]; + // allocate the buffer (free the old one if necessary) + if (buffer) + free(buffer); + buffer = calloc(logicalWidth * logicalHeight, sizeof(*buffer)); + // set up gridded geometry so this is resizeable. Only works if // the parent is a toplevel. [globalTkInterp eval: "wm grid %s %u %u %u %u; wm aspect %s 1 1 1 1", @@ -131,6 +143,14 @@ return self; } +#import +-erase { + // erase the buffer (set it to color 0, since there's no default bg) + if (buffer != NULL) + memset(buffer, 0, logicalWidth*logicalHeight*sizeof(*buffer)); + return [super erase]; +} + // drawing is just like before, only magnified. - drawPointX: (int)x Y: (int)y Color: (Color)c { @@ -138,15 +158,24 @@ X1: (x+1) * zoomFactor Y1: (y+1) * zoomFactor Color: c]; + bufferAt(x,y) = c; + return self; } - fillRectangleX0: (int)x0 Y0: (int)y0 X1: (int)x1 Y1: (int)y1 Color: (Color)c { + int x,y; + [super fillRectangleX0: x0 * zoomFactor Y0: y0 * zoomFactor X1: (x1) * zoomFactor Y1: (y1) * zoomFactor Color: c]; + // CHECK - is this consistent with X's convention for rectangle width? + for (x = x0; x < x1; x++) + for (y = y0; y < y1; y++) + bufferAt(x, y) = c; + return self; } @@ -176,6 +205,46 @@ return [super handleButton: n X: (x / (int)zoomFactor) Y: (y / (int)zoomFactor)]; +} + +-writeSelfToFile: (char *) f { + FILE * fp; + int x, y; + + fp = fopen(f, "w"); + if (fp == 0) { + char s[1024]; + sprintf(s, "Warning: couldn't open file %s for writing.", f); + raiseEvent(WarningMessage, s); + return self; + } + + fprintf(fp, "P6\n%d %d\n255\n", logicalWidth, logicalHeight); + for (y = 0; y < logicalHeight; y++) + for (x = 0; x < logicalWidth; x++) { + XColor * value = [colormap xColorValue: bufferAt(x, y)]; + + + (void)fprintf(stderr,"value->red = 0x%0x\n" + "value->green = 0x%0x\n" + "value->blue = 0x%0x\n", + value->red, + value->green, + value->blue); + fflush(0); + + + fputc(value->red >> 8, fp); + fputc(value->green >> 8, fp); + fputc(value->blue >> 8, fp); + } + fclose(fp); + return self; +} + +-(void) drop { + free(buffer); + [super drop]; } @end