DEADSOFTWARE

FlexUI: completely reworked graphics layer -- it is using drawing contexts now
[d2df-sdl.git] / src / flexui / fui_common.pas
index 76354c3b966c4acb99342519f15efcddb3768bef..744ddff1bd71de3c59974e8e70b34aac3e263c92 100644 (file)
@@ -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;