//
//	Copyright © 2006 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#pragma once

#include "../Interfaces/VectorWorks/IDrawPad.h"

#include "Control.h"

#include "CustomCtrlAttrs.h"

namespace VectorWorks
{
	namespace VWUI
	{
		// ---------------------------------------------------------------------------------------------------------------
		enum ECustomDCPreviewMode
		{
			kCustomDCPreviewMode_PlanMode			= 1,
			kCustomDCPreviewMode_Front				= 3,
			kCustomDCPreviewMode_Back				= 4,
			kCustomDCPreviewMode_Left				= 5,
			kCustomDCPreviewMode_Right				= 6,
			kCustomDCPreviewMode_Top 				= 7,
			kCustomDCPreviewMode_Bottom				= 8,
			kCustomDCPreviewMode_RightIso			= 9,
			kCustomDCPreviewMode_LeftIso 			= 10,
			kCustomDCPreviewMode_RightRearIso		= 11,
			kCustomDCPreviewMode_LeftRearIso 		= 12,
			kCustomDCPreviewMode_BottomRightIso		= 13,
			kCustomDCPreviewMode_BottomLeftIso		= 14,
			kCustomDCPreviewMode_BottomRightRearIso	= 15,
			kCustomDCPreviewMode_BottomLeftRearIso	= 16,
		};

		// ---------------------------------------------------------------------------------------------------------------
		enum ECustomDCRenderMode
		{
			kCustomDCRenderMode_WireFrame				= 0,
			kCustomDCRenderMode_Solid					= 2,
			kCustomDCRenderMode_ShadedSolid				= 3,
			kCustomDCRenderMode_ShadedNoLines			= 4,
			kCustomDCRenderMode_FinalShaded				= 5,
			kCustomDCRenderMode_FinalHiddenLine			= 6,
			kCustomDCRenderMode_DashedHiddenLine		= 7,
			kCustomDCRenderMode_OpenGL					= 11,
			kCustomDCRenderMode_FastRenderWorks			= 12,
			kCustomDCRenderMode_FastShadowRenderWorks  	= 13,
			kCustomDCRenderMode_FinalRenderWorks		= 14,
			kCustomDCRenderMode_CustomRenderWorks		= 15,
			kCustomDCRenderMode_ArtisticRenderWorks 	= 17,
			kCustomDCRenderMode_Sketch					= 18,
		};

		// ---------------------------------------------------------------------------------------------------------------
		class VWCustomCtrl;

		// ---------------------------------------------------------------------------------------------------------------
		class VWCustomCtrlDC
		{
			friend class VWCustomCtrl;
		public:
								VWCustomCtrlDC(ViewCoord width, ViewCoord height);
			virtual				~VWCustomCtrlDC();

			Uint32				GetOSDevice() const;
			ViewCoord			GetXOffset() const;
			ViewCoord			GetYOffset() const;

		public:
			void				SelectPen(const VWCustomCtrlPen& pen);
			void				SelectBrush(const VWCustomCtrlBrush& brush);
			void				SelectFont(const VWCustomCtrlFont& font);

			VWCustomCtrlPen		GetSelectedPen() const;
			VWCustomCtrlBrush	GetSelectedBrush() const;
			VWCustomCtrlFont	GetSelectedFont() const;

		public:
			void				SetClipRect(const ViewRect& rect);

			void				DrawLine(const ViewPt& fromPt, const ViewPt& toPt);
			void				DrawRect(const ViewRect& rect);
			void				FillRect(const ViewRect& rect);

			Uint32				GetStringWidth(const TXString& string);
			void				DrawString(const ViewPt& pt, const TXString& string);
			void				DrawString(const ViewPt& pt, const TXString& string, Uint8 red, Uint8 green, Uint8 blue);

			void				BitBlt(const ViewRect& destRect, const VWCustomCtrlDC& srcDC, const ViewPt& srcPt, EDrawPadTransferMode mode = eDrawPadTransferMode_Copy);
			void				BitBlt(const ViewRect& destRect, const VWCustomCtrlDC& srcDC, const ViewRect& srcRect, EDrawPadTransferMode mode = eDrawPadTransferMode_Copy);

			void				PathBegin();
			void				PathMoveTo(Sint16 x, Sint16 y);
			void				PathLineTo(Sint16 x, Sint16 y);
//			void				PathArcTo(Sint16 toX, Sint16 toY, Sint16 centerX, Sint16 centerY);
//			void				PathBezierTo(Sint16 toX, Sint16 toY, Sint16 ctrl1X, Sint16 ctrl1Y, Sint16 ctrl2X, Sint16 ctrl2Y);
			void				PathEndDraw();
			void				PathEndDrawAndFill();
			void				PathEndFill();
			void				PathEndFillAndDraw();

			void				DrawSymbolPreview(	InternalIndex resourceRefNum,
													const ViewRect& destRect,
													ECustomDCPreviewMode viewMode = kCustomDCPreviewMode_PlanMode,
													ECustomDCRenderMode renderMode = kCustomDCRenderMode_WireFrame);

		protected:
								VWCustomCtrlDC(unsigned long devHandle, void* devDC, ViewCoord xOffset, ViewCoord yOffset);
								VWCustomCtrlDC(const ViewRect& inViewRect);
								VWCustomCtrlDC(const VWCustomCtrlDC& scr);
			VWCustomCtrlDC&		operator=(const VWCustomCtrlDC& scr);

		private:
			typedef	VCOMPtr<VectorWorks::IDrawPad>	TDrawPad;
			
			unsigned long			fDevHandle;
			void*					fpDevDC;
			TDrawPad				fpDrawPad;
			ViewCoord				fXOffset;
			ViewCoord				fYOffset;

			VWCustomCtrlPen			fCurrentPen;
			VWCustomCtrlBrush		fCurrentBrush;

			void*					farrPolyPts;
		};
	}
}