Mlack

graphics.h

Apr 13th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.57 KB | None | 0 0
  1. // The winbgim library, Version 6.0, August 9, 2004
  2. // Written by:
  3. //      Grant Macklem (Grant.Macklem@colorado.edu)
  4. //      Gregory Schmelter (Gregory.Schmelter@colorado.edu)
  5. //      Alan Schmidt (Alan.Schmidt@colorado.edu)
  6. //      Ivan Stashak (Ivan.Stashak@colorado.edu)
  7. //      Michael Main (Michael.Main@colorado.edu)
  8. // CSCI 4830/7818: API Programming
  9. // University of Colorado at Boulder, Spring 2003
  10.  
  11.  
  12. // ---------------------------------------------------------------------------
  13. //                          Notes
  14. // ---------------------------------------------------------------------------
  15. // * This library is still under development.
  16. // * Please see http://www.cs.colorado.edu/~main/bgi for information on
  17. // * using this library with the mingw32 g++ compiler.
  18. // * This library only works with Windows API level 4.0 and higher (Windows 95, NT 4.0 and newer)
  19. // * This library may not be compatible with 64-bit versions of Windows
  20. // ---------------------------------------------------------------------------
  21.  
  22.  
  23. // ---------------------------------------------------------------------------
  24. //                          Macro Guard and Include Directives
  25. // ---------------------------------------------------------------------------
  26. #ifndef WINBGI_H
  27. #define WINBGI_H
  28. #include <windows.h>        // Provides the mouse message types
  29. #include <limits.h>         // Provides INT_MAX
  30. #include <sstream>          // Provides std::ostringstream
  31. // ---------------------------------------------------------------------------
  32.  
  33.  
  34.  
  35. // ---------------------------------------------------------------------------
  36. //                          Definitions
  37. // ---------------------------------------------------------------------------
  38. // Definitions for the key pad extended keys are added here.  When one
  39. // of these keys are pressed, getch will return a zero followed by one
  40. // of these values. This is the same way that it works in conio for
  41. // dos applications.
  42. #define KEY_HOME        71
  43. #define KEY_UP          72
  44. #define KEY_PGUP        73
  45. #define KEY_LEFT        75
  46. #define KEY_CENTER      76
  47. #define KEY_RIGHT       77
  48. #define KEY_END         79
  49. #define KEY_DOWN        80
  50. #define KEY_PGDN        81
  51. #define KEY_INSERT      82
  52. #define KEY_DELETE      83
  53. #define KEY_F1          59
  54. #define KEY_F2          60
  55. #define KEY_F3          61
  56. #define KEY_F4          62
  57. #define KEY_F5          63
  58. #define KEY_F6          64
  59. #define KEY_F7          65
  60. #define KEY_F8          66
  61. #define KEY_F9          67
  62.  
  63. // Line thickness settings
  64. #define NORM_WIDTH      1
  65. #define THICK_WIDTH     3
  66.  
  67. // Character Size and Direction
  68. #define USER_CHAR_SIZE  0
  69. #define HORIZ_DIR       0
  70. #define VERT_DIR        1
  71.  
  72.  
  73. // Constants for closegraph
  74. #define CURRENT_WINDOW -1
  75. #define ALL_WINDOWS -2
  76. #define NO_CURRENT_WINDOW -3
  77.  
  78. // The standard Borland 16 colors
  79. #define MAXCOLORS       15
  80. enum colors { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY,
  81.               LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE };
  82.  
  83. // The standard line styles
  84. enum line_styles { SOLID_LINE, DOTTED_LINE, CENTER_LINE, DASHED_LINE, USERBIT_LINE };
  85.  
  86. // The standard fill styles
  87. enum fill_styles { EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL,
  88.                    BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, INTERLEAVE_FILL,
  89.                    WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL };
  90.  
  91. // The various graphics drivers
  92. enum graphics_drivers { DETECT, CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, HERCMONO,
  93.                         ATT400, VGA, PC3270 };
  94.  
  95. // Various modes for each graphics driver
  96. enum graphics_modes { CGAC0, CGAC1, CGAC2, CGAC3, CGAHI,
  97.                       MCGAC0 = 0, MCGAC1, MCGAC2, MCGAC3, MCGAMED, MCGAHI,
  98.                       EGALO = 0, EGAHI,
  99.                       EGA64LO = 0, EGA64HI,
  100.                       EGAMONOHI = 3,
  101.                       HERCMONOHI = 0,
  102.                       ATT400C0 = 0, ATT400C1, ATT400C2, ATT400C3, ATT400MED, ATT400HI,
  103.                       VGALO = 0, VGAMED, VGAHI,
  104.                       PC3270HI = 0,
  105.                       IBM8514LO = 0, IBM8514HI };
  106.  
  107. // Borland error messages for the graphics window.
  108. #define NO_CLICK        -1      // No mouse event of the current type in getmouseclick
  109. enum graph_errors { grInvalidVersion = -18, grInvalidDeviceNum = -15, grInvalidFontNum,
  110.                     grInvalidFont, grIOerror, grError, grInvalidMode, grNoFontMem,
  111.                     grFontNotFound, grNoFloodMem, grNoScanMem, grNoLoadMem,
  112.                     grInvalidDriver, grFileNotFound, grNotDetected, grNoInitGraph,
  113.                     grOk };
  114.  
  115. // Write modes
  116. enum putimage_ops{ COPY_PUT, XOR_PUT, OR_PUT, AND_PUT, NOT_PUT };
  117.  
  118. // Text Modes
  119. enum horiz { LEFT_TEXT, CENTER_TEXT, RIGHT_TEXT };
  120. enum vertical { BOTTOM_TEXT, VCENTER_TEXT, TOP_TEXT }; // middle not needed other than as seperator
  121. enum font_names { DEFAULT_FONT, TRIPLEX_FONT, SMALL_FONT, SANS_SERIF_FONT,
  122.              GOTHIC_FONT, SCRIPT_FONT, SIMPLEX_FONT, TRIPLEX_SCR_FONT,
  123.              COMPLEX_FONT, EUROPEAN_FONT, BOLD_FONT };
  124. // ---------------------------------------------------------------------------
  125.  
  126.  
  127.  
  128. // ---------------------------------------------------------------------------
  129. //                              Structures
  130. // ---------------------------------------------------------------------------
  131. // This structure records information about the last call to arc.  It is used
  132. // by getarccoords to get the location of the endpoints of the arc.
  133. struct arccoordstype
  134. {
  135.     int x, y;                   // Center point of the arc
  136.     int xstart, ystart;         // The starting position of the arc
  137.     int xend, yend;             // The ending position of the arc.
  138. };
  139.  
  140.  
  141. // This structure defines the fill style for the current window.  Pattern is
  142. // one of the system patterns such as SOLID_FILL.  Color is the color to
  143. // fill with
  144. struct fillsettingstype
  145. {
  146.     int pattern;                // Current fill pattern
  147.     int color;                  // Current fill color
  148. };
  149.  
  150.  
  151. // This structure records information about the current line style.
  152. // linestyle is one of the line styles such as SOLID_LINE, upattern is a
  153. // 16-bit pattern for user defined lines, and thickness is the width of the
  154. // line in pixels.
  155. struct linesettingstype
  156. {
  157.     int linestyle;              // Current line style
  158.     unsigned upattern;          // 16-bit user line pattern
  159.     int thickness;              // Width of the line in pixels
  160. };
  161.  
  162.  
  163. // This structure records information about the text settings.
  164. struct textsettingstype
  165. {
  166.     int font;                   // The font in use
  167.     int direction;              // Text direction
  168.     int charsize;               // Character size
  169.     int horiz;                  // Horizontal text justification
  170.     int vert;                   // Vertical text justification
  171. };
  172.  
  173.  
  174. // This structure records information about the viewport
  175. struct viewporttype
  176. {
  177.     int left, top,              // Viewport bounding box
  178.         right, bottom;
  179.     int clip;                   // Whether to clip image to viewport
  180. };
  181.  
  182.  
  183. // This structure records information about the palette.
  184. struct palettetype
  185. {
  186.     unsigned char size;
  187.     signed char colors[MAXCOLORS + 1];
  188. };
  189. // ---------------------------------------------------------------------------
  190.  
  191.  
  192.  
  193. // ---------------------------------------------------------------------------
  194. //                          API Entries
  195. // ---------------------------------------------------------------------------
  196. #ifdef __cplusplus
  197. extern "C" {
  198. #endif
  199.  
  200. // Drawing Functions
  201. void arc( int x, int y, int stangle, int endangle, int radius );
  202. void bar( int left, int top, int right, int bottom );
  203. void bar3d( int left, int top, int right, int bottom, int depth, int topflag );
  204. void circle( int x, int y, int radius );
  205. void cleardevice( );
  206. void clearviewport( );
  207. void drawpoly(int n_points, int* points);
  208. void ellipse( int x, int y, int stangle, int endangle, int xradius, int yradius );
  209. void fillellipse( int x, int y, int xradius, int yradius );
  210. void fillpoly(int n_points, int* points);
  211. void floodfill( int x, int y, int border );
  212. void line( int x1, int y1, int x2, int y2 );
  213. void linerel( int dx, int dy );
  214. void lineto( int x, int y );
  215. void pieslice( int x, int y, int stangle, int endangle, int radius );
  216. void putpixel( int x, int y, int color );
  217. void rectangle( int left, int top, int right, int bottom );
  218. void sector( int x, int y, int stangle, int endangle, int xradius, int yradius );
  219.  
  220. // Miscellaneous Functions
  221. int getdisplaycolor( int color );
  222. int converttorgb( int color );
  223. void delay( int msec );
  224. void getarccoords( arccoordstype *arccoords );
  225. int getbkcolor( );
  226. int getcolor( );
  227. void getfillpattern( char *pattern );
  228. void getfillsettings( fillsettingstype *fillinfo );
  229. void getlinesettings( linesettingstype *lineinfo );
  230. int getmaxcolor( );
  231. int getmaxheight( );
  232. int getmaxwidth( );
  233. int getmaxx( );
  234. int getmaxy( );
  235. bool getrefreshingbgi( );
  236. int getwindowheight( );
  237. int getwindowwidth( );
  238. int getpixel( int x, int y );
  239. void getviewsettings( viewporttype *viewport );
  240. int getx( );
  241. int gety( );
  242. void moverel( int dx, int dy );
  243. void moveto( int x, int y );
  244. void refreshbgi(int left, int top, int right, int bottom);
  245. void refreshallbgi( );    
  246. void setbkcolor( int color );
  247. void setcolor( int color );
  248. void setfillpattern( char *upattern, int color );
  249. void setfillstyle( int pattern, int color );
  250. void setlinestyle( int linestyle, unsigned upattern, int thickness );
  251. void setrefreshingbgi(bool value);
  252. void setviewport( int left, int top, int right, int bottom, int clip );
  253. void setwritemode( int mode );
  254.  
  255. // Window Creation / Graphics Manipulation
  256. void closegraph( int wid=ALL_WINDOWS );
  257. void detectgraph( int *graphdriver, int *graphmode );
  258. void getaspectratio( int *xasp, int *yasp );
  259. char *getdrivername( );
  260. int getgraphmode( );
  261. int getmaxmode( );
  262. char *getmodename( int mode_number );
  263. void getmoderange( int graphdriver, int *lomode, int *himode );
  264. void graphdefaults( );
  265. char *grapherrormsg( int errorcode );
  266. int graphresult( );
  267. void initgraph( int *graphdriver, int *graphmode, char *pathtodriver );
  268. int initwindow
  269.     ( int width, int height, const char* title="Windows BGI", int left=0, int top=0, bool dbflag=false, bool closeflag=true );
  270. int installuserdriver( char *name, int *fp );    // Not available in WinBGI
  271. int installuserfont( char *name );               // Not available in WinBGI
  272. int registerbgidriver( void *driver );           // Not available in WinBGI
  273. int registerbgifont( void *font );               // Not available in WinBGI
  274. void restorecrtmode( );
  275. void setaspectratio( int xasp, int yasp );
  276. unsigned setgraphbufsize( unsigned bufsize );    // Not available in WinBGI
  277. void setgraphmode( int mode );
  278. void showerrorbox( const char *msg = NULL );
  279.  
  280. // User Interaction
  281. int getch( );
  282. int kbhit( );
  283.  
  284. // User-Controlled Window Functions (winbgi.cpp)
  285. int getcurrentwindow( );
  286. void setcurrentwindow( int window );
  287.    
  288. // Double buffering support (winbgi.cpp)
  289. int getactivepage( );
  290. int getvisualpage( );
  291. void setactivepage( int page );
  292. void setvisualpage( int page );
  293. void swapbuffers( );
  294.  
  295. // Image Functions (drawing.cpp)
  296. unsigned imagesize( int left, int top, int right, int bottom );
  297. void getimage( int left, int top, int right, int bottom, void *bitmap );
  298. void putimage( int left, int top, void *bitmap, int op );
  299. void printimage(
  300.     const char* title=NULL,
  301.     double width_inches=7, double border_left_inches=0.75, double border_top_inches=0.75,
  302.     int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX,
  303.     bool active=true, HWND hwnd=NULL
  304.     );
  305. void readimagefile(
  306.     const char* filename=NULL,
  307.     int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX
  308.     );
  309. void writeimagefile(
  310.     const char* filename=NULL,
  311.     int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
  312.     bool active=true, HWND hwnd=NULL
  313.     );
  314.  
  315. // Text Functions (text.cpp)
  316. void gettextsettings(struct textsettingstype *texttypeinfo);
  317. void outtext(char *textstring);
  318. void outtextxy(int x, int y, char *textstring);
  319. void settextjustify(int horiz, int vert);
  320. void settextstyle(int font, int direction, int charsize);
  321. void setusercharsize(int multx, int divx, int multy, int divy);
  322. int textheight(char *textstring);
  323. int textwidth(char *textstring);
  324. extern std::ostringstream bgiout;    
  325. void outstream(std::ostringstream& out=bgiout);
  326. void outstreamxy(int x, int y, std::ostringstream& out=bgiout);    
  327.    
  328. // Mouse Functions (mouse.cpp)
  329. void clearmouseclick( int kind );
  330. void clearresizeevent( );
  331. void getmouseclick( int kind, int& x, int& y );
  332. bool ismouseclick( int kind );
  333. bool isresizeevent( );
  334. int mousex( );
  335. int mousey( );
  336. void registermousehandler( int kind, void h( int, int ) );
  337. void setmousequeuestatus( int kind, bool status=true );
  338.  
  339. // Palette Functions
  340. palettetype *getdefaultpalette( );
  341. void getpalette( palettetype *palette );
  342. int getpalettesize( );
  343. void setallpalette( palettetype *palette );
  344. void setpalette( int colornum, int color );
  345. void setrgbpalette( int colornum, int red, int green, int blue );
  346.  
  347. // Color Macros
  348. #define IS_BGI_COLOR(v)     ( ((v) >= 0) && ((v) < 16) )
  349. #define IS_RGB_COLOR(v)     ( (v) & 0x03000000 )
  350. #define RED_VALUE(v)        int(GetRValue( converttorgb(v) ))
  351. #define GREEN_VALUE(v)      int(GetGValue( converttorgb(v) ))
  352. #define BLUE_VALUE(v)       int(GetBValue( converttorgb(v) ))
  353. #undef COLOR
  354. int COLOR(int r, int g, int b); // No longer a macro
  355.  
  356. #ifdef __cplusplus
  357. }
  358. #endif
  359. // ---------------------------------------------------------------------------
  360.  
  361. #endif // WINBGI_H
Add Comment
Please, Sign In to add comment