⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rect.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
字号:
/* ------------- rect.c --------------- */

#include "dflat32/dflat.h"

 /* --- Produce the vector end points produced by the overlap
        of two other vectors --- */
static void subVector(int *v1, int *v2,
                        int t1, int t2, int o1, int o2)
{
    *v1 = *v2 = -1;
    if (within(o1, t1, t2))    {
        *v1 = o1;
        if (within(o2, t1, t2))
            *v2 = o2;
        else
            *v2 = t2;
    }
    else if (within(o2, t1, t2))    {
        *v2 = o2;
        if (within(o1, t1, t2))
            *v1 = o1;
        else
            *v1 = t1;
    }
    else if (within(t1, o1, o2))    {
        *v1 = t1;
        if (within(t2, o1, o2))
            *v2 = t2;
        else
            *v2 = o2;
    }
    else if (within(t2, o1, o2))    {
        *v2 = t2;
        if (within(t1, o1, o2))
            *v1 = t1;
        else
            *v1 = o1;
    }
}

 /* --- Return the rectangle produced by the overlap
        of two other rectangles ---- */
DFRECT subRectangle(DFRECT r1, DFRECT r2)
{
    DFRECT r = {0,0,0,0};
    subVector((int *) &RectLeft(r), (int *) &RectRight(r),
        RectLeft(r1), RectRight(r1),
        RectLeft(r2), RectRight(r2));
    subVector((int *) &RectTop(r), (int *) &RectBottom(r),
        RectTop(r1), RectBottom(r1),
        RectTop(r2), RectBottom(r2));
    if (RectRight(r) == -1 || RectTop(r) == -1)
        RectRight(r) =
        RectLeft(r) =
        RectTop(r) =
        RectBottom(r) = 0;
    return r;
}

/* ------- return the client rectangle of a window ------ */
DFRECT ClientRect(void *wnd)
{
	DFRECT rc;

	if (wnd == NULL)
	{
		RectLeft(rc) = 1; // GetClientLeft((DFWINDOW)wnd);
		RectTop(rc) = 2; // GetClientTop((DFWINDOW)wnd);
		RectRight(rc) = DfGetScreenWidth () - 2; // GetClientRight((DFWINDOW)wnd);
		RectBottom(rc) = DfGetScreenHeight () - 2; // GetClientBottom((DFWINDOW)wnd);
		return rc;
	}

	RectLeft(rc) = GetClientLeft((DFWINDOW)wnd);
	RectTop(rc) = GetClientTop((DFWINDOW)wnd);
	RectRight(rc) = GetClientRight((DFWINDOW)wnd);
	RectBottom(rc) = GetClientBottom((DFWINDOW)wnd);

	return rc;
}

/* ----- return the rectangle relative to
            its window's screen position -------- */
DFRECT RelativeWindowRect(void *wnd, DFRECT rc)
{
    RectLeft(rc) -= GetLeft((DFWINDOW)wnd);
    RectRight(rc) -= GetLeft((DFWINDOW)wnd);
    RectTop(rc) -= GetTop((DFWINDOW)wnd);
    RectBottom(rc) -= GetTop((DFWINDOW)wnd);
    return rc;
}

/* ----- clip a rectangle to the parents of the window ----- */
DFRECT ClipRectangle(void *wnd, DFRECT rc)
{
    DFRECT sr;
    RectLeft(sr) = RectTop(sr) = 0;
    RectRight(sr) = DfGetScreenWidth()-1;
    RectBottom(sr) = DfGetScreenHeight()-1;
    if (!TestAttribute((DFWINDOW)wnd, NOCLIP))
        while ((wnd = GetParent((DFWINDOW)wnd)) != NULL)
            rc = subRectangle(rc, ClientRect(wnd));
    return subRectangle(rc, sr);
}

/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -