From d9cbdd67b9498c4851a0a26ca1cd5012c5f15b3c Mon Sep 17 00:00:00 2001 From: Troy Date: Mon, 19 Mar 2018 11:19:57 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81Button=E6=8E=A7=E4=BB=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=8A=B6=E6=80=81=E5=AD=97=E4=BD=93=EF=BC=9A=E6=96=B0?= =?UTF-8?q?=E5=A2=9Ehotfont=E3=80=81pushedfont=E3=80=81focusedfont?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=202=E3=80=81Option=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=8A=B6=E6=80=81=E5=AD=97=E4=BD=93=EF=BC=9A?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eselectedfont=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DuiLib/Control/UIButton.cpp | 55 +++++++++++++++++++++++++++++++++++-- DuiLib/Control/UIButton.h | 11 ++++++++ DuiLib/Control/UIOption.cpp | 18 ++++++++++-- DuiLib/Control/UIOption.h | 5 ++++ 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/DuiLib/Control/UIButton.cpp b/DuiLib/Control/UIButton.cpp index 1b53054a..2dda535b 100644 --- a/DuiLib/Control/UIButton.cpp +++ b/DuiLib/Control/UIButton.cpp @@ -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) @@ -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; @@ -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); } @@ -379,7 +420,7 @@ 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) ) @@ -387,12 +428,20 @@ namespace DuiLib 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) diff --git a/DuiLib/Control/UIButton.h b/DuiLib/Control/UIButton.h index ba41b214..d3d68cde 100644 --- a/DuiLib/Control/UIButton.h +++ b/DuiLib/Control/UIButton.h @@ -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); @@ -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; diff --git a/DuiLib/Control/UIOption.cpp b/DuiLib/Control/UIOption.cpp index 5a254831..94184987 100644 --- a/DuiLib/Control/UIOption.cpp +++ b/DuiLib/Control/UIOption.cpp @@ -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); @@ -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); } @@ -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; @@ -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; } diff --git a/DuiLib/Control/UIOption.h b/DuiLib/Control/UIOption.h index c09a3f73..77759234 100644 --- a/DuiLib/Control/UIOption.h +++ b/DuiLib/Control/UIOption.h @@ -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; @@ -59,6 +62,8 @@ namespace DuiLib bool m_bSelected; CDuiString m_sGroupName; + int m_iSelectedFont; + DWORD m_dwSelectedBkColor; DWORD m_dwSelectedTextColor;