home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / Amiga / plwindow.c < prev   
C/C++ Source or Header  |  1990-01-27  |  4KB  |  143 lines

  1. #include "plplot.h"
  2. #include "plamiga.h"
  3. #include <stdio.h>
  4. #include <math.h>
  5.  
  6. extern struct PLPrefs PLCurPrefs;
  7.  
  8. PLINT MaxColors;
  9.  
  10. extern PLFLT InitWSize, InitHSize;
  11.  
  12. struct Screen *PLScreen;        /* For Custom Screen */
  13. struct Window *PLWindow;
  14. struct RastPort *PLSRPort;      /* Screen rastport */
  15. struct RastPort *PLWRPort;      /* Window rastport */
  16. struct ViewPort *PLVPort;
  17. struct ColorMap *PLCMap;
  18. static struct TmpRas PLTmpRas;
  19. static PLANEPTR PLTmpPlane;
  20.  
  21. struct NewWindow NewWindow = {
  22.    0, 0,
  23.    0, 0,
  24.    0, 1,
  25.    0,
  26.    0,
  27.    NULL,
  28.    NULL,
  29.    NULL,
  30.    NULL,                            /* Screen pointer */
  31.    NULL,
  32.    205, 120, 1000, 1000,
  33.    WBENCHSCREEN
  34. };
  35.  
  36. void OpenPLWind()
  37. {
  38.    short i;
  39.  
  40.    if(PLCurPrefs.WinType & PLCUST) {
  41.       struct NewScreen NewScreen = {
  42.          0, 0, 0, 0, 1,
  43.          0, 1,
  44.          HIRES,                        /* default viewmode */
  45.          CUSTOMSCREEN,
  46.          NULL,
  47.          "Plplot Screen",
  48.          NULL,
  49.          NULL
  50.       };
  51.  
  52.       NewScreen.Height = GfxBase->NormalDisplayRows;
  53.       NewScreen.Width = GfxBase->NormalDisplayColumns;
  54.  
  55.       if(PLCurPrefs.ScrType & PLLACE) {
  56.          NewScreen.ViewModes |= INTERLACE;
  57.          NewScreen.Height *= 2;
  58.       }
  59.       if(!(PLCurPrefs.ScrType & PLHIRES)) {
  60.          NewScreen.ViewModes &= ~HIRES;
  61.          NewScreen.Width /= 2;
  62.       }
  63.  
  64.       NewScreen.Depth = PLCurPrefs.Depth;
  65.       NewWindow.Type = CUSTOMSCREEN;
  66.       if((PLScreen = OpenScreen(&NewScreen)) == NULL) {
  67.          fprintf(stderr,"Not enough memory for custom screen.\n");
  68.          CloseLibs();
  69.          pl_exit();
  70.       }
  71.       for(i=0, MaxColors=1; i<PLCurPrefs.Depth; i++)
  72.          MaxColors *= 2;
  73.       PLVPort = &(PLScreen->ViewPort);
  74.       LoadRGB4(PLVPort,&(PLCurPrefs.Color[0]),MaxColors);
  75.       NewWindow.Screen = PLScreen;
  76.       if(PLCurPrefs.CWidth == 0 || PLCurPrefs.CHeight == 0) {
  77.          NewWindow.Width = PLScreen->Width;
  78.          NewWindow.Height = PLScreen->Height - PLScreen->BarHeight - 1;
  79.          NewWindow.LeftEdge = 0;
  80.          NewWindow.TopEdge = PLScreen->BarHeight + 1;
  81.          PLCurPrefs.CXPos = NewWindow.Width;
  82.          PLCurPrefs.CYPos = NewWindow.Height;
  83.          PLCurPrefs.CWidth = NewWindow.Width;
  84.          PLCurPrefs.CHeight = NewWindow.Height;
  85.       }
  86.       else {
  87.          NewWindow.LeftEdge = PLCurPrefs.CXPos;
  88.          NewWindow.TopEdge = PLCurPrefs.CYPos;
  89.          NewWindow.Width = PLCurPrefs.CWidth;
  90.          NewWindow.Height = PLCurPrefs.CHeight;
  91.       }
  92.    }
  93.    else {
  94.       MaxColors = 4;
  95.       NewWindow.LeftEdge = PLCurPrefs.WXPos;
  96.       NewWindow.TopEdge = PLCurPrefs.WYPos;
  97.       NewWindow.Width = PLCurPrefs.WWidth;
  98.       NewWindow.Height = PLCurPrefs.WHeight;
  99.       NewWindow.Type = WBENCHSCREEN;
  100.    }
  101.  
  102.    NewWindow.IDCMPFlags = NEWSIZE|MENUPICK|CLOSEWINDOW;
  103.    NewWindow.Flags = WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|WINDOWSIZING|
  104.                      SMART_REFRESH|ACTIVATE;
  105.    NewWindow.Title = "Plplot 2.0 - Tony Richardson";
  106.  
  107.    if((PLWindow = OpenWindow(&NewWindow)) == NULL) {
  108.       fprintf(stderr,"Error opening window.\n");
  109.       if(PLCurPrefs.WinType & PLCUST)
  110.          CloseScreen(PLScreen);
  111.       CloseLibs();
  112.    }
  113.  
  114.    if(!(PLCurPrefs.WinType & PLCUST))
  115.       PLScreen = PLWindow->WScreen;
  116.  
  117.    PLSRPort = &(PLScreen->RastPort);
  118.    PLWRPort = PLWindow->RPort;
  119.    PLVPort = &(PLScreen->ViewPort);
  120.    PLCMap = PLVPort->ColorMap;
  121.    PLTmpPlane = AllocRaster(PLScreen->Width,PLScreen->Height);
  122.    if(PLTmpPlane == NULL) {
  123.       CloseWindow(PLWindow);
  124.       if(PLCurPrefs.WinType & PLCUST)
  125.          CloseScreen(PLScreen);
  126.       fprintf(stderr,"Out of memory!");
  127.    }
  128.    InitTmpRas(&PLTmpRas,PLTmpPlane,RASSIZE(PLScreen->Width,PLScreen->Height));
  129.    PLWRPort->TmpRas = &PLTmpRas;
  130.  
  131.    MakePLMenu();
  132. }
  133.  
  134. void ClosePLWind()
  135. {
  136.    FreeRaster(PLTmpPlane,PLScreen->Width,PLScreen->Height);
  137.    ClearMenuStrip(PLWindow);
  138.    CloseWindow(PLWindow);
  139.    if((PLScreen->Flags & SCREENTYPE) == CUSTOMSCREEN)
  140.       CloseScreen(PLScreen);
  141. }
  142.  
  143.