📄 dxutgui.h
字号:
ARROWSTATE m_Arrow; // State of the arrows
double m_dArrowTS; // Timestamp of last arrow event.
};
//-----------------------------------------------------------------------------
// ListBox control
//-----------------------------------------------------------------------------
struct DXUTListBoxItem
{
WCHAR strText[256];
void* pData;
RECT rcActive;
bool bSelected;
};
class CDXUTListBox : public CDXUTControl
{
public:
CDXUTListBox( CDXUTDialog *pDialog = NULL );
virtual ~CDXUTListBox();
virtual HRESULT OnInit() { return m_pDialog->InitControl( &m_ScrollBar ); }
virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
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();
DWORD GetStyle() const { return m_dwStyle; }
int GetSize() const { return m_Items.GetSize(); }
void SetStyle( DWORD dwStyle ) { m_dwStyle = dwStyle; }
int GetScrollBarWidth() const { return m_nSBWidth; }
void SetScrollBarWidth( int nWidth ) { m_nSBWidth = nWidth; UpdateRects(); }
void SetBorder( int nBorder, int nMargin ) { m_nBorder = nBorder; m_nMargin = nMargin; }
HRESULT AddItem( const WCHAR *wszText, void *pData );
HRESULT InsertItem( int nIndex, const WCHAR *wszText, void *pData );
void RemoveItem( int nIndex );
void RemoveItemByText( WCHAR *wszText );
void RemoveItemByData( void *pData );
void RemoveAllItems();
DXUTListBoxItem *GetItem( int nIndex );
int GetSelectedIndex( int nPreviousSelected = -1 );
DXUTListBoxItem *GetSelectedItem( int nPreviousSelected = -1 ) { return GetItem( GetSelectedIndex( nPreviousSelected ) ); }
void SelectItem( int nNewIndex );
enum STYLE { MULTISELECTION = 1 };
protected:
RECT m_rcText; // Text rendering bound
RECT m_rcSelection; // Selection box bound
CDXUTScrollBar m_ScrollBar;
int m_nSBWidth;
int m_nBorder;
int m_nMargin;
int m_nTextHeight; // Height of a single line of text
DWORD m_dwStyle; // List box style
int m_nSelected; // Index of the selected item for single selection list box
int m_nSelStart; // Index of the item where selection starts (for handling multi-selection)
bool m_bDrag; // Whether the user is dragging the mouse to select
CGrowableArray< DXUTListBoxItem* > m_Items;
};
//-----------------------------------------------------------------------------
// ComboBox control
//-----------------------------------------------------------------------------
struct DXUTComboBoxItem
{
WCHAR strText[256];
void* pData;
RECT rcActive;
bool bVisible;
};
class CDXUTComboBox : public CDXUTButton
{
public:
CDXUTComboBox( CDXUTDialog *pDialog = NULL );
virtual ~CDXUTComboBox();
virtual void SetTextColor( D3DCOLOR Color );
virtual HRESULT OnInit() { return m_pDialog->InitControl( &m_ScrollBar ); }
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
virtual void OnHotkey();
virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
virtual void OnFocusOut();
virtual void Render( float fElapsedTime );
virtual void UpdateRects();
HRESULT AddItem( const WCHAR* strText, void* pData );
void RemoveAllItems();
void RemoveItem( UINT index );
bool ContainsItem( const WCHAR* strText, UINT iStart=0 );
int FindItem( const WCHAR* strText, UINT iStart=0 );
void* GetItemData( const WCHAR* strText );
void* GetItemData( int nIndex );
void SetDropHeight( UINT nHeight ) { m_nDropHeight = nHeight; UpdateRects(); }
int GetScrollBarWidth() const { return m_nSBWidth; }
void SetScrollBarWidth( int nWidth ) { m_nSBWidth = nWidth; UpdateRects(); }
int GetSelectedIndex() const { return m_iSelected; }
void* GetSelectedData();
DXUTComboBoxItem* GetSelectedItem();
UINT GetNumItems() { return m_Items.GetSize(); }
DXUTComboBoxItem* GetItem( UINT index ) { return m_Items.GetAt( index ); }
HRESULT SetSelectedByIndex( UINT index );
HRESULT SetSelectedByText( const WCHAR* strText );
HRESULT SetSelectedByData( void* pData );
protected:
int m_iSelected;
int m_iFocused;
int m_nDropHeight;
CDXUTScrollBar m_ScrollBar;
int m_nSBWidth;
bool m_bOpened;
RECT m_rcText;
RECT m_rcButton;
RECT m_rcDropdown;
RECT m_rcDropdownText;
CGrowableArray< DXUTComboBoxItem* > m_Items;
};
//-----------------------------------------------------------------------------
// Slider control
//-----------------------------------------------------------------------------
class CDXUTSlider : public CDXUTControl
{
public:
CDXUTSlider( CDXUTDialog *pDialog = NULL );
virtual BOOL ContainsPoint( POINT pt );
virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
virtual bool HandleKeyboard( UINT uMsg, WPARAM wParam, LPARAM lParam );
virtual bool HandleMouse( UINT uMsg, POINT pt, WPARAM wParam, LPARAM lParam );
virtual void UpdateRects();
virtual void Render( float fElapsedTime );
void SetValue( int nValue ) { SetValueInternal( nValue, false ); }
int GetValue() const { return m_nValue; };
void GetRange( int &nMin, int &nMax ) const { nMin = m_nMin; nMax = m_nMax; }
void SetRange( int nMin, int nMax );
protected:
void SetValueInternal( int nValue, bool bFromInput );
int ValueFromPos( int x );
int m_nValue;
int m_nMin;
int m_nMax;
int m_nDragX; // Mouse position at start of drag
int m_nDragOffset; // Drag offset from the center of the button
int m_nButtonX;
bool m_bPressed;
RECT m_rcButton;
};
//-----------------------------------------------------------------------------
// CUniBuffer class for the edit control
//-----------------------------------------------------------------------------
class CUniBuffer
{
public:
CUniBuffer( int nInitialSize = 1 );
~CUniBuffer();
static void WINAPI Initialize();
static void WINAPI Uninitialize();
int GetBufferSize() { return m_nBufferSize; }
bool SetBufferSize( int nSize );
int GetTextSize() { return lstrlenW( m_pwszBuffer ); }
const WCHAR* GetBuffer() { return m_pwszBuffer; }
const WCHAR& operator[]( int n ) const { return m_pwszBuffer[n]; }
WCHAR& operator[]( int n );
DXUTFontNode* GetFontNode() { return m_pFontNode; }
void SetFontNode( DXUTFontNode *pFontNode ) { m_pFontNode = pFontNode; }
void Clear();
bool InsertChar( int nIndex, WCHAR wChar ); // Inserts the char at specified index. If nIndex == -1, insert to the end.
bool RemoveChar( int nIndex ); // Removes the char at specified index. If nIndex == -1, remove the last char.
bool InsertString( int nIndex, const WCHAR *pStr, int nCount = -1 ); // Inserts the first nCount characters of the string pStr at specified index. If nCount == -1, the entire string is inserted. If nIndex == -1, insert to the end.
bool SetText( LPCWSTR wszText );
// Uniscribe
HRESULT CPtoX( int nCP, BOOL bTrail, int *pX );
HRESULT XtoCP( int nX, int *pCP, int *pnTrail );
void GetPriorItemPos( int nCP, int *pPrior );
void GetNextItemPos( int nCP, int *pPrior );
private:
HRESULT Analyse(); // Uniscribe -- Analyse() analyses the string in the buffer
WCHAR* m_pwszBuffer; // Buffer to hold text
int m_nBufferSize; // Size of the buffer allocated, in characters
// Uniscribe-specific
DXUTFontNode* m_pFontNode; // Font node for the font that this buffer uses
bool m_bAnalyseRequired; // True if the string has changed since last analysis.
SCRIPT_STRING_ANALYSIS m_Analysis; // Analysis for the current string
private:
// Empty implementation of the Uniscribe API
static HRESULT WINAPI Dummy_ScriptApplyDigitSubstitution( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* ) { return E_NOTIMPL; }
static HRESULT WINAPI Dummy_ScriptStringAnalyse( HDC, const void *, int, int, int, DWORD, int, SCRIPT_CONTROL*, SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*, SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
static HRESULT WINAPI Dummy_ScriptStringCPtoX( SCRIPT_STRING_ANALYSIS, int, BOOL, int* ) { return E_NOTIMPL; }
static HRESULT WINAPI Dummy_ScriptStringXtoCP( SCRIPT_STRING_ANALYSIS, int, int*, int* ) { return E_NOTIMPL; }
static HRESULT WINAPI Dummy_ScriptStringFree( SCRIPT_STRING_ANALYSIS* ) { return E_NOTIMPL; }
static const SCRIPT_LOGATTR* WINAPI Dummy_ScriptString_pLogAttr( SCRIPT_STRING_ANALYSIS ) { return NULL; }
static const int* WINAPI Dummy_ScriptString_pcOutChars( SCRIPT_STRING_ANALYSIS ) { return NULL; }
// Function pointers
static HRESULT (WINAPI *_ScriptApplyDigitSubstitution)( const SCRIPT_DIGITSUBSTITUTE*, SCRIPT_CONTROL*, SCRIPT_STATE* );
static HRESULT (WINAPI *_ScriptStringAnalyse)( HDC, const void *, int, int, int, DWORD, int, SCRIPT_CONTROL*, SCRIPT_STATE*, const int*, SCRIPT_TABDEF*, const BYTE*, SCRIPT_STRING_ANALYSIS* );
static HRESULT (WINAPI *_ScriptStringCPtoX)( SCRIPT_STRING_ANALYSIS, int, BOOL, int* );
static HRESULT (WINAPI *_ScriptStringXtoCP)( SCRIPT_STRING_ANALYSIS, int, int*, int* );
static HRESULT (WINAPI *_ScriptStringFree)( SCRIPT_STRING_ANALYSIS* );
static const SCRIPT_LOGATTR* (WINAPI *_ScriptString_pLogAttr)( SCRIPT_STRING_ANALYSIS );
static const int* (WINAPI *_ScriptString_pcOutChars)( SCRIPT_STRING_ANALYSIS );
static HINSTANCE s_hDll; // Uniscribe DLL handle
};
//-----------------------------------------------------------------------------
// EditBox control
//-----------------------------------------------------------------------------
class CDXUTEditBox : public CDXUTControl
{
public:
CDXUTEditBox( CDXUTDialog *pDialog = NULL );
virtual ~CDXUTEditBox();
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 UpdateRects();
virtual bool CanHaveFocus() { return (m_bVisible && m_bEnabled); }
virtual void Render( float fElapsedTime );
virtual void OnFocusIn();
void SetText( LPCWSTR wszText, bool bSelected = false );
LPCWSTR GetText() { return m_Buffer.GetBuffer(); }
int GetTextLength() { return m_Buffer.GetTextSize(); } // Returns text length in chars excluding NULL.
HRESULT GetTextCopy( LPWSTR strDest, UINT bufferCount );
void ClearText();
virtual void SetTextColor( D3DCOLOR Color ) { m_TextColor = Color; } // Text color
void SetSelectedTextColor( D3DCOLOR Color ) { m_SelTextColor = Color; } // Selected text color
void SetSelectedBackColor( D3DCOLOR Color ) { m_SelBkColor = Color; } // Selected background color
void SetCaretColor( D3DCOLOR Color ) { m_CaretColor = Color; } // Caret color
void SetBorderWidth( int nBorder ) { m_nBorder = nBorder; UpdateRects(); } // Border of the window
void SetSpacing( int nSpacing ) { m_nSpacing = nSpacing; UpdateRects(); }
void ParseFloatArray( float *pNumbers, int nCount );
void SetTextFloatArray( const float *pNumbers, int nCount );
protected:
void PlaceCaret( int nCP );
void DeleteSelectionText();
void ResetCaretBlink();
void CopyToClipboard();
void PasteFromClipboard();
CUniBuffer m_Buffer; // Buffer to hold text
int m_nBorder; // Border of the window
int m_nSpacing; // Spacing between the text and the edge of border
RECT m_rcText; // Bounding rectangle for the text
RECT m_rcRender[9]; // Convenient rectangles for rendering elements
double m_dfBlink; // Caret blink time in milliseconds
double m_dfLastBlink; // Last timestamp of caret blink
bool m_bCaretOn; // Flag to indicate whether caret is currently visible
int m_nCaret; // Caret position, in characters
bool m_bInsertMode; // If true, control is in insert mode. Else, overwrite mode.
int m_nSelStart; // Starting position of the selection. The caret marks the end.
int m_nFirstVisible;// First visible character in the edit control
D3DCOLOR m_TextColor; // Text color
D3DCOLOR m_SelTextColor; // Selected text color
D3DCOLOR m_SelBkColor; // Selected background color
D3DCOLOR m_CaretColor; // Caret color
// Mouse-specific
bool m_bMouseDrag; // True to indicate drag in progress
// Static
static bool s_bHideCaret; // If true, we don't render the caret.
};
#endif // DXUT_GUI_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -