⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ddcompo.h

📁 网页游戏赤壁
💻 H
字号:
/////////////
//	DDCompo.h		:	v0043
//	Written by		:	Liu Gang
//	Compiler		:	Microsoft Visual C++ 4.0 & DirectX
//	Library			:	DDraw.Lib
//	Copyright (C)	:	1996 WayAhead Corporation 
//	v0020			:	Nov.12.1996
//	v0030			:	Dec.11.1996, upgrade to DirectDraw 2.0 or higher
//	v0031			:	Jan.22.1997, fix one reported bug, and change something in SetRange()
//	v0040			:	Feb.13.1997, changed some cursor functions, deleted surface m_lpSpriteBuffer
//	v0041			:	Mar.5.1997,	add member m_bShow and function Show()
//	v0042			:	Mar.22.1997, add some global functions for cursor
//						Fixed a bug when cursor is animating, add Erase() to CDDCursor
//	v0043			:	Apr.9.1997, changed the name of one of cursor's member m_bCreated to m_bCreatedC
/////////////
// header file
// DirectDraw components
// mouse cursor, framerate, etc

#ifndef	__DDCOMPO_H__
#define	__DDCOMPO_H__
#include "DDAPI.h"		// direct draw objects

#define	DDC_ERROR_ID	200
//////////////////


// frame rate
//////////////////
// load frame rate file
// filename		:	bitmap file to display framerate
// return value	:	TRUE if succeeded
BOOL DDC_LoadFrameRate( LPCTSTR filename );

// draw frame rate
void DDC_DisplayFrameRate( void );

// show frame rate or not
// bShow	:	TRUE for show frame rate
void DDC_ShowFrameRate( BOOL bShow = TRUE );

// get frame rate
int DDC_GetFrameRate();
//////////////////


// cursor
//////////////////
#define		DDC_CURSOR_STATE_MAX	16
#define		DDC_CURSOR_STATE_NONE	-1
#define		DDC_CURSOR_STATE_NORMAL	0

//////////////////
class CDDCursor	:	public CDDSurface
{
	BOOL m_bCreatedC;	// TRUE after run Load(), before run Release()
	BOOL m_bShow;		// 是否隐藏鼠标

#ifdef	_CURSOR_OLD_VERSION_
	// 显示sprite时要更新鼠标,存储中间结果的面
	class CDDSurface	*m_lpSpriteBuffer;	// Sprite buffer
#endif	// _CURSOR_OLD_VERSION_

	// 显示鼠标时用来存储中间结果的面
	class CDDSurface	*m_lpMixBuffer;	// mix buffer

	SIZE	m_szSize;		// size of cursor
	POINT	m_ptPos;		// positoin of cursor

	RECT	m_rcRange;		// moving range
	int		m_nState;		// state of cursor, column of cursor
	int		m_nStateLast;	// last state of cursor, column of cursor
	int		m_nFrame;		// frame of cursor, row of cursor
	int		m_nFrameLast;	// last frame of cursor, row of cursor
	int		m_nSpeed;		// animation speed, the more the slower

	POINT	m_ptHotspot[DDC_CURSOR_STATE_MAX];		// hotspot of each state
	int		m_nFrameCount[DDC_CURSOR_STATE_MAX];	// frames per state

public:
	// constructor
	CDDCursor();
	// destructor
	~CDDCursor();

	// create cursor 
	// filename		:	cursor bitmap filename 
	// nCol			:	cursor state, 横向排列在位图中,大小一样, cannot be zero
	// nRow			:	cursor frame, 纵向排列在位图中,动画鼠标的每一帧, cannot be zero
	// return value	:	TRUE if succeeded
	BOOL Load( LPCTSTR filename, int nCol=1, int pnRow[]=NULL, POINT pptHotspot[]=NULL );

	// create cursor 
	// filename		:	cursor bitmap compact file
	// nIndex		:	index number in compact file
	// nCol			:	cursor state, 横向排列在位图中,大小一样, cannot be zero
	// nRow			:	cursor frame, 纵向排列在位图中,动画鼠标的每一帧, cannot be zero
	// return value	:	TRUE if succeeded
	BOOL LoadEx( LPSTR filename, LPSTR fileIndex, int nIndex, int nCol=1, int pnRow[]=NULL, POINT pptHotspot[]=NULL );

	// release surfaces
	void Release();

	// set cursor moving range
	// rcRange		:	new range for mouse moving in
	// return value	:	old range for mouse moving in
	// Warning	:	A bug report here:
	//				Cannot erase old cursor if change range in run time
	RECT SetRange( CONST RECT *lprcRange );

	// set cursor state
	// nState		:	new state
	// return value	:	old state
	int	SetState( int nState );

	// set cursor frame
	// nFrame		:	new frame
	// return value	:	old frame
	int SetFrame( int nFrame );

