1 (* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License ONLY.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
19 interface
22 // ////////////////////////////////////////////////////////////////////////// //
23 type
25 public
28 private
32 public
38 public
43 public
46 private
50 public
57 public
62 public
65 public
75 // ////////////////////////////////////////////////////////////////////////// //
76 type
78 public
81 public
90 // WARNING! This function does blending in RGB space, and RGB space is not linear!
91 // alpha value of `self` doesn't matter
92 // `aa` means: 255 for replace color, 0 for keep `self`
97 public
100 public
108 // modifies this rect, so it won't be bigger than `r`
109 // returns `false` if this rect becomes empty
114 public
117 public
122 // ////////////////////////////////////////////////////////////////////////// //
123 // return `false` if destination rect is empty
124 // modifies rect0
125 function intersectRect (var x0, y0, w0, h0: Integer; const x1, y1, w1, h1: Integer): Boolean; inline;
129 implementation
131 uses
132 utils;
134 // ////////////////////////////////////////////////////////////////////////// //
136 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;
137 procedure TLaySize.setIdx (idx, v: Integer); inline; begin if (idx = 0) then w := v else if (idx = 1) then h := v; end;
139 function TLaySize.equals (constref a: TLaySize): Boolean; inline; begin result := (w = a.w) and (h = a.h); end;
142 function TLayPos.getIdx (idx: Integer): Integer; inline; begin if (idx = 0) then result := x else if (idx = 1) then result := y else result := -1; end;
143 procedure TLayPos.setIdx (idx, v: Integer); inline; begin if (idx = 0) then x := v else if (idx = 1) then y := v; end;
145 function TLayPos.equals (constref a: TLayPos): Boolean; inline; begin result := (x = a.x) and (y = a.y); end;
148 begin
158 function TLayMargins.toString (): AnsiString; begin result := formatstrf('(%s,%s,%s,%s)', [top, right, bottom, left]); end;
163 // ////////////////////////////////////////////////////////////////////////// //
165 begin
172 function TGxRGBA.asUInt (): LongWord; inline; begin result := LongWord(r) or (LongWord(g) shl 8) or (LongWord(b) shl 16) or (LongWord(a) shl 24); end;
178 var
180 begin
186 a_tmp_ := (256-(255-(it shr 24))) and (-(1-(((255-(it shr 24))+1) shr 8))); // to not loose bits, but 255 should become 0
202 begin
208 // ////////////////////////////////////////////////////////////////////////// //
209 constructor TGxRect.Create (ax, ay, aw, ah: Integer); begin x := ax; y := ay; w := aw; h := ah; end;
215 begin
219 function TGxRect.toString (): AnsiString; begin result := formatstrf('(%s,%s;%sx%s)', [x, y, w, h]); end;
222 // ////////////////////////////////////////////////////////////////////////// //
226 // ////////////////////////////////////////////////////////////////////////// //
227 //TODO: overflow checks
228 function intersectRect (var x0, y0, w0, h0: Integer; const x1, y1, w1, h1: Integer): Boolean; inline;
229 var
232 begin
235 // check for intersection
242 // ok, intersects
254 begin