/*----------------------------------------------*/
/*                                              */
/*      Nindows Library Header File             */
/*                                              */
/*          Create 1997-08-31 SEGA System R&D   */
/*                                              */
/*----------------------------------------------*/

#ifndef _NINDOWS_H_
#define _NINDOWS_H_

#include <NinjaWin.h>

/*--------------------------------------*/
/*      System Information              */
/*--------------------------------------*/
#define NWD_SM_CXSIZEFRAME  2           /* Frame width of THICKFRAME        */
#define NWD_SM_CYSIZEFRAME  2           /* Frame height of THICKFRAME       */
#define NWD_SM_CXBORDER     1           /* Single Boarder width             */
#define NWD_SM_CYBORDER     1           /* Single Boarder height            */
#define NWD_SM_CXMINTRACK   32          /* Width of the smallest window     */
#define NWD_SM_CYMINTRACK   10          /* Height of the smallest window    */
#define NWD_SM_CYCAPTION    20          /* Caption height                   */
#define NWD_SM_SZCAPTION    16          /* Caption height                   */
#define NWD_SM_CXSHADOW     8           /* Shadow                           */
#define NWD_SM_CYSHADOW     8           /* Shadow                           */

/*--------------------------------------*/
/*      Window Style                    */
/*--------------------------------------*/
#define NWD_WS_CAPTION      0x00000001  /* With Caption                     */
#define NWD_WS_THICKFRAME   0x00000002  /* With Frame                       */
#define NWD_WS_BORDER       0x00000004  /* Window with boundary             */
#define NWD_WS_SHADING      0x00000008  /* With shading                     */
#define NWD_WS_CONTROL      0x00000010  /* With close-box                   */
#define NWD_WS_OFFSET       0x00000020  /* Use relative coordinate for parent window*/
#define NWD_WS_SHADOW       0x00000040  /* Window with shadow               */
#define NWD_WS_INVISIBLE    0x00000080  /* Window without drawing           */
#define NWD_WS_NOMOVE       0x00000100  /* No move with mouse               */

#define NWD_WS_CLOSEBOX     NWD_WS_CONTROL
#define NWD_WS_MAXIMIZEBOX  0x00000200  /* To have maximize box             */
#define NWD_WS_MINIMIZEBOX  0x00000400  /* To have minimize box             */

#define NWD_WS_SB_HORZ      0x00001000  /* Horizontal scroll bar            */
#define NWD_WS_SB_VERT      0x00002000  /* Vertical scroll bar              */

#define NWD_WS_CLOSE        0x80000000  /* Window close request             */

/*--------------------------------------*/
/*      Window Class                    */
/*--------------------------------------*/
enum {
	NWD_WC_WIN,                         /* Normal Window                */
	NWD_WC_BUTTON,                      /* Button                       */
	NWD_WC_SCRBAR,                      /* Scroll bar                   */
	NWD_WC_SCRWIN,                      /* Scroll Window                */
	NWD_WC_EDITWIN,                     /* Edit Window                  */
	NWD_WC_MENUWIN,                     /* Menu Window                  */

	NWD_WC_CTLBOX,                      /* Control Box                  */
};

/*--------------------------------------*/
/*      Button Status                   */
/*--------------------------------------*/
#define NWD_BS_DOWN         0x00000001      /* Button being pressed         */
#define NWD_BS_INVOKED      0x00000100      /* Button function selected     */
#define NWD_BS_GRAYED       0x00000002      /* Cannot select                */

/*--------------------------------------*/
/*      Mouse Status                    */
/*--------------------------------------*/
#define NWD_MS_MOVE         0x00010000      /* Mouse moved                  */

#define NWD_MS_BUTTON       0x000f          /* Button pressed               */
#define NWD_MS_LBUTTON      0x0001          /* Left button being pressed    */
#define NWD_MS_RBUTTON      0x0002          /* Right button being pressed   */
#define NWD_MS_MBUTTON      0x0004          /* Middle button being pressed  */

