Quelltext /~heha/hs/graphwin.zip/graphwin.h

/* graphwin.h -- Borland graphics.h replacement for Windows
 *
 * haftmann#software FREEWARE 12/02
 * This file is under development and may work or not. Tested with Windows XP
 * Requires Borland C++ 3.1, 4.0 or 4.5 to compile happily!
 *
 : You should modify your #include <graphics.h> to
 :
 : #ifdef _Windows
 : # include "graphwin.h"
 : #else
 : # include <graphics.h>
 : #endif
 :
 : and without*) any further changes your program will compile both
 : for DOS and Windows.
 : (But you should disable the linker warning: "warn duplicate symbols".)
 : *) You should insert some calls to yield() when you make lengthy
 :    calculations, printing jobs etc. to keep Windows alive meanwhile.
 :    See hint below for mouse access. There is no general solution.
 *
 * Why you may want to switch to Windows using graphwin.h?
 * + You tried Borland's EASYWIN library, but it is not graphical
 * + Same try, but you have no access to cursor and function keys 
 * + You have much more, easy addressable memory in Windows (=DPMI)
 * - Your screen does flicker in DOS (56 Hz)
 * + Your program is able to run in a window (and you hate monitor blackouts)
 * + You want to stay at the OEM (DOS) character set (technical symbols etc.)
 * + You can move step-by-step to a true Windows application,
 *   most programmers may replace their self-made file open/save hassle
 *   by GetOpenFileName() / GetSaveFileName() at next - and don't forget to
 *   #define OFN_LONGNAMES 0x200000
 *   and some extra OemToAnsi() / AnsiToOem() calls with its struct!
 *
 * Hint:
 * Mouse access routines must be changed from Int33 to Windows
 * GetCursorPos() and GetKeyState() functions! The good news:
 * You don't need functions like MouseShow() and MouseHide() anymore.
 *
 * Known Bugs:
 * Almost everywhere are bugs: This library is simply NOT THROUGHOUTLY TESTED
 * Drawing functions seem to be bug-free with some differences in appearance,
 * but some seldom used functions like restorecrtmode() may not work at all.
 */
#ifndef _Windows
#error graphwin.h is for Windows
#endif
#include <windows.h>

#ifndef __GRAPHWIN.H
#define __GRAPHWIN.H

enum graphics_errors {      /* graphresult error return codes */
 grOk		=  0,
 grNoInitGraph	= -1,
 grNotDetected	= -2,
 grFileNotFound	= -3,
 grInvalidDriver= -4,
 grNoLoadMem	= -5,
 grNoScanMem	= -6,
 grNoFloodMem	= -7,
 grFontNotFound	= -8,
 grNoFontMem	= -9,
 grInvalidMode	=-10,
 grError	=-11,   /* generic error */
 grIOerror	=-12,
 grInvalidFont	=-13,
 grInvalidFontNum=-14,
 grInvalidVersion=-18
};

enum graphics_drivers {     /* define graphics drivers */
 DETECT,         /* requests autodetection */
 CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514,    /* 1 - 6 */
 HERCMONO, ATT400, VGA, PC3270,          /* 7 - 10 */
 UNIVERSAL,				/* 11 */
 CURRENT_DRIVER = -1
};

enum graphics_modes {       /* graphics modes for each driver */
 CGAC0      = 0,  /* 320x200 palette 0; 1 page   */
 CGAC1      = 1,  /* 320x200 palette 1; 1 page   */
 CGAC2      = 2,  /* 320x200 palette 2: 1 page   */
 CGAC3      = 3,  /* 320x200 palette 3; 1 page   */
 CGAHI      = 4,  /* 640x200 1 page          */
 MCGAC0     = 0,  /* 320x200 palette 0; 1 page   */
 MCGAC1     = 1,  /* 320x200 palette 1; 1 page   */
 MCGAC2     = 2,  /* 320x200 palette 2; 1 page   */
 MCGAC3     = 3,  /* 320x200 palette 3; 1 page   */
 MCGAMED    = 4,  /* 640x200 1 page          */
 MCGAHI     = 5,  /* 640x480 1 page          */
 EGALO      = 0,  /* 640x200 16 color 4 pages    */
 EGAHI      = 1,  /* 640x350 16 color 2 pages    */
 EGA64LO    = 0,  /* 640x200 16 color 1 page     */
 EGA64HI    = 1,  /* 640x350 4 color  1 page     */
 EGAMONOHI  = 0,  /* 640x350 64K on card, 1 page - 256K on card, 4 pages */
 HERCMONOHI = 0,  /* 720x348 2 pages         */
 ATT400C0   = 0,  /* 320x200 palette 0; 1 page   */
 ATT400C1   = 1,  /* 320x200 palette 1; 1 page   */
 ATT400C2   = 2,  /* 320x200 palette 2; 1 page   */
 ATT400C3   = 3,  /* 320x200 palette 3; 1 page   */
 ATT400MED  = 4,  /* 640x200 1 page          */
 ATT400HI   = 5,  /* 640x400 1 page          */
 VGALO      = 0,  /* 640x200 16 color 4 pages    */
 VGAMED     = 1,  /* 640x350 16 color 2 pages    */
 VGAHI      = 2,  /* 640x480 16 color 1 page     */
 PC3270HI   = 0,  /* 720x350 1 page          */
 IBM8514LO  = 0,  /* 640x480 256 colors      */
 IBM8514HI  = 1   /*1024x768 256 colors      */
};

/* Colors for setpalette and setallpalette */

#if !defined(__COLORS)
#define __COLORS

enum COLORS {
 BLACK,		/* dark colors */
 BLUE,
 GREEN,
 CYAN,
 RED,
 MAGENTA,
 BROWN,
 LIGHTGRAY,
 DARKGRAY,	/* light colors */
 LIGHTBLUE,
 LIGHTGREEN,
 LIGHTCYAN,
 LIGHTRED,
 LIGHTMAGENTA,
 YELLOW,
 WHITE
};
#endif

enum CGA_COLORS {
 CGA_LIGHTGREEN     = 1,     /* Palette C0 Color Names   */
 CGA_LIGHTRED       = 2,
 CGA_YELLOW         = 3,

 CGA_LIGHTCYAN      = 1,     /* Palette C1 Color Names   */
 CGA_LIGHTMAGENTA   = 2,
 CGA_WHITE          = 3,

 CGA_GREEN          = 1,     /* Palette C2 Color Names   */
 CGA_RED	    = 2,
 CGA_BROWN          = 3,

 CGA_CYAN           = 1,     /* Palette C3 Color Names   */
 CGA_MAGENTA        = 2,
 CGA_LIGHTGRAY      = 3
};


enum EGA_COLORS {
 EGA_BLACK        =  0,      /* dark colors */
 EGA_BLUE         =  1,
 EGA_GREEN        =  2,
 EGA_CYAN         =  3,
 EGA_RED          =  4,
 EGA_MAGENTA      =  5,
 EGA_BROWN        =  20,
 EGA_LIGHTGRAY    =  7,
 EGA_DARKGRAY     =  56,     /* light colors */
 EGA_LIGHTBLUE    =  57,
 EGA_LIGHTGREEN   =  58,
 EGA_LIGHTCYAN    =  59,
 EGA_LIGHTRED     =  60,
 EGA_LIGHTMAGENTA     =  61,
 EGA_YELLOW       =  62,
 EGA_WHITE        =  63
};

enum line_styles {      /* Line styles for get/setlinestyle */
 SOLID_LINE   = 0,
 DOTTED_LINE  = 1,
 CENTER_LINE  = 2,
 DASHED_LINE  = 3,
 USERBIT_LINE = 4,   /* User defined line style */
};

enum line_widths {      /* Line widths for get/setlinestyle */
 NORM_WIDTH  = 1,
 THICK_WIDTH = 3,
};

enum font_names {
 DEFAULT_FONT    = 0,    /* 8x8 bit mapped font */
 TRIPLEX_FONT    = 1,    /* "Stroked" fonts */
 SMALL_FONT  = 2,
 SANS_SERIF_FONT = 3,
 GOTHIC_FONT = 4,
 SCRIPT_FONT = 5,
 SIMPLEX_FONT = 6,
 TRIPLEX_SCR_FONT = 7,
 COMPLEX_FONT = 8,
 EUROPEAN_FONT = 9,
 BOLD_FONT = 10
};

