home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Graphics / ToyViewer-2.6a / src / ToyWinDraw.m < prev    next >
Encoding:
Text File  |  1996-12-04  |  2.6 KB  |  109 lines

  1. #import <dpsclient/wraps.h>    /* for PSxxx functions */
  2. #import <appkit/Control.h>
  3. #import <appkit/TextField.h>
  4. #import <appkit/ScrollView.h>
  5. #import <appkit/tiff.h>        /* NXImageBitmap */
  6. #import <appkit/graphics.h>
  7. #import <appkit/appkit.h>
  8. #import <stdio.h>
  9. #import <stdlib.h>
  10. #import <string.h>
  11. #import "ToyWin.h"
  12. #import "ToyView.h"
  13. #import "TVController.h"
  14. #import "strfunc.h"
  15.  
  16.  
  17. @implementation ToyWin (Drawing)
  18.  
  19. - drawView:(unsigned char **)map info:(commonInfo *)cinf
  20. {
  21.     ToyView *view;
  22.     id tmp;
  23.  
  24.     [scView setHorizScrollerRequired: YES];
  25.     [scView setVertScrollerRequired: YES];
  26.     [scView setBorderType: NX_NOBORDER];
  27.     tmp = [[ToyView alloc] setCommText: commentText];
  28.     if ((view = [tmp initDataPlanes:map info:cinf]) == nil) {
  29.         [tmp free];
  30.         return nil;
  31.     }
  32.     if ((tmp = [scView setDocView: view]) != nil)
  33.         [tmp free];
  34.     [scView setCopyOnScroll: YES];
  35.     [self scrollProperly];
  36.     [thiswindow display];
  37.     [thiswindow makeKeyAndOrderFront: self];
  38.     [commentText setStringValue: cinf->memo];
  39.     NXPing();
  40.     return self;
  41. }
  42.  
  43.  
  44. - (int)drawFromFile:(const char *)fileName or:(NXStream *)stream
  45. {
  46.     id tmp, view;
  47.     commonInfo *cinf;
  48.  
  49.     [scView setHorizScrollerRequired: YES];
  50.     [scView setVertScrollerRequired: YES];
  51.     [scView setBorderType: NX_NOBORDER];
  52.     tmp = [[ToyView alloc] setCommText: commentText];
  53.     view = stream
  54.         ? [tmp initFromStream: stream]
  55.         : [tmp initFromFile: fileName];
  56.     if (view == nil) {
  57.         [tmp free];
  58.         return Err_OPEN;
  59.     }
  60.     cinf = [view commonInfo];
  61.     [self initLocateWindow:fileName width:cinf->width height:cinf->height];
  62.     [self makeComment: cinf];
  63.     [commentText setStringValue: cinf->memo];
  64.     if ((tmp = [scView setDocView: view]) != nil)
  65.         [tmp free];
  66.     [scView setCopyOnScroll: YES];
  67.     [self scrollProperly];
  68.     [thiswindow display];
  69.     [thiswindow makeKeyAndOrderFront: self];
  70.     NXPing();
  71.     return 0;
  72. }
  73.  
  74. - makeComment:(commonInfo *)cinf
  75. {
  76.     const char *alp = cinf->alpha ? "  Alpha" : "";
  77.  
  78.     if (cinf->bits == 1 && cinf->numcolors <= 2)
  79.         sprintf(cinf->memo, "%d x %d  Bilevel%s",
  80.             cinf->width, cinf->height, alp);
  81.     else
  82.         sprintf(cinf->memo, "%d x %d  %dbit%s%s%s",
  83.             cinf->width, cinf->height, cinf->bits,
  84.             ((cinf->bits > 1) ? "s" : ""), 
  85.             ((cinf->numcolors <= 2) ? " gray" : ""), alp);
  86.     return self;
  87. }
  88.  
  89. - makeComment:(commonInfo *)cinf from:(const commonInfo *)originfo
  90. {
  91.     const char *p;
  92.  
  93.     [self makeComment: cinf];
  94.     if ((p = begin_comm(originfo->memo, YES)) != NULL) {
  95.         strcat(cinf->memo, " : ");
  96.         comm_cat(cinf->memo, p);
  97.     }
  98.     return self;
  99. }
  100.  
  101. - (commonInfo *)drawToyWin:(const char *)fileName type:(int)type
  102.     map:(unsigned char **)map err:(int *)err
  103. {
  104.     *err = [self drawFromFile: fileName or: NULL];
  105.     return NULL;
  106. }
  107.  
  108. @end
  109.