#define NWD_MS_BUTTONDOWN   0x00f0          /* Button gets free             */
#define NWD_MS_LBUTTONDOWN  0x0010          /* Left button clicked          */
#define NWD_MS_RBUTTONDOWN  0x0020          /* Right button clicked         */
#define NWD_MS_MBUTTONDOWN  0x0040          /* Middle button clicked        */
#define NWD_MS_BUTTONUP     0x0f00          /* Button gets free             */
#define NWD_MS_LBUTTONUP    0x0100          /* Left button gets free        */
#define NWD_MS_RBUTTONUP    0x0200          /* Right button gets free       */
#define NWD_MS_MBUTTONUP    0x0400          /* Middle button gets free      */

#define NWD_MS_LBUTTONUP    0x0100          /* Left button gets free        */
#define NWD_MS_RBUTTONUP    0x0200          /* Right button gets free       */
#define NWD_MS_MBUTTONUP    0x0400          /* Middle button gets free      */

#define NWD_MS_CONTROL      0x1000          /* Control key pressed          */
#define NWD_MS_SHIFT        0x2000          /* Shift key pressed            */

/* Mouse Cursor shape */
#define NWD_MCS_DRAG        0x40000000      /* Window can be moved          */
#define NWD_MCS_RESIZE      0x20000000      /* Window size can be changed   */
#define NWD_MCS_AREAMASK    0x0000ffff      /*                              */

#define NWD_MCS_AREAFRAMET      0x0001      /* Window frame UP              */
#define NWD_MCS_AREAFRAMELT     0x0002      /* Window frame Upper Left      */
#define NWD_MCS_AREAFRAMEL      0x0003      /* Window frame Left            */
#define NWD_MCS_AREAFRAMELB     0x0004      /* Window frame Bottom Left     */
#define NWD_MCS_AREAFRAMEB      0x0005      /* Window frame BOTTOM          */
#define NWD_MCS_AREAFRAMERB     0x0006      /* Window frame Bottom Right    */
#define NWD_MCS_AREAFRAMER      0x0007      /* Window frame Right           */
#define NWD_MCS_AREAFRAMERT     0x0008      /* Window frame Upper Right     */
#define NWD_MCS_AREACLIENT      0x0009      /* window client                */
#define NWD_MCS_AREACAPTION     0x000a      /* Window caption               */

/* SCROLL WINDOW FLAG */
#define NWD_ES_HORIZONTAL       0x00000001  /* Scrollable in horizontal     */
#define NWD_ES_VERTICAL         0x00000002  /* Scrollable in vertical       */
#define NWD_ES_USECLIP          0x00010000  /* Clipping                     */


/*--------------------------------------*/
/*      Message Type                    */
/*--------------------------------------*/
enum {
	NWD_MSG_NULL,                           /*                              */
	NWD_MSG_ALL,                            /*                              */
	NWD_MSG_CLICK,                          /*                              */
	NWD_MSG_LBUTTONDOWN,                    /*                              */
	NWD_MSG_FOCUS,                          /*                              */
	NWD_MSG_CLOSE                           /*                              */
};

/*--------------------------------------*/
/*      Data Type                       */
/*--------------------------------------*/
enum {
	NWD_DT_CHAR,                            /* Signed 1 byte                */
	NWD_DT_SHORT,                           /* Signed 2 bytes               */
	NWD_DT_INT,                             /* Signed 4 bytes               */
	NWD_DT_LONG,                            /* Signed 4 bytes               */
	NWD_DT_FLOAT,                           /* 32bit floating point         */
	NWD_DT_UCHAR,                           /* Unsigned 1 byte              */
	NWD_DT_USHORT,                          /* Unsigned 2 bytes             */
	NWD_DT_UINT,                            /* Unsigned 4 bytes             */
	NWD_DT_ULONG                            /* Unsigned 4 bytes             */
};

