📄 dxutgui.h
字号:
struct DXUTFontNode
{
WCHAR strFace[MAX_PATH];
LONG nHeight;
LONG nWeight;
ID3DXFont* pFont9;
ID3DX10Font* pFont10;
};
//-----------------------------------------------------------------------------
// Manages shared resources of dialogs
//-----------------------------------------------------------------------------
class CDXUTDialogResourceManager
{
public:
CDXUTDialogResourceManager();
~CDXUTDialogResourceManager();
bool MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
// D3D9 specific
HRESULT OnD3D9CreateDevice( LPDIRECT3DDEVICE9 pd3dDevice );
HRESULT OnD3D9ResetDevice();
void OnD3D9LostDevice();
void OnD3D9DestroyDevice();
IDirect3DDevice9* GetD3D9Device() { return m_pd3d9Device; }
// D3D10 specific
HRESULT OnD3D10CreateDevice( ID3D10Device *pd3dDevice );
HRESULT OnD3D10ResizedSwapChain( ID3D10Device *pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc );
void OnD3D10ReleasingSwapChain();
void OnD3D10DestroyDevice();
ID3D10Device* GetD3D10Device() { return m_pd3d10Device; }
DXUTFontNode* GetFontNode( int iIndex ) { return m_FontCache.GetAt( iIndex ); };
DXUTTextureNode* GetTextureNode( int iIndex ) { return m_TextureCache.GetAt( iIndex ); };
int AddFont( LPCWSTR strFaceName, LONG height, LONG weight );
int AddTexture( LPCWSTR strFilename );
int AddTexture( LPCWSTR strResourceName, HMODULE hResourceModule );
bool RegisterDialog( CDXUTDialog *pDialog );
void UnregisterDialog( CDXUTDialog *pDialog );
void EnableKeyboardInputForAllDialogs();
// Shared between all dialogs
// D3D9
IDirect3DStateBlock9* m_pStateBlock;
ID3DXSprite* m_pSprite; // Sprite used for drawing
// D3D10
ID3D10Effect* m_pEffect10; // Effect used to render UI with D3D10
ID3D10EffectTechnique* m_pTechRenderUI10; // Technique: RenderUI
ID3D10EffectTechnique* m_pTechRenderUIUntex10; // Technique: RenderUI without texture
ID3D10EffectShaderResourceVariable *m_pFxTexture10;
ID3D10InputLayout* m_pInputLayout10;
ID3D10Buffer* m_pVBScreenQuad10;
ID3D10StateBlock* m_pStateBlock10;
ID3DX10Sprite* m_pSprite10;
UINT m_nBackBufferWidth;
UINT m_nBackBufferHeight;
CGrowableArray< CDXUTDialog* > m_Dialogs; // Dialogs registered
protected:
// D3D9 specific
IDirect3DDevice9* m_pd3d9Device;
HRESULT CreateFont9( UINT index );
HRESULT CreateTexture9( UINT index );
// D3D10 specific
ID3D10Device* m_pd3d10Device;
HRESULT CreateFont10( UINT index );
HRESULT CreateTexture10( UINT index );
CGrowableArray< DXUTTextureNode* > m_TextureCache; // Shared textures
CGrowableArray< DXUTFontNode* > m_FontCache; // Shared fonts
};
//-----------------------------------------------------------------------------
// Base class for controls
//-----------------------------------------------------------------------------
class CDXUTControl
{
public:
CDXUTControl( CDXUTDialog *pDialog = NULL );
virtual ~CDXUTControl();
virtual HRESULT OnInit() { return S_OK; }
virtual void Refresh();
virtual void Render( float fElapsedTime ) { };
// Windows message handler
virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam ) { return false; }
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam ) { return false; }
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam ) { return false; }
virtual bool CanHaveFocus() { return false; }
virtual void OnFocusIn() { m_bHasFocus = true; }
virtual void OnFocusOut() { m_bHasFocus = false; }
virtual void OnMouseEnter() { m_bMouseOver = true; }
virtual void OnMouseLeave() { m_bMouseOver = false; }
virtual void OnHotkey() {}
virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
virtual void SetEnabled( bool bEnabled ) { m_bEnabled = bEnabled; }
virtual bool GetEnabled() { return m_bEnabled; }
virtual void SetVisible( bool bVisible ) { m_bVisible = bVisible; }
virtual bool GetVisible() { return m_bVisible; }
UINT GetType() const { return m_Type; }
int GetID() const { return m_ID; }
void SetID( int ID ) { m_ID = ID; }
void SetLocation( int x, int y ) { m_x = x; m_y = y; UpdateRects(); }
void SetSize( int width, int height ) { m_width = width; m_height = height; UpdateRects(); }
void SetHotkey( UINT nHotkey ) { m_nHotkey = nHotkey; }
UINT GetHotkey() { return m_nHotkey; }
void SetUserData( void *pUserData ) { m_pUserData = pUserData; }
void *GetUserData() const { return m_pUserData; }
virtual void SetTextColor( D3DCOLOR Color );
CDXUTElement* GetElement( UINT iElement ) { return m_Elements.GetAt( iElement ); }
HRESULT SetElement( UINT iElement, CDXUTElement* pElement);
bool m_bVisible; // Shown/hidden flag
bool m_bMouseOver; // Mouse pointer is above control
bool m_bHasFocus; // Control has input focus
bool m_bIsDefault; // Is the default control
// Size, scale, and positioning members
int m_x, m_y;
int m_width, m_height;
// These members are set by the container
CDXUTDialog* m_pDialog; // Parent container
UINT m_Index; // Index within the control list
CGrowableArray< CDXUTElement* > m_Elements; // All display elements
protected:
virtual void UpdateRects();
int m_ID; // ID number
DXUT_CONTROL_TYPE m_Type; // Control type, set once in constructor
UINT m_nHotkey; // Virtual key code for this control's hotkey
void *m_pUserData; // Data associated with this control that is set by user.
bool m_bEnabled; // Enabled/disabled flag
RECT m_rcBoundingBox; // Rectangle defining the active region of the control
};
//-----------------------------------------------------------------------------
// Contains all the display information for a given control type
//-----------------------------------------------------------------------------
struct DXUTElementHolder
{
UINT nControlType;
UINT iElement;
CDXUTElement Element;
};
//-----------------------------------------------------------------------------
// Static control
//-----------------------------------------------------------------------------
class CDXUTStatic : public CDXUTControl
{
public:
CDXUTStatic( CDXUTDialog *pDialog = NULL );
virtual void Render( float fElapsedTime );
virtual BOOL ContainsPoint( POINT pt ) { return false; }
HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount );
LPCWSTR GetText() { return m_strText; }
HRESULT SetText( LPCWSTR strText );
protected:
WCHAR m_strText[MAX_PATH]; // Window text
};
//-----------------------------------------------------------------------------
// Button control
//-----------------------------------------------------------------------------
class CDXUTButton : public CDXUTStatic
{
public:
CDXUTButton( CDXUTDialog *pDialog = NULL );
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
virtual void OnHotkey() { if( m_pDialog->IsKeyboardInputEnabled() ) m_pDialog->RequestFocus( this ); m_pDialog->SendEvent( EVENT_BUTTON_CLICKED, true, this ); }
virtual BOOL ContainsPoint( POINT pt ) { return PtInRect( &m_rcBoundingBox, pt ); }
virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
virtual void Render( float fElapsedTime );
protected:
bool m_bPressed;
};
//-----------------------------------------------------------------------------
// CheckBox control
//-----------------------------------------------------------------------------
class CDXUTCheckBox : public CDXUTButton
{
public:
CDXUTCheckBox( CDXUTDialog *pDialog = NULL );
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
virtual void OnHotkey() { if( m_pDialog->IsKeyboardInputEnabled() ) m_pDialog->RequestFocus( this ); SetCheckedInternal( !m_bChecked, true ); }
virtual BOOL ContainsPoint( POINT pt );
virtual void UpdateRects();
virtual void Render( float fElapsedTime );
bool GetChecked() { return m_bChecked; }
void SetChecked( bool bChecked ) { SetCheckedInternal( bChecked, false ); }
protected:
virtual void SetCheckedInternal( bool bChecked, bool bFromInput );
bool m_bChecked;
RECT m_rcButton;
RECT m_rcText;
};
//-----------------------------------------------------------------------------
// RadioButton control
//-----------------------------------------------------------------------------
class CDXUTRadioButton : public CDXUTCheckBox
{
public:
CDXUTRadioButton( CDXUTDialog *pDialog = NULL );
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
virtual void OnHotkey() { if( m_pDialog->IsKeyboardInputEnabled() ) m_pDialog->RequestFocus( this ); SetCheckedInternal( true, true, true ); }
void SetChecked( bool bChecked, bool bClearGroup=true ) { SetCheckedInternal( bChecked, bClearGroup, false ); }
void SetButtonGroup( UINT nButtonGroup ) { m_nButtonGroup = nButtonGroup; }
UINT GetButtonGroup() { return m_nButtonGroup; }
protected:
virtual void SetCheckedInternal( bool bChecked, bool bClearGroup, bool bFromInput );
UINT m_nButtonGroup;
};
//-----------------------------------------------------------------------------
// Scrollbar control
//-----------------------------------------------------------------------------
class CDXUTScrollBar : public CDXUTControl
{
public:
CDXUTScrollBar( CDXUTDialog *pDialog = NULL );
virtual ~CDXUTScrollBar();
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
virtual bool MsgProc( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual void Render( float fElapsedTime );
virtual void UpdateRects();
void SetTrackRange( int nStart, int nEnd );
int GetTrackPos() { return m_nPosition; }
void SetTrackPos( int nPosition ) { m_nPosition = nPosition; Cap(); UpdateThumbRect(); }
int GetPageSize() { return m_nPageSize; }
void SetPageSize( int nPageSize ) { m_nPageSize = nPageSize; Cap(); UpdateThumbRect(); }
void Scroll( int nDelta ); // Scroll by nDelta items (plus or minus)
void ShowItem( int nIndex ); // Ensure that item nIndex is displayed, scroll if necessary
protected:
// ARROWSTATE indicates the state of the arrow buttons.
// CLEAR No arrow is down.
// CLICKED_UP Up arrow is clicked.
// CLICKED_DOWN Down arrow is clicked.
// HELD_UP Up arrow is held down for sustained period.
// HELD_DOWN Down arrow is held down for sustained period.
enum ARROWSTATE { CLEAR, CLICKED_UP, CLICKED_DOWN, HELD_UP, HELD_DOWN };
void UpdateThumbRect();
void Cap(); // Clips position at boundaries. Ensures it stays within legal range.
bool m_bShowThumb;
bool m_bDrag;
RECT m_rcUpButton;
RECT m_rcDownButton;
RECT m_rcTrack;
RECT m_rcThumb;
int m_nPosition; // Position of the first displayed item
int m_nPageSize; // How many items are displayable in one page
int m_nStart; // First item
int m_nEnd; // The index after the last item
POINT m_LastMouse;// Last mouse position
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -