// GrWinC Library 1.0.0  (build 1368900088)
// Copyright (C) 1998 - 2011  TAMARIBUCHI, Tsuguhiro
// Created: Sat Jul 23 23:08:08 JST 2011

#include <windows.h>

#ifdef __cplusplus
extern "C" {
#endif

// Logical colors
#define GWC_BLACK          0
#define GWC_DARKRED        1
#define GWC_DARKGREEN      2
#define GWC_DARKYELLOW     3
#define GWC_DARKBLUE       4
#define GWC_DARKMAGENTA    5
#define GWC_DARKCYAN       6
#define GWC_LIGHTGRAY      7
#define GWC_MONEYGREEN     8
#define GWC_SKYBLUE        9
#define GWC_CREAM         10
#define GWC_MEDIUMGRAY    11
#define GWC_DARKGRAY      12
#define GWC_RED           13
#define GWC_GREEN         14
#define GWC_YELLOW        15
#define GWC_BLUE          16
#define GWC_MAGENTA       17
#define GWC_CYAN          18
#define GWC_WHITE         19
#define GWC_FGCOLOR       -2
#define GWC_BKCOLOR       -3
#define GWC_PENCOLOR      -4
#define GWC_BRUSHCOLOR    -5
#define GWC_MARKCOLOR     -6
#define GWC_MARKBKCOLOR   -7
#define GWC_TEXTCOLOR     -8
#define GWC_TEXTBKCOLOR   -9
#define GWC_SYMCOLOR     -10
#define GWC_SYMBKCOLOR   -11
#define GWC_PXLCOLOR     -12
#define GWC_TRANSPARENT -100

// Destination
#define GWD_FGCOLOR        1
#define GWD_BKCOLOR        2
#define GWD_PENCOLOR       3
#define GWD_BRUSHCOLOR     4
#define GWD_MARKCOLOR      5
#define GWD_MARKBKCOLOR    6
#define GWD_TEXTCOLOR      7
#define GWD_TEXTBKCOLOR    8
#define GWD_SYMCOLOR       9
#define GWD_SYMBKCOLOR    10
#define GWD_PXLCOLOR      11

// GetSysColor
#define GWS_SCROLLBAR            0
#define GWS_BACKGROUND           1
#define GWS_ACTIVECAPTION        2
#define GWS_INACTIVECAPTION      3
#define GWS_MENU                 4
#define GWS_WINDOW               5
#define GWS_WINDOWFRAME          6
#define GWS_MENUTEXT             7
#define GWS_WINDOWTEXT           8
#define GWS_CAPTIONTEXT          9
#define GWS_ACTIVEBORDER        10
#define GWS_INACTIVEBORDER      11
#define GWS_APPWORKSPACE        12
#define GWS_HIGHLIGHT           13
#define GWS_HIGHLIGHTTEXT       14
#define GWS_BTNFACE             15
#define GWS_BTNSHADOW           16
#define GWS_GRAYTEXT            17
#define GWS_BTNTEXT             18
#define GWS_INACTIVECAPTIONTEXT 19
#define GWS_BTNHIGHLIGHT        20

// Pen styles
#define GWL_NULL       0
#define GWL_SOLID      1
#define GWL_DASH       2
#define GWL_DOT        3
#define GWL_DASHDOT    4
#define GWL_DASHDOTDOT 5

// Brush styles
#define GWB_NULL       0
#define GWB_SOLID      1
#define GWB_HATCHED    2

// Hatch styles
#define GWB_HORIZONTAL 1
#define GWB_VERTICAL   2
#define GWB_FDIAGONAL  3
#define GWB_BDIAGONAL  4
#define GWB_CROSS      5
#define GWB_DIAGCROSS  6

// Mark types
#define GWM_DOT          0
#define GWM_SOLIDSQUARE  1
#define GWM_PLUS         2
#define GWM_TIMES        3
#define GWM_ASTERISK     4
#define GWM_SQUARE       5
#define GWM_CIRCLE       6

// MIX (ROP2) modes
#define GWX_NOP          0
#define GWX_BLACK        1
#define GWX_WHITE        2
#define GWX_NOT          3
#define GWX_COPYPEN      4
#define GWX_MASKPEN      5
#define GWX_MERGEPEN     6
#define GWX_XORPEN       7
#define GWX_NOTCOPYPEN   8
#define GWX_NOTMASKPEN   9
#define GWX_NOTMERGEPEN 10
#define GWX_NOTXORPEN   11
#define GWX_MASKNOTPEN  12
#define GWX_MASKPENNOT  13
#define GWX_MERGENOTPEN 14
#define GWX_MERGEPENNOT 15

// Bitmap MIX (ROP3) modes
#define GWY_INVERTNOT    0
#define GWY_SRCCOPY      1
#define GWY_SRCPAINT     2
#define GWY_SRCAND       3
#define GWY_SRCINVERT    4
#define GWY_SRCERASE     5
#define GWY_NOTSRCCOPY   6
#define GWY_NOTSRCERASE  7
#define GWY_MERGECOPY    8
#define GWY_MERGEPAINT   9
#define GWY_PATCOPY     10
#define GWY_PATPAINT    11
#define GWY_PATINVERT   12
#define GWY_DSTINVERT   13
#define GWY_BLACKNESS   14
#define GWY_WHITENESS   15

// View mode
#define GWV_BITMAP      1
#define GWV_ISOTROPIC   2
#define GWV_FIT         3
#define GWV_TOTAL       4
#define GWV_ZOOM        5

// File format
#define GWF_GWD         1
#define GWF_EMF         2
#define GWF_BMP         3
#define GWF_EPS         4
#define GWF_JPG         5
#define GWF_PNG         6

// Reference point at
#define GWO_CENTER      0
#define GWO_BOTTOMLEFT  1
#define GWO_BOTTOMRIGHT 2
#define GWO_TOPRIGHT    3
#define GWO_TOPLEFT     4
#define GWO_LEFT        5
#define GWO_BOTTOM      6
#define GWO_RIGHT       7
#define GWO_TOP         8

#if !defined(__LCC__) && !defined(_MSC_VER) && !defined(__BORLANDC__)
int kbhit();
#endif

#ifdef __CYGWIN32__
int getch (void);
int getche (void);
#endif

#ifdef __F2C__
float rand_(void);
#endif

int GWinit(void);
int GWinitx(int IRB, int IX, int IY, int IW, int IH, int MA, int MM, 
		int MZ, int ND);
int GWopen(int NW);
int GWopenx(int NW, int IW, int IH, int IFC, int IBC, int M, char *FN, int l);
int GWquit(void);
int GWquitx(int MQ);
int GWleave(void);
int GWjoin(int NW, int IN, int IS, char *JND, int l);
int GWreset(void);
int GWclose(int NW);
int GWindow(float X1, float Y1, float X2, float Y2);
int GWgetwn(float *X1, float *Y1, float *X2, float *Y2);
int GWvport(float U1, float V1, float U2, float V2);
int GWport(float X1, float Y1, float X2, float Y2);
int GWgetvp(float *U1, float *V1, float *U2, float *V2);
int GWsavevp(int IVP);
int GWselvp(int IVP);
int GWfirst(void);
int GWnext(int NW);
int GWselect(int NW);
int GWshowwn(int NW, int IS);
int GWshowfr(int IS);
int GWarrange(int M);
int GWldcpos(float X, float Y, int *IU, int *IV);
int GWldcsiz(float W, float H, int *IU, int *IV);
int GWpxlsiz(float *W, float *H);
int GWsetpen(int IPC, int IPS, int IPW, int MX);
int GWgetpen(int *IPC, int *IPS, int *IPW, int *MX);
int GWsetbrs(int IBC, int IBS, int IBH);
int GWgetbrs(int *IBC, int *IBS, int *IBH);
int GWsettxt(float H, float A, int IO, int K, int KB, char *FACE, int l);
int GWgettxt(float *W, float *H, float *X, float *Y, char *TXT, int l);
int GWputtxt(float X, float Y, char *TXT, int l);
int GWsetsym(float H, float A, int IO, int K, int KB, char *FACE, int l);
int GWgetsym(float *W, float *H, int IC);
int GWputsym(float X, float Y, int IC);
int GWsetmsg(char *TXT, int l);
int GWmsgbox(char *TXT, int l);
int GWgetpos(float *X, float *Y);
int GWmove2(float X, float Y);
int GWline2(float X, float Y);
int GWline(float X1, float Y1, float X2, float Y2);
int GWrect(float X1, float Y1, float X2, float Y2);
int GWsrect(float X1, float Y1, float X2, float Y2, int K);
int GWrrect(float X1, float Y1, float X2, float Y2, float W, float H);
int GWellipse(float X1, float Y1, float X2, float Y2);
int GWarc(float X1, float Y1, float X2, float Y2, float A, float AW);
int GWchord(float X1, float Y1, float X2, float Y2, float A, float AW);
int GWpie(float X1, float Y1, float X2, float Y2, float A, float AW);
int GWplot1(int M, int N, float P1, float PN, float S, float O, 
                float A, float B, float *ARRY);
int GWpolygon(float *POINTS, int N, int MF);
int GWpolylin(float *POINTS, int N);
int GWbezier(float *POINTS, int N);
int GWflood(float X, float Y);
int GWclear(int K);
int GWsetmrk(int MT, float S, int K, int KB, int MX);
int GWputmrk(float X, float Y);
int GWgetmrk(int *MT, float *S, int *K, int *KB, int *MX);
int GWsetxfrm(float *XFRM);
int GWgetxfrm(float *XFRM);
int GWsetrgn(float X1, float Y1, float X2, float Y2, int M);
int GWsetpxl(float X, float Y, int K);
int GWgetpxl(float X, float Y);
int GWcolor(int K, int IDST);
int GWgetrgb(int K, int *IR, int *IG, int *IB);
int GWkrgb(int IR, int IG, int IB);
int GWkcolor(int IC);
int GWipalette(int IP);
int GWncolor(void);
int GWsavecc(char *FN, int l);
int GWloadcc(char *FN, int l);
int GWsysclr(int IDX);
int GWcappnt(float *X, float *Y, char *TEXT, int l);
int GWcapvec(float X1, float Y1, float *X2, float *Y2, char *TEXT, int l);
int GWcaplin(float *X1, float *Y1, float *X2, float *Y2, char *TEXT, int l);
int GWcaprect(float *X1, float *Y1, float *X2, float *Y2, char *TEXT, int l);
int GWloadbmp(int NB, char *FN, int l);
int GWsavebmp(int NB, char *FN, int l);
int GWmakebmp(int NB, int IW, int IH, int IBC, int *IBITS);
int GWpeekbmp(int NB, int IXY, int LEN, int *IBC, int *IBITS);
int GWpokebmp(int NB, int IXY, int LEN, int MX, int *IBITS);
int GWfnt2bmp(int NB, int IW, int IH, int IU, int IV, char *TEXT, int l);
int GWsetbmp(int NB, float W, float H, int MX, int ITR, int IOF);
int GWgetbmp(int NB, float *W, float *H, int *IW, int *IH, 
		int *NC, int *MAXNB, char *FN, int l);
int GWputbmp(int NB, float X, float Y, int IBK);
int GWcopybmp(int NB1, int NB2);
int GWdelbmp(int NM);
int GWcapimg(int NB, float X1, float Y1, float X2, float Y2);
int GWclipimg(float X1, float Y1, float X2, float Y2);
int GWloademf(int NM, char *FN, int l);
int GWsaveemf(int NM, char *FN, int l);
int GWemfmrk(int NM, int MT, float S, int K, int KB, int MX);
int GWbeginemf(int NM, float W, float H);
int GWendemf(void);
int GWputemf(int NM, float X, float Y, float W, float H, int IOF);
int GWgetemf(int NM, int II, int *IX1, int *IY1, int *IX2, int *IY2, 
		int *MAXNM, char *FN, int l);
int GWcopyemf(int NM1, int NM2);
int GWdelemf(int NM);
int GWinput(char *TITLE, int l1, char *TXT, int l2);
int GWfiledlg(char *FN, int l);
int GWload(int IC, char *FN, int l);
int GWsaveas(int MF, int MV, int IW, int IH, char *FN, int l);
int GWprint(int IW, int MV);
int GWsetogn(int ISRC, int IDST);
int GWanchor(int N);
int GWsetbk(int N);
int GWerase(int N, int LRF);
int GWflush(int N);
int GWrefresh(void);
int GWvwmod(int M);
int GWmode(int MD, int M);
int GWkybrd(int *ICH, int *NCNT, int *IFLG, int M);
int GWmouse(int *IRB, float *X, float *Y);
int GWtimer(int MS, int N);
int GWevent(float *X, float *Y);
int GWidle(int *ICH, float *X, float *y, int MSEC);
int GWidle2(int *ICH, float *X, float *y, int MSEC);
int GWsleep(int MS);
int GWsleep2(int MS);
int GWctime(void);
int GWpause(char *TXT, int l);
int GWsize(int N, int *IW, int *IH);
float GWaspect(int N);
float GWfmax(void);
int GWversion(int IS, char *STR, int l);
int kbgetch(int N);
int GWTspawn(int IT, int IS, int M);
int GWTturn(int IT, float DA);
int GWDTturn(int IT, double DA);
int GWTforward(int IT, float D);
int GWDTforward(int IT, double D);
int GWTshift(int IT, float DX, float DY);
int GWDTshift(int IT, double DX, double DY);
int GWTmove2(int IT, float X, float Y);
int GWDTmove2(int IT, double X, double Y);
int GWTclone(int IT1, int IT2);
int GWTremove(int IT);
int GWTsetpos(int IT, float X, float Y);
int GWDTsetpos(int IT, double X, double Y);
int GWTgetpos(int IT, float *X, float *Y);
int GWDTgetpos(int IT, double *X, double *Y);
int GWTsetdir(int IT, float A);
int GWDTsetdir(int IT, double A);
int GWTgetdir(int IT, float *A);
int GWDTgetdir(int IT, double *A);
int GWTsetcol(int IT, int IPC);
int GWTgetcol(int IT);
int GWTsetpen(int IT, int IPC, int IPS, int IPW);
int GWTsetmrk(int IT, int MT, float S, int K, int KS, int KB, int MX);
int GWDTsetmrk(int IT, int MT, double S, int K, int KS, int KB, int MX);

// Low Level Functions
int GW_init(int bri, int x, int y, int w, int h, int a, int m, int z, int d);
int GW_join(int nDoc, int nCli, int bDo, char *str, int l);
int GW_quit(int bPause);
int GW_open(int nDoc, int Width, int Height, int fc, int bc, 
	int Mode, char *fname, int l, int bfor);
int GW_close(int nDoc);
int GW_wsize(int nDoc, int n, int *width, int *height);
int GW_viewmode(int nDoc, int m);
int GW_idle(int nDoc, int *ch, int *u, int *v, int ms);
int GW_idle2(int nDoc, int *ch, int *u, int *v, int ms);
int GW_kybrd(int nDoc, int *ch, int *cnt, int *flg, int t);
int GW_putmark(int nDoc, int u, int v);
int GW_move2(int nDoc, int u, int v);
int GW_line2(int nDoc, int u, int v);
int GW_settext(int nDoc, int h, int a, int o, int c, int b, char *face, int l);
int GW_setsymbol(int nDoc, int h, int a, int o, int c, int b, char *face, int l);
int GW_input(int nDoc, char *ttl, int l1, char *str, int l2, int bfor);
int GW_puttext(int nDoc, int x, int y, char *txt, int l);
int GW_setmsg(int nDoc, char *txt, int l);
int GW_msgbox(int nDoc, char *txt, int l);
int GW_load(int nDoc, char c, int x, int y, char *fname, int l, char *wc, int lwc);
int GW_savecc(int nDoc, char *fname, int l);
int GW_loadcc(int nDoc, char *fname, int l);
int GW_reset(int nDoc);
int GW_getvp(int nDoc, int *u1, int *v1, int *u2, int *v2);
int GW_next(int nw);
int GW_selwin(int nDoc);
int GW_arrange(int nDoc, int m);
int GW_setpen(int nDoc, int pc, int ps, int pw, int pm);
int GW_setbrush(int nDoc, int k, int style, int hatch);
int GW_gettext(int nDoc, int *u, int *v, int *ox, int *oy, char *txt, int l);
int GW_getsymbol(int nDoc, int *u, int *v, int c);
int GW_putsymbol(int nDoc, int x, int y, int c);
int GW_getpos(int nDoc, int *u, int *v);
int GW_line(int nDoc, int u1, int v1, int u2, int v2);
int GW_rectangle(int nDoc, int u1, int v1, int u2, int v2);
int GW_solidrect(int nDoc, int u1, int v1, int u2, int v2, int k);
int GW_roundrect(int nDoc, int u1, int v1, int u2, int v2, int w, int h);
int GW_ellipse(int nDoc, int u1, int v1, int u2, int v2);
int GW_arc(int nDoc, int u1, int v1, int u2, int v2, 
		   int u3, int v3, int u4, int v4);
int GW_chord(int nDoc, int u1, int v1, int u2, int v2, 
		   int u3, int v3, int u4, int v4);
int GW_pie(int nDoc, int u1, int v1, int u2, int v2, 
		   int u3, int v3, int u4, int v4);
int GW_plot1(int nDoc, int M, int N, int P1, int PN, int W, int O, INT *ARRY);
int GW_polygon(int nDoc, POINT* pnts, int N, int mf);
int GW_polyline(int nDoc, POINT *pnts, int N);
int GW_bezier(int nDoc, POINT *pnts, int N);
int GW_flood(int nDoc, int u, int v);
int GW_clear(int nDoc, int k);
int GW_setmrk(int nDoc, int t, int s, int k, int kb, int mix);
int GW_getmrk(int nDoc, int *t, int *s, int *k, int *kb, int *m);
int GW_setxfrm(int nDoc, int x0, int y0, 
		float t11, float t12, float t21, float t22);
int GW_getxfrm(int nDoc, int *x0, int *y0, 
		float *t11, float *t12, float *t21, float *t22);
int GW_setrgn(int nDoc, int u1, int v1, int u2, int v2, int m);
int GW_setpixel(int nDoc, int x, int y, int k);
int GW_getpixel(int nDoc, int x, int y);
int GW_color(int nDoc, int k, int dest);
int GW_getrgb(int nDoc, int k, int *r, int *g, int *b);
int GW_krgb(int r, int g, int b);
int GW_kcolor(int c);
int GW_ipalette(int c);
COLORREF GW_syscolor(int nindex);
int GW_cappoint(int nDoc, int *u, int *v, char *txt, int l);
int GW_capvec(int nDoc, int x1, int y1, int *x2, int *y2, char *txt, int l);
int GW_capline(int nDoc, int *x1, int *y1, int *x2, int *y2, char *txt, int l);
int GW_caprect(int nDoc, int *x1, int *y1, int *x2, int *y2, char *txt, int l);
int GW_savebitmap(int nDoc, int nb, char *fname, int l);
int GW_makebitmap(int nDoc, int nb, int w, int h, int bc, int *bits);
int GW_peekbitmap(int nDoc, int nb, int p, int l, int *bc, int *bits);
int GW_pokebitmap(int nDoc, int nb, int p, int l, int m, int *bits);
int GW_font2bitmap(int nDoc, int nb, int w, int h, int u, int v, char *text, int l);
int GW_setbitmap(int nDoc, int nb, int w, int h, int m, int t, int o);
int GW_getbitmap(int nDoc, int nb, int *width, int *height, 
	int *bw, int *bh, int *bc, int *maxnb, char *fname, int l);
int GW_putbitmap(int nDoc, int nb, int x, int y, int bk);
int GW_copybitmap(int nDoc, int nb1, int nb2);
int GW_delbmp(int nDoc, int nb);
int GW_capimage(int nDoc, int nb, int x1, int y1, int x2, int y2);
int GW_clipimage(int nDoc, int x1, int y1, int x2, int y2);
int GW_saveemf(int nDoc, int nm, char *fname, int l);
int GW_emfmrk(int nDoc, int nm, int t, int s, int k, int kb, int mix);
int GW_beginemf(int nDoc, int nm, int w, int h);
int GW_endemf(int nDoc);
int GW_putemf(int nDoc, int nm, int x, int y, int w, int h, int o);
int GW_getemf(int nDoc, int nm, int ii, int *x1, int *y1, int *x2, int *y2, 
		int *maxnb, char *fname, int l);
int GW_getcmb(int nDoc, int nm, int *width, int *height, 
	int *mw, int *mh, int *maxnb, char *fname, int l);
int GW_copyemf(int nDoc, int nb1, int nb2);
int GW_delemf(int nDoc, int nb);
int GW_filedlg(int nDoc, char *fname, int l);
int GW_saveas(int nDoc, int f, int m, int w, int h, char *fname, int l);
int GW_print(int nDoc, int nMode);
int GW_setbk(int nDoc, int m);
int GW_erase(int nDoc, int ogn, int rdrw);
int GW_flush(int nDoc, int ogn);
int GW_refresh(int nDoc);
int GW_mode(int nDoc, int md, int m);
int GW_mouse(int nDoc, int *R, int *x, int *y);
int GW_timer(int nDoc, int MS, int N);
int GW_event(int nDoc, int *x, int *y);
int GW_sleep(int nDoc, int ms);
int GW_sleep2(int nDoc, int ms);
int GW_ctime(int nDoc);
int GW_pause(int nDoc, char *txt, int l);

// Functions with double prec args
int GWDTspawn(int it, int s, int m);
int GWDTturn(int it, double a);
int GWDTforward(int it, double d);
int GWDTshift(int it, double dx, double dy);
int GWDTmove2(int it, double x, double y);
int GWDTclone(int it1, int it2);
int GWDTremove(int it);
int GWDTsetpos(int it, double x, double y);
int GWDTgetpos(int it, double *x, double *y);
int GWDTsetdir(int it, double a);
int GWDTgetdir(int it, double *a);
int GWDTsetcol(int it, int pc);
int GWDTgetcol(int it);
int GWDTsetpen(int it, int pc, int ps, int pw);
int GWDTgetpen(int it, int *pc, int *ps, int *pw);
int GWDTsetmrk(int it, int t, double s, int k, int ks, int kb, int mix);
int GWDTgetmrk(int it, int *t, double *s, int *k, int *ks, int *kb, int *m);
int GWDTsetsym(int it, int m);
int GWDTgetsym(int it, double *w, double *h, int *c);
int GWDTsetbmp(int it, int b, double w, double h, int x, int t, int o);
int GWDTsetcmb(int it, int c, double w, double h, int o);

// Obsolete functions only for compatibilities
int GWloadcmb(int NM, char *FN, int l);
int GWsavecmb(int NM, char *FN, int l);
int GWcmbmrk(int NM, int MT, float S, int K, int KB, int MX);
int GWbegincmb(int NM, float W, float H);
int GWendcmb(void);
int GWputcmb(int NM, float X, float Y, float W, float H, int IOF);
int GWgetcmb(int NM, float *W, float *H, float *W0, float *H0, 
		int *MAXNM, char *FN, int l);
int GWcopycmb(int NM1, int NM2);
int GWdelcmb(int NM);
int GW_savecmb(int nDoc, int nm, char *fname, int l);
int GW_cmbmrk(int nDoc, int nm, int t, int s, int k, int kb, int mix);
int GW_begincmb(int nDoc, int nm, int w, int h);
int GW_endcmb(int nDoc);
int GW_putcmb(int nDoc, int nm, int x, int y, int w, int h, int o);
int GW_getcmb(int nDoc, int nm, int *width, int *height, 
	int *mw, int *mh, int *maxnb, char *fname, int l);
int GW_copycmb(int nDoc, int nb1, int nb2);
int GW_delcmb(int nDoc, int nb);

#ifdef __cplusplus
}
#endif
