zoukankan      html  css  js  c++  java
  • CustomUI Direct3D9_Sample

     刚开始建这个项目的时候编译器报了很多Link2019的错误。

    后来添加了一些lib文件才解决,参考    缺少.lib文件导致的Link2019 解决方案汇总

     ============================================================================================================================

    Dialog::InitDefaultElements()

    创建各种Element(元素,组成Control的单元),放到CDXUTElementHolder类型的Dialog::m_DefaultElements中.

    1 struct DXUTElementHolder
    2 {
    3     UINT nControlType;
    4     UINT iElement;
    5 
    6     CDXUTElement Element;
    7 };

    m_DefaultElements存放的ElementHolder根据所属控件的类型(nControlType)从小到大(0开始)编号

     1 //-------------------------------------
     2     // CDXUTButton - Button
     3     //-------------------------------------
     4     SetRect( &rcTexture, 0, 0, 136, 54 );
     5     Element.SetTexture( 0, &rcTexture );
     6     Element.SetFont( 0 );
     7     Element.TextureColor.States[ DXUT_STATE_NORMAL ] = D3DCOLOR_ARGB( 150, 255, 255, 255 );
     8     Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB( 200, 255, 255, 255 );
     9     Element.FontColor.States[ DXUT_STATE_MOUSEOVER ] = D3DCOLOR_ARGB( 255, 0, 0, 0 );
    10 
    11     // Assign the Element
    12     SetDefaultElement( DXUT_CONTROL_BUTTON, 0, &Element );
    13 
    14 
    15     //-------------------------------------
    16     // CDXUTButton - Fill layer
    17     //-------------------------------------
    18     SetRect( &rcTexture, 136, 0, 252, 54 );
    19     Element.SetTexture( 0, &rcTexture, D3DCOLOR_ARGB( 0, 255, 255, 255 ) );
    20     Element.TextureColor.States[ DXUT_STATE_MOUSEOVER ] = D3DCOLOR_ARGB( 160, 255, 255, 255 );
    21     Element.TextureColor.States[ DXUT_STATE_PRESSED ] = D3DCOLOR_ARGB( 60, 0, 0, 0 );
    22     Element.TextureColor.States[ DXUT_STATE_FOCUS ] = D3DCOLOR_ARGB( 30, 255, 255, 255 );
    23 
    24 
    25     // Assign the Element
    26     SetDefaultElement( DXUT_CONTROL_BUTTON, 1, &Element );

    这段代码定义了两个Button类型的Element,编号为0和1。

    如果继续添加的话编号递增。

    添加另一种类型的话,编号重新从零开始。

     

    ===================================================================================================================

    CDXUTControl::SetElement
     1 HRESULT CDXUTControl::SetElement( UINT iElement, CDXUTElement* pElement )
     2 {
     3     HRESULT hr = S_OK;
     4 
     5     if( pElement == NULL )
     6         return E_INVALIDARG;
     7     
     8     //m_DefaultElements中的元素同类型编号按从小到大的顺序排列
     9     //所以从m_DefaultElements中挑选出来的pElement的编号iElement递增(0,1,2.....)
    10     //某一种控件第一次调用此函数(SetElement)时,控件的m_Elements为空,将编号为0的Element存入,循环退出
    11     // Make certain the array is this large
    12     for( UINT i = m_Elements.GetSize(); i <= iElement; i++ )
    13     {
    14         CDXUTElement* pNewElement = new CDXUTElement();
    15         if( pNewElement == NULL )
    16             return E_OUTOFMEMORY;
    17 
    18         hr = m_Elements.Add( pNewElement );
    19         if( FAILED( hr ) )
    20         {
    21             SAFE_DELETE( pNewElement );
    22             return hr;
    23         }
    24     }
    25 
    26     // Update the data
    27     CDXUTElement* pCurElement = m_Elements.GetAt( iElement );
    28     *pCurElement = *pElement;
    29 
    30     return S_OK;
    31 }

     ===================================================================================================

    Element的定义如下

     1 class CDXUTElement
     2 {
     3 public:
     4     void    SetTexture( UINT iTexture, RECT* prcTexture, D3DCOLOR defaultTextureColor = D3DCOLOR_ARGB( 255, 255, 255,
     5                                                                                                        255 ) );
     6     void    SetFont( UINT iFont, D3DCOLOR defaultFontColor = D3DCOLOR_ARGB( 255, 255, 255,
     7                                                                             255 ), DWORD dwTextFormat = DT_CENTER |
     8                      DT_VCENTER );
     9 
    10     void    Refresh();
    11   //纹理, 文本字体, 文本格式,  
    12     UINT iTexture;          // Index of the texture for this Element 
    13     UINT iFont;             // Index of the font for this Element
    14     DWORD dwTextFormat;     // The format argument to DrawText 
    15   // 放纹理的边界矩形
    16     RECT rcTexture;         // Bounding rect of this element on the composite texture
    17   //纹理和文本的Blend颜色, Blend分量用于控制透明度
    18     DXUTBlendColor TextureColor;
    19     DXUTBlendColor FontColor;
    20 };

    ======================================================================================================

    可以使用输入法(Input Method Editor)的IMEEditBox

     1 //已经定义了g_SampleUI
     2     CDXUTDialog                 g_SampleUI;             // dialog for sample specific controls
     3     g_SampleUI.Init( &g_DialogResourceManager );
     4     g_SampleUI.SetCallback( OnGUIEvent );
     5 // IME-enabled edit box
     6     CDXUTIMEEditBox* pIMEEdit;
     7     CDXUTIMEEditBox::InitDefaultElements( &g_SampleUI );
     8     if( SUCCEEDED( CDXUTIMEEditBox::CreateIMEEditBox( &g_SampleUI, IDC_EDITBOX2,
     9                                                       L"IME-capable edit control with custom styles. Type and press Enter", 20, 390, 600, 45, false, &pIMEEdit ) ) )
    10     {
    11         g_SampleUI.AddControl( pIMEEdit );
    12         pIMEEdit->GetElement( 0 )->iFont = 1;
    13         pIMEEdit->GetElement( 1 )->iFont = 1;
    14         pIMEEdit->GetElement( 9 )->iFont = 1;
    15         pIMEEdit->GetElement( 0 )->TextureColor.Init( D3DCOLOR_ARGB( 128, 255, 255, 255 ) );  // Transparent center
    16         pIMEEdit->SetBorderWidth( 7 );
    17         pIMEEdit->SetTextColor( D3DCOLOR_ARGB( 255, 64, 64, 64 ) );
    18         pIMEEdit->SetCaretColor( D3DCOLOR_ARGB( 255, 64, 64, 64 ) );
    19         pIMEEdit->SetSelectedTextColor( D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
    20         pIMEEdit->SetSelectedBackColor( D3DCOLOR_ARGB( 255, 40, 72, 72 ) );
    21     }

    CDXUTIMEEditBox继承自CDXUTEditBox, 定义在DXUTguiIME.h/cpp文件中

    包含了静态函数:

    static void             InitDefaultElements( CDXUTDialog* pDialog );

    负责为该类定义所使用的Element(元素),并通过

    HRESULT CDXUTDialog::SetDefaultElement( UINT nControlType, UINT iElement, CDXUTElement* pElement );

    添加到所属Dialog的默认元素表(m_DefaultElements)中,  一共9个Element

    Please refer to DXUTguiIME.h/cpp  for more details  .

    =-=========================================================================================================================

     单选列表框                                                     多选列表框

                               

     1 class CDXUTListBox : public CDXUTControl
     2 {
     3 public:
     4                     CDXUTListBox( CDXUTDialog* pDialog = NULL );
     5     virtual         ~CDXUTListBox();
     6     .
     7     .
     8     .
     9     .//member function skipped
    10     .
    11     .
    12 
    13 protected:
    14     RECT m_rcText;      // Text rendering bound
    15     RECT m_rcSelection; // Selection box bound
    16     CDXUTScrollBar m_ScrollBar;
    17     int m_nSBWidth;
    18     int m_nBorder;
    19     int m_nMargin;
    20     int m_nTextHeight;  // Height of a single line of text
    21     DWORD m_dwStyle;    // List box style
    22     int m_nSelected;    // Index of the selected item for single selection list box
    23     int m_nSelStart;    // Index of the item where selection starts (for handling multi-selection)
    24     bool m_bDrag;       // Whether the user is dragging the mouse to select
    25 
    26     CGrowableArray <DXUTListBoxItem*> m_Items;
    27 };
    CDXUTListBox成员里的两个类型
    CDXUTScrollBar m_ScrollBar; 滚动条定义如下
     1 class CDXUTScrollBar : public CDXUTControl
     2 {
     3 public:
     4                     CDXUTScrollBar( CDXUTDialog* pDialog = NULL );
     5     virtual         ~CDXUTScrollBar();
     6     .
     7     .
     8     .    //member functions skipped
     9     .
    10     .
    11     .
    12 
    13 protected:
    14     // ARROWSTATE indicates the state of the arrow buttons.
    15     // CLEAR            No arrow is down.
    16     // CLICKED_UP       Up arrow is clicked.
    17     // CLICKED_DOWN     Down arrow is clicked.
    18     // HELD_UP          Up arrow is held down for sustained period.
    19     // HELD_DOWN        Down arrow is held down for sustained period.
    20     enum ARROWSTATE
    21     {
    22         CLEAR,
    23         CLICKED_UP,
    24         CLICKED_DOWN,
    25         HELD_UP,
    26         HELD_DOWN
    27     };
    28 
    29     void            UpdateThumbRect();
    30     void            Cap();  // Clips position at boundaries. Ensures it stays within legal range.
    31 
    32     bool m_bShowThumb;
    33     bool m_bDrag;
    34     RECT m_rcUpButton;
    35     RECT m_rcDownButton;
    36     RECT m_rcTrack;
    37     RECT m_rcThumb;
    38     int m_nPosition;  // Position of the first displayed item
    39     int m_nPageSize;  // How many items are displayable in one page
    40     int m_nStart;     // First item
    41     int m_nEnd;       // The index after the last item
    42     POINT m_LastMouse;// Last mouse position
    43     ARROWSTATE m_Arrow; // State of the arrows
    44     double m_dArrowTS;  // Timestamp of last arrow event.
    45 };
    View Code
    CGrowableArray <DXUTListBoxItem*> m_Items  选项的类型如下
    1 struct DXUTListBoxItem
    2 {
    3     WCHAR strText[256];
    4     void* pData;
    5 
    6     RECT rcActive;
    7     bool bSelected;
    8 };
    CGrowableArray解析
  • 相关阅读:
    通过注册表读取设置字体
    StretchBlt
    PatBlt
    如何用MaskBlt实现两个位图的合并,从而实现背景透明
    输出旋转字体
    用字体开透明窟窿
    输出空心字体
    光滑字体
    画贝塞尔曲线
    一些点运算函数
  • 原文地址:https://www.cnblogs.com/Agravity/p/5142029.html
Copyright © 2011-2022 走看看