home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / 3DTOSHI2.ZIP / mpgfx / source / gfxxwin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  9.4 KB  |  339 lines

  1.  
  2. // gfxxwin.cpp
  3. //
  4. // Copyright (c) 1995 by Toshiaki Tsuji, all rights reserved.
  5.  
  6. #include "stdgfx.h"
  7. #include "gfxxwin.h"
  8.   
  9. XWINDRIVER::XWINDRIVER ()
  10.   {
  11.     Width = Height = 0;
  12.     #if defined (__FORUNIX__)
  13.       MainXDisplay = NULL;
  14.       XWinGC = NULL;
  15.       XWinImage = NULL;
  16.       XWinColormap = NULL;
  17.     #endif
  18.   } // End of Constructor for XWINDRIVER
  19.  
  20. XWINDRIVER::~XWINDRIVER ()
  21.   {
  22.     #if defined (__FORUNIX__)
  23.       if (XWinGC!=NULL)      
  24.         XFreeGC ( MainXDisplay, XWinGC );
  25.       XWinGC = NULL;
  26.  
  27.       if (XWinImage!=NULL)
  28.         XDestroyImage ( XWinImage );
  29.       XWinImage = NULL;
  30.  
  31.       if (XWinColormap!=NULL)
  32.         XFreeColormap ( MainXDisplay, XWinColormap );
  33.     #endif
  34.   } // End of Destructor for XWINDRIVER
  35.  
  36. BOOLEAN XWINDRIVER::SetUp ( DISPLAYDATA *Data )
  37.   {
  38.     if (Data)
  39.       {}  
  40.     #if defined (__FORWINDOWS__)
  41.       return FAILURE;
  42.     #elif defined (__FOROS2__)
  43.       return FAILURE;
  44.     #elif defined (__FORDOS__)
  45.       return FAILURE;
  46.     #elif defined (__FORUNIX__)
  47.       MainXDisplay = Data->MainXDisplay;
  48.       Window Root;
  49.  
  50.       MainXScreen = DefaultScreenOfDisplay ( MainXDisplay );
  51.       Root = RootWindowOfScreen ( MainXScreen );
  52.       
  53.       if (XWinGC!=NULL)
  54.         XFreeGC ( MainXDisplay, XWinGC );
  55.       XWinGC = XCreateGC ( MainXDisplay, Root, NULL, NULL );
  56.  
  57.       Visual *XWinVisual;
  58.       XWinVisual = DefaultVisual ( MainXDisplay, DefaultScreen(MainXDisplay) );
  59.       INT Format,Offset,BitmapPad,BytesPerLine;
  60.       UINT Width,Height,Depth;
  61.  
  62.       Format = ZPixmap;
  63.       Offset = 0;
  64.       BitmapPad = 8;
  65.       BytesPerLine = 0;
  66.       Depth = 8;
  67.       
  68.       /*if (XWinImage!=NULL)
  69.         XDestroyImage ( XWinImage );
  70.       XWinImage = XCreateImage ( MainXDisplay, XWinVisual, Depth, Format,
  71.                                  Offset, NULL, Width, Height, BitmapPad,
  72.                                  BytesPerLine );
  73.       XWinImage->byte_order = LSBFirst;*/
  74.       return SUCCESS;
  75.     #endif
  76.   } // End of SetUp for XWINDRIVER
  77.  
  78. VOID XWINDRIVER::Reset ()
  79.   {
  80.     SetUp ( M80x25x16 );
  81.   } // End of SetUp for XWINDRIVER
  82.  
  83. VOID XWINDRIVER::Clear ( HDISPLAY hDisplay, LONG Color )
  84.   {
  85.     if (hDisplay)
  86.       {}
  87.     if (Color)
  88.       {}
  89.  
  90.     #if defined (__FORUNIX__)
  91.       XClearArea ( MainXDisplay, hDisplay, 0, 0, 0, 0, FALSE );
  92.     #endif
  93.   } // End of Clear for XWINDRIVER
  94.  
  95. LONG XWINDRIVER::GetWidth ( HDISPLAY hDisplay )
  96.   {
  97.     if (hDisplay)
  98.       {}
  99.     return 3000;
  100.   } // End of GetWidth for XWINDRIVER
  101.  
  102. LONG XWINDRIVER::GetHeight ( HDISPLAY hDisplay )
  103.   {
  104.     if (hDisplay)
  105.       {}
  106.     return 2000;
  107.   } // End of GetHeight for XWINDRIVER
  108.  
  109. VOID XWINDRIVER::DisplayImage ( IMAGE *Image, LONG Sx, LONG Sy,
  110.                                 LONG Wd, LONG Ht, HDISPLAY Dest,
  111.                                 LONG Cx, LONG Cy, LONG DestWd, LONG DestHt )
  112.   {
  113.     if (Image)
  114.       {}
  115.     if (Sx&Sy&Wd&Ht&Cx&Cy&DestWd&DestHt)
  116.       {}
  117.     if (Dest)
  118.       {}  
  119.     #if defined (__FORUNIX__)
  120.       Visual *XWinVisual;
  121.       XWinVisual = DefaultVisual ( MainXDisplay, DefaultScreen(MainXDisplay) );
  122.  
  123.       XWinImage = XCreateImage ( MainXDisplay, XWinVisual, 8, ZPixmap,
  124.                                  0, Image->GetBuffer(), Image->GetWidth(),
  125.                                  Image->GetHeight(), 8, 0 );
  126.  
  127.       INT Depth;
  128.  
  129.       Depth = DefaultDepth ( MainXDisplay, DefaultScreen ( MainXDisplay ) );
  130.  
  131.       if (Depth>=8)
  132.         {
  133.           /*XWinImage->data = (char*)(Image->GetBuffer());
  134.           XWinImage->width = Image->GetWidth();
  135.           XWinImage->height = Image->GetHeight();
  136.           XWinImage->xoffset = 0;
  137.           XWinImage->bitmap_unit = 8;
  138.           XWinImage->bits_per_pixel = 8;
  139.           XWinImage->bytes_per_line = 0;      
  140. */
  141.           XPutImage ( MainXDisplay, Dest, XWinGC, XWinImage, 
  142.                       Sx, Sy, Cx, Cy, 
  143.                       DestWd, DestHt );
  144.         } // End if
  145.       else
  146.         {
  147.           INT i,j;
  148.           BYTE *Buffer;
  149.           for (i=Sy;i<Sy+DestHt;i++)
  150.             {
  151.               Buffer = Image->SetOffset ( 0, i );
  152.               for (j=Sx;j<Sx+DestWd;j++)
  153.                 {
  154.                   DrawPixel ( Dest, Cx+j-Sx, Cy+i-Sy, Buffer[j] ); 
  155.                 } // End for
  156.             } // End for
  157.         } // End else 
  158.  
  159.       XFree ( XWinImage );
  160.       XWinImage = NULL;
  161.     #endif
  162.   } // End of DisplayImage for XWINDRIVER
  163.  
  164. #if defined (__FORUNIX__)
  165.   Visual* GetProperVisual ( Display *MainXDisplay, INT ScreenID, INT Depth, INT Class )
  166.     {
  167.       XVisualInfo *VisualList, TemplateVisual;
  168.       INT NumVisuals;
  169.  
  170.       TemplateVisual.screen = ScreenID;
  171.       
  172.       VisualList = XGetVisualInfo ( MainXDisplay, VisualScreenMask,
  173.                                     &TemplateVisual, &NumVisuals );
  174.       if (NumVisuals==0)
  175.         return NULL;
  176.  
  177.       INT i;
  178.  
  179.       for (i=0;i<NumVisuals;i++)
  180.         {
  181.           if ((VisualList[i].c_class==Class)&&(VisualList[i].depth>=Depth))
  182.             {
  183.               return VisualList[i].visual;
  184.             } // End if
  185.         } // End for 
  186.  
  187.       return NULL;
  188.     } // End of GetProperVisual
  189. #endif 
  190.  
  191. VOID XWINDRIVER::SetPalette ( HDISPLAY hDisplay, RGBPALETTE *Pal )
  192.   {
  193.     RGBCOLOR *Entry;
  194.  
  195.     if (hDisplay)
  196.       {}
  197.       
  198.     if (Pal==NULL)
  199.       return;
  200.  
  201.     Entry = Pal->GetEntry ();
  202.     if (Entry==NULL)
  203.       return;
  204.  
  205.     #if defined (__FORUNIX__)
  206.       XColor XWinColors[256];
  207.       INT i;
  208.       for (i=0;i<256;i++)
  209.         {
  210.           XWinColors[i].red = Entry[i].Red*256;
  211.           XWinColors[i].green = Entry[i].Green*256;
  212.           XWinColors[i].blue = Entry[i].Blue*256;
  213.           XWinColors[i].pixel = i;
  214.           XWinColors[i].flags = DoRed | DoGreen | DoBlue;
  215.         } // End for
  216.  
  217.       Visual *LocalVisual;
  218.  
  219.       LocalVisual = DefaultVisual ( MainXDisplay, DefaultScreen(MainXDisplay) );
  220.       if (DefaultDepth ( MainXDisplay, DefaultScreen(MainXDisplay))<8)
  221.         LocalVisual = GetProperVisual ( MainXDisplay, DefaultScreen(MainXDisplay),
  222.                                         8,  PseudoColor );
  223.   
  224.       if (LocalVisual==NULL)
  225.         return;
  226.  
  227.       if (XWinColormap==NULL)
  228.         XWinColormap = XCreateColormap ( MainXDisplay, 
  229.                           RootWindow(MainXDisplay,DefaultScreen(MainXDisplay)),
  230.                           LocalVisual, AllocAll );
  231.  
  232.       XStoreColors ( MainXDisplay, XWinColormap, XWinColors, 256 );
  233.       XSetWindowColormap ( MainXDisplay, hDisplay, XWinColormap );
  234.     #endif
  235.   } // End of SetPalette for XWINDRIVER
  236.  
  237. VOID XWINDRIVER::GetPalette ( HDISPLAY hDisplay, RGBPALETTE *Pal )
  238.   {
  239.     RGBCOLOR *Entry;
  240.  
  241.     if (hDisplay)
  242.       {}
  243.     if (Pal==NULL)
  244.       return;
  245.  
  246.     Entry = Pal->GetEntry ();
  247.     if (Entry==NULL)
  248.       return;
  249.   } // End of GetPalette for XWINDRIVER
  250.  
  251. VOID XWINDRIVER::DrawLine ( HDISPLAY hDisplay, LONG x1, LONG y1, LONG x2, LONG y2,
  252.                             COLOR  Color )
  253.   {
  254.     if (hDisplay)
  255.       {}
  256.     if (x1&y1&x2&y2)
  257.       {}
  258.     if (Color)
  259.       {}
  260.     #if defined (__FORUNIX__)      
  261.       XSetForeground ( MainXDisplay, XWinGC, Color );
  262.       XDrawLine ( MainXDisplay, hDisplay, XWinGC, x1, y1, x2, y2 );
  263.     #endif
  264.   } // End of DrawLine for XWINDRIVER
  265.  
  266. VOID XWINDRIVER::DrawRect ( HDISPLAY hDisplay, LONG x1, LONG y1, LONG x2, LONG y2,
  267.                            COLOR Color )
  268.   {
  269.     DrawLine ( hDisplay, x1, y2, x2, y2, Color );
  270.     DrawLine ( hDisplay, x1, y1, x2, y1, Color );
  271.     DrawLine ( hDisplay, x1, y1, x1, y2, Color );
  272.     DrawLine ( hDisplay, x2, y1, x2, y2, Color );
  273.   } // End of DrawRect for XWINDRIVER
  274.  
  275. VOID XWINDRIVER::FillRect ( HDISPLAY hDisplay, LONG x1, LONG y1, LONG x2, LONG y2,
  276.                            COLOR Color )
  277.   {
  278.     if (hDisplay)
  279.       {}
  280.     if (x1&y1&x2&y2)
  281.       {}
  282.     if (Color)
  283.       {}      
  284.     #if defined (__FORUNIX__)      
  285.       XSetForeground ( MainXDisplay, XWinGC, Color );
  286.       XFillRectangle ( MainXDisplay, hDisplay, XWinGC, x1, y1, x2-x1+1, 
  287.                        y2-y1+1 );
  288.     #endif
  289.   } // End of FillRect for XWINDRIVER
  290.  
  291. VOID XWINDRIVER::DrawPixel ( HDISPLAY hDisplay, LONG x, LONG y,
  292.                             COLOR Color )
  293.   {
  294.     if (hDisplay)
  295.       {}
  296.     if (x&y)
  297.       {}
  298.     if (Color)
  299.       {}      
  300.     #if defined (__FORUNIX__)      
  301.       XSetForeground ( MainXDisplay, XWinGC, Color );
  302.       
  303.       XDrawPoint ( MainXDisplay, hDisplay, XWinGC, x, y );
  304.     #endif
  305.   } // End of DrawPixel for XWINDRIVER
  306.  
  307. VOID XWINDRIVER::DrawEllipse ( HDISPLAY hDisplay, LONG Cx, LONG Cy, LONG Rx, LONG Ry,
  308.                               COLOR Color )
  309.   {
  310.     if (hDisplay)
  311.       {}
  312.     if (Cx&Cy&Rx&Ry)
  313.       {}
  314.     if (Color)
  315.       {}      
  316.     #if defined (__FORUNIX__)      
  317.       XSetForeground ( MainXDisplay, XWinGC, Color );      
  318.       XDrawArc ( MainXDisplay, hDisplay, XWinGC, Cx-Rx, Cy-Ry, Rx*2, Ry*2,
  319.                  0, 360*64 );
  320.     #endif
  321.   } // End of DrawEllipse for XWINDRIVER
  322.  
  323. VOID XWINDRIVER::FillEllipse ( HDISPLAY hDisplay, LONG Cx, LONG Cy,
  324.                               LONG Rx, LONG Ry, COLOR Color )
  325.   {
  326.     if (hDisplay)
  327.       {}
  328.     if (Cx&Cy&Rx&Ry)
  329.       {}
  330.     if (Color)
  331.       {}      
  332.     #if defined (__FORUNIX__)      
  333.       XSetForeground ( MainXDisplay, XWinGC, Color );      
  334.       XDrawArc ( MainXDisplay, hDisplay, XWinGC, Cx-Rx, Cy-Ry, Rx*2, Ry*2,
  335.                  0, 360*64 );
  336.     #endif
  337.   } // End of FillEllipse for XWINDRIVER
  338.  
  339.