/*--------------------------------------*/
/*      Menu Type                       */
/*--------------------------------------*/
#define NWD_MF_NULL       0x0000            /* Munu terminator              */
#define NWD_MF_NORMAL     0x0001            /* Normal Menu items            */
#define NWD_MF_SEPARATOR  0x0002            /* Separator                    */
#define NWD_MF_POPUP      0x0004            /* Sub-menu                     */
#define NWD_MF_CHECKED    0x8000            /* with check mark              */
#define NWD_MF_GRAYED     0x0008            /* Selection denied                     */

/*--------------------------------------*/
/*      Font Size                       */
/*--------------------------------------*/
#define NWD_FONTTYPE_SMALL  1               /*                              */
#define NWD_FONTTYPE_NORMAL 2               /*                              */
#define NWD_FONTTYPE_LARGE  3               /*                              */

/*--------------------------------------*/
/*      Nindows Utility Type            */
/*--------------------------------------*/
#define NWD_DEFWIN_SYSMENU     0            /*                          */
#define NWD_DEFWIN_NINJAINFO   1            /*                          */
#define NWD_DEFWIN_WINDOWINFO  2            /*                          */
#define NWD_DEFWIN_TEXCONTROL  3            /*                          */
#define NWD_DEFWIN_TEXVIEWER   4            /*                          */
#define NWD_DEFWIN_PERINFO     5            /*                          */
#define NWD_DEFWIN_DEBUG       6            /*                          */
#define NWD_DEFWIN_PERFORMANCE 7            /*                          */


/*--------------------------------------*/
/*      Basic Structure                 */
/*--------------------------------------*/
typedef struct _NWS_RGBA {
	Uint8 r;                                /* Red(0-255)                   */
	Uint8 g;                                /* Green(0-255)                 */
	Uint8 b;                                /* Blue(0-255)                  */
	Uint8 a;                          /* Transparent level(0-255) 255:opaque*/
} NWS_RGBA;

typedef struct _NWS_RECT {
	Sint32 left;                            /* Left edge                    */
	Sint32 top;                             /* Up edge                      */
	Sint32 right;                           /* Right edge                   */
	Sint32 bottom;                          /* Bottom edge                  */
} NWS_RECT;

typedef struct _NWS_RECTF {
	Float left;                             /* Left edge                    */
	Float top;                              /* Up edge                      */
	Float right;                            /* Right edge                   */
	Float bottom;                           /* Bottom edge                  */
} NWS_RECTF;

typedef struct _NWS_POINT {
	Sint32 x, y;                            /* Coordinate                   */
} NWS_POINT;

typedef struct _NWS_MOUSE {
	NWS_POINT pt;                           /* Current coordinate           */
	Sint32    dt;                           /* Current status               */
	Sint32    cursor;                       /* Current cursor status        */
	NWS_POINT oldPt;                        /* Old coordinate               */
	NWS_POINT mv;                           /* Amount of move               */
	NWS_POINT dragPt;                       /* Drag start point             */
} NWS_MOUSE;

/*--------------------------------------*/
/*      Basic Macro                     */
/*--------------------------------------*/
#define nwSetRGBA(_d, _r, _g, _b, _a)	\
	(_d)->r = (_r); (_d)->g = (_g); (_d)->b = (_b); (_d)->a = (_a)
#define nwSetRect(a, b , c, d, e)	\
	(a)->left = (b); (a)->top = (c); (a)->right = (d); (a)->bottom = (e);

/*--------------------------------------*/
/*      Message Structure               */
/*--------------------------------------*/
typedef Bool (*NWF_MSGPROC)(Sint32 msg, Sint32 param1, Sint32 param2);

typedef struct _NWS_MSGHANDLE {
	Sint32      msg;                        /*                              */
	NWF_MSGPROC func;                       /*                              */
} NWS_MSGHANDLE;

/*--------------------------------------*/
/*      Data Structure                  */
/*--------------------------------------*/
typedef struct _NWS_DATA {
	void *dt;                               /* Data pointer                 */
	Sint32 type;                            /* Data type                    */
} NWS_DATA;


/*--------------------------------------*/
/*      Window Structure                */
/*--------------------------------------*/
typedef struct _NWS_WIN {
	Sint32 style;                           /* Window style                 */
	Sint32 wClass;                          /* Window class                 */
	Sint8 *caption;                         /* Window caption name          */
	Sint32 font;                            /* Font type                    */

	struct _NWS_WIN *parent;                /* Pointer for parent window    */
	struct _NWS_WIN *child;                 /* Pointer for child window     */
	struct _NWS_WIN *before;                /* Pointer for sibling window   */
	struct _NWS_WIN *next;                  /* Pointer for sibling window   */

	Sint32 x, y;                            /* Client coordinate            */
	Sint32 w, h;                            /* Width/Height for client      */
/*	Sint32 sx,sy;                           /* Offset point for client      */

	NWS_RGBA col[4];                        /* Window color                 */
	NWS_MSGHANDLE *msgHandle;               /* Message handler              */
	void *menuTable;                        /* Menu table                   */

	void *userBuf;                          /* User buffer                  */
	void (*clientDraw)(struct _NWS_WIN *NWFUNC);
	                                        /* Client drawing callback      */
	void (*execFunc)(struct _NWS_WIN *NWFUNC);
	                                      /* Window process function pointer*/
	void (*destructor)(struct _NWS_WIN* NWFUNC);
	                                        /* Callback when window cancel  */
	Sint32 param1, param2;                  /* User parameters              */
	struct _NWS_WIN* hClose;                /* Close-box handle             */
	struct _NWS_WIN* hMaximize;             /* Maximizing button handle     */
	struct _NWS_WIN* hMinimize;             /* Minimizing button hancle     */
} NWS_WIN;

typedef NWS_WIN *NWHWND;
typedef void (*NWF_BUTTONFUNC)(NWHWND);




/*--------------------------------------*/
/*      Button Structure                */
/*--------------------------------------*/
typedef struct _NWS_BUTTON {
	NWS_WIN         base;                   /* Base Window                  */
	NWF_BUTTONFUNC  func;                   /* Called function when moved   */
	Sint32          state;                  /* button status                */
	Sint32          count;                  /* Wait till function execution */
} NWS_BUTTON;

/*--------------------------------------*/
/*      ScrollBar Structure             */
/*--------------------------------------*/
typedef struct _NWS_SCRBAR {
	NWS_WIN base;                           /* Base window                  */
	Float pos;                              /* Current value                */
	Float min;                              /* Minimum value                */
	Float max;                              /* Maximum value                */
	Float lineMove;                         /* move value                   */
	Float pageMove;                         /* move value                   */
	NWS_DATA dt;                            /* data                         */
} NWS_SCRBAR;

typedef struct {
	Sint8* caption;                         /* Caption                      */
	NWS_DATA data;                          /* Related data                 */
	Float min, max;                         /* max data, minimum data       */
	Float line, page;                       /* aount of move for line & page*/
	Float pos;                              /* Data initial value           */
} NWS_SCROLLBARINFO;

typedef struct {
	Sint32 n;                               /* # of scroll bar              */
	Sint32 style;                           /* Scroll bar style             */
	Sint16 x, y;                            /* Coordinate                   */
	Sint16 w, h;                            /* Size                         */
	NWS_SCROLLBARINFO* info;                /* Scroll bar information       */
} NWS_SCROLLBARLIST;


/*--------------------------------------*/
/*      Scroll Window Structure         */
/*--------------------------------------*/
typedef struct _NWS_SCRWIN {
	NWS_WIN base;                           /* Base Window                  */
	Sint32 sx, sy;                          /* Scroll position              */
	Sint32 flag;                            /* Scrollable direction flag    */
	NWS_RECT clip;                          /* Scrollable range             */
} NWS_SCRWIN;

