home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / misc / gnuplot.lzh / term / amiga.trm
Encoding:
Text File  |  1992-02-03  |  8.2 KB  |  301 lines

  1. /* V1.1 24 Nov 91
  2.  
  3.  *  Added key-hit to quit
  4.  *  Changed colors and line-types
  5.  */
  6. /* Amiga GnuPlot interface v1.0 29 Sep 90 */
  7. /* Michael D. Black, 1380 Croftwood Dr. Melbourne, FL 32935 */
  8.  
  9. #include <stdio.h>
  10. #include <functions.h>
  11. #include <exec/types.h>
  12. #include <intuition/intuition.h>
  13. #include <graphics/display.h>
  14.  
  15. static struct IntuitionBase *IntuitionBase=0;
  16. static struct GfxBase *GfxBase=0;
  17. struct Library *DiskfontBase;
  18. static struct TextAttr AMIGA_Font = {
  19.   "topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT
  20. };
  21.  
  22. #define INTUITION_REV 0
  23. #define GRAPHICS_REV 0
  24.  
  25. #define AMIGA_XMAX 640
  26. #define AMIGA_YMAX 400
  27. #define AMIGA_VCHAR 8
  28. #define AMIGA_HCHAR 8
  29. #define AMIGA_VTIC 4
  30. #define AMIGA_HTIC 5
  31. /* The origin is in the upper left hand corner, so we have to translate */
  32. /* and flip the coordinates: */
  33. #define AMIGA_VTF(y) (AMIGA_ymax-1-(y))
  34.  
  35. static struct NewScreen NewScreen = {
  36.     0L,0L,AMIGA_XMAX,AMIGA_YMAX,3L,
  37.     0L,0L,
  38.     HIRES|INTERLACE,CUSTOMSCREEN,
  39.     &AMIGA_Font,
  40.     (UBYTE*)"GNUPlot",
  41.     NULL,NULL};
  42.  
  43. static struct Screen *Screen;
  44. static struct Window *Window;
  45. static struct NewWindow NewWindow = {
  46.     0L, 0L, 640L, 400L, -1L, -1L, MOUSEBUTTONS | VANILLAKEY,
  47. /*    SMART_REFRESH | ACTIVATE | GIMMEZEROZERO*/
  48.     SMART_REFRESH | ACTIVATE
  49.     | NOCAREREFRESH | BORDERLESS | RMBTRAP,
  50.     NULL, NULL, (UBYTE*)"GNUPlot", NULL, NULL,
  51.     0L, 0L, 0L, 0L, CUSTOMSCREEN
  52. };
  53.  
  54. static struct RastPort *rp;
  55. static long AMIGA_xmax=AMIGA_XMAX,AMIGA_ymax=AMIGA_YMAX;
  56. static struct TextFont *AMIGA_TextFont;
  57. static enum JUSTIFY AMIGA_justify = LEFT;
  58. static WORD AMIGA_cwd,AMIGA_cht,AMIGA_bsl,AMIGA_vadj;
  59.  
  60. AMIGA_init()
  61. {
  62.     char *s;
  63.  
  64.     if (s=getenv("GNUXMAX")) {
  65.         AMIGA_xmax = atol(s);
  66.         NewScreen.Width = AMIGA_xmax;
  67.         NewWindow.Width = AMIGA_xmax;
  68.         term_tbl[term].xmax = AMIGA_xmax;
  69.     }
  70.     if (s=getenv("GNUYMAX")) {
  71.         AMIGA_ymax = atol(s);
  72.         NewScreen.Height = AMIGA_ymax;
  73.         NewWindow.Height = AMIGA_ymax;
  74.         term_tbl[term].ymax = AMIGA_ymax;
  75.     }
  76.  
  77.     return 0;
  78. }
  79.  
  80. AMIGA_reset()
  81. {
  82.     return 0;
  83. }
  84.  
  85. /* scale() not provided */
  86.  
  87. AMIGA_graphics()
  88. {
  89.     char *colors,fontname[80],*gnufont,*search;
  90.     static int fsize;
  91.     static char *test_str =
  92.     " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
  93.     static WORD test_len,test_pxl;
  94.  
  95.     IntuitionBase = (struct IntuitionBase *)
  96.         OpenLibrary("intuition.library",INTUITION_REV);
  97.     if(IntuitionBase == NULL) {
  98.         puts("Can't open intution.library");
  99.         goto cleanup1;
  100.     }
  101.  
  102.     GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",GRAPHICS_REV);
  103.     if (GfxBase == NULL) {
  104.         puts("Can't open graphics.library");
  105.         goto cleanup2;
  106.     }
  107.  
  108.     DiskfontBase = OpenLibrary("diskfont.library",0);
  109.     if (DiskfontBase == NULL) {
  110.         puts("Can't open diskfont.library");
  111.         goto cleanup2a;
  112.     }
  113.     if((Screen = (struct Screen *) OpenScreen(&NewScreen)) == NULL) {
  114.         puts("Screen error");
  115.         goto cleanup3;
  116.     }
  117.     NewWindow.Screen = Screen;
  118.     if (( Window = (struct Window *) OpenWindow(&NewWindow)) == NULL) {
  119.         puts("Window error");
  120.         goto cleanup4;
  121.     }
  122.     rp = Window->RPort;
  123.  
  124.     if (colors=getenv("GNUCOLORS")) {
  125.         long color=0,r,g,b;
  126.         char *s;
  127.         while (s=strtok(colors,", ")) {
  128.             colors=0;
  129.             if (sscanf (s,"%1x%1x%1x",&r,&g,&b)==3)
  130.                 SetRGB4(&Screen->ViewPort,color++,r,g,b);
  131.             else {
  132.                 printf("Error in GNUCOLORS at '%s'\n",s);
  133.             }
  134.         }
  135.     }
  136.     else {
  137.         long r[8] = { 0x08,0x00,0x00,0x0b,0x00,0x0f,0x0f,0x0f };
  138.         long g[8] = { 0x08,0x00,0x00,0x00,0x0b,0x09,0x0f,0x00 };
  139.         long b[8] = { 0x08,0x00,0x0b,0x00,0x00,0x00,0x0f,0x0f };
  140.         long i;
  141.         for(i=0;i<8;i++)
  142.             SetRGB4(&Screen->ViewPort,i,r[i],g[i],b[i]);
  143.     }
  144.  
  145.     gnufont = getenv("GNUFONT");
  146.     if (gnufont != NULL ) {
  147.         search = strchr(gnufont,'/');
  148.         if (search != NULL) {
  149.             *search++ = '\0';
  150.             strncpy(fontname,gnufont,74);
  151.             strcat(fontname,".font");
  152.             sscanf(search,"%d",&fsize);
  153.             if ((strcmp("topaz.font",fontname) == 0) &&
  154.                 ((fsize == TOPAZ_EIGHTY) || (fsize == TOPAZ_SIXTY))) {
  155.                 AMIGA_Font.ta_Name = fontname;
  156.                 AMIGA_Font.ta_YSize = fsize;
  157.                 AMIGA_Font.ta_Style = FS_NORMAL;
  158.                 AMIGA_Font.ta_Flags = FPF_ROMFONT;
  159.                 AMIGA_TextFont = OpenFont(&AMIGA_Font);
  160.                 if (AMIGA_TextFont != NULL)
  161.                     SetFont(rp,AMIGA_TextFont);
  162.             }
  163.             else {
  164.                 if (DiskfontBase != NULL) {
  165.                     AMIGA_Font.ta_Name = fontname;
  166.                     AMIGA_Font.ta_YSize = fsize;
  167.                     AMIGA_Font.ta_Style = FS_NORMAL;
  168.                     AMIGA_Font.ta_Flags = FPF_ROMFONT|FPF_DISKFONT;
  169.                     AMIGA_TextFont = OpenDiskFont(&AMIGA_Font);
  170.                     if (AMIGA_TextFont != NULL)
  171.                         SetFont(rp,AMIGA_TextFont);
  172.                 }
  173.             }
  174.         }
  175.     }
  176.     /* Width of characters: This works better for proportional fonts than */
  177.     /* AMIGA_Screen->RastPort.TxWidth + AMIGA_Screen->RastPort.TxSpacing */
  178.     test_len = strlen(test_str);
  179.     test_pxl = TextLength(rp,test_str,test_len);
  180.     AMIGA_cwd = test_pxl / test_len;
  181.     AMIGA_cht = rp->TxHeight; /* Height of characters */
  182.     AMIGA_bsl = rp->TxBaseline; /* Reference line */
  183.     /* Amount by which characters have to be shifted upwards to be */
  184.     /* vertically justified: */
  185.     AMIGA_vadj = AMIGA_bsl / 2;
  186.     term_tbl[term].v_char = AMIGA_cht + 4; /* So lines won't be too close */
  187.     term_tbl[term].h_char = AMIGA_cwd;
  188.  
  189.     goto ok;
  190.  
  191.     CloseWindow(Window);
  192.     cleanup4:
  193.         CloseScreen(Screen);
  194.     cleanup3:
  195.         CloseLibrary(DiskfontBase);
  196.     cleanup2a:
  197.         CloseLibrary(GfxBase);
  198.     cleanup2:
  199.         CloseLibrary(IntuitionBase);
  200.     cleanup1:;
  201.         exit(5);
  202.     ok:;
  203.     return 0;
  204. }
  205.  
  206. AMIGA_text()
  207. {
  208.     Wait(1L<<Window->UserPort->mp_SigBit);
  209.     CloseWindow(Window);
  210.     CloseScreen(Screen);
  211.     CloseLibrary(DiskfontBase);
  212.     CloseLibrary(GfxBase);
  213.     CloseLibrary(IntuitionBase);
  214.     return 0;
  215. }
  216.  
  217. AMIGA_move(x,y)
  218. int x,y;
  219. {
  220.     if ((x<AMIGA_xmax) && (y<AMIGA_ymax))
  221.         Move(rp,(long)x,AMIGA_ymax-1-(long)y);
  222.     return 0;
  223. }
  224.  
  225. AMIGA_vector(x,y)
  226. int x,y;
  227. {
  228.     if ((x<AMIGA_xmax) && (y<AMIGA_ymax))
  229.         Draw(rp,(long)x,AMIGA_ymax-1-(long)y);
  230.     return 0;
  231. }
  232.  
  233. AMIGA_linetype(linetype)
  234. int linetype;
  235. {
  236.     static long pattern[] = {0xffff, 0x8888, /* these 2 are the border & axis */
  237.                              0xffff, 0xffff, 0xffff, 0xffff,
  238.                              0xffff, 0xffff, 0xffff, 0xf0f0,
  239.                              0xf0f0, 0xf0f0, 0xf0f0, 0xf0f0,
  240.                              0x8888, 0x8888, 0x8888, 0x8888,
  241.                              0x8888, 0x8888, 0x8888 };
  242.     static long colors[] = {  1, 1,
  243.                               1, 2, 3, 4,
  244.                               5, 6, 7, 1,
  245.                               2, 3, 4, 5,
  246.                               1, 2, 3, 4,
  247.                               5, 6, 7 };
  248.  
  249.     linetype = linetype % 19;
  250.     SetDrPt(rp,pattern[linetype+2]);
  251.     SetAPen(rp,colors[linetype+2]);
  252.     return 0;
  253. }
  254.  
  255. AMIGA_put_text(x,y,str)
  256. int x,y;
  257. char *str;
  258. {
  259.     long len,tx_len;
  260.     int xmin,xmax,ymin,ymax;
  261.  
  262.     len = strlen(str);
  263.     tx_len = TextLength(rp,str,len);
  264.     SetDrMd(rp,JAM1);
  265.     switch (AMIGA_justify) {
  266.         case LEFT:
  267.             xmin = x;
  268.             xmax = x + tx_len;
  269.             break;
  270.         case CENTRE:
  271.             xmin = x - tx_len / 2;
  272.             xmax = x + tx_len - tx_len / 2; /* aviod roundoff errors ! */
  273.             break;
  274.         case RIGHT:
  275.             xmin = x - tx_len;
  276.             xmax = x;
  277.             break;
  278.     }
  279.     ymin = AMIGA_VTF(y) - AMIGA_vadj;
  280.     ymax = ymin + AMIGA_cht;
  281.     /* Check if character-string lies completely within the screen: */
  282.     if ((xmax < AMIGA_xmax) && (ymin >=0) && (ymax < AMIGA_ymax)) {
  283.         Move(rp,xmin,ymin+AMIGA_bsl);
  284.         Text(rp,str,(long)strlen(str));
  285.     }
  286.     return 0;
  287. }
  288.  
  289. AMIGA_text_angle(mode)
  290. enum JUSTIFY mode;
  291. {
  292.     AMIGA_justify = mode;
  293.     return TRUE; /* we can't rotate text */
  294. }
  295.  
  296. AMIGA_justify_text(ang)
  297. int ang;
  298. {
  299.     return 0; /* we can't justify text either */
  300. }
  301.