home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / wbgi.c < prev    next >
C/C++ Source or Header  |  1991-03-17  |  8KB  |  406 lines

  1. /*! WBGI.C
  2.  *
  3.  *
  4.  *  Interface the windows library routines with TurboC BGI
  5.  *    all calls to the Borland Graphics Interface are made in this module.
  6.  *
  7.  *    walign () -     set the BGI veiwport, activepage, and position
  8.  *            also set cursor status, video-ram pointer, etc.
  9.  *                      to match the current window.
  10.  *
  11.  *    wgrmode ()-    set graphics mode, initialize the BGI routines
  12.  *    wtxmode ()-    shut down the BGI drivers, restore CRT mode = text.
  13.  *    wmovepxpy()-     move current graphics location to winpx,winpy.
  14.  *    wherepxpy()-    get current graphics location, set in px, py.
  15.  *
  16.  * Second half of this routine contains code for microsoft C version
  17.  *
  18.  */
  19.  
  20. #ifdef __TURBOC__
  21.     /* This file contains TURBOC specific graphics library calls 
  22.      * for other compilers, you must generate a functionally equivalent
  23.      * file for all of the routines defined here.
  24.      */
  25.  
  26.  
  27. #include  "wscreen.h"
  28. #include  "wsys.h"
  29.  
  30. #include <graphics.h>   /* Turbo C graphics */
  31.  
  32.  
  33.  
  34. #ifdef TEXTONLY
  35.  
  36.     /* in text only library, never call the graphics drivers 
  37.      * Therefore, provide 'dummy entry points for the linker
  38.      */
  39.  
  40. void      walign      ( int x )       {return;}
  41. void      wgraphmode     ( void )    {return;}
  42. void     wtextmode     ( void )    {return;}
  43. void     wherepxpy     ( void )    {return;}
  44. void     movepxpy      ( void )    {return;}
  45.  
  46. #else         /* graphics version of these functions */
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. void     walign  (int currpage)
  55.     {
  56.     /* This function 'aligns' the graphics driver with the windows settings
  57.      * settings which must be aligned include 
  58.      * activepage  (which page graphics library calls write to)
  59.      * w0-> pixel bounds (winpxmax, winpymax) computed from text-bounds
  60.      * setviewport () sets graphics driver co-ords to current window
  61.      *                  and sets clipping ON
  62.      *current graphics position set to current window pixel position.
  63.       */
  64.     int pl, pt;    /* pixels offsets */
  65.  
  66.  
  67.     if ( wmode == 'T' )
  68.         {
  69.         return;
  70.         }
  71.  
  72.  
  73.     /* tell BGI to start using the current windows page #
  74.      * only if it doesn't match the curretn active page #
  75.      */
  76.     if ( currpage != w0-> winpage )
  77.         {
  78.         setactivepage(w0-> winpage);
  79.         }
  80.     w0-> winpxmax = wpxchar * (w0->winxmax)
  81.              + wpxchar-1;
  82.     w0-> winpymax = wpychar * (w0->winymax)
  83.              + wpychar -1;
  84.  
  85.     pl = wpxchar * w0->winleft ;
  86.     pt = wpychar * w0->wintop  ;
  87.  
  88.     setviewport ( pl , pt, (pl + w0->winpxmax), (pt + w0->winpymax), 1);
  89.  
  90.     wmovepxpy();
  91.  
  92.     return;
  93.     }  /*end of walign for BGI */
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. /* wmovepxpy()
  103.  *     set BGI graphics position to match the position in the current window
  104.  */
  105. void wmovepxpy (void)
  106.     {
  107.     if ( wmode == 'G' )
  108.         {
  109.         moveto ( w0-> winpx, w0-> winpy );
  110.         }
  111.     return;    /* wmovepxpy */
  112.     }
  113.  
  114.  
  115. /* wherepxpy ()
  116.  *    get the current x,y position from the BGI driver. save in WINDOW 
  117.  */
  118. void wherepxpy (void)
  119.     {
  120.     if ( wmode == 'G' )
  121.         {
  122.         w0->winpx = getx ();
  123.         w0->winpy = gety ();
  124.         }
  125.     return;    /* wherepxpy */
  126.     }
  127.  
  128. /* wtextmode()
  129.  *    restore CRT mode to text, shut down BGI
  130.  */
  131. void wtextmode (void)
  132.     {
  133.     if ( wmode == 'G' )
  134.         {
  135.         restorecrtmode();
  136.         closegraph();
  137.         }
  138.     return;    /* wtextmdoe() */
  139.     }
  140.  
  141.  
  142. static char errmsg[] = "Graphics initializing error #= check DOS ERRORLEVEL";
  143.  
  144.  
  145. /* wgraphmode()
  146.  *    initialize BGI to appropriate graphics mode
  147.  *  initialize screen size globals 
  148.  *  setup mouse to page 0 in hercules mode.
  149.  */
  150. void wgraphmode (void)
  151.     {
  152.     int BGImode, BGIdriver, n;
  153.  
  154.  
  155.  
  156.     switch (wmonitor)
  157.         {
  158.     case    ('V'):
  159.         BGIdriver = VGA;
  160.         if ( wneedpage )
  161.             {
  162.             /* video mode 0x10 */
  163.             BGImode = VGAMED;    /* 640*350, 2 pages*/
  164.             wlastpage = 1;
  165.             }
  166.         else
  167.             {
  168.             /* video mode 0x12 */
  169.             BGImode = VGAHI;    /* 640*480 */
  170.             wlastpage =0;
  171.             }
  172.             break;
  173.  
  174.     case     ('E'):
  175.         BGIdriver = EGA;
  176.         /* video mode 0x10 */
  177.         BGImode   = EGAHI;        /* 640 * 350 */
  178.         wlastpage = wega256 ? 1 : 0;     /*need 256k to page*/
  179.         break;
  180.  
  181.     case     ('H'):
  182.         BGIdriver   = HERCMONO;
  183.         BGImode     = HERCMONOHI;
  184.  
  185.         /* tell the mouse driver that we're starting on page 0
  186.          * ( This is important for Microsoft mouse but not Logitech.)
  187.          *    see the Microsoft mouse book ---
  188.          *    (or see notes in file wmouse.c)
  189.          */
  190.         *( HERC_ROM_VIDMODE_AREA ) = 6;
  191.  
  192.         wlastpage   =1;
  193.         break;
  194.  
  195.     default:
  196.         werror ('W', "UNSUPPORTED MONITOR");
  197.  
  198.         }    /* end switch on monitor */
  199.  
  200.  
  201.  
  202.  
  203.     initgraph ( &BGIdriver, &BGImode, wpath_BGI );
  204.     if ( grOk != (n=graphresult() ) )
  205.         {
  206.         werror (n, errmsg);
  207.         }
  208.     wpxabsmax = getmaxx ();
  209.     wxabsmax  = ((wpxabsmax +1) / wpxchar) -1;
  210.     wpyabsmax = getmaxy ();
  211.     wyabsmax  = ((wpyabsmax +1) / wpychar) -1;
  212.  
  213.  
  214.     return;    /*wgraphmode */
  215.     }
  216.  
  217.  
  218.  
  219. #endif     /* end graphics version */
  220.  
  221. #else    
  222.     /*---------------------- Microsoft C version ----------------------*/
  223.  
  224. #include <stdlib.h>
  225. #include <graph.h>
  226. #include <dos.h>
  227.  
  228. #include "wscreen.h"
  229. #include "wsys.h"
  230.  
  231. void    walign          ( int currpage )
  232.     {
  233.     /* This function 'aligns' the graphics driver with the windows settings
  234.      * settings which must be aligned include:
  235.      * activepage  (which page graphics library calls write to)
  236.      * w0-> pixel bounds (winpxmax, winpymax) computed from text-bounds
  237.      * setviewport () sets graphics driver co-ords to current window
  238.      *                               and sets clipping ON
  239.      *current graphics position set to current window pixel position.
  240.      */
  241.     int pl, pt;     /* pixels offsets */
  242.  
  243.  
  244.     if ( wmode == 'T' )
  245.         {
  246.         return;
  247.         }
  248.  
  249.  
  250.     /* tell MSC to start using the current windows page #
  251.      * only if it doesn't match the curretn active page #
  252.      */
  253.     if ( currpage != w0-> winpage )
  254.         {
  255.         _setactivepage(w0-> winpage);
  256.         }
  257.     w0-> winpxmax = wpxchar * (w0->winxmax)
  258.              + wpxchar-1;
  259.     w0-> winpymax = wpychar * (w0->winymax)
  260.              + wpychar -1;
  261.  
  262.     pl = wpxchar * w0->winleft ;
  263.     pt = wpychar * w0->wintop  ;
  264.  
  265.     _setviewport ( pl , pt, (pl + w0->winpxmax), (pt + w0->winpymax));
  266.  
  267.  
  268.     wmovepxpy();
  269.  
  270.     
  271.     
  272.     return;        /* walign, microsoft */
  273.     }
  274.  
  275.  
  276. /* wmovepxpy()
  277.  *      set MSC graphics position to match position in the current window
  278.  */
  279. void wmovepxpy (void)
  280.     {
  281.     if ( wmode == 'G' )
  282.         {
  283.         _moveto ( w0-> winpx, w0-> winpy );
  284.         }
  285.     return; /* wmovepxpy */
  286.     }
  287.  
  288.  
  289. /* wherepxpy ()
  290.  *      get the current x,y position from the driver. save in WINDOW
  291.  */
  292. void wherepxpy (void)
  293.     {
  294.     struct xycoord  xy;
  295.     if ( wmode == 'G' )
  296.         {
  297.         xy = _getcurrentposition();
  298.         w0->winpx = xy.xcoord;
  299.         w0->winpy = xy.ycoord;
  300.         }
  301.     return; /* wherepxpy, microsoft */
  302.     }
  303.  
  304. /* wtextmode()
  305.  *      restore CRT mode to text, shut down BGI
  306.  */
  307. void wtextmode (void)
  308.     {
  309.     short  vidmode;
  310.     if ( wmode == 'G' )
  311.         {
  312.         _setvideomode ( _DEFAULTMODE );
  313.         }
  314.     return; /* wtextmode, microsoft */
  315.     }
  316.  
  317.  
  318. static char errmsg[] = "Graphics initializing error #= check DOS ERRORLEVEL";
  319.  
  320.  
  321. /* wgraphmode()
  322.  *      initialize MSC to appropriate graphics mode
  323.  *  initialize screen size globals
  324.  *  setup mouse to page 0 in hercules mode.
  325.  */
  326. void wgraphmode (void)
  327.     {
  328.     short vidmode;
  329.     int  n;
  330.  
  331.     int maxx, maxy;
  332.  
  333.  
  334.     switch (wmonitor)
  335.         {
  336.     case    ('V'):
  337.         vidmode   = _VRES16COLOR;
  338.         maxx = 640;
  339.         maxy = 480;
  340.         if ( wneedpage )
  341.             {
  342.             /* video mode 0x10 */
  343.             vidmode = _ERESCOLOR;         /* 640 x 350 */
  344.             maxy = 350;
  345.             wlastpage = 1;
  346.             }
  347.         else
  348.             {
  349.             /* video mode 0x12 */
  350.             wlastpage =0;
  351.             }
  352.             break;
  353.  
  354.     case    ('E'):
  355.         vidmode = _HRES16COLOR;         /* 640 x 350 */
  356.         /* video mode 0x10 */
  357.         wlastpage = wega256 ? 1 : 0;    /*need 256k to page*/
  358.         maxx = 640;
  359.         maxy = 350;
  360.         break;
  361.  
  362.     case    ('H'):
  363.         vidmode    = _HERCMONO;
  364.         maxx = 720;
  365.         maxy = 348;
  366.  
  367.         /* tell the mouse driver that we're starting on page 0
  368.          * ( This is important for Microsoft mouse but not Logitech.)
  369.          *      see the Microsoft mouse book ---
  370.          *      (or see notes in file wmouse.c)
  371.          */
  372.         *( HERC_ROM_VIDMODE_AREA ) = 6;
  373.  
  374.         wlastpage   =1;
  375.         break;
  376.  
  377.     default:
  378.         werror ('W', "UNSUPPORTED MONITOR");
  379.  
  380.         }       /* end switch on monitor */
  381.  
  382.  
  383.  
  384.  
  385.     n = _setvideomode ( vidmode );
  386.     if ( n == 0 )
  387.         {
  388.         werror (n, "Error initializing graphics" );
  389.         }
  390.     wpxabsmax = maxx;
  391.     wxabsmax  = ((wpxabsmax +1) / wpxchar) -1;
  392.     wpyabsmax = maxy;
  393.     wyabsmax  = ((wpyabsmax +1) / wpychar) -1;
  394.  
  395.  
  396.     return; /*wgraphmode, microsoft */
  397.     }
  398.  
  399.  
  400.  
  401.  
  402.  
  403. #endif  /* end if not TURBOC...Microsoft */
  404.  
  405. /*--------------------- end of WBGI.C ---------------------*/
  406.