/*--------------------------------------*/
/*      Edit Window Structure           */
/*--------------------------------------*/
typedef struct _NWS_EDITLINE {
	struct _NWS_EDITLINE *before;           /* Pointer to the previous line */
	struct _NWS_EDITLINE *next;             /* Pointer to the next line     */
	Sint8 *buf;                             /* Char. buffer pointer         */
	Sint32 len;                             /* number of characters         */
} NWS_EDITLINE;

typedef struct _NWS_EDITWIN {
	NWS_SCRWIN    base;                     /* Base Window                  */
	Sint32        maxLine;                  /* Max number of line           */
	NWS_EDITLINE  *lineBuf;                 /* Line buffer                  */
	Sint32        lineSum;                  /* # of lines currently reserved*/
	NWS_EDITLINE  *startLine;               /* First line                   */
	NWS_EDITLINE  *curLine;                 /* Current line                 */
} NWS_EDITWIN;

/*--------------------------------------*/
/*      Menu Handle                     */
/*--------------------------------------*/
typedef void (*NWF_MENUHANDLE)(NWHWND, Sint32 idx, Sint32 param);

/*--------------------------------------*/
/*      Menu Table Structure            */
/*--------------------------------------*/
typedef struct _NWS_MENUTABLE {
	Sint32         type;                    /* Menu Type                    */
	Sint8          *title;                  /* Menu Title                   */
	NWF_MENUHANDLE func;                    /* Callback function            */
	Sint32         param;                   /* Parameter                    */
} NWS_MENUTABLE;


/*--------------------------------------*/
/*      Menu Window Structure           */
/*--------------------------------------*/
typedef struct _NWS_MENUWIN {
	NWS_WIN       base;                     /* Base Window                  */
	Sint32        check;                    /* Items being checked          */
	NWS_MENUTABLE *menuTable;               /* Menu table                   */
} NWS_MENUWIN;


/*--------------------------------------*/
/*      Font Structure                  */
/*--------------------------------------*/
typedef struct _NWS_FONT {
	Sint32      baseChar;                   /* Base Character               */
	Sint32      w,  h;                      /* Character true size          */
	Sint32      u, v;                       /* Character uv size            */
	Sint32      gw, gh;                     /* grid size                    */
	Sint32      dw;                         /* Char. number in texture width*/
	NJS_TEXNAME *texname;                   /* Texture information          */
	Uint32      globalIndex;                /* Global index                 */
} NWS_FONT;


/*--------------------------------------*/
/*      Prototypes                      */
/*--------------------------------------*/

/****************************************/
/*      System                          */
/****************************************/
void nwInitSystem(Uint32 numTextures);
Sint32 nwExecute(void);
void nwExitSystem(void);
void nwInitResource(void);
Uint32 nwVersion(void);

Float nwGetZ(void);
Float nwAddZ(void);

/****************************************/
/*      Menu                            */
/****************************************/
NWHWND nwCreateMenuWindow(NWS_MENUTABLE *menuTbl, Sint8 *caption,
            Sint32 x, Sint32 y, NWHWND parent);

/****************************************/
/*      Font                            */
/****************************************/
void nwTextOut(NWHWND hWnd, Sint32 x, Sint32 y, Sint8 *fmt, ...);
void nwSetTextColor(NWS_RGBA* col);
Sint32 nwGetFontSize(Sint32* width, Sint32* height);

/****************************************/
/*      Button                          */
/****************************************/

NWHWND nwCreateButton(NWF_BUTTONFUNC func, Sint8 *title,
	Sint32 x, Sint32 y, Sint32 w, Sint32 h, NWHWND parent);
void nwEnableButton(NWHWND hWnd, Bool flag);

/****************************************/
/*      Scroll Bar                      */
/****************************************/
NWHWND nwCreateScrollBar(Sint32 type, Sint8 *title,
	Sint32 x, Sint32 y, Sint32 w, Sint32 h, NWHWND parent);
