home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 206.lha / Flist_v1.2 / Sources / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-28  |  6.3 KB  |  244 lines

  1. /* 
  2.     This module contain all of the routines that interface directly with 
  3.     the display.
  4.  
  5.     Written by Steve (Raz) Berry.
  6. */
  7.  
  8. #include "flist.h"
  9. #include <libraries/arpbase.h>
  10. #include <stdio.h>
  11.  
  12. UWORD coltbl[8] = {
  13.     0x047, /* background color */
  14.     0xBBB, /* title text, inutuition boarders */
  15.     0xB15, /* gadget, title bar */
  16.     0x09B, /* Auto text */
  17.     0x0a0, /* Auto text */
  18.     0xC97, /* screen text */
  19.     0xfff, /* gadget selected*/
  20.     0x000  /* cursor */
  21. };
  22.  
  23. static struct Image   cc_img;
  24. static struct PropInfo   cc_prop = {AUTOKNOB | FREEVERT, 0,0, 0,0x1000,0,0,0,0,0,0 };
  25. struct Gadget pg = { NL,RWDTH-28,20,15,170,      /* Scroll Bar   */
  26.     GADGHCOMP,RELVERIFY | GADGIMMEDIATE | FOLLOWMOUSE, PROPGADGET,
  27.     (APTR)&cc_img,NL,NL,NL,(APTR)&cc_prop,FGAD,NL };
  28.  
  29. struct NewScreen scr = {
  30.     0,0,                /* x,y start */
  31.     640,200,            /* width, height */
  32.     2,                  /* depth */
  33.     2,1,                /* detail, block pens */
  34.     HIRES,              /* view mode */
  35.     WBENCHSCREEN,       /* screen type */
  36.     NULL,               /* font */
  37.     (UBYTE *) "Flist V1.2 - By Steve (Raz) Berry",         /* title */
  38.     NULL,               /* gadgets */
  39.     NULL                /* bitmap pntr */
  40.     };
  41.  
  42. struct NewWindow mywin = {
  43.     0,0,                        /* x,y start */
  44.     640,200,                    /* width, height */
  45.     2,1,                        /* detail, block pens */
  46.     RAWKEY | REFRESHWINDOW | GADGETDOWN | GADGETUP | MOUSEMOVE | 
  47.                                 /* IDCMP flags */
  48.     MOUSEBUTTONS | MENUPICK | REQCLEAR | SELECTDOWN | SELECTUP,
  49.     NORMALFLAGS,                /* window flags */
  50.     NULL, NULL,                 /* pntr gadget, checkmark */
  51.     (UBYTE *) "Flist",          /* title */
  52.     NULL,                   /* screen pointer filled in later (run time) */
  53.     NULL,                   /* bitmap pntr */
  54.     0, 0, 8000, 8000,       /* default x,y, &size */
  55.     CUSTOMSCREEN
  56.     };
  57.  
  58. /* Globals */
  59.  
  60. extern long numfiles, remember;
  61. extern long (*finfo[MAXDIR])[4];  /* miscelaneous info -- file size,blocks,dir type etc... */
  62. extern char (*fname[MAXDIR])[FCHARS];     /* file name and comment */
  63. extern char (*comm[MAXDIR])[FCHARS];
  64. extern char (*fstring[MAXDIR])[LEN_DATSTRING];
  65. extern char (*ftime[MAXDIR])[LEN_DATSTRING];
  66. extern struct Image cursor_image;
  67. extern long row,collum,line,first;
  68. extern struct Window *winptr;
  69. extern struct Screen *scrptr;
  70.  
  71. /* Globals defined here */
  72.  
  73. struct RastPort *rp;
  74.  
  75. /* Scrprt - print text to a screen (actually a rastport) */
  76.  
  77. scrprt(numb,top)
  78. short numb,top;
  79. {
  80.     struct IntuiText itext;
  81.     register long temp,i;
  82.  
  83.     if (top == remember )
  84.         return;
  85.         
  86.     /* for FAST movements of the screen... use the hardware */
  87.         
  88.     if ((top-remember) == 1 || (top-remember) == -1)
  89.         doBlit(top); 
  90.     else{
  91.         Move(rp,0,0);
  92.         ClearScreen(rp); 
  93.         if (numfiles != 0) {    /* Watch for empty directories! */
  94.             if (line > numfiles)
  95.                 temp = numfiles;
  96.             else
  97.                 temp = top;
  98.  
  99.             for(i=0;(i<numb)&&(i<NUMLINES);i++) {
  100.                 prtline(temp,i);
  101.                 if (temp < numfiles)
  102.                         temp++;
  103.             }
  104.         }
  105.     }
  106.     RefreshGadgets(&pg,winptr,NULL);
  107.     doborder();
  108.     remember = top;
  109. }
  110.  
  111. struct IntuiText itext = {
  112.         TEXTCOLOR, 0,
  113.         JAM2,
  114.         0,0,                    /* x, y */
  115.         NULL,                   /* font */
  116.         NULL,                   /* &text */
  117.         NULL,                   /* &next */
  118. };
  119.  
  120. /* Print a line associated with a file to the screen */
  121.  
  122. /* **** This could be optimized in assembly for speed **** */
  123.  
  124. prtline(pline,i)
  125. register long pline,i;
  126. {
  127.      char buffer[FCHARS];
  128.      struct BitMap *bmptr;
  129.  
  130.      if (pline >= numfiles)
  131.         return;
  132.      
  133.      bmptr = &scrptr->BitMap;
  134.  
  135.      itext.LeftEdge = 0;
  136.      itext.TopEdge = i * LINEH; 
  137.      strcpy(&buffer[0],fname[pline]);
  138.      buffer[13] = 0;
  139.      itext.IText = buffer; 
  140.      PrintIText(rp,&itext,3L,14L); 
  141.      itext.LeftEdge = 368; 
  142.      itext.IText = fstring[pline];
  143.      PrintIText(rp,&itext,3L,14L); 
  144.      itext.LeftEdge = 456; 
  145.      itext.IText = ftime[pline];
  146.      PrintIText(rp,&itext,3L,14L); 
  147.  
  148.      if (*finfo[pline][0] < 0)
  149.         sprintf(buffer,"%d         ",(*finfo[pline])[2]);
  150.      else
  151.         strcpy(buffer," Dir");
  152.  
  153.      itext.LeftEdge = 528; 
  154.      buffer[7] = 0;
  155.      itext.IText = buffer; 
  156.      PrintIText(rp,&itext,3L,14L); 
  157. }
  158.  
  159. doBlit(stop)
  160. long stop;
  161. {
  162.         long inter,i;        
  163.         struct BitMap *bmptr;
  164.         
  165.         inter = stop - remember;
  166.         bmptr = &scrptr->BitMap;
  167.  
  168.         WaitTOF();
  169.         if (inter > 0)
  170.                 ScrollRaster(rp,0L,LINEH,0L,(LONG)TOP+2,600L,189L);
  171. /*                    BltBitMap(bmptr,0L,22L,bmptr,0L,12L,600L,170L,
  172.                       (LONG)0x0c0,(LONG)0x0ff,tempblit); */
  173.         else
  174.                 ScrollRaster(rp,0L,-(LINEH),0L,(LONG)TOP+2,600L,189L);
  175. /*                    BltBitMap(bmptr,0L,12L,bmptr,0L,22L,600L,170L,
  176.                     (LONG)0x0c0,(LONG)0x0ff,tempblit); */
  177.         
  178.         if (inter > 0)
  179.                 prtline(stop+NLMO,NLMO);
  180.         else
  181.                 prtline(stop,0); 
  182. }
  183.  
  184. /* draw the border around the console display */
  185.  
  186. doborder()
  187. {
  188.         SetAPen(rp,3);
  189.         Move(rp,LEFT-2,TOP-1);
  190.         Draw(rp,RIGHT,TOP-1);
  191.         Draw(rp,RIGHT,BOT+1);
  192.         Draw(rp,LEFT-2,BOT+1);
  193.         Draw(rp,LEFT-2,TOP-1);
  194. }
  195.  
  196. /* this function captures the abort from cntrl c */
  197.  
  198. _abort()
  199. {
  200.     int ret;
  201.     ret = auto_req("User abort!!!");
  202.  
  203.     if(scrptr->FirstWindow->NextWindow != NULL) 
  204.         auto_req("Kill all other Applications first!");
  205.     else
  206.         if (ret) {
  207.             Cleanup();
  208.             exit(1);
  209.         }
  210.     menu();     /* no abort, go to the menu again! */
  211. }
  212.  
  213. openstuff()
  214. {
  215.     int i;
  216.     struct ViewPort *vp;
  217.  
  218.     scrptr = OpenScreen(&scr);
  219.     if (scrptr == NULL) {
  220.         fprintf(stderr,"Couldn't open Screen!\n");
  221.         FreeFlistMem();
  222.         exit(30L);
  223.     }
  224.  
  225.     mywin.FirstGadget = &pg;   /* prop gadget attached to the window */
  226.     mywin.Screen = scrptr;
  227.     winptr = OpenWindow(&mywin);
  228.     if (winptr == NULL) {
  229.         fprintf(stderr,"Couldn't open Window!\n");
  230.         FreeFlistMem();
  231.         CloseScreen(scrptr);
  232.         exit(40L);
  233.     }
  234.  
  235.     OpenConsole();
  236.     
  237.     rp = winptr->RPort;
  238.     vp = &scrptr->ViewPort;
  239.  
  240. /*     LoadRGB4(vp,&coltbl,4L); */
  241.  
  242.     refresh();
  243. }
  244.