#define HORIZ_DIR   0   /* left to right */
#define VERT_DIR    1   /* bottom to top */

#define USER_CHAR_SIZE  0   /* user-defined char size */

enum fill_patterns {        /* Fill patterns for get/setfillstyle */
 EMPTY_FILL,     /* fills area in background color */
 SOLID_FILL,     /* fills area in solid fill color */
 LINE_FILL,      /* --- fill */
 LTSLASH_FILL,       /* /// fill */
 SLASH_FILL,     /* /// fill with thick lines */
 BKSLASH_FILL,       /* \\\ fill with thick lines */
 LTBKSLASH_FILL,     /* \\\ fill */
 HATCH_FILL,     /* light hatch fill */
 XHATCH_FILL,        /* heavy cross hatch fill */
 INTERLEAVE_FILL,    /* interleaving line fill */
 WIDE_DOT_FILL,      /* Widely spaced dot fill */
 CLOSE_DOT_FILL,     /* Closely spaced dot fill */
 USER_FILL       /* user defined fill */
};

enum putimage_ops {     /* BitBlt operators for putimage */
 COPY_PUT,       /* MOV */
 XOR_PUT,        /* XOR */
 OR_PUT,         /* OR  */
 AND_PUT,        /* AND */
 NOT_PUT         /* NOT */
};

enum text_just {        /* Horizontal and vertical justification
                   for settextjustify */
 LEFT_TEXT   = 0,
 CENTER_TEXT = 1,
 RIGHT_TEXT  = 2,

 BOTTOM_TEXT = 0,
  /* CENTER_TEXT = 1,  already defined above */
 TOP_TEXT    = 2
};


#define MAXCOLORS 15

struct palettetype {
 unsigned char size;
 signed char colors[MAXCOLORS+1];
};

struct linesettingstype {
 int linestyle;
 unsigned upattern;
 int thickness;
};

struct textsettingstype {
 int font;
 int direction;
 int charsize;
 int horiz;
 int vert;
};

struct fillsettingstype {
 int pattern;
 int color;
};

struct pointtype {
 int x, y;
};

struct viewporttype {
 int left, top, right, bottom;
 int clip;
};

struct arccoordstype {
 int x, y;
 int xstart, ystart, xend, yend;
};

