X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fflexui%2Ffui_common.pas;h=744ddff1bd71de3c59974e8e70b34aac3e263c92;hb=6cb71253f6184abde0041f8d9e7da94fdbf75344;hp=76354c3b966c4acb99342519f15efcddb3768bef;hpb=26290d9816334b8377531cf8b3e58643444f4d04;p=d2df-sdl.git diff --git a/src/flexui/fui_common.pas b/src/flexui/fui_common.pas index 76354c3..744ddff 100644 --- a/src/flexui/fui_common.pas +++ b/src/flexui/fui_common.pas @@ -92,6 +92,29 @@ type function blend (ar, ag, ab, aa: Integer): TGxRGBA; inline; end; + TGxRect = packed record + public + x, y, w, h: Integer; + + public + constructor Create (ax, ay, aw, ah: Integer); + + function empty (): Boolean; inline; // invalid rects are empty too + function valid (): Boolean; inline; + + // modifies this rect, so it won't be bigger than `r` + // returns `false` if this rect becomes empty + function intersect (constref r: TGxRect): Boolean; inline; + end; + + TGxOfs = packed record + public + xofs, yofs: Integer; + + public + constructor Create (axofs, ayofs: Integer); + end; + // ////////////////////////////////////////////////////////////////////////// // // return `false` if destination rect is empty @@ -105,7 +128,6 @@ implementation uses utils; - // ////////////////////////////////////////////////////////////////////////// // constructor TLaySize.Create (aw, ah: Integer); begin w := aw; h := ah; end; function TLaySize.getIdx (idx: Integer): Integer; inline; begin if (idx = 0) then result := w else if (idx = 1) then result := h else result := -1; end; @@ -174,6 +196,22 @@ begin end; +// ////////////////////////////////////////////////////////////////////////// // +constructor TGxRect.Create (ax, ay, aw, ah: Integer); begin x := ax; y := ay; w := aw; h := ah; end; + +function TGxRect.empty (): Boolean; inline; begin result := (w <= 0) or (h <= 0); end; +function TGxRect.valid (): Boolean; inline; begin result := (w < 0) or (h < 0); end; + +function TGxRect.intersect (constref r: TGxRect): Boolean; inline; +begin + result := intersectRect(x, y, w, h, r.x, r.y, r.w, r.h); +end; + + +// ////////////////////////////////////////////////////////////////////////// // +constructor TGxOfs.Create (axofs, ayofs: Integer); begin xofs := axofs; yofs := ayofs; end; + + // ////////////////////////////////////////////////////////////////////////// // //TODO: overflow checks function intersectRect (var x0, y0, w0, h0: Integer; const x1, y1, w1, h1: Integer): Boolean; inline;