您当前的位置: 首页 >  ui

插件开发

暂无认证

  • 2浏览

    0关注

    492博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

第一章 第二小节Duilib的基本支撑类(一)

插件开发 发布时间:2022-03-21 11:01:06 ,浏览量:2

  任何一个有体系的SDK,为了维护自己的数据结构和算法,都会有些自己的,作用于全局的基础类,这些类在使用和阅读源代码的时候是非常常见的,也是必须要掌握和理解的。如下表所示:

CDuiPointCDuiSizeCDuiRectCStdPtrArrayCStdValArrayCDuiStringCStdStringPtrMapCDuiVariant

  接下来从源码上依次分析:

1. CDuiPoint

  它是一个有x,y属性的点坐标,并且是整形点,这与屏幕像素坐标都是整形密不可分。

typedef struct  tagPOINT
    {
    LONG x;
    LONG y;
    }	POINT;
class UILIB_API CDuiPoint : public tagPOINT
    {
    public:
        CDuiPoint();
        CDuiPoint(const POINT& src);
        CDuiPoint(int x, int y);
        CDuiPoint(LPARAM lParam);
    };
2.CDuiSize

  它是一个表示长宽的数据结构,由cx和cy两个参数表示在x和y方向的长度。也是整数。

typedef struct  tagSIZE
    {
    LONG cx;
    LONG cy;
    }	SIZE;
class UILIB_API CDuiSize : public tagSIZE
    {
    public:
        CDuiSize();
        CDuiSize(const SIZE& src);
        CDuiSize(const RECT rc);
        CDuiSize(int cx, int cy);
    };

3.CDuiRect

  它表示一个矩形,它由left,top,right,bottom四个属性构成。以及与矩形相关的常用算法构成。见注释。

typedef struct  tagRECT
    {
    LONG left;
    LONG top;
    LONG right;
    LONG bottom;
    }	RECT;
class UILIB_API CDuiRect : public tagRECT
    {
    public:
        CDuiRect();
        CDuiRect(const RECT& src);
        CDuiRect(int iLeft, int iTop, int iRight, int iBottom);

        int GetWidth() const;
        int GetHeight() const;
        void Empty();//使四个属性值为零
        bool IsNull() const;//判读四个属性值是否为零
        void Join(const RECT& rc);//当前与rc的联合矩形
        void ResetOffset();//平移到左上角为圆点
        void Normalize();//使右大于左,下大于上
        void Offset(int cx, int cy);//平移矩形
        void Inflate(int cx, int cy);//扩大矩形
        void Deflate(int cx, int cy);//缩小矩形
        void Union(CDuiRect& rc);//联合之后的矩形区域
    };
4.CStdPtrArray

  它表示一个指针数组,内有数组的常见操作,如清空,设置大小,查找,增加,修改,插入和删除。如下图所示:

    class UILIB_API CStdPtrArray
    {
    public:
        CStdPtrArray(int iPreallocSize = 0);
        CStdPtrArray(const CStdPtrArray& src);
        ~CStdPtrArray();

        void Empty();
        void Resize(int iSize);
        bool IsEmpty() const;
        int Find(LPVOID iIndex) const;
        bool Add(LPVOID pData);//队尾加一个
        bool SetAt(int iIndex, LPVOID pData);
        bool InsertAt(int iIndex, LPVOID pData);
        bool Remove(int iIndex);
        int GetSize() const;
        LPVOID* GetData();

        LPVOID GetAt(int iIndex) const;
        LPVOID operator[] (int nIndex) const;

    protected:
        LPVOID* m_ppVoid;
        int m_nCount;
        int m_nAllocated;
    };
5.CStdValArray

  它与CStdPtrArray相比,没有太大的不同,只是一个基本元素类型为LPVOID,另一个为LPCVOID,一个指针类型,另一个为常量指针类型。

class UILIB_API CStdValArray
    {
    public:
        CStdValArray(int iElementSize, int iPreallocSize = 0);
        ~CStdValArray();

        void Empty();
        bool IsEmpty() const;
        bool Add(LPCVOID pData);
        bool Remove(int iIndex);
        int GetSize() const;
        LPVOID GetData();

        LPVOID GetAt(int iIndex) const;
        LPVOID operator[] (int nIndex) const;

    protected:
        LPBYTE m_pVoid;
        int m_iElementSize;
        int m_nCount;
        int m_nAllocated;
    };
6.作者答疑

  如有疑问,请留言。

关注
打赏
1665481431
查看更多评论
立即登录/注册

微信扫码登录

0.0534s