📄 dxutgui.cpp
字号:
}
//--------------------------------------------------------------------------------------
void CDXUTDialog::OnCycleFocus( bool bForward )
{
// This should only be handled by the dialog which owns the focused control, and
// only if a control currently has focus
if( s_pControlFocus == NULL || s_pControlFocus->m_pDialog != this )
return;
CDXUTControl* pControl = s_pControlFocus;
for( int i=0; i < 0xffff; i++ )
{
pControl = (bForward) ? GetNextControl( pControl ) : GetPrevControl( pControl );
// If we've gone in a full circle then focus doesn't change
if( pControl == s_pControlFocus )
return;
// If the dialog accepts keybord input and the control can have focus then
// move focus
if( pControl->m_pDialog->m_bKeyboardInput && pControl->CanHaveFocus() )
{
s_pControlFocus->OnFocusOut();
s_pControlFocus = pControl;
s_pControlFocus->OnFocusIn();
return;
}
}
// If we reached this point, the chain of dialogs didn't form a complete loop
DXTRACE_ERR( L"CDXUTDialog: Multiple dialogs are improperly chained together", E_FAIL );
}
//--------------------------------------------------------------------------------------
void CDXUTDialog::OnMouseEnter( CDXUTControl* pControl )
{
if( pControl == NULL )
return;
//pControl->m_bMouseOver = true;
}
//--------------------------------------------------------------------------------------
void CDXUTDialog::OnMouseLeave( CDXUTControl* pControl )
{
if( pControl == NULL )
return;
//pControl->m_bMouseOver = false;
}
//--------------------------------------------------------------------------------------
HRESULT CDXUTDialogResourceManager::CreateFont( UINT iFont )
{
HRESULT hr = S_OK;
DXUTFontNode* pFontNode = m_FontCache.GetAt( iFont );
SAFE_RELEASE( pFontNode->pFont );
V_RETURN( D3DXCreateFont( m_pd3dDevice, pFontNode->nHeight, 0, pFontNode->nWeight, 1, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
pFontNode->strFace, &pFontNode->pFont ) );
return S_OK;
}
//--------------------------------------------------------------------------------------
HRESULT CDXUTDialogResourceManager::CreateTexture( UINT iTexture )
{
HRESULT hr = S_OK;
DXUTTextureNode* pTextureNode = m_TextureCache.GetAt( iTexture );
// Make sure there's a texture to create
if( pTextureNode->strFilename[0] == 0 )
return S_OK;
// Find the texture on the hard drive
WCHAR strPath[MAX_PATH];
hr = DXUTFindDXSDKMediaFileCch( strPath, MAX_PATH, pTextureNode->strFilename );
if( FAILED(hr) )
{
return DXTRACE_ERR( L"DXUTFindDXSDKMediaFileCch", hr );
}
// Create texture
D3DXIMAGE_INFO info;
hr = D3DXCreateTextureFromFileEx( m_pd3dDevice, strPath, D3DX_DEFAULT, D3DX_DEFAULT,
D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED,
D3DX_DEFAULT, D3DX_DEFAULT, 0,
&info, NULL, &pTextureNode->pTexture );
if( FAILED(hr) )
{
return DXTRACE_ERR( L"D3DXCreateTextureFromFileEx", hr );
}
// Store dimensions
pTextureNode->dwWidth = info.Width;
pTextureNode->dwHeight = info.Height;
return S_OK;
}
//--------------------------------------------------------------------------------------
void CDXUTDialog::InitDefaultElements()
{
SetTexture( 0, L"UI\\DXUTControls.dds" );
SetFont( 0, L"Arial", 14, FW_NORMAL );
CDXUTElement Element;
RECT rcTexture;
//-------------------------------------
// Element for the caption
//-------------------------------------
m_CapElement.SetFont( 0 );
SetRect( &rcTexture, 17, 269, 241, 287 );
m_CapElement.SetTexture( 0, &rcTexture );
m_CapElement.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(255, 255, 255, 255);
m_CapElement.FontColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(255, 255, 255, 255);
m_CapElement.SetFont( 0, D3DCOLOR_ARGB(255, 255, 255, 255), DT_LEFT | DT_VCENTER );
// Pre-blend as we don't need to transition the state
m_CapElement.TextureColor.Blend( DXUT_STATE_NORMAL, 10.0f );
m_CapElement.FontColor.Blend( DXUT_STATE_NORMAL, 10.0f );
//-------------------------------------
// CDXUTStatic
//-------------------------------------
Element.SetFont( 0 );
Element.FontColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB( 200, 200, 200, 200 );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_STATIC, 0, &Element );
//-------------------------------------
// CDXUTButton - Button
//-------------------------------------
SetRect( &rcTexture, 0, 0, 136, 54 );
Element.SetTexture( 0, &rcTexture );
Element.SetFont( 0 );
Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(150, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB(200, 255, 255, 255);
Element.FontColor.States[ DXUT_STATE_MOUSEOVER ] = D3DCOLOR_ARGB(255, 0, 0, 0);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_BUTTON, 0, &Element );
//-------------------------------------
// CDXUTButton - Fill layer
//-------------------------------------
SetRect( &rcTexture, 136, 0, 272, 54 );
Element.SetTexture( 0, &rcTexture, D3DCOLOR_ARGB(0, 255, 255, 255) );
Element.TextureColor.States[ DXUT_STATE_MOUSEOVER ] = D3DCOLOR_ARGB(160, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB(60, 0, 0, 0);
Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB(30, 255, 255, 255);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_BUTTON, 1, &Element );
//-------------------------------------
// CDXUTCheckBox - Box
//-------------------------------------
SetRect( &rcTexture, 0, 54, 27, 81 );
Element.SetTexture( 0, &rcTexture );
Element.SetFont( 0, D3DCOLOR_ARGB(255, 255, 255, 255), DT_LEFT | DT_VCENTER );
Element.FontColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB( 200, 200, 200, 200 );
Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(150, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB(200, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB(255, 255, 255, 255);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_CHECKBOX, 0, &Element );
//-------------------------------------
// CDXUTCheckBox - Check
//-------------------------------------
SetRect( &rcTexture, 27, 54, 54, 81 );
Element.SetTexture( 0, &rcTexture );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_CHECKBOX, 1, &Element );
//-------------------------------------
// CDXUTRadioButton - Box
//-------------------------------------
SetRect( &rcTexture, 54, 54, 81, 81 );
Element.SetTexture( 0, &rcTexture );
Element.SetFont( 0, D3DCOLOR_ARGB(255, 255, 255, 255), DT_LEFT | DT_VCENTER );
Element.FontColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB( 200, 200, 200, 200 );
Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(150, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB(200, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB(255, 255, 255, 255);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_RADIOBUTTON, 0, &Element );
//-------------------------------------
// CDXUTRadioButton - Check
//-------------------------------------
SetRect( &rcTexture, 81, 54, 108, 81 );
Element.SetTexture( 0, &rcTexture );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_RADIOBUTTON, 1, &Element );
//-------------------------------------
// CDXUTComboBox - Main
//-------------------------------------
SetRect( &rcTexture, 7, 81, 247, 123 );
Element.SetTexture( 0, &rcTexture );
Element.SetFont( 0 );
Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(150, 200, 200, 200);
Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB(170, 230, 230, 230);
Element.TextureColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(70, 200, 200, 200);
Element.FontColor.States[ DXUT_STATE_MOUSEOVER ] = D3DCOLOR_ARGB(255, 0, 0, 0);
Element.FontColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB(255, 0, 0, 0);
Element.FontColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(200, 200, 200, 200);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_COMBOBOX, 0, &Element );
//-------------------------------------
// CDXUTComboBox - Button
//-------------------------------------
SetRect( &rcTexture, 272, 0, 325, 49 );
Element.SetTexture( 0, &rcTexture );
Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(150, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB(255, 150, 150, 150);
Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB(200, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(70, 255, 255, 255);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_COMBOBOX, 1, &Element );
//-------------------------------------
// CDXUTComboBox - Dropdown
//-------------------------------------
SetRect( &rcTexture, 7, 123, 241, 265 );
Element.SetTexture( 0, &rcTexture );
Element.SetFont( 0, D3DCOLOR_ARGB(255, 0, 0, 0), DT_LEFT | DT_TOP );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_COMBOBOX, 2, &Element );
//-------------------------------------
// CDXUTComboBox - Selection
//-------------------------------------
SetRect( &rcTexture, 7, 266, 241, 289 );
Element.SetTexture( 0, &rcTexture );
Element.SetFont( 0, D3DCOLOR_ARGB(255, 255, 255, 255), DT_LEFT | DT_TOP );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_COMBOBOX, 3, &Element );
//-------------------------------------
// CDXUTSlider - Track
//-------------------------------------
SetRect( &rcTexture, 1, 290, 280, 331 );
Element.SetTexture( 0, &rcTexture );
Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB(150, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB(200, 255, 255, 255);
Element.TextureColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(70, 255, 255, 255);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_SLIDER, 0, &Element );
//-------------------------------------
// CDXUTSlider - Button
//-------------------------------------
SetRect( &rcTexture, 248, 55, 289, 96 );
Element.SetTexture( 0, &rcTexture );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_SLIDER, 1, &Element );
//-------------------------------------
// CDXUTScrollBar - Track
//-------------------------------------
SetRect( &rcTexture, 243, 144, 265, 155 );
Element.SetTexture( 0, &rcTexture );
Element.TextureColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(255, 200, 200, 200);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_SCROLLBAR, 0, &Element );
//-------------------------------------
// CDXUTScrollBar - Up Arrow
//-------------------------------------
SetRect( &rcTexture, 243, 124, 265, 144 );
Element.SetTexture( 0, &rcTexture );
Element.TextureColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(255, 200, 200, 200);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_SCROLLBAR, 1, &Element );
//-------------------------------------
// CDXUTScrollBar - Down Arrow
//-------------------------------------
SetRect( &rcTexture, 243, 155, 265, 176 );
Element.SetTexture( 0, &rcTexture );
Element.TextureColor.States[ DXUT_STATE_DISABLED ] = D3DCOLOR_ARGB(255, 200, 200, 200);
// Assign the Element
SetDefaultElement( DXUT_CONTROL_SCROLLBAR, 2, &Element );
//-------------------------------------
// CDXUTScrollBar - Button
//-------------------------------------
SetRect( &rcTexture, 266, 123, 286, 167 );
Element.SetTexture( 0, &rcTexture );
// Assign the Element
SetDefaultElement( DXUT_CONTROL_SCROLLBAR, 3, &Element );
//-------------------------------------
// CDXUTEditBox
//-------------------------------------
// Element assignment:
// 0 - text area
// 1 - top left border
// 2 - top border
// 3 - top right border
// 4 - left border
// 5 - right border
// 6 - lower left border
// 7 - lower border
// 8 - lower right border
Element.SetFont( 0, D3DCOLOR_ARGB( 255, 0, 0, 0 ), DT_LEFT | DT_TOP );
// Assign the style
SetRect( &rcTexture, 14, 90, 241, 113 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 0, &Element );
SetRect( &rcTexture, 8, 82, 14, 90 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 1, &Element );
SetRect( &rcTexture, 14, 82, 241, 90 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 2, &Element );
SetRect( &rcTexture, 241, 82, 246, 90 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 3, &Element );
SetRect( &rcTexture, 8, 90, 14, 113 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 4, &Element );
SetRect( &rcTexture, 241, 90, 246, 113 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 5, &Element );
SetRect( &rcTexture, 8, 113, 14, 121 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 6, &Element );
SetRect( &rcTexture, 14, 113, 241, 121 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 7, &Element );
SetRect( &rcTexture, 241, 113, 246, 121 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_EDITBOX, 8, &Element );
//-------------------------------------
// CDXUTIMEEditBox
//-------------------------------------
Element.SetFont( 0, D3DCOLOR_ARGB( 255, 0, 0, 0 ), DT_LEFT | DT_TOP );
// Assign the style
SetRect( &rcTexture, 14, 90, 241, 113 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_IMEEDITBOX, 0, &Element );
SetRect( &rcTexture, 8, 82, 14, 90 );
Element.SetTexture( 0, &rcTexture );
SetDefaultElement( DXUT_CONTROL_IMEEDITBOX, 1, &Element );
SetRect( &rcTexture, 14, 82, 241, 90 );
Element.SetTextu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -