📄 didcfgview.h
字号:
m_size =( newCap < m_size ? newCap : m_size );
UINT old_cap = m_capacity;
UINT numoverlap =( newCap > m_capacity ? m_capacity : newCap );
Item* oldList = m_list;
this->Alloc( newCap );
if( oldList )
{
memcpy( m_list, oldList, sizeof( Item )* numoverlap );
// free( oldList );
delete [] oldList;
}
}
Item & operator[]( UINT index )
{
if( index >= m_capacity )
assert( index >= 0 && index < m_capacity );
return m_list[index];
}
const Item & operator[]( UINT index ) const
{
if( index >= m_capacity )
assert( index >= 0 && index < m_capacity );
return m_list[index];
}
void PushBack( const Item & item )
{
if( m_capacity == 0 )
SetSize( 2 );
else if( m_size >= m_capacity )
SetSize( m_capacity* 2 );
m_list[m_size] = item;
m_size++;
}
void Resize( UINT newCap ) { SetSize( newCap ); }
void PopBack() { if( m_size ) m_size--; }
void Clear() { m_size = 0; }
void Trim() { Resize( m_size ); }
UINT Capacity() const { return m_capacity; }
UINT Size() const { return m_size; }
protected:
inline void Alloc( UINT cap )
{
if( cap == 0 )
m_list = NULL;
else
{
m_list = new Item[cap];
assert( m_list );
memset( m_list, 0, sizeof( Item )* cap );
}
m_capacity = cap;
}
inline void DeAlloc()
{
if( m_list != NULL )
{
//free( m_list );
delete [] m_list;
m_list = NULL;
}
m_capacity = 0;
}
protected:
// array
Item* m_list;
// number of entries the array can hold
UINT m_capacity;
// number of entries added using PushBack() minus # removed using PopBack()
UINT m_size;
};
//-----------------------------------------------------------------------------
// Name: class DidcvCalloutApplicant
// Desc: abstract base class for processing DidcvCallout
//-----------------------------------------------------------------------------
class DidcvCalloutApplicant
{
public:
virtual ~DidcvCalloutApplicant() { }
virtual BOOL Apply( DidcvCallout* pCallout ) = 0;
};
//-----------------------------------------------------------------------------
// Name: class DidcvCalloutSet
// Desc: a group of DidcvCallout references
// A callout is the line drawn from each axis/button to a label
//-----------------------------------------------------------------------------
class DidcvCalloutSet
{
public:
DidcvCalloutSet();
~DidcvCalloutSet();
public:
BOOL AddCallout( DidcvCallout* pCallout );
void Apply( DidcvCalloutApplicant* pCalloutApp );
void SetIdentifier( DWORD dwID );
DWORD GetIdentifier() const;
void SetData( void* pData );
void* GetData() const;
const GwArray <DidcvCallout*> & GetInternalArrayRef() const;
void TrimArrays();
protected:
void CleanUp();
protected:
GwArray <DidcvCallout*> m_calloutList;
DWORD m_dwSetID;
void* m_lpData;
};
//-----------------------------------------------------------------------------
// Name: class DidcvCalloutManager
// Desc: data structure for storing and managing callouts
// A callout is the line drawn from each axis/button to a label
//-----------------------------------------------------------------------------
class DidcvCalloutManager
{
public:
DidcvCalloutManager();
~DidcvCalloutManager();
// main interface
BOOL AddCallout( DidcvCallout* pCallout, INT nView );
BOOL SetCalloutState( const DidcvCalloutState* pCalloutState, DWORD dwObjID );
BOOL SetAllCalloutState( const DidcvCalloutState* pCalloutState );
BOOL SetActionMap( const LPDIACTION pAction, DWORD dwObjID );
void ClearAllActionMaps();
// information
DWORD GetObjectIDByLocation( const LPPOINT pPt, INT nView );
BOOL GetCalloutState( DidcvCalloutState* pCalloutState, DWORD dwObjID );
BOOL GetActionMap( DidcvActionMap* pActionMap, DWORD dwObjID );
const DidcvCalloutSet* GetCalloutSetByView( INT nView ) const;
const DidcvCalloutSet* GetCalloutSetByObjID( DWORD dwObjID ) const;
const DidcvCalloutData* GetCalloutDataRef( DWORD dwObjID ) const;
UINT GetNumUniqueCallouts() const;
BOOL EnumObjects( LPDIRECTINPUTDEVICE8 pDevice, LPDIENUMDEVICEOBJECTSCALLBACK pCallback, LPVOID pvRef, DWORD dwMapOnly );
BOOL CalcCanBeCollapsed();
// allocation
BOOL SetCapacity( DWORD dwNumCallouts, DWORD dwNumUniqueObjID, DWORD dwNumViews, BOOL bDeleteContent = TRUE );
void TrimArrays();
void CleanUp();
protected:
// helper functions
DidcvCalloutSet* Find( const GwArray <DidcvCalloutSet*> & array, DWORD dwIdentifier ) const;
DidcvCalloutData* GetCalloutData( DWORD dwObjID ) const;
protected:
// list of all callouts added
GwArray <DidcvCallout*> m_calloutList;
// list of callout sets, one for each unique callout id
GwArray <DidcvCalloutSet*> m_calloutSetListByObjID;
// list of callout sets, one for each view
GwArray <DidcvCalloutSet*> m_calloutSetListByView;
};
//-----------------------------------------------------------------------------
// Name: struct DidcvCalloutData
// Desc: data structure holding references to callout data components
//-----------------------------------------------------------------------------
struct DidcvCalloutData
{
DidcvCalloutState* lpState; // callout state info
DidcvActionMap* lpActionMap; // action mapped this callout
DidcvCalloutData( DidcvCalloutState* s, DidcvActionMap* a )
: lpState( s ), lpActionMap( a )
{ }
};
//-----------------------------------------------------------------------------
// Name: struct DidcvCalloutState
// Desc: state information for a callout
//-----------------------------------------------------------------------------
struct DidcvCalloutState
{
// whether to draw
BOOL bDrawCallout;
BOOL bDrawOverlay;
BOOL bDrawHighlight;
BOOL bDrawEmptyCallout;
BOOL bDrawFullname;
// specifies which state is valid
DWORD dwFlags;
// --- member functions ---
DidcvCalloutState( DWORD f = 0, BOOL c = FALSE, BOOL o = FALSE,
BOOL h = FALSE, BOOL e = FALSE, BOOL d = FALSE )
: dwFlags( f ), bDrawCallout( c ), bDrawOverlay( o ), bDrawHighlight( h ),
bDrawEmptyCallout( e ), bDrawFullname( d )
{ }
void SmartSet( const DidcvCalloutState* other );
void Copy( const DidcvCalloutState* other ) { *this = *other; }
DWORD MakeFlag() const;
void SetFlag( DWORD dwExtFlags );
};
//-----------------------------------------------------------------------------
// Name: struct DidcvActionMap
// Desc: action mapping information for a callout
//-----------------------------------------------------------------------------
struct DidcvActionMap
{
DIACTION dia;
DidcvActionMap() { ZeroMemory( &dia, sizeof( DIACTION ) ); }
void Copy( const DidcvActionMap* other ) { this->dia = other->dia; }
LPCSTR GetActionName() const { return dia.lptszActionName; }
};
// utility functions
void DidcvPolyLineArrow( HDC hDC, const POINT* rgpt, INT nPoints, BOOL bDoShadow = FALSE );
HFONT DidcvCreateFont( HDC hdc, const TCHAR* szFaceName, int iDeciPtHeight, int iDeciPtWidth, int iAttributes, BOOL fLogRes);
//-----------------------------------------------------------------------------
// Name: struct rgref
// Desc: templated lightweight c-style array
//-----------------------------------------------------------------------------
template <class T>
struct rgref {
rgref( T* p ) : pt( p ) {}
T & operator []( int i ) { return pt[i]; }
const T & operator []( int i ) const { return pt[i]; }
private:
T *pt;
};
//-----------------------------------------------------------------------------
// Name: struct SPOINT
// Desc: used by line drawing routine
//-----------------------------------------------------------------------------
struct SPOINT {
SPOINT()
#define SPOINT_INITIALIZERS \
p( u.p ), \
s( u.s ), \
a((( int* )( void* ) u.a ) ), \
x( u.p.x ), \
y( u.p.y ), \
cx( u.s.cx ), \
cy( u.s.cy )
: SPOINT_INITIALIZERS
{ x = y = 0; }
SPOINT( int, POINT *r )
: p( *r ),
s( *(( SIZE* )( void* ) r ) ),
a((( int* )( void* ) r ) ),
x( r->x ),
y( r->y ),
cx( r->x ),
cy( r->y )
{ }
SPOINT( const SPOINT & sp )
: SPOINT_INITIALIZERS
{ p = sp.p; }
SPOINT( int b, int c )
: SPOINT_INITIALIZERS
{ x = b; y = c; }
SPOINT( const POINT &point )
: SPOINT_INITIALIZERS
{ p = point; }
SPOINT( const SIZE &size )
: SPOINT_INITIALIZERS
{ s = size; }
#undef SPOINT_INITIALIZERS
SPOINT operator =( const SPOINT &sp ) { p = sp.p; return *this; }
SPOINT operator =( const POINT &_p ) { p = _p; return *this; }
SPOINT operator =( const SIZE &_s ) { s = _s; return *this; }
operator POINT() const { return p; }
operator SIZE() const { return s; }
long &x, &y, &cx, &cy;
POINT &p;
SIZE &s;
rgref<int> a;
private:
union {
POINT p;
SIZE s;
int a[2];
} u;
};
//-----------------------------------------------------------------------------
// Name: class DidcvBitmap
// Desc: object containing a bitmap
//-----------------------------------------------------------------------------
class DidcvBitmap
{
public:
~DidcvBitmap();
// drawing interface
BOOL Draw( HDC hDC, INT xStart, INT yStart);
BOOL Blend( HDC hDC, INT xStart, INT yStart );
BOOL Blend( VOID* lpBits, INT xStart, INT yStart, INT width, INT height );
// information
BOOL GetSize( SIZE* lpSize ) const;
HBITMAP GetHandle();
LPVOID GetBits();
public:
// static function for instantiating a DidcvBitmap
static DidcvBitmap* Create( LPCTSTR tszFilename );
static DidcvBitmap* Create( INT width, INT height );
private:
// private constructor
DidcvBitmap();
protected:
// helper functions
void CleanUp();
void FigureSize();
static DidcvBitmap* CreateViaD3dx( LPCTSTR tszFilename );
static DidcvBitmap* CreateViaLoadImage( HINSTANCE hinst, LPCTSTR tszName,
UINT uType, int cx, int cy, UINT fuLoad );
protected:
// GDI handle to bitmap
HBITMAP m_hbitmap;
VOID* m_lpBits;
SIZE m_size;
};
// alpha blending information
#define DIDCV_ALPHABLEND_DLL_NAME TEXT( "MSIMG32.DLL" )
#define DIDCV_ALPHABLEND_PROC_NAME TEXT( "AlphaBlend" )
#if( WINVER >= 0x400 )
typedef WINGDIAPI BOOL( WINAPI* DIDCV_ALPHABLEND )( HDC, int, int, int, int, HDC, int, int, int, int, BLENDFUNCTION );
#else
typedef DIDCV_ALPHABLEND DWORD
#endif
//-----------------------------------------------------------------------------
// Name: class DidcvAlphaBlend
// Desc: utility class for alpha blending
//-----------------------------------------------------------------------------
class DidcvAlphaBlend
{
public:
// reference counting interface
static BOOL AddClient();
static BOOL ReleaseClient();
// functions to perform blending
static BOOL Blend( HDC hDC, INT xStart, INT yStart, INT width, INT height, HBITMAP hbitmap, const SIZE* lpSize );
static BOOL Blend( VOID* lpDestBits, INT xStart, INT yStart, INT destWidth, INT destHeight, VOID* lpSrcBits, INT srcWidth, INT srcHeight );
protected:
static DIDCV_ALPHABLEND s_alphaBlendProc;
static HMODULE s_hDll;
static DWORD s_dwNumClients;
};
#endif // #ifndef __DIDCV_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -