//-----------------------------------------------------------------------------
#ifndef drawingCanvasH
#define drawingCanvasH drawingCanvasH
//-----------------------------------------------------------------------------
#include <wx/scrolwin.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>

//-----------------------------------------------------------------------------
struct AOI
//-----------------------------------------------------------------------------
{
	wxRect		m_rect;
	wxColour	m_colour;
	wxString	m_description;
	AOI( const wxRect& r, const wxColour& c, const wxString& desc ) : m_rect(r), m_colour(c), m_description(desc) {}
};

//-----------------------------------------------------------------------------
class DrawingCanvas : public wxScrolledWindow
//-----------------------------------------------------------------------------
{
	DECLARE_DYNAMIC_CLASS(DrawingCanvas)
	bool				m_boActive;
protected:
	//-----------------------------------------------------------------------------
	enum
	//-----------------------------------------------------------------------------
	{
		VAL_COUNT_8_BIT = 256,
		VAL_COUNT_10_BIT = 1024,
		VAL_COUNT_12_BIT = 4096,
		VAL_COUNT_14_BIT = 16384,
		VAL_COUNT_16_BIT = 65536,
	};
	//-----------------------------------------------------------------------------
	enum TPlane
	//-----------------------------------------------------------------------------
	{
		pRed = 0,
		pGreen = 1,
		pBlue = 2,
		PLANE_CNT
	};
	unsigned int				m_valCount;
	mutable wxCriticalSection	m_critSect;
public:
	DrawingCanvas() {}
	DrawingCanvas( wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
				   const wxSize& size = wxDefaultSize, long style = wxSUNKEN_BORDER,
				   const wxString& name = "DrawingCanvas", bool boActive = false );
	bool				IsActive( void ) const { return m_boActive; }
	virtual void		SetActive( bool boActive );
};

class ImageCanvas;

//-----------------------------------------------------------------------------
class PlotCanvas : public DrawingCanvas
//-----------------------------------------------------------------------------
{
	wxColour		m_AOIColour;
	int				m_BorderWidth;
	ImageCanvas*	m_pImageCanvas;
	bool			SetAOI( const mvIMPACT::acquire::ImageBuffer* pIB, int x, int y, int w, int h );
protected:
	int				m_AOIx;
	int				m_AOIy;
	int				m_AOIw;
	int				m_AOIh;
	AOI*			m_pAOI;
	int				m_ChannelCount;
	TImageBufferPixelFormat m_pixelFormat;
	int				m_ImageCount;
	wxColour*		m_Pens[PLANE_CNT];
	int				m_UpdateFrequency;
	bool			MustUpdate( const mvIMPACT::acquire::ImageBuffer* pIB, int x, int y, int w, int h, bool boForceRefresh, bool* pboAOIChanged = 0, bool* pboImageFormatChanged = 0 );
public:
	PlotCanvas() {}
	PlotCanvas( wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
				const wxSize& size = wxDefaultSize, long style = wxSUNKEN_BORDER,
				const wxString& name = wxT("PlotCanvas"), bool boActive = false, int channelCount = 0 );
	virtual void	RefreshData( const mvIMPACT::acquire::ImageBuffer* pIB, int x = -1, int y = -1, int w = -1, int h = -1, bool boForceRefresh = false ) = 0;
	int				GetBorderWidth( void ) const { return m_BorderWidth; }
	void			SetBorderWidth( int borderWidth );
	virtual void	SetActive( bool boActive );
	void			SetAOIColour( const wxColour& );
	bool			SetUpdateFrequency( int frequency );
	void			RegisterImageCanvas( ImageCanvas* p );
	//-----------------------------------------------------------------------------
	enum TUpdateLimit
	//-----------------------------------------------------------------------------
	{
		ulMin = 1,
		ulMax = 100
	};
};

#endif // drawingCanvasH
