 
#ifndef __RV_GLGUI_H_INCLUDED_
#define __RV_GLGUI_H_INCLUDED_

  
#if defined(__RV_CGUI_H_INCLUDED_)
   #error conflicted with cgui module
#endif

#if defined(__RV_DXGUI_H_INCLUDED_)
   #error conflicted with dxgui module
#endif


/*
#ifdef DXGUI_EXPORTS
#define XGUI_API __declspec(dllexport)
#else
#define XGUI_API __declspec(dllimport)
#endif
*/

#define XGUI_API   WINAPI

 
#include <rvb\rvtypes.h> 

 

//HGDC  color
#define GDC_WHITE          GRGB(0xFF, 0xFF, 0xFF)
#define GDC_BLACK          GRGB(0x00, 0x00, 0x00) 
#define GDC_GREY           GRGB(0x80, 0x80, 0x80)

#define GDC_BLUE           GRGB(0x00, 0x00, 0xFF)
#define GDC_GREEN          GRGB(0x00, 0xFF, 0x00)
#define GDC_CYAN           GRGB(0x00,  0xFF,0xFF )
#define GDC_RED            GRGB(0xFF, 0x00, 0x00)
#define GDC_MAGENTA        GRGB(0x8B, 0x00, 0x8B)
#define GDC_BROWN          GRGB(0xA5, 0x2A,0x2A )
#define GDC_YELLOW         GRGB(0xFF, 0xFF, 0x00)

#define GDC_DARKGRAY       GRGB(0x40, 0x40, 0x40)

#define GDC_LIGHTGREY      GRGB(0xD3, 0xD3, 0xD3)
#define GDC_LIGHTBLUE      GRGB(0x80, 0x80, 0xFF)
#define GDC_LIGHTGREEN     GRGB(0x80, 0xFF, 0x80)
#define GDC_LIGHTCYAN      GRGB(0xFF , 0xFF,0x80 )
#define GDC_LIGHTRED       GRGB(0xFF , 0x80,0x80 )
#define GDC_LIGHTMAGENTA   GRGB(0xFF, 0x80, 0xFF)

 
 
enum RV_CONTEXT_TYPE{
 	RV_CT_GENERIC   = 0,  //无画布对象,用于实时播放。
    RV_CT_ENHANCED  ,     //有画布对象， 也可以用于实时播放。
};


//LOGO ALIGNMENT
#define  RV_LA_LEFTTOP       0
#define  RV_LA_RIGHTTOP      1
#define  RV_LA_LEFTBOTTOM    2
#define  RV_LA_RIGHTBOTTOM   3




/*      *********************************
        *
        *      Pen Patterns
        *
        *********************************
*/
#define RV_PS_SOLID         0    // .....................
#define RV_PS_HIDDEN        1    // ..  ..  ..  ..  ..  .
#define RV_PS_CENTER        2    // .......  ..  ........
#define RV_PS_INCLUSION     3    // .....  ..  ..  ......
 

  

 
//#define RV_MOS_DIV        (0x1000 << 16)



//***************************Layer Type********************************
//如果定义自定义层：
//
// #define RV_LT_MYCANVAS1  (RV_LT_CANVAS + 1)
// 
//每类层可以有65535个自定义层。
//在使用自定义层的时候，不要进行或运算。如下面的RV_ALL_LAYER
//
//目前： 已知自定义层对rvgClear和 rvgErase有影响。
//
//*********************************************************************
#define RV_LT_CANVAS            (0x02 << 16)
#define RV_LT_VIRTUAL           (0x04 << 16)
#define RV_LT_DISPLAY           (0x08 << 16)

#define RV_LT_BACKGROUND        (0x01 << 16 )

//#define RV_ALL_BACKGROUND       (RV_LT_BACKGROUND  )
#define RV_ALL_CANVAS           (RV_LT_CANVAS  | (0x02<<24) )
#define RV_ALL_VIRTUAL          (RV_LT_VIRTUAL | (0x04<<24) )
#define RV_ALL_DISPLAY          (RV_LT_DISPLAY | (0x08<<24) )
#define RV_ALL_GRAPHICS         (RV_ALL_VIRTUAL | RV_ALL_CANVAS | RV_ALL_DISPLAY)
#define RV_ALL_LAYER            (RV_LT_BACKGROUND | RV_ALL_GRAPHICS)
 


//Graphical Device Context(GDC) Style
#define RV_GS_ANTIALIAS         0x0001
#define RV_GS_QUALITY           0x0002  //最好质量
#define RV_GS_TRANSPARENT       0x0004 
#define RV_GS_USE_MIP           0x0010  //MIP for texture
#define RV_GS_INVISIBLE_CHAR    0x0020  //show  a space for an invisible charater(空格)   




//erase type
#define RV_ET_SHADOW    0
#define RV_ET_DELETE   -1
#define RV_ET_RESTORE   1


//modify stroke type
#define RV_MT_OPACITY         0x0001 //透明
#define RV_MT_COLOR           0x0002
//#define RV_MT_MOVE            0x0004  //移动相对位置:参数类型：RvOffset*
//#define RV_MT_VISIBLE         0x0008
//#define RV_MT_ABSPOS          0x0014  //将笔画移动到绝对位置.参数类型: GPoint*
#define RV_MT_IMAGE           0x0020
#define RV_MT_TEXT            0x0030 
 


//canvas background,小于5.2版,过时
//enum RV_CANVAS_BACKCOLOR{
//    RV_CB_CHECK  = -1,
//    RV_CB_BLACK  = RV_COLOR_BLACK ,
//    RV_CB_WHITE  = RV_COLOR_WHITE  ,  
//	RV_CB_GRAY   = RV_COLOR_GREY  ,  
//	RV_CB_RED    = RV_COLOR_RED    ,  
//};

//画布背景风格，V5.3
enum RV_CANVAS_BACKSTYLE{
	RV_BS_DEFAULT =0, //纯色
	RV_BS_CHECK,      //方格
	RV_BS_HORIBAR,    //水平条,保留
	RV_BS_VERTBAR,    //垂直条，保留
	RV_BS_GRID  ,     //方格点，保留
};


//canvas display(view) mode
enum  RV_VIEW_MODE{
  RV_VM_DEFAULT      =0,
  RV_VM_CENTER       ,
  RV_VM_STRETCH      ,
  RV_VM_STRETCH_KR   ,
  RV_VM_MULTI   ,   //多视图,待实现
  RV_VM_FULL3D    , //3D视图，待实现
  RV_VM_CUSTOM =10 ,   //自定义显示模式
};

 

#define RV_DEFAULT_FONT_NAME    _T("Arial")
#define RV_DEFAULT_FONT_SIZE   12

// Font style flags
#define RV_FS_DEFAULT       0x0000
#define RV_FS_BOLD          0x0001
#define RV_FS_ITALIC        0x0002
#define RV_FS_UNDERLINE     0x0004
#define RV_FS_STRIKEOUT     0x0008
#define RV_FS_OUTLINE       0x0010 //空心字
#define RV_FS_NOBKGROUND    0x0020
 


//对齐参数用于drawtext
#define RV_DT_TOP          0x01
#define RV_DT_VCENTER      0x02
#define RV_DT_BOTTOM       0x04

#define RV_DT_LEFT         (RV_DT_TOP << 8)
#define RV_DT_HCENTER      (RV_DT_VCENTER << 8) 
#define RV_DT_RIGHT        (RV_DT_BOTTOM << 8)

//Multiline flags
//在多行情况下，所有的换行符都会换行。
//当一行长度大于指定区域长度的时候，
//可以进行字符或单词换行，当同时指定两种换行方式的时候，
//单词换行优先
#define RV_DT_MULTILINE    (0x01 << 16) //default linefeed break
#define RV_DT_WORDBREAK    (0x02 << 16)  //
#define RV_DT_CHARBREAK    (0x04 << 16)
//#define RV_DT_NOBKGROUND   (0x08 << 16)  //透明
#define RV_DT_NOCLIP       (0x10 << 16)  //不剪裁

//#define RV_DT_SINGLELINE    (~(RV_DT_MULTILINE))  
 
//Draw text: format flags
//text alignment flags
#define RV_DT_DEFAULT       (RV_DT_TOP | RV_DT_LEFT)


//brush style
//#define RV_BT_CUSTOM     -2
#define RV_BT_BLANK      -1
#define RV_BT_SOLID      0
#define RV_BT_BDIAG      1   //Downward hatch   at 45 degrees(like '\')
#define RV_BT_CROSS      2   //Horizontal and vertical crosshatch
#define RV_BT_DIAGCROSS  3   //  Crosshatch at 45 degrees
#define RV_BT_FDIAG      4  // Upward hatch   at 45 degrees (like '/')
#define RV_BT_HORI       5  // Horizontal hatch
#define RV_BT_VERT       6  // Vertical hatch
#define RV_BT_DOT        7     // dot hatch
#define RV_BT_OUTLINE    8

  
//
//用于rvgDrawImage 
//mold type
#define RV_DI_DEFAULT    -1
#define RV_DI_SPECIFIC    0
#define RV_DI_ALIGN       1
#define RV_DI_ROTATE      2
#define RV_DI_STRETCH     3   //拉伸
#define RV_DI_SCALE       4
#define RV_DI_SKEW        5
#define RV_DI_TILE        6                      //平铺
#define RV_DI_FLIP        7                      //翻转
#define RV_DI_INBOX       8                      //矩形框里面绘制


//用于rvgDrawImageEx
//mold extra type
//
//除了以下几个类型以外，还支持
//RV_DI_DEFAULT, RV_DI_STRETCH,和RV_DI_TILE
//
//平铺默认为2 x 2
#define RV_DI_ISOTROPY    (RV_DI_STRETCH << 8)  //等比例拉伸
#define RV_DI_MIRROR_H    (RV_DI_TILE << 8)      //镜像平铺
#define RV_DI_MIRROR_V    (RV_DI_TILE << 9)      //镜像平铺
#define RV_DI_MIRROR_HV   (RV_DI_TILE << 10)      //镜像平铺
#define RV_DI_CENTER      (RV_DI_ALIGN << 8)
#define RV_DI_FLIP_H      (RV_DI_FLIP << 8)
#define RV_DI_FLIP_V      (RV_DI_FLIP << 9)
#define RV_DI_FLIP_HV     (RV_DI_FLIP << 10)

//mirror type
#define RV_PMT_NONE    0
#define RV_PMT_VERT    1
#define RV_PMT_HORI    2
#define RV_PMT_BOTH    3

//翻转类型
#define RV_PFT_VERT    1
#define RV_PFT_HORI    2
#define RV_PFT_BOTH    3


//subtype for specified method
#define RV_PST_RECT        0x00
#define RV_PST_MASK        0x01
//#define RV_PST_INBOX       0x02


//mold alignment  type
#define RV_MA_TOP          0x01
#define RV_MA_VCENTER      0x02
#define RV_MA_BOTTOM       0x03

#define RV_MA_LEFT         0x01
#define RV_MA_HCENTER      0x02
#define RV_MA_RIGHT        0x03

#define RV_MA_CENTER       0x02

#define RV_IGNORE_COLOR     RV_RGBA(255,255,255,255)

 
 



typedef struct __g_pen_{
   int    size;
   GRgb   color;
   int    style;
}GPen;

typedef struct __g_brush_
{
 	int          size; // default 9
    int          type;
    GRgb         color;
 }GBrush;

typedef struct __g_dock_
{
	GSize srcSize;  //原来的画布大小
	GRect dstRect;  //目标显示区域
}GDock;

