2024-05-13 22:35:46 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// File: DXUTgui.cpp
|
|
|
|
//
|
|
|
|
// Desc:
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
#include "dxstdafx.h"
|
|
|
|
#include "DXUTgui.h"
|
2024-05-18 22:53:38 +08:00
|
|
|
#include "DXUTsettingsDlg.h"
|
2024-05-13 22:35:46 +08:00
|
|
|
#undef min // use __min instead
|
|
|
|
#undef max // use __max instead
|
|
|
|
|
2024-05-16 22:41:42 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// CDXUTDialog class
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CDXUTDialog::CDXUTDialog()
|
|
|
|
{
|
|
|
|
m_x = 0;
|
|
|
|
m_y = 0;
|
|
|
|
m_width = 0;
|
|
|
|
m_height = 0;
|
|
|
|
|
|
|
|
m_pManager = NULL;
|
|
|
|
m_bVisible = true;
|
|
|
|
m_bCaption = false;
|
|
|
|
m_bMinimized = false;
|
|
|
|
m_wszCaption[0] = L'\0';
|
|
|
|
m_nCaptionHeight = 18;
|
|
|
|
|
|
|
|
m_colorTopLeft = 0;
|
|
|
|
m_colorTopRight = 0;
|
|
|
|
m_colorBottomLeft = 0;
|
|
|
|
m_colorBottomRight = 0;
|
|
|
|
|
|
|
|
m_pCallbackEvent = NULL;
|
|
|
|
m_pCallbackEventUserContext = NULL;
|
|
|
|
|
|
|
|
m_fTimeLastRefresh = 0;
|
|
|
|
|
|
|
|
m_pControlMouseOver = NULL;
|
|
|
|
|
|
|
|
m_pNextDialog = this;
|
|
|
|
m_pPrevDialog = this;
|
|
|
|
|
|
|
|
m_nDefaultControlID = 0xffff;
|
|
|
|
m_bNonUserEvents = false;
|
|
|
|
m_bKeyboardInput = false;
|
|
|
|
m_bMouseInput = true;
|
|
|
|
}
|
|
|
|
|
2024-05-13 22:42:05 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CDXUTDialogResourceManager::CDXUTDialogResourceManager()
|
|
|
|
{
|
|
|
|
m_pd3dDevice = NULL;
|
|
|
|
m_pStateBlock = NULL;
|
|
|
|
m_pSprite = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-15 22:21:07 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
HRESULT CDXUTDialogResourceManager::OnResetDevice()
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
for( int i=0; i < m_FontCache.GetSize(); i++ )
|
|
|
|
{
|
|
|
|
DXUTFontNode* pFontNode = m_FontCache.GetAt( i );
|
|
|
|
|
|
|
|
if( pFontNode->pFont )
|
|
|
|
pFontNode->pFont->OnResetDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_pSprite )
|
|
|
|
m_pSprite->OnResetDevice();
|
|
|
|
|
|
|
|
m_pd3dDevice->CreateStateBlock( D3DSBT_ALL, &m_pStateBlock );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2024-05-15 22:23:34 +08:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
void CDXUTDialogResourceManager::OnLostDevice()
|
|
|
|
{
|
|
|
|
for( int i=0; i < m_FontCache.GetSize(); i++ )
|
|
|
|
{
|
|
|
|
DXUTFontNode* pFontNode = m_FontCache.GetAt( i );
|
|
|
|
|
|
|
|
if( pFontNode->pFont )
|
|
|
|
pFontNode->pFont->OnLostDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_pSprite )
|
|
|
|
m_pSprite->OnLostDevice();
|
|
|
|
|
|
|
|
SAFE_RELEASE( m_pStateBlock );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-15 22:24:47 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
void CDXUTDialogResourceManager::OnDestroyDevice()
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
//m_pd3dDevice = NULL;
|
|
|
|
|
|
|
|
// Release the resources but don't clear the cache, as these will need to be
|
|
|
|
// recreated if the device is recreated
|
|
|
|
for( i=0; i < m_FontCache.GetSize(); i++ )
|
|
|
|
{
|
|
|
|
DXUTFontNode* pFontNode = m_FontCache.GetAt( i );
|
|
|
|
SAFE_RELEASE( pFontNode->pFont );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i=0; i < m_TextureCache.GetSize(); i++ )
|
|
|
|
{
|
|
|
|
DXUTTextureNode* pTextureNode = m_TextureCache.GetAt( i );
|
|
|
|
SAFE_RELEASE( pTextureNode->pTexture );
|
|
|
|
}
|
|
|
|
|
|
|
|
SAFE_RELEASE( m_pSprite );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-15 22:52:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// CDXUTControl class
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CDXUTControl::CDXUTControl( CDXUTDialog *pDialog )
|
|
|
|
{
|
|
|
|
m_Type = DXUT_CONTROL_BUTTON;
|
|
|
|
m_pDialog = pDialog;
|
|
|
|
m_ID = 0;
|
|
|
|
m_Index = 0;
|
|
|
|
m_pUserData = NULL;
|
|
|
|
|
|
|
|
m_bEnabled = true;
|
|
|
|
m_bVisible = true;
|
|
|
|
m_bMouseOver = false;
|
|
|
|
m_bHasFocus = false;
|
|
|
|
m_bIsDefault = false;
|
|
|
|
|
|
|
|
m_pDialog = NULL;
|
|
|
|
|
|
|
|
m_x = 0;
|
|
|
|
m_y = 0;
|
|
|
|
m_width = 0;
|
|
|
|
m_height = 0;
|
|
|
|
|
|
|
|
ZeroMemory( &m_rcBoundingBox, sizeof( m_rcBoundingBox ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-16 22:23:43 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// CDXUTStatic class
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
HRESULT CDXUTStatic::GetTextCopy( PCHAR strDest, UINT bufferCount )
|
|
|
|
{
|
|
|
|
// Validate incoming parameters
|
|
|
|
if( strDest == NULL || bufferCount == 0 )
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the window text
|
|
|
|
StringCchCopy( strDest, bufferCount, m_strText );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2024-05-13 22:35:46 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
void DXUTBlendColor::Init( D3DCOLOR defaultColor, D3DCOLOR disabledColor, D3DCOLOR hiddenColor )
|
|
|
|
{
|
|
|
|
for( int i=0; i < MAX_CONTROL_STATES; i++ )
|
|
|
|
{
|
|
|
|
States[ i ] = defaultColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
States[ DXUT_STATE_DISABLED ] = disabledColor;
|
|
|
|
States[ DXUT_STATE_HIDDEN ] = hiddenColor;
|
|
|
|
Current = hiddenColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
void DXUTBlendColor::Blend( UINT iState, float fElapsedTime, float fRate )
|
|
|
|
{
|
|
|
|
D3DXCOLOR destColor = States[ iState ];
|
|
|
|
D3DXColorLerp( &Current, &Current, &destColor, 1.0f - powf( fRate, 30 * fElapsedTime ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-18 22:53:38 +08:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
void CDXUTElement::SetTexture( UINT iTexture, RECT* prcTexture, D3DCOLOR defaultTextureColor )
|
|
|
|
{
|
|
|
|
this->iTexture = iTexture;
|
|
|
|
|
|
|
|
if( prcTexture )
|
|
|
|
rcTexture = *prcTexture;
|
|
|
|
else
|
|
|
|
SetRectEmpty( &rcTexture );
|
|
|
|
|
|
|
|
TextureColor.Init( defaultTextureColor );
|
|
|
|
}
|
|
|
|
|
|
|
|
|