graphics.h头文件代码
时间: 2023-11-13 22:05:19 浏览: 132
`graphics.h` 是一个早期的 C 语言库,用于创建图形用户界面。它主要被用于 DOS 系统下的图形编程,现在已经被淘汰了。以下是一个简单的 `graphics.h` 头文件代码示例:
```c
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <conio.h>
#include <dos.h>
/* 定义颜色 */
enum COLORS {
BLACK,
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY,
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
};
/* 定义图形驱动器 */
enum GRAPHICS_DRIVER {
DETECT,
CGA,
MCGA,
EGA,
EGA64,
EGAMONO,
IBM8514,
HERCMONO
};
/* 定义线样式 */
enum LINE_STYLE {
SOLID_LINE,
DOTTED_LINE,
CENTER_LINE,
DASHED_LINE,
USERBIT_LINE
};
/* 定义填充样式 */
enum FILL_STYLE {
EMPTY_FILL,
SOLID_FILL,
LINE_FILL,
LTSLASH_FILL,
SLASH_FILL,
BKSLASH_FILL,
LTBKSLASH_FILL,
HATCH_FILL,
XHATCH_FILL,
INTERLEAVE_FILL,
WIDE_DOT_FILL,
CLOSE_DOT_FILL,
USER_FILL
};
/* 定义文本方向 */
enum TEXT_DIRECTION {
HORIZ_DIR,
VERT_DIR
};
/* 定义字体 */
enum FONT {
DEFAULT_FONT,
TRIPLEX_FONT,
SMALL_FONT,
SANS_SERIF_FONT,
GOTHIC_FONT
};
/* 定义图形窗口 */
struct viewporttype {
int left, top, right, bottom;
int clip;
};
/* 定义宏 */
#define MAXCOLORS 15
#define MAXMODES 7
#define MAXHANDLES 4
/* 函数声明 */
void arc(int x, int y, int start_angle, int end_angle, int radius);
void bar(int left, int top, int right, int bottom);
void circle(int x, int y, int radius);
void cleardevice();
void clearviewport();
void closegraph();
void detectgraph(int *graphdriver, int *graphmode);
void drawpoly(int numpoints, int *polypoints);
void ellipse(int x, int y, int start_angle, int end_angle, int xradius, int yradius);
void fillellipse(int x, int y, int xradius, int yradius);
void fillpoly(int numpoints, int *polypoints);
void floodfill(int x, int y, int border);
void getarccoords(struct arccoordstype *arccoords);
void getaspectratio(int *xasp, int *yasp);
int getbkcolor();
int getcolor();
struct palettetype *getdefaultpalette();
char *getdrivername();
void getfillpattern(char *pattern);
void getfillsettings(struct fillsettingstype *fillinfo);
int getgraphmode();
void getimage(int left, int top, int right, int bottom, void *bitmap);
void getlinesettings(struct linesettingstype *lineinfo);
int getmaxcolor();
int getmaxmode();
int getmaxx();
int getmaxy();
char *getmodename(int mode_number);
void getmoderange(int graphdriver, int *lomode, int *himode);
unsigned getpixel(int x, int y);
void getpalette(struct palettetype *palette);
int getpalettesize();
void gettextsettings(struct textsettingstype *texttypeinfo);
void getviewsettings(struct viewporttype *viewport);
int getx();
int gety();
void graphdefaults();
char *grapherrormsg(int errorcode);
int graphresult();
unsigned imagesize(int left, int top, int right, int bottom);
void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);
int installuserdriver(char *name, int (*detect)(void));
int installuserfont(char *name);
void line(int x1, int y1, int x2, int y2);
void linerel(int dx, int dy);
void lineto(int x, int y);
void moverel(int dx, int dy);
void moveto(int x, int y);
void outtext(char *textstring);
void outtextxy(int x, int y, char *textstring);
void pieslice(int x, int y, int start_angle, int end_angle, int radius);
void putimage(int left, int top, void *bitmap, int op);
void putpixel(int x, int y, int color);
void rectangle(int left, int top, int right, int bottom);
void restorecrtmode();
void sector(int x, int y, int start_angle, int end_angle, int xradius, int yradius);
void setactivepage(int page);
void setallpalette(struct palettetype *palette);
void setaspectratio(int xasp, int yasp);
void setbkcolor(int color);
void setcolor(int color);
void setfillpattern(char *upattern, int color);
void setfillstyle(int pattern, int color);
unsigned setgraphbufsize(unsigned bufsize);
void setgraphmode(int mode);
void setlinestyle(int linestyle, unsigned upattern, int thickness);
void setpalette(int colornum, int color);
void settextjustify(int horiz, int vert);
void settextstyle(int font, int direction, int charsize);
void setusercharsize(int multx, int divx, int multy, int divy);
void setviewport(int left, int top, int right, int bottom, int clip);
void setvisualpage(int page);
void setwritemode(int mode);
int textheight(char *textstring);
int textwidth(char *textstring);
#endif
```
阅读全文