找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 67|回复: 0

SOUI5自定义控件示例Demo

[复制链接]
  • TA的每日心情
    开心
    2025-7-21 08:55
  • 签到天数: 60 天

    [LV.6]常住居民II

    76

    主题

    12

    回帖

    1677

    积分

    管理员

    积分
    1677
    发表于 2025-7-20 19:54:00 | 显示全部楼层 |阅读模式
    2025-07-20_194544.png


    如上图所示,需要一个继承自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的颜色即可。


    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|SOUI官方论坛

    GMT+8, 2025-8-19 08:51 , Processed in 0.087926 second(s), 24 queries .

    Powered by Discuz! X3.5

    © 2001-2025 Discuz! Team.

    快速回复 返回顶部 返回列表