TA的每日心情 | 开心 2025-7-21 08:55 |
---|
签到天数: 60 天 [LV.6]常住居民II
管理员
- 积分
- 1677
|
如上图所示,需要一个继承自SButton的SColorButton,这个有什么好处?无须制作skin,直接使用colorBkgnd来表示其皮肤,用于大量创建纯色的按钮,不需要制作很多皮肤
使用方式如下
<colorbutton name="btn_c1" pos="3,[3,@24,@24" colorBkgnd="rgb(255,0,0)" animate="1" />
SColorButton.h
(541 Bytes, 下载次数: 0)
SColorButton.cpp
(301 Bytes, 下载次数: 0)
使用时需要先注册这个定义的控件,
m_theApp->RegisterWindowClass<SColorButton>();
class SColorButton : public SButton{
DEF_SOBJECT(SButton, L"colorbutton")
注意在声明这个控件时,上面红色的SButton表示SColorButton的父类是SButton,这是不同于SOUI前几代的地方。
由于本控制从SButton继承,且只需要显示颜色而不是特定的皮肤
void SColorButton::OnPaint(IRenderTarget * pRT)
{
SPainter painter;
BeforePaint(pRT, painter);
CRect rc;
GetClientRect(&rc);
pRT->FillSolidRect(&rc, GetBkgndColor());
AfterPaint(pRT, painter);
}
所以在OnPaint时只需要填充colorBkgnd的颜色即可。
|
|