#ifdef __cplusplus
extern "C" {
#endif
void far _cdecl arc(int x,int y,int stangle,int endangle,int radius);
void far _cdecl bar(int left,int top,int right,int bottom);
void far _cdecl bar3d(int left,int top,int right,int bottom,int depth,int topflag);
void far _cdecl circle(int x,int y,int radius);
void far _cdecl cleardevice(void);
void far _cdecl clearviewport(void);
void far _cdecl closegraph(void);
void far _cdecl detectgraph(int far*graphdriver,int far*graphmode);
void far _cdecl drawpoly(int numpoints,const int far*polypoints);
void far _cdecl ellipse(int x,int y,int stangle,int endangle,int xradius,int yradius);
void far _cdecl fillellipse(int x,int y,int xradius,int yradius );
void far _cdecl fillpoly(int numpoints,const int far*polypoints);
void far _cdecl floodfill(int x,int y,int border);
void far _cdecl getarccoords(struct arccoordstype far*arccoords);
void far _cdecl getaspectratio(int far*xasp,int far*yasp);
int  far _cdecl getbkcolor(void);
int  far _cdecl getcolor(void);
struct palettetype far* far _cdecl getdefaultpalette(void);
char*far _cdecl getdrivername(void);
void far _cdecl getfillpattern(char far*pattern);
void far _cdecl getfillsettings(struct fillsettingstype far*fillinfo);
int  far _cdecl getgraphmode(void);
void far _cdecl getimage(int left,int top,int right,int bottom,void far*bitmap);
void far _cdecl getlinesettings(struct linesettingstype far*lineinfo);
int  far _cdecl getmaxcolor(void);
int  far _cdecl getmaxmode(void);
int  far _cdecl getmaxx(void);
int  far _cdecl getmaxy(void);
char*far _cdecl getmodename(int mode_number);
void far _cdecl getmoderange(int graphdriver,int far*lomode,int far*himode);
unsigned   far _cdecl getpixel(int x,int y);
void far _cdecl getpalette(struct palettetype far*palette);
int  far _cdecl getpalettesize( void );
void far _cdecl gettextsettings(struct textsettingstype far*texttypeinfo);
void far _cdecl getviewsettings(struct viewporttype far*viewport);
int  far _cdecl getx(void);
int  far _cdecl gety(void);
void far _cdecl graphdefaults(void);
char*far _cdecl grapherrormsg(int errorcode);
int  far _cdecl graphresult(void);
#define imagesize(left,top,right,bottom) 6
void far _cdecl initgraph(int far*graphdriver,int far*graphmode,const char far*pathtodriver);
void far pascal initgraph2(int x, int y, int z, int c);	//new: free X and Y ranges
#define installuserdriver(name,detect) _ret(9)
#define installuserfont(name) _ret(5)
void far _cdecl line(int x1,int y1,int x2,int y2);
void far _cdecl linerel(int dx,int dy);
void far _cdecl lineto(int x,int y);
void far _cdecl moverel(int dx,int dy);
void far _cdecl moveto(int x,int y);
void far _cdecl outtext(const char far*textstring);
void far _cdecl outtextxy(int x,int y,const char far*textstring);
void far _cdecl pieslice(int x,int y,int stangle,int endangle,int radius);
void far _cdecl putimage(int left,int top,const void far*bitmap,int op);
void far _cdecl putpixel(int x,int y,int color);
void far _cdecl rectangle(int left,int top,int right,int bottom);
void far _cdecl restorecrtmode(void);
void far _cdecl sector(int X,int Y,int StAngle,int EndAngle,int XRadius,int YRadius);
void far _cdecl setactivepage(int page);
void far _cdecl setallpalette(const struct palettetype far*palette);
void far _cdecl setaspectratio( int xasp,int yasp );
void far _cdecl setbkcolor(int color);
void far _cdecl setcolor(int color);
void far _cdecl setfillpattern(const char far*upattern,int color);
void far _cdecl setfillstyle(int pattern,int color);
#define setgraphbufsize(bufsize) _ret(0);
void far _cdecl setgraphmode(int mode);
void far _cdecl setlinestyle(int linestyle,unsigned upattern,int thickness);
void far _cdecl setpalette(int colornum,int color);
void far _cdecl setrgbpalette(int colornum,int red,int green,int blue);
void far _cdecl settextjustify(int horiz,int vert);
void far _cdecl settextstyle(int font,int direction,int charsize);
void far _cdecl setusercharsize(int multx,int divx,int multy,int divy);
void far _cdecl setviewport(int left,int top,int right,int bottom,int clip);
void far _cdecl setvisualpage(int page);
void far _cdecl setwritemode(int mode);
long far pascal textextent(const char far *textstring);	//new: both X(LO) and Y(HI)
int  far _cdecl textheight(const char far *textstring);
int  far _cdecl textwidth(const char far *textstring);

/***** graphics drivers *****/
int  far pascal _ret(int x);				// do nothing but return x
                                                                         
#define registerbgidriver(driver) _ret(9)	// return VGA, most wanted result
#define registerfarbgidriver(driver) _ret(9)

/***** graphics fonts *****/

#define registerbgifont(font) _ret(5)
#define registerfarbgifont(font) _ret(5)

//for beauty
void far pascal setwindowtitle(char far*title);
//for keeping Windows alive while calculations or similar
void far pascal yield(void);

extern BOOL CanClose;
extern HWND CrtWindow;
extern int  scale;
extern char _WindowTitle[80];
extern char*_InactiveTitle;
extern char*_KillWarning;
extern BOOL _AutoTracking;
extern BOOL _CheckEOF;
extern BOOL _DirectDraw;


#ifdef __cplusplus
}
#endif

#endif
Vorgefundene Kodierung: ASCII (7 bit)2