?? ddcompo.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 + -