home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / prbgi097.zip / C.ZIP / GRAPHAPP.CPP < prev    next >
C/C++ Source or Header  |  1992-12-15  |  3KB  |  114 lines

  1. /*-------------------------------------------------------------------*/
  2. /*                                                                   */
  3. /*   Turbo Vision 1.0                                                */
  4. /*   Turbo Vision Demo                                               */
  5. /*   Copyright (c) 1991 by Borland International                     */
  6. /*                                                                   */
  7. /*   BGI support file for use with Turbo Vision BGI (TVBGI) program. */
  8. /*-------------------------------------------------------------------*/
  9.  
  10. #define Uses_TProgram
  11. #include <tv.h>
  12.  
  13. #if !defined( __GRAPHAPP_H )
  14. #include "Graphapp.h"
  15. #endif  // __GRAPHAPP_H
  16.  
  17. #if !defined( __STRING_H )
  18. #include <string.h>
  19. #endif  // __STRING_H
  20.  
  21. #if !defined( __FSTREAM_H )
  22. #include <fstream.h>
  23. #endif  // __FSTREAM_H
  24.  
  25. #if !defined( __STRSTREA_H )
  26. #include <strstrea.h>
  27. #endif  // __STRSTREA_H
  28.  
  29. #if !defined( __IO_H )
  30. #include <io.h>
  31. #endif  // __IO_H
  32.  
  33. #include "BGI2.h"
  34. //Utility functions
  35.  
  36.  
  37.  
  38. typedef void(*function)();
  39.  
  40.  
  41. //------------------------------------------------------------------//
  42. // Init BGI. If loadAtInit is true, try to locate and load driver.  //
  43. // Returns true if LoadAtInit succeeds or is set to False. Does     //
  44. // not "own" bgiPath, but instead is passed a pointer to a string   //
  45. // that is allocated elsewhere. Does not de-allocate bgiPath when   //
  46. // done.                                                            //
  47. //------------------------------------------------------------------//
  48.  
  49. Boolean graphAppInit( int aDriver, int aMode,
  50.             char *aBGIPath, Boolean loadAtInit )
  51. {
  52.     if (aBGIPath != 0)
  53.         bgiPath = aBGIPath;
  54.     driver = aDriver;
  55.     mode = aMode;
  56.     if ( loadAtInit == True )
  57.     {
  58.         if ( driver == 0 )
  59.             detectgraph(&driver, &mode);
  60.         if ( BGI_LoadDriver(driver,aBGIPath)==NULL ) return False;
  61.     }
  62.     if ( driver > 0 )
  63.        return True;
  64.     else
  65.        return False;
  66. }
  67.  
  68. void graphAppDone()
  69. {
  70.     if ( graphActive == True )
  71.         closegraph();
  72.     graphActive = False;
  73.     bgiPath = emptyString;
  74.     driver = DETECT;
  75.     mode = 0;
  76. }
  77.  
  78. void graphicsStop(void);
  79.  
  80. Boolean graphicsStart(void)
  81. {
  82.     if ( graphActive == True )
  83.         return(True);
  84.  
  85.     initgraph( &driver, &mode, bgiPath );
  86.  
  87.     if ( driver < 0 )
  88.         {
  89.         graphicsStop();
  90.         return False;
  91.         }
  92.     else
  93.         graphActive = True;
  94.     return True;
  95. }
  96.  
  97. Boolean graphicsActive(void)
  98. {
  99.     if ( graphActive == True )
  100.         return True;
  101.     else
  102.         return False;
  103. }
  104.  
  105. void graphicsStop(void)
  106. {
  107.     if ( graphActive == True )
  108.         closegraph();
  109.  
  110.     graphActive = False;
  111.     TProgram::application->redraw();
  112. }
  113.  
  114.