📄 pw_region.c
字号:
* +-----------+ * | A | * | | * +-------------+ * | Z | * +-------------+ * | | * | B | * +-----------+ * */ case (T_GAP | B_GAP): { b->x = a->x; b->y = z->y + z->h; b->w = a->w; b->h = a->y + a->h - b->y; a->h = z->y - a->y; IPW_TRACE_RECT2(RE2, a, b); IPW_TRACE_EXIT_V(RE2, d, 1); return(1); } /* * Gaps on right and bottom * * +------+ * | |-----+ * | Z | | * | | A | * | | | * +------+=====+ * | | * | B | * | | * +-----------+ */ case (R_GAP | B_GAP): { Pw_Int dx = z->x + z->w - a->x; b->x = a->x; b->y = z->y + z->h; b->w = a->w; b->h = a->y + a->h - b->y; a->x += dx; a->w -= dx; a->h = b->y - a->y; IPW_TRACE_RECT2(RE2, a, b); IPW_TRACE_EXIT_V(RE2, d, 1); return(1); } /* * Gaps on left, top and right * * +-----------+ * | A | * | | * +===+---+===+ * | | | | * | B | | C | * | | Z | | * | | | | * +---| |---+ * +---+ */ case (L_GAP | T_GAP | R_GAP): { b->x = a->x; b->y = z->y; b->w = z->x - b->x; b->h = a->y + a->h - b->y; c->x = z->x + z->w; c->y = b->y; c->w = a->x + a->w - c->x; c->h = b->h; a->h = z->y - a->y; IPW_TRACE_RECT3(RE2, a, b, c); IPW_TRACE_EXIT_V(RE2, d, 2); return(2); } /* * Gaps on left, top and bottom * * +-----------+ * | A | * | | * +====+-------+ * | B | Z | * +====+-------+ * | | * | C | * +-----------+ */ case (L_GAP | T_GAP | B_GAP): { b->x = a->x; b->y = z->y; b->w = z->x - b->x; b->h = z->y + z->h - b->y; c->x = a->x; c->y = b->y + b->h; c->w = a->w; c->h = a->y + a->h - c->y; a->h = z->y - a->y; IPW_TRACE_RECT3(RE2, a, b, c); IPW_TRACE_EXIT_V(RE2, d, 2); return(2); } /* * Gaps on left, right and bottom * * +---+ * +---| |---+ * | | Z | | * | A | | B | * | | | | * | | | | * +===+---+===+ * | | * | C | * +-----------+ */ case (L_GAP | R_GAP | B_GAP): { b->x = z->x + z->w; b->y = a->y; b->w = a->x + a->w - b->x; b->h = z->y + z->h - b->y; c->x = a->x; c->y = z->y + z->h; c->w = a->w; c->h = a->y + a->h - c->y; a->w = z->x - a->x; a->h = b->h; IPW_TRACE_RECT3(RE2, a, b, c); IPW_TRACE_EXIT_V(RE2, d, 2); return(2); } /* * Gaps on top, right and bottom * * +-----------+ * | A | * | | * +-------+====+ * | Z | B | * +-------+====+ * | | * | C | * +-----------+ */ case (T_GAP | R_GAP | B_GAP): { b->x = z->x + z->w; b->y = z->y; b->w = a->x + a->w - b->x; b->h = z->y + z->h - b->y; c->x = a->x; c->y = z->y + z->h; c->w = a->w; c->h = a->y + a->h - c->y; a->h = z->y - a->y; IPW_TRACE_RECT3(RE2, a, b, c); IPW_TRACE_EXIT_V(RE2, d, 2); return(2); } /* * Gaps on all sides * * +-----------+ * | A | * | | * +==+-----+==+ * |B | Z | C| * +==+-----+==+ * | | * | D | * +-----------+ */ case (L_GAP | T_GAP | R_GAP | B_GAP): { b->x = a->x; b->y = z->y; b->w = z->x - b->x; b->h = z->y + z->h - b->y; c->x = z->x + z->w; c->y = b->y; c->w = a->x + a->w - c->x; c->h = b->h; d->x = a->x; d->y = z->y + z->h; d->w = a->w; d->h = a->y + a->h - d->y; a->h = z->y - a->y; IPW_TRACE_RECT4(RE2, a, b, c, d); IPW_TRACE_EXIT_V(RE2, d, 3); return(3); } default: { IPW_FAIL(FALSE, ("Unexpected gap code (%d)!", gaps)); } } IPW_FAIL(FALSE, ("OOPS! Should not be HERE!")); return(0); /* Not reached */}/** * Excludes the area of rectangle @p z from each rectangle in * the list of regions @p rlist. The newly generated rectangles * are stored into @p rlist as new regions. NOTE: region list * @p rlist bounds don't get updated. * @param z pointer to rectangle z * @param rlist pointer to region list rlist * @return true if there was enough space for new regions * @internal */Pw_BoolIPw_RectExcludeFromRegionList(Pw_Rectangle* z, Pw_RegionList* rlist){ Pw_Int ncnt, rcnt; Pw_Region* reg; Pw_Region* oregs; Pw_Region* last; Pw_Rectangle nrects[3]; IPW_TRACE_ENTER(RE3); IPW_TRACE_RECT(RE3, z); IPW_TRACE_RLIST(RE3, rlist); IPW_CHECK_PTR2(z, rlist); /* * For each rect in region rlist list we call IPw_RectExclude * if the num returned is -1 - delete the current region, * if the num returned is 0 - do nothing * if the num returned is >0 - append newly created rectangles * as regions at the beginning on the list * * last is the pointer to last processed (previous) region * reg is the pointer to current region * oregs is the pointer to old reglion list start (changed when we * add new regions) */ last = PW_NULL; reg = oregs = rlist->regs; while (PW_NULL != reg) { ncnt = IPw_RectExclude(z, ®->area, &nrects[0], &nrects[1], &nrects[2]); IPW_TRACE1(RE3, d, ncnt); switch (ncnt) { case -1: { if (PW_NULL == last) { IPW_CHECK_COND(oregs == rlist->regs); rlist->regs = reg->next; IPw_RegionFree(reg); reg = oregs = rlist->regs; } else { last->next = reg->next; IPw_RegionFree(reg); reg = last->next; } rlist->regs_num--; break; } case 0: { last = reg; reg = reg->next; break; } case 1: case 2: case 3: { rcnt = ncnt; rlist->regs = IPw_RegionNewListFromArray(nrects, &rcnt, oregs); rlist->regs_num += rcnt; IPW_TRACE2(RE3, d, rcnt, rlist->regs_num); if (rcnt != ncnt) { IPW_CHECK_RLIST(rlist); IPW_TRACE_EXIT_V(RE3, d, 0); return(FALSE); } oregs = rlist->regs; last = reg; reg = reg->next; break; } default: { IPW_FAIL(FALSE, ("Unexpected new rect cnt = %d!", ncnt)); } } IPW_TRACE_RLIST(RE3, rlist); IPW_TRACE4(RE3, p, last, reg, oregs, rlist->regs); } IPW_CHECK_RLIST(rlist); IPW_TRACE_EXIT_V(RE3, d, 1); return(TRUE);}#if IPW_CHECK_EN(REGION_LIST)Pw_BoolIPw_RegionListCheck(Pw_RegionList* rlist, Pw_Bool hard_chk){ if (rlist->regs_num < 0) { IPW_ASSERT(FALSE, ("Region list (%p) len = %d!", rlist, rlist->regs_num)); return(FALSE); } if ((PW_NULL == rlist->regs && rlist->regs_num != 0) || (rlist->regs_num == 0 && PW_NULL != rlist->regs)) { IPW_ASSERT(FALSE, ("Region list (%p) regs error (regs = %p len = %d)!", rlist, rlist->regs, rlist->regs_num)); return(FALSE); } if (hard_chk) { Pw_Int i; Pw_Rectangle r; Pw_Region* reg; IPW_RECT_EMPTY(&r); i = 0; reg = rlist->regs; while (PW_NULL != reg) { IPW_ASSERT(reg->area.w > 0 && reg->area.h > 0, ("empty region (w=%d h=%d)!", reg->area.w, reg->area.h)); IPw_RectUnionize(&r, ®->area); reg = reg->next; i++; } if (i != rlist->regs_num) { IPW_ASSERT(FALSE, ("Region list (%p) regs_num error %d != %d!", rlist, i, rlist->regs_num)); return(FALSE); } if (!IPW_RECT_IS_EQUAL(&r, &rlist->bounds)) { IPW_ASSERT(FALSE, ("Region list (%p) bounds error " "(%d %d %d %d) != (%d %d %d %d)!", rlist, r.x, r.y, r.w, r.h, rlist->bounds.x, rlist->bounds.y, rlist->bounds.w, rlist->bounds.h)); return(FALSE); } } else { Pw_Int i; Pw_Region* reg; i = 0; reg = rlist->regs; while (PW_NULL != reg) { IPW_ASSERT(reg->area.w > 0 && reg->area.h > 0, ("empty region (w=%d h=%d)!", reg->area.w, reg->area.h)); reg = reg->next; i++; } if (i != rlist->regs_num) { IPW_ASSERT(FALSE, ("Region list (%p) regs_num error %d != %d!", rlist, i, rlist->regs_num)); return(FALSE); } } return(TRUE);}#endif /* IPW_CHECK_EN(REGION_LIST) *//*---------------------------------------------------------------------------// end of pw_region.c //--------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -