Duilib 源码分析之工具类 CDuiRect 篇

今天介绍一个比较简单的类,但是用起来还是挺方便的: CDuiRect
老规矩,二话不说,直接贴代码 :

typedef struct tagRECT
{
    LONG    left;
    LONG    top;
    LONG    right;
    LONG    bottom;
} RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;
class DUILIB_API CDuiRect : public tagRECT
{
public:
    CDuiRect();
    CDuiRect(const RECT& src);
    CDuiRect(long iLeft, long iTop, long iRight, long iBottom);
    CDuiRect(LPCTSTR pstrValue);
    CDuiString ToString();

    int GetWidth() const;
    int GetHeight() const;
    void Empty();
    bool IsNull() const;
    void Join(const RECT& 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);
};

由于是继承的 tagRECT, 所以也有 left/top/right/bottom 属性, 接下来看一下成员函数

  • void Empty() 将左上右下坐标全部重置为 0
  • bool IsNull() const 是否左上右下全为 0, 不过我认为这个函数是用来作判断是否有效的,最好是加上一个判断:left < right && top < bottom
  • void Join(const RECT& rc) 将矩形扩大,扩大的方法是取两个举行中较小的 lefttop,但是取较大的 rightbottom
  • void ResetOffset() 实现为 ::OffsetRect(this, -left, -top),所以可以知道这个函数是作用是移动此矩形到 (0,0) 位置
  • void Normalize()left 大于 right 或者 top 大于 bottom 则交换值,不过我认为这个函数没有多少适用场合吧
  • void Offset(int cx, int cy) 按指定的 x 和 y 移动矩形
  • void Inflate(int cx, int cy) 扩大矩形,扩大的方法是 leftright 各延长 cxtopbottom 各延长 cy, 当然,如果 cxcy 为负数,则就变成了缩小了,还有可能结果变为负数,就是无效矩形了
  • void Deflate(int cx, int cy),缩小矩形,和 void Inflate(int cx, int cy) 正好相反
  • void Union(CDuiRect& rc) 调用的是 UnionRect(),所以作用应该和 void Join(const RECT& rc) 是一样的,
  • 应该还少了一个函数: void CDuiRect::Intersect(const CDuiRect& rc) , 作用是取得2个矩形的交集
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值