仿酷狗音乐播放器开发日志二十三 修复Option控件显示状态不全的bug(附源码)...
轉(zhuǎn)載請說明原出處,謝謝~~
? ? ? ? ?整個仿酷狗工程的開發(fā)將近尾聲,現(xiàn)在還差選項設(shè)置窗體的部分,顯然在設(shè)置窗體里用的最多的就是OptionUI控件,我在寫好大致的布局后去測試效果,發(fā)現(xiàn)Option控件的顯示效果很不理想。在源碼中可以知道(屬性列表中列的不全面)Option提供了8種顯示狀態(tài),分別為
<Attribute name="normalimage" default="" type="STRING" comment="普通狀態(tài)圖片"/> <Attribute name="hotimage" default="" type="STRING" comment="鼠標(biāo)懸浮的狀態(tài)圖片"/> <Attribute name="pushedimage" default="" type="STRING" comment="鼠標(biāo)按下的狀態(tài)圖片"/> <Attribute name="focusedimage" default="" type="STRING" comment="獲得焦點時的狀態(tài)圖片"/> <Attribute name="disabledimage" default="" type="STRING" comment="禁用的狀態(tài)圖片"/> <Attribute name="selectedimage" default="" type="STRING" comment="選中的狀態(tài)圖片"/> <Attribute name="selectedhotimage" default="" type="STRING" comment="選中的鼠標(biāo)懸浮的的狀態(tài)圖片"/> <Attribute name="foreimage" default="" type="STRING" comment="前景圖片"/>
? ? ? ? 這些屬性可以大致模仿出check控件分別在選中和非選中狀態(tài)下的一些效果,我設(shè)置了其中的normalimage、hotimage、pushedimage、disabledimage、selectedimage、selectedhotimage屬性,但是在測試時發(fā)現(xiàn),只有pushedimage屬性沒有效果,也就是check控件和option控件沒有被按下的狀態(tài)的效果,同時也注意到原控件沒有提供選中的鼠標(biāo)按下的的狀態(tài)圖片,這就讓Option控件和Check控件的效果很不好。查看源碼后發(fā)現(xiàn)問題。原代碼如下:
void COptionUI::PaintStatusImage(HDC hDC){m_uButtonState &= ~UISTATE_PUSHED;if( (m_uButtonState & UISTATE_HOT) != 0 && IsSelected() && !m_sSelectedHotImage.IsEmpty()) {if( !DrawImage(hDC, (LPCTSTR)m_sSelectedHotImage) )m_sSelectedHotImage.Empty();else goto Label_ForeImage;}else if( (m_uButtonState & UISTATE_SELECTED) != 0 ) {if( !m_sSelectedImage.IsEmpty() ) {if( !DrawImage(hDC, (LPCTSTR)m_sSelectedImage) ) m_sSelectedImage.Empty();else goto Label_ForeImage;}else if(m_dwSelectedBkColor != 0) {CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwSelectedBkColor));return;} }CButtonUI::PaintStatusImage(hDC);Label_ForeImage:if( !m_sForeImage.IsEmpty() ) {if( !DrawImage(hDC, (LPCTSTR)m_sForeImage) ) m_sForeImage.Empty();}}? ? ? ? 可以看到,代碼的第一句就把按下狀態(tài)給去掉了,雖然不知道作者這樣寫的意圖,但我覺得這是不對的,去掉這句代碼后Option控件在非選中狀態(tài)下就可以顯示鼠標(biāo)按下的狀態(tài)了。
? ? ? ? 隨后我給Option控件增加了一個selectedpushedimage屬性,用來設(shè)置選中的鼠標(biāo)按下的的狀態(tài)圖片,讓Option的顯示狀態(tài)更加完全,為了使用這個屬性,需要修改SetAttribute函數(shù),另外增加了兩個函數(shù)SetSelectedPushedImage和GetSelectedPushedImage,這是修改后的PaintStatusImage函數(shù):
if( (m_uButtonState & UISTATE_PUSHED) != 0 && IsSelected() && !m_sSelectedPushedImage.IsEmpty()) {if( !DrawImage(hDC, (LPCTSTR)m_sSelectedPushedImage) )m_sSelectedPushedImage.Empty();else goto Label_ForeImage;}else if( (m_uButtonState & UISTATE_HOT) != 0 && IsSelected() && !m_sSelectedHotImage.IsEmpty()) {if( !DrawImage(hDC, (LPCTSTR)m_sSelectedHotImage) )m_sSelectedHotImage.Empty();else goto Label_ForeImage;}else if( (m_uButtonState & UISTATE_SELECTED) != 0 ) {if( !m_sSelectedImage.IsEmpty() ) {if( !DrawImage(hDC, (LPCTSTR)m_sSelectedImage) ) m_sSelectedImage.Empty();else goto Label_ForeImage;}else if(m_dwSelectedBkColor != 0) {CRenderEngine::DrawColor(hDC, m_rcPaint, GetAdjustColor(m_dwSelectedBkColor));return;} }CButtonUI::PaintStatusImage(hDC);Label_ForeImage:if( !m_sForeImage.IsEmpty() ) {if( !DrawImage(hDC, (LPCTSTR)m_sForeImage) ) m_sForeImage.Empty();}? ? ? ? ? 這樣就可以讓Option控件顯示出9種狀態(tài)了,完全可以模仿出真正的Option控件的樣子,這是我做的一部分的設(shè)置窗體的樣子:
? ? ? ? ? ?這里給出完整的狀態(tài)屬性列表:
<Attribute name="normalimage" default="" type="STRING" comment="普通狀態(tài)圖片"/> <Attribute name="hotimage" default="" type="STRING" comment="鼠標(biāo)懸浮的狀態(tài)圖片"/> <Attribute name="pushedimage" default="" type="STRING" comment="鼠標(biāo)按下的狀態(tài)圖片"/> <Attribute name="focusedimage" default="" type="STRING" comment="獲得焦點時的狀態(tài)圖片"/> <Attribute name="disabledimage" default="" type="STRING" comment="禁用的狀態(tài)圖片"/> <Attribute name="selectedimage" default="" type="STRING" comment="選中的狀態(tài)圖片"/> <Attribute name="selectedhotimage" default="" type="STRING" comment="選中的鼠標(biāo)懸浮的的狀態(tài)圖片"/> <Attribute name="selectedpushedimage" default="" type="STRING" comment="選中的鼠標(biāo)按下的的狀態(tài)圖片"/> <Attribute name="foreimage" default="" type="STRING" comment="前景圖片"/>
? ? ? ? 另外因為需要大量重復(fù)使用Option控件,為了避免重復(fù)設(shè)置屬性,我這里給出我的仿酷狗設(shè)置窗體的Default標(biāo)簽,方便大家用,大家根據(jù)自己的情況再去修改: <Default name="CheckBox" value="textcolor="#FF454545" disabledtextcolor="#FF454545" width="10" height="14" textpadding="16,1,0,0" align="left" normalimage="file='UI\setting\check_normal.png' dest='0,0,14,14'" hotimage="file='UI\setting\check_hover.png' dest='0,0,14,14'" pushedimage="file='UI\setting\check_down.png' dest='0,0,14,14'" disabledimage="file='UI\setting\check_disable.png' dest='0,0,14,14'" selectedimage="file='UI\setting\checked_normal.png' dest='0,0,14,14'" selectedhotimage="file='UI\setting\checked_hover.png' dest='0,0,14,14'" selectedpushedimage="file='UI\setting\checked_down.png' dest='0,0,14,14'" autocalcwidth="true""/>
總結(jié):
? ? ? ? 其實還可以在寫一個selecteddisabledimage屬性,用來給選中狀態(tài)下的Option控件設(shè)置禁用效果,這個代碼我目前不需要,就不寫了,留給大家自己寫吧,很簡單的。
? ? ? ? 修改好的OPtion控件下載地址:點擊打開鏈接
Redrain 2014.8.25
轉(zhuǎn)載于:https://www.cnblogs.com/redrainblog/p/3936092.html
總結(jié)
以上是生活随笔為你收集整理的仿酷狗音乐播放器开发日志二十三 修复Option控件显示状态不全的bug(附源码)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QQ微派狼人杀经典秘籍进阶篇
- 下一篇: centos服务器 java 项目new