//#define RV_MAX_LIGHT_COUNT    8
//
//typedef struct __g_light_{
//	int       flags;
//	RvScalar_f  ambient;
//	RvScalar_f  diffuse;
//	RvScalar_f  specular;
//	RvScalar_f  position;     //位置
//
//	RvScalar_f  direction;    //聚光灯方向
//	RvScalar_f  spotOptions;  //指数，切角
//	RvScalar_f  attenuation;  // 常量衰减因子， 线性衰减因子， 二次衰减因子 
//}GLight;
//
//typedef struct __g_material_{
//	int       flags;
//	float     shininess;
//    RvScalar_f  ambient;
//	RvScalar_f  diffuse;
//	RvScalar_f  specular;
//	RvScalar_f  emission;
//}GMaterial;
//
//typedef struct __g_lighter_
//{
//	BOOL     bLocalViewer;
//	BOOL     bTowSides;
//	int      colorControl;
//	RvScalar_f ambient;
//
//	GMaterial* pMaterial;
//	GLight   * pLightArray[RV_MAX_LIGHT_COUNT];
//}GLighter;

#define RV_MAX_FONT_NAME_LEN   63
/* Font structure */
typedef struct _g_font_
{
	TCHAR   strFaceName[RV_MAX_FONT_NAME_LEN+1] ;  //字体名称
	int     fontSize;   //字体大小
	int     style;  //字体风格：加粗，正常，斜体，等.

	int     refcnt; //引用计数 
	HANDLE  hFontManager;
	 
}GFont;


typedef struct __g_mold_{
    int      type;
	GColor   ignore; //忽略颜色,该参数已经放弃，目前仅保留，

	union {
		int       i32;
		float     f32;
		BOOL      bl;
		RvDim_f  fxy;
		void*     ptr;
	}wParam;

	union{
		int        i32;
		float      f32;
		BOOL       bl;
		void*     ptr;
	}lParam;

  //  DWORD    dwPrime;
  //  DWORD    dwMinor;
}GMold;
 
//rgb COLOR=============================================
inline GRgb GRGB(GByte red, GByte green, GByte blue)
{
	GRgb clr;

	clr.blue =blue; 	clr.green = green; 	clr.red=red; 	clr.alpha=255/*0*/;

	return clr;
}

inline GRgb InvertRgb(GRgb& rgb)
{
	GRgb clr;

	clr.alpha = rgb.alpha;
	clr.blue = 255-rgb.blue;
	clr.green = 255-rgb.green;
	clr.red = 255-rgb.red;

	return clr;
}



#define INV_RGB(color) {       \
	color.blue = 255-color.blue;   \
	color.green = 255-color.green; \
	color.red = 255-color.red;     \
}


//RGB TO TRUE COLOR
inline  BOOL IS_COLOR_SAME(GRgb* pC1, GRgb* pC2)
{
	return ((pC1->red == pC2->red) && (pC1->green == pC2->green) && (pC1->blue == pC2->blue) );
}

inline GDock GDOCK(int srcWidth, int srcHeight, int dstLeft, int dstTop, int dstRight, int dstBottom)
{
	GDock d;
	d.srcSize.w = srcWidth;
	d.srcSize.h = srcHeight;

	d.dstRect.left = dstLeft;
	d.dstRect.right = dstRight;
	d.dstRect.top = dstTop;
	d.dstRect.bottom = dstBottom;

	return d;
}


//brush=====================================================
extern "C" GBrush* XGUI_API  rvgCreateBrush(int type=RV_BT_SOLID, int size=9,  GRgb color=GRGB(255,0,0) );
extern "C" void    XGUI_API  rvgDestroyBrush(GBrush* pBrush);

 


//pen ====================================================
inline GPen GPEN( GRgb color=GDC_BLACK,  int size=1, int style = RV_PS_SOLID)
{
	
	GPen p;

	p.color =color; 	p.style = style;	p.size =size;  

	return p;
};


//rect ========================================================
inline GRect GRECT(int left , int top , int right , int bottom ){
	GRect r;
	r.left =left;
	r.right =right;
	r.top =top;
	r.bottom = bottom;
	return r;
}

//inline GRect GRECT(GRect peer){
//
//	return GRECT(peer.left , peer.top, peer.right , peer.bottom );
//}


inline GRect GRECT(GPoint p1, GPoint p2,GPoint p3){
	GPoint lt, rb;
	
	lt.x =RV_MIN( RV_MIN(p1.x, p2.x), p3.x);
 	lt.y =RV_MIN( RV_MIN(p1.y, p2.y), p3.y);
   
	rb.x =RV_MAX( RV_MAX(p1.x, p2.x), p3.x);
 	rb.y =RV_MAX( RV_MAX(p1.y, p2.y), p3.y);
 
	return GRECT(lt.x, lt.y ,rb.x ,rb.y ); 
}

inline GRect GRECT(GPoint leftTop, GPoint rightBottom){
	return GRECT(leftTop.x, leftTop.y ,rightBottom.x ,rightBottom.y ); 
}

inline GSize GSIZE(int sx, int sy){
	GSize sz ={sx, sy};
    return sz;
}

inline GBrush  GBRUSH(int type , int size,   GRgb color)
{
 
	
	GBrush b;
 

	if (size < 3) size =3;
	if (size > 64) size =64;
 
	b.type = type;

	b.size = size / 2 * 2 +1;  
	b.color =color;
 
	return b;
 

} 

extern "C" GPen* XGUI_API rvgCreatePen( GRgb color=GDC_BLACK,int size=1, int style = RV_PS_SOLID  );

extern "C" void XGUI_API rvgDestroyPen(GPen* pPen);

//point ==============================================
inline GPoint GPOINT(int x =0, int y=0 )
{
	 
	GPoint p;
	p.x =x; p.y=y;
	return p;
};

#define GPNT_CVT   GPoint p; \
                   p.x =(int)(x+0.5f); p.y=(int)(y+0.5f); \
                   return p;


inline GPoint GPOINT(double x, double y)
{
     GPNT_CVT
}
inline GPoint GPOINT(float x, double y)
{
     GPNT_CVT
}
inline GPoint GPOINT(double x, float y){
     GPNT_CVT
}