void nwSetScrollBarPos(NWHWND hWnd, Float pos);
void nwSetScrollBarRange(NWHWND hWnd, Float min, Float max);
void nwSetScrollBarData(NWHWND hWnd, NWS_DATA *dt);
void nwSetScrollBarLineMove(NWHWND hWnd, Float step);
void nwSetScrollBarPageMove(NWHWND hWnd, Float step);
void nwCreateScrollBarArray(NWS_SCROLLBARLIST* list, NWHWND parent);

/****************************************/
/*      Scroll Window                   */
/****************************************/
Bool nwScrWinEnableScroll(NWHWND hWnd, Sint32 flag);
Bool nwScrWinSetClip(NWHWND hWNd, NWS_RECT* rect);
Bool nwScrWinScroll(NWHWND hWnd, Sint32 x, Sint32 y);
Bool nwScrWinGetScroll(NWHWND hWnd, Sint32* x, Sint32* y);

/****************************************/
/*      Edit Window                     */
/****************************************/
NWHWND nwCreateEditWindow(Sint32 lineSum, Sint8 *caption, Sint32 style,
	Sint32 x, Sint32 y, Sint32 w, Sint32 h, NWHWND parent);
Bool nwEditWinAddString(NWHWND hWnd, Sint8 *string);
Bool nwEditWinPrintf(NWHWND hWnd, Sint8 *fmt, ...);

/****************************************/
/*      Window Management               */
/****************************************/
NWHWND nwCreateWindow(Sint32 wClass, Sint8 *caption, Sint32 style,
	Sint32 x, Sint32 y, Sint32 w, Sint32 h, NWHWND parent);
void nwDestroyWindow(NWHWND hWnd);

void nwBringWindowToTop(NWHWND hWnd);
NWHWND nwFindWindow(NWHWND hWnd, Sint8 *name);
NWHWND nwFindWindowByPos(Sint16 x, Sint16 y);

void nwGetClientRect(NWHWND hWnd, NWS_RECT *rc);
Bool nwGetWindowColor(NWHWND hWnd, NWS_RGBA* col);
Bool nwGetWindowPos(NWHWND hWnd, Sint32* x, Sint32* y);
void nwGetWindowRect(NWHWND hWnd, NWS_RECT *rc);
Bool nwGetWindowSize(NWHWND hWnd, Sint32* w, Sint32* h);
Bool nwGetWindowStyle(NWHWND hWnd, Sint32* style);
Sint32 nwGetWindowText(NWHWND hWnd, Sint8 *buf, Sint32 size);

Bool nwSetWindowColor(NWHWND hWnd, NWS_RGBA* col);
Bool nwSetWindowStyle(NWHWND hWnd, Sint32 and_style, Sint32 or_style);
Bool nwSetWindowPos(NWHWND hWnd, Sint32 x, Sint32 y);
Bool nwSetWindowSize(NWHWND hWnd, Sint32 w, Sint32 h);
Bool nwSetWindowText(NWHWND hWnd, Sint8 *text);


/****************************************/
/*      Common Dialog                   */
/****************************************/
NWHWND nwCreateColorDialog(Sint32 x, Sint32 y, NWS_RGBA *rgba, NWHWND parent);
NWHWND nwCreatePropertyDialog(NWHWND hWnd, Sint32 x, Sint32 y);

/****************************************/
/*      Nindows Utility                 */
/****************************************/
void nwDebugPrintf(Sint8 *fmt, ...);
void nwSetDefWindowColor(Sint32 win, NWS_RGBA* col);
void nwSetDefWindowStyle(Sint32 win, Sint32 and_style, Sint32 or_style);
void nwSetDefWindowPos(Sint32 win, Sint32 x, Sint32 y);
void nwSetDefWindowSize(Sint32 win, Sint32 w, Sint32 h);
void nwSetUserMenu(NWS_MENUTABLE* menu);


#endif /* _NINDOWS_H_ */