	// set cursor animation speed
	// nSpeed		:	new speed
	// return value	:	old speed
	int SetSpeed( int nSpeed );

	// get cursor position
	POINT GetPos(){ return m_ptPos; }

	// get cursor rectangle
	RECT GetRect();

	// get cursor range
	RECT GetRange(){ return m_rcRange; }

	// get cursor state
	int GetState(){ return m_nState; }

	// get cursor frame
	int GetFrame(){ return m_nFrame; }

	// get animate speed
	int GetSpeed(){ return m_nSpeed; }

	// change cursor to next frame when display
	void Animate();

	// 应用程序在显示鼠标光标时应该使用此函数
	// draw cursor to front surface
	// bForce		:	TRUE for force drawing
	// return value	:	TRUE for has drew
	BOOL Draw( BOOL bForce=FALSE );

	// 应用程序在擦除鼠标光标时应该使用此函数
	// erase cursor to front surface, doesn't change frame
	// return value	:	TRUE for has erased
	BOOL CDDCursor::Erase();

	// 把鼠标显示在背景面上(BackBuffer),特殊情况下使用
	// 把背景面保存在m_lpMixBuffer中
	// draw corsor to back buffer
	// stores back ground to m_lpMixBuffer
	// prcCut		:	只显示在此矩形区域内,if NULL则不操作
	// return value	:	TRUE for has drew
	BOOL Draw2Back( CONST RECT *prcCut = NULL );

	// 把保存的背景面(在m_lpMixBuffer中)放回背景
	// restores from m_lpMixBuffer to back buffer
	// prcCut		:	只显示在此矩形区域内,if NULL则不操作
	// return value	:	TRUE for has drew
	BOOL Restore2Back( CONST RECT *prcCut = NULL );

	// 显示或隐藏鼠标光标
	void Show( BOOL bShow = TRUE ){ m_bShow = bShow; }
	// 该光标是否在显示中
	BOOL IfShow(){return m_bShow;}

#ifdef	_CURSOR_OLD_VERSION_
	// when draw sprite should draw cursor on it
	// used only in DDCompo.cpp, do not use outside
	// pRect1, pRect2	:	the new and old positoin of the sprite
	// return value		:	if one rectangle is NULL, or did not draw, return FALSE
	// Warning	:	A bug report here
	//				Draw cursor on any sprite even if cursor is out of range
	BOOL drawSprite( CONST RECT *pRect1, CONST RECT *pRect2 );
#endif	// _CURSOR_OLD_VERSION_
};
//////////////////

// global functions for cursor
//////////////////
// set the cursor as the current cursor
// pCursor	:	cursor pointer to be set
// return	:	TRUE if the cursor is not null now
BOOL CURSOR_Set( class CDDCursor *pCursor );

// get the current cursor
extern class CDDCursor *CURSOR_Get();

// animate cursor, should be called each cycle
extern void CURSOR_Animate();
//////////////////

// display sprite functions
//////////////////
// set sprite moving range
// rcRange		:	range for sprites to move
// return value	:	old range for sprites to move
RECT DDC_SetSSpriteRange( RECT rcRange );

// 应用程序在更新完sprites后应该调用此函数,而不是DD_UpdateScreen()
// this function will redraw cursor automatically
// 两个矩形一般为该sprite在旧位置上的矩形和新位置上的矩形
// update two rectangles from back buffer to front buffer
// if the two rectangles cross, it will combine it to a large rectangle,
// else	update two rectangles seperatly
// pRect1, pRect2	:	the two rectangles
// return value		:	if one is NULL, return FALSE
BOOL DDC_UpdateSprite( CONST RECT *pRect1, CONST RECT *pRect2 );

// when need update, should use this functions instead of DD_UpdateScreen() in DDAPI.h
// update only one rectangle of back buffer to front buffer
void DDC_UpdateScreen( RECT *pRect=NULL );

// set max size of sprites
// in order to take effect, you must call this function before CDDCursor::Load()
// szMax		:	max size of sprites
// return value	:	old max size of sprites
// sprite的矩形乘2或新旧位置的总矩形不能大于此值,用于优化显示
SIZE DDC_SetSpriteMaxSize( SIZE szMax );
//////////////////

// sub-draw functions
//////////////////
// draw rectangle on screen, by using DC
// pRect		:	rectangle to draw
// color		:	color to draw
// bFront		:	TRUE for draw it on front buffer
// return value	:	TRUE if succeeded
BOOL DDC_FrameRect( CONST RECT *pRect, COLORREF color, BOOL bFront=FALSE );

// draw rectangle on one surface, by using DC
// pRect		:	rectangle to draw
// color		:	color to draw
// bFront		:	TRUE for draw it on front buffer
// return value	:	TRUE if succeeded
BOOL DDC_FrameRect( LPDIRECTDRAWSURFACE2 lpDDS, CONST RECT *pRect, COLORREF color );
//////////////////
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -