00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef MEMGFX_H
00012 #define MEMGFX_H
00013
00014 #ifndef GFXPOLY_H
00015 #include "gfxPoly.h"
00016 #endif
00017
00018 #define MG_WHITE 0
00019 #define MG_BLACK 1
00020 #define MG_RED 2
00021 #define MG_GREEN 3
00022 #define MG_BLUE 4
00023 #define MG_CYAN 5
00024 #define MG_MAGENTA 6
00025 #define MG_YELLOW 7
00026 #define MG_GRAY 8
00027 #define MG_FREE_COLORS_START 9
00028
00029
00030 typedef unsigned char Color;
00031
00032 struct rgbColor
00033 {
00034 unsigned char r, g, b;
00035 };
00036
00037 extern struct rgbColor mgFixedColors[9];
00038
00039 struct memGfx
00040 {
00041 Color *pixels;
00042 int width, height;
00043 struct rgbColor colorMap[256];
00044 int colorsUsed;
00045 int clipMinX, clipMaxX;
00046 int clipMinY, clipMaxY;
00047 struct colHash *colorHash;
00048 };
00049
00050 struct memGfx *mgNew(int width, int height);
00051
00052
00053 void mgFree(struct memGfx **pmg);
00054
00055
00056 void mgClearPixels(struct memGfx *mg);
00057
00058
00059 void mgSetClip(struct memGfx *mg, int x, int y, int width, int height);
00060
00061
00062 void mgUnclip(struct memGfx *mg);
00063
00064
00065 Color mgFindColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b);
00066
00067
00068
00069
00070 Color mgClosestColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b);
00071
00072
00073 Color mgAddColor(struct memGfx *mg, unsigned char r, unsigned char g, unsigned char b);
00074
00075
00076 int mgColorsFree(struct memGfx *mg);
00077
00078
00079
00080 #define _mgBpr(mg) ((mg)->width)
00081
00082
00083 #define _mgPixAdr(mg,x,y) ((mg)->pixels+_mgBpr(mg) * (y) + (x))
00084
00085
00086 #define _mgPutDot(mg, x, y, color) (*_mgPixAdr(mg,x,y) = (color))
00087
00088
00089 #define _mgGetDot(mg, x, y) (*_mgPixAdr(mg,x,y))
00090
00091
00092
00093 #define mgPutDot(mg,x,y,color) if ((x)>=(mg)->clipMinX && (x) < (mg)->clipMaxX && (y)>=(mg)->clipMinY && (y) < (mg)->clipMaxY) _mgPutDot(mg,x,y,color)
00094
00095
00096 #define mgGetDot(mg,x,y) ((x)>=(mg)->clipMinX && (x) < (mg)->clipMaxX && (y)>=(mg)->clipMinY && (y) < (mg)->clipMaxY) ? _mgGetDot(mg,x,y) : 0
00097
00098
00099
00100 void mgPutSeg(struct memGfx *mg, int x, int y, int width, Color *dots);
00101
00102
00103 void mgPutSegZeroClear(struct memGfx *mg, int x, int y, int width, Color *dots);
00104
00105
00106
00107 void mgDrawBox(struct memGfx *mg, int x, int y, int width, int height, Color color);
00108
00109
00110 void mgDrawLine(struct memGfx *mg, int x1, int y1, int x2, int y2, Color color);
00111
00112
00113 void mgDrawHorizontalLine(struct memGfx *mg, int y1, Color color);
00114
00115
00116 void mgLineH(struct memGfx *mg, int y, int x1, int x2, Color color);
00117
00118
00119 void mgSaveGif(struct memGfx *mg, char *name);
00120
00121
00122 boolean mgSaveToGif(FILE *gif_file, struct memGfx *screen);
00123
00124
00125 struct memGfx *mgLoadGif(char *name);
00126
00127
00128
00129
00130
00131
00132
00133 typedef void (*TextBlit)(int bitWidth, int bitHeight, int bitX, int bitY,
00134 unsigned char *bitData, int bitDataRowBytes,
00135 struct memGfx *dest, int destX, int destY,
00136 Color color, Color backgroundColor);
00137
00138
00139
00140
00141 void mgTextBlit(int bitWidth, int bitHeight, int bitX, int bitY,
00142 unsigned char *bitData, int bitDataRowBytes,
00143 struct memGfx *dest, int destX, int destY,
00144 Color color, Color backgroundColor);
00145
00146
00147 void mgTextBlitSolid(int bitWidth, int bitHeight, int bitX, int bitY,
00148 unsigned char *bitData, int bitDataRowBytes,
00149 struct memGfx *dest, int destX, int destY,
00150 Color color, Color backgroundColor);
00151
00152
00153 typedef struct font_hdr MgFont;
00154
00155
00156 MgFont *mgTinyFont();
00157 MgFont *mgSmallFont();
00158 MgFont *mgMediumFont();
00159 MgFont *mgLargeFont();
00160 MgFont *mgHugeFont();
00161 MgFont *mgTinyBoldFont();
00162 MgFont *mgSmallBoldFont();
00163 MgFont *mgMediumBoldFont();
00164 MgFont *mgLargeBoldFont();
00165 MgFont *mgHugeBoldFont();
00166 MgFont *mgTinyFixedFont();
00167 MgFont *mgSmallFixedFont();
00168 MgFont *mgMediumFixedFont();
00169 MgFont *mgLargeFixedFont();
00170 MgFont *mgHugeFixedFont();
00171
00172 void mgText(struct memGfx *mg, int x, int y, Color color,
00173 MgFont *font, char *text);
00174
00175
00176 void mgTextCentered(struct memGfx *mg, int x, int y, int width, int height,
00177 Color color, MgFont *font, char *text);
00178
00179
00180 void mgTextRight(struct memGfx *mg, int x, int y, int width, int height,
00181 Color color, MgFont *font, char *text);
00182
00183
00184 int mgFontPixelHeight(MgFont *font);
00185
00186
00187 int mgFontLineHeight(MgFont *font);
00188
00189
00190 int mgFontWidth(MgFont *font, char *chars, int charCount);
00191
00192
00193 int mgFontStringWidth(MgFont *font, char *string);
00194
00195
00196 int mgFontCharWidth(MgFont *font, char c);
00197
00198
00199 void mgFillUnder(struct memGfx *mg, int x1, int y1, int x2, int y2,
00200 int bottom, Color color);
00201
00202
00203
00204
00205
00206 struct memGfx *mgRotate90(struct memGfx *in);
00207
00208
00209 void mgCircle(struct memGfx *mg, int xCen, int yCen, int rad,
00210 Color color, boolean filled);
00211
00212
00213
00214 void mgDrawPoly(struct memGfx *mg, struct gfxPoly *poly, Color color,
00215 boolean filled);
00216
00217
00218 #endif