Skip to content

Commit

Permalink
1、Button控件支持状态字体:新增hotfont、pushedfont、focusedfont属性
Browse files Browse the repository at this point in the history
2、Option控件支持状态字体:新增selectedfont属性
  • Loading branch information
qdtroy committed Mar 19, 2018
1 parent ddd5983 commit d9cbdd6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
55 changes: 52 additions & 3 deletions DuiLib/Control/UIButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace DuiLib

CButtonUI::CButtonUI()
: m_uButtonState(0)
, m_iHotFont(-1)
, m_iPushedFont(-1)
, m_iFocusedFont(-1)
, m_dwHotTextColor(0)
, m_dwPushedTextColor(0)
, m_dwFocusedTextColor(0)
Expand Down Expand Up @@ -128,6 +131,40 @@ namespace DuiLib
}
}


void CButtonUI::SetHotFont(int index)
{
m_iHotFont = index;
Invalidate();
}

int CButtonUI::GetHotFont() const
{
return m_iHotFont;
}

void CButtonUI::SetPushedFont(int index)
{
m_iPushedFont = index;
Invalidate();
}

int CButtonUI::GetPushedFont() const
{
return m_iPushedFont;
}

void CButtonUI::SetFocusedFont(int index)
{
m_iFocusedFont = index;
Invalidate();
}

int CButtonUI::GetFocusedFont() const
{
return m_iFocusedFont;
}

void CButtonUI::SetHotBkColor( DWORD dwColor )
{
m_dwHotBkColor = dwColor;
Expand Down Expand Up @@ -353,6 +390,10 @@ namespace DuiLib
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
SetFocusedTextColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("hotfont")) == 0 ) SetHotFont(_ttoi(pstrValue));
else if( _tcsicmp(pstrName, _T("pushedfont")) == 0 ) SetPushedFont(_ttoi(pstrValue));
else if( _tcsicmp(pstrName, _T("focuedfont")) == 0 ) SetFocusedFont(_ttoi(pstrValue));

else CLabelUI::SetAttribute(pstrName, pstrValue);
}

Expand All @@ -379,20 +420,28 @@ namespace DuiLib
rc.bottom -= m_rcTextPadding.bottom;

DWORD clrColor = IsEnabled()?m_dwTextColor:m_dwDisabledTextColor;

if( ((m_uButtonState & UISTATE_PUSHED) != 0) && (GetPushedTextColor() != 0) )
clrColor = GetPushedTextColor();
else if( ((m_uButtonState & UISTATE_HOT) != 0) && (GetHotTextColor() != 0) )
clrColor = GetHotTextColor();
else if( ((m_uButtonState & UISTATE_FOCUSED) != 0) && (GetFocusedTextColor() != 0) )
clrColor = GetFocusedTextColor();

int iFont = GetFont();
if( ((m_uButtonState & UISTATE_PUSHED) != 0) && (GetPushedFont() != -1) )
iFont = GetPushedFont();
else if( ((m_uButtonState & UISTATE_HOT) != 0) && (GetHotFont() != -1) )
iFont = GetHotFont();
else if( ((m_uButtonState & UISTATE_FOCUSED) != 0) && (GetFocusedFont() != -1) )
iFont = GetFocusedFont();

if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, sText, clrColor, \
NULL, NULL, nLinks, m_iFont, m_uTextStyle);
NULL, NULL, nLinks, iFont, m_uTextStyle);
else
CRenderEngine::DrawText(hDC, m_pManager, rc, sText, clrColor, \
m_iFont, m_uTextStyle);
iFont, m_uTextStyle);
}

void CButtonUI::PaintBkColor(HDC hDC)
Expand Down
11 changes: 11 additions & 0 deletions DuiLib/Control/UIButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ namespace DuiLib
int GetBindTabLayoutIndex();
LPCTSTR GetBindTabLayoutName();

void SetHotFont(int index);
int GetHotFont() const;
void SetPushedFont(int index);
int GetPushedFont() const;
void SetFocusedFont(int index);
int GetFocusedFont() const;

void SetHotBkColor(DWORD dwColor);
DWORD GetHotBkColor() const;
void SetPushedBkColor(DWORD dwColor);
Expand All @@ -65,6 +72,10 @@ namespace DuiLib
protected:
UINT m_uButtonState;

int m_iHotFont;
int m_iPushedFont;
int m_iFocusedFont;

DWORD m_dwHotBkColor;
DWORD m_dwPushedBkColor;
DWORD m_dwHotTextColor;
Expand Down
18 changes: 16 additions & 2 deletions DuiLib/Control/UIOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ namespace DuiLib
m_sSelectedStateImage = pStrImage;
Invalidate();
}
void COptionUI::SetSelectedFont(int index)
{
m_iSelectedFont = index;
Invalidate();
}

int COptionUI::GetSelectedFont() const
{
return m_iSelectedFont;
}
void COptionUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
if( _tcsicmp(pstrName, _T("group")) == 0 ) SetGroup(pstrValue);
Expand All @@ -220,6 +229,7 @@ namespace DuiLib
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
SetSelectedTextColor(clrColor);
}
else if( _tcsicmp(pstrName, _T("selectedfont")) == 0 ) SetSelectedFont(_ttoi(pstrValue));
else CButtonUI::SetAttribute(pstrName, pstrValue);
}

Expand Down Expand Up @@ -317,6 +327,10 @@ namespace DuiLib
if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor();
if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();

int iFont = GetFont();
if(GetSelectedFont() != -1) {
iFont = GetSelectedFont();
}
CDuiString sText = GetText();
if( sText.IsEmpty() ) return;
int nLinks = 0;
Expand All @@ -330,10 +344,10 @@ namespace DuiLib

if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, sText, IsEnabled()?m_dwTextColor:m_dwDisabledTextColor, \
NULL, NULL, nLinks, m_iFont, m_uTextStyle);
NULL, NULL, nLinks, iFont, m_uTextStyle);
else
CRenderEngine::DrawText(hDC, m_pManager, rc, sText, IsEnabled()?m_dwTextColor:m_dwDisabledTextColor, \
m_iFont, m_uTextStyle);
iFont, m_uTextStyle);

m_dwTextColor = oldTextColor;
}
Expand Down
5 changes: 5 additions & 0 deletions DuiLib/Control/UIOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace DuiLib
virtual LPCTSTR GetSelectedStateImage();
virtual void SetSelectedStateImage(LPCTSTR pStrImage);

void SetSelectedFont(int index);
int GetSelectedFont() const;

LPCTSTR GetGroup() const;
void SetGroup(LPCTSTR pStrGroupName = NULL);
bool IsSelected() const;
Expand All @@ -59,6 +62,8 @@ namespace DuiLib
bool m_bSelected;
CDuiString m_sGroupName;

int m_iSelectedFont;

DWORD m_dwSelectedBkColor;
DWORD m_dwSelectedTextColor;

Expand Down

0 comments on commit d9cbdd6

Please sign in to comment.