// DXDDraw.h: interface for the CDXDDraw class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DXDDRAW_H__0CF93A0F_94A1_43DA_A87D_44B740330F4B__INCLUDED_)
#define AFX_DXDDRAW_H__0CF93A0F_94A1_43DA_A87D_44B740330F4B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <windows.h>
#include <ddraw.h>
#include "mydef.h"

#define FPS_SHOW_ON
#define SURFACE_MAX_NUM		512

struct SSurface
{
	char FileName[256];
	LPDIRECTDRAWSURFACE7	pSurface;
	long Width;
	long Height;
	SSurface(){ pSurface=NULL; Release();}
	~SSurface(){ Release(); }
	void Release(){ SAFE_RELEASE(pSurface); ZeroMemory(FileName, 256); Width=0; Height=0; }
};

class CDXDDraw  
{
public:
	CDXDDraw();
	virtual ~CDXDDraw();
	void	ClassInit();
	void	ClassRelease();

	LPDIRECTDRAW7               m_pDDraw;			// 다이렉트 드로우..
	LPDIRECTDRAWSURFACE7        m_pDDSPrimary;		// 표면.
	LPDIRECTDRAWSURFACE7        m_pDDSBack;			// 백표면.
	LPDIRECTDRAWCLIPPER         m_pClipper;			// 클리퍼.
	DDPIXELFORMAT				m_DDPixelFormat;	// 픽셀 포맷을 알아내기 위한 변수.
	SSurface					m_Surface[SURFACE_MAX_NUM];	// 서피스의 스트럭쳐.

	SIZE						m_MaxScrSz;			// 화면 해상도
	RECT						m_MaxScrRt;			// 마찬가지로 해상도
	HWND						m_hWnd;				// 윈도우 핸들
	
	bool						m_bFullModeOn;		// 풀모드를 사용할지 안할지.
	BOOL						m_bDrawOn;			// 화면을 스킵할 것인지 체크.
	DWORD						m_FrmCur, m_Fps, m_TimeCur, m_TimeOld;	// 프레임 시간과 관련된 것...
	char						m_TimeStr[64];
	long						m_BitPerPixel;

	void FpsShow();

	// 크래스 관련 함수들....
	bool DDrawCreate(HWND hwnd, long width, long height, long bitPerPixel, bool fullModeOn);

	// MySurface 조작 함수..
	bool SurfaceCreate(long nSurface, long width, long height);
	bool SurfaceCreate(long nSurface, char * pFileName);
	bool SurfaceCreate(long nSurface, char * pFileName, COLORREF col);
	bool ColorKeySet(long nSurface, COLORREF colKey);

	bool SurfaceRelease(long nSurface);
	void SurfaceRestoreAll();
	void SurfaceToBack(long nSurface, long x, long y, RECT rt);
	void SurfaceToBackTrans(long nSurface, long x, long y, RECT rt);
	void SurfaceToSurface(long nSource, long nTarget, long x, long y, RECT rt);

	// GDI 함수....
	void PutString(long x, long y, char * pSstr, COLORREF tempCol);
	void PutString(long x, long y, char * pStr);
	void PutCheckString(long x, long y, char * pStr);
	void Rect(RECT rt, COLORREF col, bool filOn);
	void FillColor(RECT rt, COLORREF col);
	long PixelFormatCheck();
	
	// DirectDraw 함수.
	HRESULT	Blt(long nSource, RECT rtSource, long ntarget, RECT rtTarget);

	// 플립 함수.
	void Flip();
	void DrawOn(BOOL drawOn);		// 그릴지 안그릴지를 체크.
	void RestoreAll();

	// 비트맵 관련 함수들...
	LPDIRECTDRAWSURFACE7 BmpLoad(LPCSTR szBitmap, long dx, long dy);
	HRESULT BmpReload(LPDIRECTDRAWSURFACE7 pdds, LPCSTR szBitmap);
	HRESULT BmpToSurface(LPDIRECTDRAWSURFACE7 pdds, HBITMAP hbm, long x, long y, long dx, long dy);
	SIZE	BmpSizeGet(char *pFileName);
};

#endif // !defined(AFX_DXDDRAW_H__0CF93A0F_94A1_43DA_A87D_44B740330F4B__INCLUDED_)
