Skip to content

Commit

Permalink
Button控件支持颜色
Browse files Browse the repository at this point in the history
Button控件支持颜色(bkcolor-hotbkcolor-pushedbkcolor)
  • Loading branch information
duisharp committed Jun 16, 2015
1 parent fcc3bdb commit 2f45267
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
26 changes: 24 additions & 2 deletions DuiLib/Control/UIButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace DuiLib
, m_dwHotTextColor(0)
, m_dwPushedTextColor(0)
, m_dwFocusedTextColor(0)
,m_dwHotBkColor(0)
,m_iBindTabIndex(-1)
, m_dwHotBkColor(0)
, m_dwPushedBkColor(0)
, m_iBindTabIndex(-1)
{
m_uTextStyle = DT_SINGLELINE | DT_VCENTER | DT_CENTER;
}
Expand Down Expand Up @@ -139,6 +140,16 @@ namespace DuiLib
{
return m_dwHotBkColor;
}

void CButtonUI::SetPushedBkColor( DWORD dwColor )
{
m_dwPushedBkColor = dwColor;
}

DWORD CButtonUI::GetPushedBkColor() const
{
return m_dwPushedBkColor;
}

void CButtonUI::SetHotTextColor(DWORD dwColor)
{
Expand Down Expand Up @@ -311,6 +322,13 @@ namespace DuiLib
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
SetHotBkColor(clrColor);
}
else if( _tcscmp(pstrName, _T("pushedbkcolor")) == 0 )
{
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
SetPushedBkColor(clrColor);
}
else if( _tcscmp(pstrName, _T("hottextcolor")) == 0 )
{
if( *pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
Expand Down Expand Up @@ -410,6 +428,10 @@ namespace DuiLib
}
else goto Label_ForeImage;
}
else if(m_dwPushedBkColor != 0) {
CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwPushedBkColor));
return;
}
}
else if( (m_uButtonState & UISTATE_HOT) != 0 ) {
if( !m_sHotImage.IsEmpty() ) {
Expand Down
3 changes: 3 additions & 0 deletions DuiLib/Control/UIButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace DuiLib

void SetHotBkColor(DWORD dwColor);
DWORD GetHotBkColor() const;
void SetPushedBkColor(DWORD dwColor);
DWORD GetPushedBkColor() const;
void SetHotTextColor(DWORD dwColor);
DWORD GetHotTextColor() const;
void SetPushedTextColor(DWORD dwColor);
Expand All @@ -58,6 +60,7 @@ namespace DuiLib
UINT m_uButtonState;

DWORD m_dwHotBkColor;
DWORD m_dwPushedBkColor;
DWORD m_dwHotTextColor;
DWORD m_dwPushedTextColor;
DWORD m_dwFocusedTextColor;
Expand Down
1 change: 1 addition & 0 deletions bin/skin/duidemo/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Button name="button1" text="普通按钮" textcolor="#FF555555" normalimage="res='button_normal.png' corner='4,4,4,4'" hotimage="res='button_hover.png' corner='4,4,4,4'" pushedimage="res='button_pushed.png' corner='4,4,4,4'" width="100"/>
<Button name="button2" text="图标按钮" textcolor="#FF555555" normalimage="res='button_normal.png' corner='4,4,4,4'" hotimage="res='button_hover.png' corner='4,4,4,4'" pushedimage="res='button_pushed.png' corner='4,4,4,4'" width="100" textpadding="20,0,0,0" foreimage="dest='4,7,20,23' res='icon.png'" />
<Button name="sendbtn" text="命令按钮(&S)" textcolor="#FF555555" normalimage="res='button_normal.png' corner='4,4,4,4'" hotimage="res='button_hover.png' corner='4,4,4,4'" pushedimage="res='button_pushed.png' corner='4,4,4,4'" shortcut="S" width="120"/>
<Button name="sendbtn" text="颜色按钮" textcolor="#FF555555" bkcolor="#FFFF0000" hotbkcolor="#FFFFFF00" pushedbkcolor="#FFFF00FF" borderround="4,4" width="120"/>

</HorizontalLayout>
<Control />
Expand Down

0 comments on commit 2f45267

Please sign in to comment.