index 76354c3b966c4acb99342519f15efcddb3768bef..b53311e043688f0d54a3caa1d1a22553da232e22 100644 (file)
function isOpaque (): Boolean; inline;
function isTransparent (): Boolean; inline;
+ function toString (): AnsiString;
+
// WARNING! This function does blending in RGB space, and RGB space is not linear!
// alpha value of `self` doesn't matter
// `aa` means: 255 for replace color, 0 for keep `self`
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;
+
+ function toString (): AnsiString;
+
+ // 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
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;
result.a := a;
end;
+function TGxRGBA.toString (): AnsiString;
+begin
+ if (a = 255) then result := formatstrf('rgb(%s,%s,%s)', [r, g, b])
+ else result := formatstrf('rgba(%s,%s,%s,%s)', [r, g, b, a]);
+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;
+
+function TGxRect.toString (): AnsiString; begin result := formatstrf('(%s,%s;%sx%s)', [x, y, w, h]); end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+constructor TGxOfs.Create (axofs, ayofs: Integer); begin xofs := axofs; yofs := ayofs; end;
+
// ////////////////////////////////////////////////////////////////////////// //
//TODO: overflow checks