inline GPoint GPOINT(float x, float y)
{
     GPNT_CVT
}

inline GPoint GPOINT(double x, int y){
	GPNT_CVT
}
inline GPoint GPOINT(float x, int y)
{
	GPNT_CVT;
}

inline GPoint GPOINT(int x, float y)
{
	GPNT_CVT;
}
inline GPoint GPOINT(int x, double y){
	GPNT_CVT;
}
 

inline RvPoint RPOINT(GPoint  self){
	RvPoint p;

	p.x = self.x; p.y= self.y ;

 	return p;
}

inline GPoint  GPOINT(RvPoint point){
	return GPOINT(point.x, point.y);
}

inline RvPoint_f RPOINT_F(GPoint  self){
	RvPoint_f p;

	p.x = (float)self.x; p.y= (float)self.y ;

	return p;
}


inline GPoint  GPOINT(RvPoint_f point){
	return GPOINT((int)point.x , (int)point.y );
}
 
 

#define GPOINT_MINUS(p1, p2)   (p1).x -=(p2).x; (p1).y -= (p2).y;
#define GPOINT_PLUS(p1, p2)    p1.x +=p2.x; p1.y += p2.y;
 
#define GPOINT_IS_EQUEAL(p1, p2)  ((p1).x == (p2).x && (p1).y == (p2).y) 

 

//generic GUI functions ===================================================

//
//创建GDC可能失败的原因:
//1  没有licence.dvl文件，或许可文件过期，失效
//2  opengl(directx9)初始化失败
//3  创建画布失败
//4  传入无效的hwnd
//5  创建DSM等对象失败
//
// opengl 1.1需要画布大小为2的n次方
extern "C" HGDC  XGUI_API  rvgCreateContext(HWND hWnd, int width=-1, int height=-1, RV_CONTEXT_TYPE type = RV_CT_GENERIC, BOOL bFullScreen = FALSE);
#define    rvInitGC(hWnd, width, height, type)  rvgCreateContext(hWnd, width, height, type, FALSE) 

//上层程序在应在窗口销毁之前，调用rvgDestroyContext。
//否则会陷入死循环,造成死锁。虽然不是所有操作系统都如此，
//但还是强烈建议在窗口销毁之前，释放HGDC。
extern "C" void  XGUI_API   rvgDestroyContext(HGDC dc);
#define    rvReleaseGC(dc)  rvgDestroyContext(dc) 
 
extern "C" void XGUI_API  rvgSetDrawStyle(HGDC dc, int flag);
extern "C" int  XGUI_API  rvgGetDrawStyle(HGDC dc);
 


//XGUI_API void  rvgUpdate(HGDC dc);
extern "C" void XGUI_API  rvgClear(HGDC dc, int layers = RV_ALL_LAYER, BOOL bRefresh=FALSE);

extern "C" void XGUI_API  rvgErase(HGDC dc, RV_HANDLE hStroke, int flag = RV_ET_SHADOW, BOOL bRefresh=FALSE);

extern "C" void XGUI_API  rvgRealize(HGDC dc , int layers = RV_ALL_LAYER , BOOL bRefresh=FALSE);

extern "C" BOOL XGUI_API  rvgFlush(HGDC dc/*, BOOL bRefresh=FALSE*/);
 
 //extern "C" RvImage XGUI_API  rvgExport(HGDC dc, RvImage image=NULL);

extern "C" void XGUI_API  rvgArrangeText(HGDC dc, int charSpace, int lineGap);

//0, 0.1, 0.01, 0.001, etc
extern "C" void XGUI_API   rvgSetGraphAccuracy(HGDC dc, float accuracy);
extern "C" float XGUI_API  rvgGetGraphAccuracy(HGDC dc);




//specific can be set as index of graphical objects in the stroke
//
//if type is RV_MT_IMAGE,  RvImge, const RvImage
//if type is RV_MT_TEXT,  const TCHAR*, TCHAR*
//if type is RV_MT_COLOR, dwParam should be  GColor 
//
//透明度 范围: 0 -> 100
extern "C" void XGUI_API  rvgModify(HGDC dc, RV_HANDLE hStroke, int type , DWORD value, BOOL bRefresh=FALSE);

//移动画笔
extern "C" void XGUI_API  rvgOffset(HGDC dc, RV_HANDLE hStroke, float dx, float dy, BOOL bRefresh=FALSE);

//隐藏画笔
extern "C" void XGUI_API  rvgHide(HGDC dc, RV_HANDLE hStroke,  BOOL flag,  BOOL bRefresh=FALSE);


	

//免费版不能隐藏RVB图标 since v5.1
extern "C" void XGUI_API  rvgSetRvbLogoVisible(HGDC dc, BOOL flag);

extern "C" BOOL XGUI_API  rvgIsRvbLogoVisible(HGDC dc );

extern "C" void XGUI_API  rvgSetRvbLogoAlignment(HGDC dc, int alignment);
extern "C" int  XGUI_API  rvgGetRvbLogoAlignment(HGDC dc );

 
extern "C" RV_CONTEXT_TYPE  XGUI_API  rvgGetContextType(HGDC dc );
//extern "C" RV_ORIGIN_TYPE  XGUI_API  rvgGetOriginType(HGDC dc );
extern "C" BOOL  XGUI_API  rvgIsFullScreen(HGDC dc );


//extern "C" RV_HANDLE XGUI_API rvgGetDevice(HGDC dc);
//窗口实际区域
extern "C" GRect XGUI_API rvgGetDisplayRect(HGDC dc);

//画布在窗口中的有效区域（不是实际画布大小，是窗口中画布可见的大小），可能小于窗口区域
extern "C" GRect XGUI_API rvgGetClientRect(HGDC dc);

extern "C" void XGUI_API  rvgResizeDisplayRect(HGDC dc, int width, int height, BOOL bRefresh);


//extern "C" BOOL XGUI_API  rvgIsContextNormal(HGDC dc);
//extern "C" BOOL XGUI_API  rvgTryRestoreContext(HGDC dc);
//extern "C" HCANVAS XGUI_API  rvgGetCanvas(HGDC dc);

// opengl 1.1需要画布大小为2的n次方
extern "C" BOOL XGUI_API rvgSetCanvasSizeEx(HGDC dc, RvSize size, BOOL    bRefresh=FALSE);
extern "C" BOOL XGUI_API rvgSetCanvasSize(HGDC dc, int width, int height, BOOL    bRefresh=FALSE);

//深度目前仅支持8,24,32
extern "C" BOOL XGUI_API rvgSetCanvasDepth(HGDC dc, int depth, BOOL  bRefresh=FALSE);
extern "C" int XGUI_API rvgGetCanvasDepth(HGDC dc );


extern "C" int XGUI_API rvgGetCanvasWidth(HGDC dc );
extern "C" int XGUI_API rvgGetCanvasHeight(HGDC dc  );

extern "C" RvSize XGUI_API rvgGetCanvasSize(HGDC dc);



extern "C" void XGUI_API   rvgSetBlankColor(HGDC dc, GRgb color);
extern "C" GRgb  XGUI_API  rvgGetBlankColor(HGDC dc );

//有空白背景图优先空白背景图，否则使用空白颜色填充
extern "C" void XGUI_API   rvgSetBlankImage(HGDC dc, const RvImage image);
//外部不可释放返回的RvImage
extern "C" const RvImage  XGUI_API  rvgGetBlankImage(HGDC dc );
 
//放大后视图位置
extern "C" void  XGUI_API  rvgSetViewPos(HGDC dc, int x, int y, BOOL bRefresh=TRUE);
extern "C" GPoint XGUI_API rvgGetViewPos(HGDC dc );

//显示层的左上角点
extern "C" void   XGUI_API  rvgSetDisplayLeftTop(HGDC dc , int x, int y);
extern "C" GPoint XGUI_API  rvgGetDisplayLeftTop(HGDC dc );
 


extern "C" void  XGUI_API  rvgGetViewDelta(HGDC dc, int* dx, int* dy);
extern "C" GSize XGUI_API  rvgGetViewDeltaEx(HGDC dc);
 
//设置字符是否可以按照视图缩放
//extern "C" void  XGUI_API  rvgSetFontScalable(HGDC dc, BOOL flag);
//extern "C" BOOL XGUI_API   rvgIsFontScalable(HGDC dc);

//比例范围: 0.1 ~ 8.0
//比例设置因该在视图模式（rvgSetViewMode）更改对应的模式以后进行
//否则，可能引起混乱，无法得到正确结果
extern "C" void XGUI_API       rvgSetViewScale(HGDC dc, float scale, BOOL bScaleY = FALSE);
extern "C"   void   XGUI_API   rvgSetViewScaleEx(HGDC dc, float scaleX, float scaleY );
extern "C" float XGUI_API  rvgGetViewScale(HGDC dc, BOOL bScaleY=FALSE);
extern "C" void  XGUI_API  rvgGetViewScaleEx(HGDC dc, float* pScaleX, float* pScaleY);


extern "C" void XGUI_API   rvgSetViewRect(HGDC dc, GRect rect);
//可以看到的画布区域（不是实际的可见画布大小，可能放大或缩小）
extern "C" GRect XGUI_API  rvgGetViewRect(HGDC dc);
extern "C" GSize XGUI_API  rvgGetViewSize(HGDC dc);



extern "C" void          XGUI_API  rvgSetViewMode(HGDC dc, RV_VIEW_MODE mode );
extern "C" void          XGUI_API  rvgSetViewModeEx(HGDC dc, RV_VIEW_MODE mode, void* pParam = NULL);
extern "C" RV_VIEW_MODE  XGUI_API  rvgGetViewMode(HGDC dc);


extern "C" void XGUI_API rvgMoveTo(HGDC dc, int x, int y);
extern "C" void XGUI_API rvgMoveToEx(HGDC dc, GPoint pos);

extern "C" void  XGUI_API  rvgLineTo(HGDC dc, int x, int y );
extern "C" void XGUI_API   rvgLineToEx(HGDC dc, GPoint pos );

//graphical shapes//
extern "C" RV_HANDLE XGUI_API rvgDrawRectEx(HGDC dc, float left, float top, float right, float bottom,    float rotate,BOOL bFill=FALSE, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawRectE1(HGDC dc, int left, int top, int right, int bottom,  float rotate,BOOL bFill=FALSE, RV_HANDLE hStroke=NULL);
 

extern "C" RV_HANDLE XGUI_API rvgDrawRect(HGDC dc, int left, int top, int right, int bottom, BOOL bFill=FALSE, RV_HANDLE hStroke=NULL);
 

 

extern "C" RV_HANDLE XGUI_API  rvgDrawLine(HGDC dc, int x0, int y0, int x1, int y1, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API  rvgDrawLineEx(HGDC dc, GPoint p0, GPoint p1, RV_HANDLE hStroke=NULL);

extern "C" RV_HANDLE XGUI_API rvgDrawPoint(HGDC dc, int x , int y, RV_HANDLE hStroke=NULL );
extern "C" RV_HANDLE XGUI_API rvgDrawPointEx(HGDC dc, GPoint pos, RV_HANDLE hStroke=NULL);

extern "C" RV_HANDLE XGUI_API rvgDrawCircle(HGDC dc,  int x0, int y0,   int radius,  BOOL bFill, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawCircleEx(HGDC dc,  GPoint center,   int radius,  BOOL bFill, RV_HANDLE hStroke=NULL);


extern "C" RV_HANDLE XGUI_API rvgDrawEllipse(HGDC dc,  int x0, int y0,   int rx, int ry, float angle=0.0f,  BOOL bFill=FALSE, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawEllipseEx(HGDC dc,  GPoint center,   int rx, int ry, float angle=0.0f, BOOL bFill=FALSE, RV_HANDLE hStroke=NULL);

//画十字线
extern "C" RV_HANDLE XGUI_API rvgDrawCross(HGDC dc,  int cx, int cy,   int sx, int sy, float angle=0.0f,RV_HANDLE hStroke=NULL);
//画等边三角形
extern "C" RV_HANDLE XGUI_API rvgDrawTriangle(HGDC dc,  int cx, int cy,   int size, float angle=0.0f, BOOL bFill= FALSE, RV_HANDLE hStroke=NULL);



extern "C" RV_HANDLE XGUI_API rvgDrawArcEx(HGDC dc,  GPoint center,  int radius, float startAngle, float endAngle, BOOL bSector = FALSE, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawArc(HGDC dc,  int x0, int y0,  int radius, float startAngle, float endAngle, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawPolygon (HGDC dc,  const GPoint* pVertexSet , int nVertexCount,   BOOL bFill, RV_HANDLE hStroke=NULL) ;
extern "C" RV_HANDLE XGUI_API rvgDrawPolyline (HGDC dc,  const GPoint* pVertexSet , int nVertexCount,  RV_HANDLE hStroke=NULL);


//float type 
extern "C" RV_HANDLE XGUI_API rvgDrawPolylineE1 (HGDC dc,  const RvPoint_f* pVertexSet , int nVertexCount,  RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawPolygonE1 (HGDC dc,  const RvPoint_f* pVertexSet , int nVertexCount,   BOOL bFill, RV_HANDLE hStroke ) ;
extern "C" RV_HANDLE XGUI_API rvgDrawLineE1(HGDC dc, float x0, float y0, float x1, float y1, RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawArcE1(HGDC dc,  float cx, float cy,  float radius, float startAngle, float endAngle, RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawCircleE1(HGDC dc,  float cx, float cy,   float radius,  BOOL bFill, RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawDotsE1(HGDC dc, RvPoint_f* pPointArray , int nPointCount,  RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawSegmentsE1(HGDC dc, RvPoint_f* pPointArray , int nPointCount,  RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawCrossE1(HGDC dc,  float cx, float cy,   float sx, float sy, float angle , RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawPointE1(HGDC dc,  float x, float y   , RV_HANDLE hStroke );
extern "C" RV_HANDLE XGUI_API rvgDrawEllipseE1(HGDC dc,  float cx, float cy,   float rx, float ry, float angle ,  BOOL bFill , RV_HANDLE hStroke );


//如pRect为NULL, nFormat将自动忽略
extern "C" RV_HANDLE XGUI_API rvgDrawTextEx(HGDC dc,  const TCHAR* strText,  int nCount=-1, int nFormat = RV_DT_DEFAULT, GRect* pRect=NULL,   RV_HANDLE hStroke=NULL );

extern "C" RV_HANDLE XGUI_API  rvgDrawText(HGDC dc, const TCHAR* strText,  int x , int y ,  RV_HANDLE hStroke=NULL );
extern "C" RV_HANDLE XGUI_API  rvgDrawTextE1(HGDC dc, const TCHAR* strText,  int dx , int dy , GRect rect, RV_HANDLE hStroke=NULL );


extern "C" GSize  XGUI_API  rvgGetTextSize(HGDC dc,  const TCHAR* strText, int count =-1 );
extern "C" void   XGUI_API  rvgTextOut(HGDC dc, const TCHAR* strText );

extern "C" RV_HANDLE XGUI_API rvgDrawImage(HGDC dc, const RvImage image, int x=0, int y=0, int width=-1, int height=-1, RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawImageEx(HGDC dc, const RvImage image, int moldType = RV_DI_STRETCH, GRect* pRect=NULL,  RV_HANDLE hStroke=NULL);

extern "C" RV_HANDLE XGUI_API rvgDrawImageE1(HGDC dc, const RvImage image, RvPoint_f  vertexArray[4], RV_HANDLE hStroke=NULL);
extern "C" RV_HANDLE XGUI_API rvgDrawImageE2(HGDC dc, const RvImage image, int x, int y, GRect rect,  RV_HANDLE hStroke=NULL);


 
 extern "C" RV_HANDLE XGUI_API rvgDrawMask(HGDC dc, RvMask mask,   int x=0, int y=0 , RV_HANDLE hStroke=NULL);
 
 extern "C" RV_HANDLE XGUI_API rvgDrawMaskEx(HGDC dc, RvMask mask, RvFloat offsetx, RvFloat offsety,    RvFloat angle, RV_HANDLE hStroke=NULL);

extern "C" RV_HANDLE XGUI_API rvgDrawMatrix(HGDC dc, const RvMatrix matrix , RV_HANDLE hStroke=NULL);


extern "C" RV_HANDLE XGUI_API rvgDrawBlob(HGDC dc, const RvBlob blob,int x=0, int y=0,  GRgb foreColor = GRGB(255,255,255), GRgb backColor = GRGB(0,0,0),  RV_HANDLE hStroke=NULL);

extern "C" RV_HANDLE XGUI_API rvgDrawContour(HGDC dc, const RvContour contour,int x=0, int y=0,  RV_HANDLE hStroke=NULL);



//绘制多个的点
extern "C" RV_HANDLE XGUI_API rvgDrawDots(HGDC dc, GPoint* pPointArray , int nPointCount,  RV_HANDLE hStroke=NULL);

//绘制多个非连续的线段,每条线段使用两个点（GPoint）
extern "C" RV_HANDLE XGUI_API rvgDrawSegments(HGDC dc, GPoint* pPointArray , int nPointCount,  RV_HANDLE hStroke=NULL);



//绘制多个非连续的填充三角形,每条三角形需要使用三个点（GPoint），不同类型的三角形，需要的点数量不一样
//
#define RV_DT_SEPARATE    0
#define RV_DT_FAN         1
#define RV_DT_STRIP       2
extern "C" RV_HANDLE XGUI_API rvgDrawTriangles(HGDC dc, GPoint* pPointArray , int nPointCount, int type = RV_DT_SEPARATE,  RV_HANDLE hStroke=NULL);

extern "C" RV_HANDLE XGUI_API rvgDrawBox2D(HGDC dc, RvBox2D box, int dx, int dy,  RV_HANDLE hStroke=NULL);


//绘制哑元对象，有笔画对象产生，但无实际绘制。
extern "C" RV_HANDLE XGUI_API rvgDrawDummy(HGDC dc, RV_HANDLE hStroke=NULL);
 
//以下函数没有更新，慎用@240130
extern "C" void XGUI_API  rvgBitBlt(HGDC dc, const RvImage image, int canvasLeft=0 , int canvasTop=0 , int canvasWidth=-1 , int canvasHeight=-1, int imageLeft=0  , int imageTop=0 , int imageWidth=-1, int imageHeight=-1, GColor ignore =-1);
extern "C" void XGUI_API  rvgPaintImage(HGDC dc, const RvImage image, int align=RV_PI_DEFAULT);
extern "C" void XGUI_API  rvgPaintImageEx(HGDC dc, const RvImage image, int left=0, int top=0, const RvMask mask=NULL);
//end of @240130
 
 
//该函数主要用于实时图像显示,多线程可以。
extern "C" BOOL XGUI_API  rvgFeedFrame(HGDC dc, const RvImage image );

//速度更快,仅限于在界面线程下调用,非UI线程会产生其它意象不到的异常。
extern "C" BOOL XGUI_API  rvgDirectFeed(HGDC dc, const RvImage image );

extern "C" BOOL XGUI_API  rvgIsFrameFed(HGDC dc );
extern "C" BOOL XGUI_API  rvgHasNewFrame(HGDC dc );


 //仅支持RV_CT_ENHANCED画布@240130
extern "C" BOOL XGUI_API  rvgGetFramePixel(HGDC dc, int x, int y, RvRgb*  pColor);
extern "C" BOOL XGUI_API  rvgGetCurFrame(HGDC dc, RvImage image);
//End of @240130

 
//"Arial" , 12, RV_RGB(0,0,0), RV_RGB(255,255,255), RV_FS_DEFAULT
extern "C" GFont* XGUI_API rvgCreateFont(/*HGDC dc,*/ const TCHAR* strFaceName, int size, /*GColor textColor, GColor backColor, */ int flags );
extern "C" void XGUI_API   rvgDestroyFont(GFont* pFont);


extern "C" GPen*    XGUI_API  rvgGetCurPen(HGDC dc);
extern "C" GBrush*  XGUI_API  rvgGetCurBrush(HGDC dc);
extern "C" GFont*   XGUI_API  rvgGetCurFont(HGDC dc);
extern "C" GMold*   XGUI_API  rvgGetCurMold(HGDC dc);
//extern "C" GLighter*   XGUI_API  rvgGetCurLight(HGDC dc);




//drawing objects
extern "C" GPen*    XGUI_API  rvgSelectPen(HGDC dc, GPen *pPen);
extern "C" GBrush* XGUI_API   rvgSelectBrush(HGDC dc, GBrush *pBrush);
extern "C" GFont* XGUI_API    rvgSelectFont(HGDC dc, GFont *pFont);
extern "C" GMold*   XGUI_API rvgSelectMold(HGDC dc, GMold* pModel);
 
//extern "C" GLighter*  XGUI_API rvgSelectLighter(HGDC dc, GLighter* pModel);
 
extern "C" int    XGUI_API    rvgSetCurrentLayer(HGDC dc, int nLayer  );
extern "C" int    XGUI_API     rvgGetCurrentLayer(HGDC dc);

//透明度在0~1之间, 0表示不透明， 1表示全透明
extern "C" float XGUI_API  rvgSetTrasparence(HGDC self, float rate);
extern "C" float XGUI_API rvgGetTrasparence(HGDC self  );

 extern "C" GDock* XGUI_API   rvgSetDock(HGDC self, GDock* pDock);
 extern "C" GDock*  XGUI_API  rvgGetDock(HGDC self);



//canvas ==================================================
//extern "C" HCANVAS XGUI_API rvgCreateCanvas(HGDC dc, RV_CANVAS_TYPE type, GColor backColor, int width, int height);
//extern "C" HCANVAS XGUI_API rvgCreateCanvasEx(HGDC dc,   RV_CANVAS_TYPE type,  GColor backColor,   const RvImage image);

//extern "C" void XGUI_API rvgDestroyCanvas(HCANVAS canvas);

 extern "C" void XGUI_API rvgResetCanvas(HGDC dc, BOOL bRefresh = FALSE );

extern "C" void XGUI_API   rvgSetCanvasBackColor(HGDC dc , GColor color);
extern "C" GColor XGUI_API rvgGetCanvasBackColor(HGDC dc  );

extern "C" void XGUI_API   rvgSetCanvasBackStyle(HGDC dc , int style);
extern "C" int  XGUI_API   rvgGetCanvasBackStyle(HGDC dc);

extern "C" void XGUI_API     rvgSetCanvasGridSize(HGDC dc , int sx, int sy);
extern "C" RvSize  XGUI_API  rvgGetCanvasGridSize(HGDC dc);


extern "C" RvImage XGUI_API rvgExportCanvas(HGDC dc, RvImage image);




//获得GL版本，版本由主版本和次版本组成，格式为 (main_version << 16) | sub_version
//即前两字节为主版本，后两字节为次版本。
extern "C" int XGUI_API rvgGetDriverVersion(HGDC dc);




//extern "C" BOOL XGUI_API rvgResizeCanvas(HGDC dc , int width, int height, BOOL bCleaned =TRUE);


 
#define     RV_LP_AMBIENT      0x0001
#define  	RV_LP_DIFFUSE      0x0002
#define  	RV_LP_SPECULAR     0x0004
#define  	RV_LP_POSITION     0x0008
#define  	RV_LP_DIRECTION    0x0010
#define  	RV_LP_SPOT         0x0020
#define  	RV_LP_ATTENUATION  0x0040 
 
//APIs for light model
//extern "C" GLight * XGUI_API  rvgCreateLight();
//extern "C" void  XGUI_API    rvgDestroyLight(GLight * pLight);
//
//extern "C" void  XGUI_API    rvgSetLightProperty(GLight * pLight, int name, RvScalar_f value);
//extern "C" void  XGUI_API    rvgSetLightMask(GLight * pLight, int mask = 0);
//
//
//extern "C" GMaterial* XGUI_API  rvgCreateMaterial();
//extern "C" void  XGUI_API       rvgDestroyMaterial(GMaterial* pMaterial);


// 
#define     RV_MP_SHININESS  0x0001
#define  	RV_MP_AMBIENT    0x0002
#define  	RV_MP_DIFFUSE    0x0004
#define  	RV_MP_SPECULAR   0x0008
#define  	RV_MP_EMISSION    0x0010 
//
//extern "C" void  XGUI_API    rvgSetMaterialProperty(GMaterial* pMaterial, int name, RvScalar_f value);
//extern "C" void  XGUI_API    rvgSetMaterialMask(GMaterial* pMaterial, int mask =0);


#define RV_SINGLE_COLOR    0
#define RV_SPECULAR_COLOR  1

//extern "C" GLighter* XGUI_API  rvgCreateLighter();
//extern "C" GLighter* XGUI_API  rvgCreateLighterEx(RvScalar_f ambient, BOOL bLocalViewer, BOOL bTwoSides, int colorControl);
//
//extern "C" void  XGUI_API      rvgDestroyLighter(GLighter* pLighter);
//
//extern "C" void XGUI_API  rvgAddLight(GLighter* pModel, int index, GLight* pLight);
//extern "C" void XGUI_API  rvgRemoveLight(GLighter* pModel, int index);
//
//extern "C" void  XGUI_API  rvgDeclareMaterial(GLighter* pModel, GMaterial* pMaterrial );

//表面相关
extern "C" void  XGUI_API  rvgSetSurfaceSize(HGDC dc, int size );
extern "C" int   XGUI_API  rvgGetSurfaceSize(HGDC dc );

extern "C" int   XGUI_API  rvgGetMaxSurfaceSize(HGDC dc );

  

 
 

extern "C" GMold* XGUI_API rvgCreateMold(int type,   GColor ignore=-1, DWORD dwPrime=0, DWORD dwMinor=0);

extern "C" void XGUI_API  rvgDestroyMold(GMold* pMold);


 
//坐标转换： canvas坐标到display坐标, 或反向转换，坐标以整数表示。
//layer为原值所在层
extern "C" int XGUI_API  rvgConvertXToDisplay(HGDC dc , int layer,   int value  );
extern "C" int XGUI_API  rvgConvertYToDisplay(HGDC dc , int layer,  int value  );

//保证精度
extern "C" double XGUI_API  rvgConvertXToDisplayE1(HGDC dc , int layer,   double value  );
extern "C" double XGUI_API  rvgConvertYToDisplayE1(HGDC dc , int layer,   double value  );


extern "C" GPoint XGUI_API  rvgConvertPointToDisplay(HGDC dc , int layer, int x , int y);
extern "C" GPoint XGUI_API  rvgConvertPointToDisplayEx(HGDC dc , int layer, GPoint* pPoint);
extern "C" GRect  XGUI_API  rvgConvertRectToDisplay(HGDC dc , int layer, int left, int top, int right, int bottom);
extern "C" GRect  XGUI_API  rvgConvertRectToDisplayEx(HGDC dc ,  int layer, GRect* pRect);

extern "C" RvPoint_f XGUI_API  rvgConvertPointToDisplayE1(HGDC dc , int layer, float x , float y);



//layer为原值所在层
extern "C" int XGUI_API   rvgConvertXToCanvas(HGDC dc , int layer, int value  );
extern "C" int XGUI_API   rvgConvertYToCanvas(HGDC dc , int layer, int value  );

//高精度转换
extern "C" double XGUI_API   rvgConvertXToCanvasE1(HGDC dc , int layer, double value  );
extern "C" double XGUI_API   rvgConvertYToCanvasE1(HGDC dc , int layer, double value  );

extern "C" GPoint XGUI_API  rvgConvertPointToCanvas(HGDC dc , int layer, int x , int y);
extern "C" RvPoint_f XGUI_API  rvgConvertPointToCanvasE1(HGDC dc , int layer, float x , float y);


extern "C" GPoint XGUI_API  rvgConvertPointToCanvasEx(HGDC dc , int layer, GPoint* pPoint);
extern "C" GRect  XGUI_API  rvgConvertRectToCanvas(HGDC dc , int layer, int left, int top, int right, int bottom);
extern "C" GRect  XGUI_API  rvgConvertRectToCanvasEx(HGDC dc , int layer,  GRect* pRect);


//combined strokes, 同时删除原来数组中单个笔画对象。
extern "C" RV_HANDLE XGUI_API rvgCombine(HGDC dc, RV_HANDLE* hStrokeArray, int nStrokeCount/*, RV_HANDLE hResult*/);

//拆分联合的 strokes成独立单个的stroke（输出到hResultArray）,
//如果成功，删除原来的stroke
extern "C" int XGUI_API rvgUncombine(HGDC dc, RV_HANDLE hStroke, RV_HANDLE* hResultArray, int nArraySize/*,BOOL bCreateDummy=FALSE, BOOL bEraseOriginal = FALSE*/);


BOOL XGUI_API rvgAuthorize(const TCHAR* strFilePath, const TCHAR* strAppName , const TCHAR* strLicence );
BOOL XGUI_API rvgIsAuthorized();



#endif
