Files
SA-MP/saco/d3d9/common/DXUTgui.h

199 lines
6.2 KiB
C
Raw Normal View History

//--------------------------------------------------------------------------------------
// File: DXUTgui.h
//
// Desc:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#ifndef DXUT_GUI_H
#define DXUT_GUI_H
//--------------------------------------------------------------------------------------
// Enums for pre-defined control types
//--------------------------------------------------------------------------------------
enum DXUT_CONTROL_TYPE
{
DXUT_CONTROL_BUTTON,
DXUT_CONTROL_STATIC,
DXUT_CONTROL_CHECKBOX,
DXUT_CONTROL_RADIOBUTTON,
DXUT_CONTROL_COMBOBOX,
DXUT_CONTROL_SLIDER,
DXUT_CONTROL_EDITBOX,
DXUT_CONTROL_IMEEDITBOX,
DXUT_CONTROL_LISTBOX,
DXUT_CONTROL_SCROLLBAR,
};
enum DXUT_CONTROL_STATE
{
DXUT_STATE_NORMAL = 0,
DXUT_STATE_DISABLED,
DXUT_STATE_HIDDEN,
DXUT_STATE_FOCUS,
DXUT_STATE_MOUSEOVER,
DXUT_STATE_PRESSED,
};
#define MAX_CONTROL_STATES 6
struct DXUTBlendColor
{
void Init( D3DCOLOR defaultColor, D3DCOLOR disabledColor = D3DCOLOR_ARGB(200, 128, 128, 128), D3DCOLOR hiddenColor = 0 );
void Blend( UINT iState, float fElapsedTime, float fRate = 0.7f );
D3DCOLOR States[ MAX_CONTROL_STATES ]; // Modulate colors for all possible control states
D3DXCOLOR Current;
};
2024-05-15 22:49:02 +08:00
//-----------------------------------------------------------------------------
// Contains all the display tweakables for a sub-control
//-----------------------------------------------------------------------------
class CDXUTElement
{
public:
UINT iTexture; // Index of the texture for this Element
UINT iFont; // Index of the font for this Element
DWORD dwTextFormat; // The format argument to DrawText
RECT rcTexture; // Bounding rect of this element on the composite texture
DXUTBlendColor TextureColor;
DXUTBlendColor FontColor;
};
//--------------------------------------------------------------------------------------
// Structs for shared resources
//--------------------------------------------------------------------------------------
struct DXUTTextureNode
{
TCHAR strFilename[MAX_PATH];
IDirect3DTexture9* pTexture;
DWORD dwWidth;
DWORD dwHeight;
};
struct DXUTFontNode
{
TCHAR strFace[MAX_PATH];
ID3DXFont* pFont;
LONG nHeight;
LONG nWeight;
};
//-----------------------------------------------------------------------------
// Manages shared resources of dialogs
//-----------------------------------------------------------------------------
class CDXUTDialogResourceManager
{
public:
CDXUTDialogResourceManager();
HRESULT OnResetDevice();
void OnLostDevice();
void OnDestroyDevice();
// Shared between all dialogs
IDirect3DStateBlock9* m_pStateBlock;
ID3DXSprite* m_pSprite; // Sprite used for drawing
protected:
CGrowableArray< DXUTTextureNode* > m_TextureCache; // Shared textures
CGrowableArray< DXUTFontNode* > m_FontCache; // Shared fonts
IDirect3DDevice9* m_pd3dDevice;
};
//-----------------------------------------------------------------------------
// Base class for controls
//-----------------------------------------------------------------------------
class CDXUTControl
{
public:
CDXUTControl( CDXUTDialog *pDialog = NULL );
virtual HRESULT OnInit() { return S_OK; }
virtual void Render( IDirect3DDevice9* pd3dDevice, 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 SetHotkey( UINT nHotkey ) { m_nHotkey = nHotkey; }
UINT GetHotkey() { return m_nHotkey; }
void SetUserData( void *pUserData ) { m_pUserData = pUserData; }
void *GetUserData() const { return m_pUserData; }
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:
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
};
//-----------------------------------------------------------------------------
// Static control
//-----------------------------------------------------------------------------
class CDXUTStatic : public CDXUTControl
{
public:
HRESULT GetTextCopy( PCHAR strDest, UINT bufferCount );
protected:
TCHAR m_strText[MAX_PATH]; // Window text
};
#endif // DXUT_GUI_H