#ifndef __RV_REAL_VIEW_H_INCLUDED_
#define __RV_REAL_VIEW_H_INCLUDED_

#ifdef RVIEW_EXPORTS
#define RVIEW_API __declspec(dllexport)
#else
#define RVIEW_API __declspec(dllimport)
#endif

#include <sst\WindowDelegate.h>
#include <sst\ucb.h>

#include <indx\Mark.h>
#include <indx\Label.h>



//event id(tag)
//#define RV_EID_CLICK               0x0001
//#define RV_EID_DOUBLE_CLICK        0x0002
//#define RV_EID_DEVICELOST          0x0003
//#define RV_EID_MOUSE_ENTER         0x0004
//#define RV_EID_MOUSE_LEAVE         0x8004
//#define RV_EID_RBUTTON_CLICK       0x0005
//#define RV_EID_CHECKBOX_CHANGED    0x0006
//#define RV_EID_SELECTION_CHANGED   0x0007
//#define RV_EID_RADIOBUTTON_CHANGED 0x0008

//选择改变
#define RV_EID_UC_HIT                 0x0080
#define RV_EID_UC_UNHIT               0x0081

 


//designer windows events
//#define RV_EID_WINDOW_MAXIMIZED       0x0030 
//#define RV_EID_WINDOW_TIMER           0x0031
//#define RV_EID_WINDOW_MOUSE_MOVE      0x0032
 
//计时器ID
#define RV_TIMER_ID   0

class RVIEW_API CRealView: public CWindowDelegate
{
public:
	 
	enum CANVAS_TYPE{
	    CT_DEFAULT = RV_CT_GENERIC,
		CT_ENHANCE = RV_CT_ENHANCED,
	};

	enum WINDOW_STYLE{
	    RV_WS_CHILD = 1,
		RV_WS_BORDER = (1<<1) ,
		RV_WS_CLIP   = (1<<2) , 
	};

	//某些显卡或操作系统下,opengl绘制的图可能会丢失，
	//这样需要不断刷新对应的窗口。
	enum REDRAW_TYPE{
		RT_DEFAULT = 0,  //默认，窗口模式, window10或高性能显卡可以使用该模式
		RT_TIMER,        //时钟定时刷新,用于刷新帧图像，自动刷新模式，低性能显卡需要该模式刷新
		RT_MANUAL,       //手动刷新， 外部应用程序控制刷新
	};

	enum USER_CURSOR
	{
		UC_IGNORE  = -1,
		UC_PENTIP,     //笔尖
		UC_TAR_S,      //方形目标
		UC_TAR_R,      //圆形目标
		UC_DIVIDER,      //动态十字线  
		UC_RULER_H,    //水平线  
		UC_RULER_V,      //垂直线
		UC_RULER_HV,      //十字线
		UC_IMAGE,        //任意图象文件
		UC_CROSS = 11,   //静态十字线
		UC_CROSS_R ,     //十字线+圆
	    UC_CROSS_S,      //十字线+方
		UC_TRIANGLE=21,  //动态三角形(等边)
	};

	enum LINE_TYPE{
		LT_SOLID = RV_PS_SOLID,
		LT_HIDDEN = RV_PS_HIDDEN,
		LT_CENTER = RV_PS_CENTER,
		LT_INCLUSION = RV_PS_INCLUSION,
	};

	enum PIXBAR_TYPE{
	     PB_DEFAULT =0, //像素值
		 PB_TIMESTAMP,  //时间戳
		 PB_CUSTOM,     //自定义
	};

	CRealView(void);
	virtual ~CRealView(void);


	//create函数仅仅调用CreateEx，
	//重载的时候需要注意，以免创建出错。
	virtual BOOL Create(HWND hParentWnd, const TCHAR* strWindowName , int sightWidth , int sightHeight , GRect& rect);
	virtual BOOL CreateEx(HWND hParentWnd, GRect rect, RV_IMAGE_TYPE imageType=RIT_RGB, int sightWidth=-1, int sightHeight=-1, \
		                   CANVAS_TYPE canvasType = CT_DEFAULT , int style =RV_UCS_BORDER, TCHAR* strWindowName =  "unnamed" );

	virtual void Destroy();
 
	//一般情况下，如果需要更新pixelbar或user cursor的绘制，请使用REDRAW.
	virtual void Refresh(REFRESH_TYPE type);

	 //移动窗口
	 virtual void SetDisplayRect(int left, int top, int width, int height,  BOOL bRefresh= FALSE);
	
	 //不移动窗口
	 virtual void SetDisplaySize( int width, int height,  BOOL bRefresh= FALSE);

	void SetUserCursorType(USER_CURSOR cursorType, BOOL bRefresh=FALSE);
	int  GetUserCursorType();

	void SetUserCursorSize(GSize size,  BOOL bRefresh=FALSE);
	GSize GetUserCursorSize();

	//0-100，数字越大越透明
	void SetUserCursorTransparence(int ratio,  BOOL bRefresh=FALSE);
	int  GetUserCursorTransparence();

	void SetUserCursorColor(GRgb color,   BOOL bRefresh=FALSE);
	GRgb GetUserCursorColor();

	//线型：实线，虚线，中心线，双点划线
	int  GetUserCursorLineType();
	void SetUserCursorLineType(LINE_TYPE lineType, BOOL bRefresh= FALSE);

	//线宽：1-5
	int  GetUserCursorThickness();
	void SetUserCursorThickness(int thickness, BOOL bRefresh= FALSE);

	void SetUserCursorImage(const RvImage image, BOOL bRefresh=FALSE);

	void SetPixelBarFontSize(int size, BOOL bRefresh=FALSE);
	int  GetPixelBarLabelFontSize();

	//0-100，数字越大越透明
	void SetPixelBarTransparence(int ratio,  BOOL bRefresh=FALSE);
	int  GetPixelBarTransparence();

	void SetPixelBarColor(GRgb color,   BOOL bRefresh=FALSE);
	GRgb GetPixelBarColor();

	void SetPixelBarVisible(BOOL flag, BOOL bRefresh=FALSE );
	BOOL IsPixelBarVisible();

	void SetPixelBarType(PIXBAR_TYPE type, BOOL bRefresh=FALSE);
	int  GetPixelBarType(PIXBAR_TYPE type );

	void SetPixelBarText(const TCHAR* strText,  BOOL bRefresh=FALSE);

	CLabel* GetPixelBarUc(){ return &m_pixelBar; }
	CMark* GetUserCursorUc() { return &m_userCursor;}
	
	int  GetRedrawType();

	//rate：显示速率,每秒多少帧
	void SetRedrawType(int type, int rate=25);

	//保留
	BOOL  ModifyWindowStyle(int adds, int dels);

public:
  
	//overridable
	//处理窗口系统事件。
	virtual BOOL MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam , LRESULT* pResult);
	 
protected:
	//FOR INternale use only
	BOOL ProcRuntimeMsg(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	BOOL ProcDesignMsg(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
 
	void DrawUserCursor(HGDC dc, BOOL bForce =TRUE);
	void DrawPixelBar(HGDC dc,  BOOL bForce = TRUE);
	 
	//窗口尺寸发生变换时，相应的重新调整cursor尺寸
	void ResizeUserCursor();

	//表示mouse正在窗口上方移动。
	BOOL m_bMouseOverWindow;

	//BOOL m_bViewUpdatedOnMsg;
	
    int   m_nRedrawType;

	
protected:
	 
	 //外部响应消息
	 BOOL DoLButtonDown(UINT nFlags, POINT point);

	 //ctrl增加选择
	 BOOL DoLButtonDownE1(UINT nFlags, POINT point);

  	 BOOL DoRButtonDown(RvList  pList, HWND hWnd, int mode, UINT nFlags, POINT point );
	 BOOL DoLButtonDblClk(UINT nFlags, POINT point);
	 BOOL DoRButtonDblClk(UINT nFlags, POINT point);

 	 BOOL DoSetCursor( UINT nHitTest, UINT message);
	  
	//BOOL RaiseInternalEvents(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	
//private:
		
	 BOOL   IsRealMouseMove(POINT curpos);
	
private:
	//游标属性
	int    m_cursorType;
	CMark  m_userCursor;
	BOOL   m_bCursorChanged;

	//当前鼠标位置，用于过滤多余的MOUSEMOVE事件
	POINT  m_prevMousePos;
	 
	//图象像素属性
	//绘制在display（窗口）层
	CLabel m_pixelBar;

	
	

	//BOOL   m_bPixelBarChanged;
	BOOL        m_bPixelBarVisible; 
	PIXBAR_TYPE m_nPixelBarType;
  
	
};









































#endif  //__RV_REAL_VIEW_H_INCLUDED_