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, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *)
17 {$INCLUDE ../shared/a_modes.inc}
20 interface
23 // ////////////////////////////////////////////////////////////////////////// //
24 type
26 public
29 private
33 public
39 public
44 public
47 private
51 public
58 public
63 public
66 public
76 // ////////////////////////////////////////////////////////////////////////// //
77 type
79 public
82 public
91 // WARNING! This function does blending in RGB space, and RGB space is not linear!
92 // alpha value of `self` doesn't matter
93 // `aa` means: 255 for replace color, 0 for keep `self`
98 public
101 public
109 // modifies this rect, so it won't be bigger than `r`
110 // returns `false` if this rect becomes empty
115 public
118 public
123 // ////////////////////////////////////////////////////////////////////////// //
124 // return `false` if destination rect is empty
125 // modifies rect0
126 function intersectRect (var x0, y0, w0, h0: Integer; const x1, y1, w1, h1: Integer): Boolean; inline;
130 implementation
132 uses
133 utils;
135 // ////////////////////////////////////////////////////////////////////////// //
137 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;
138 procedure TLaySize.setIdx (idx, v: Integer); inline; begin if (idx = 0) then w := v else if (idx = 1) then h := v; end;
140 function TLaySize.equals (constref a: TLaySize): Boolean; inline; begin result := (w = a.w) and (h = a.h); end;
143 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;
144 procedure TLayPos.setIdx (idx, v: Integer); inline; begin if (idx = 0) then x := v else if (idx = 1) then y := v; end;
146 function TLayPos.equals (constref a: TLayPos): Boolean; inline; begin result := (x = a.x) and (y = a.y); end;
149 begin
159 function TLayMargins.toString (): AnsiString; begin result := formatstrf('(%s,%s,%s,%s)', [top, right, bottom, left]); end;
164 // ////////////////////////////////////////////////////////////////////////// //
166 begin
173 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;
179 var
181 begin
187 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
203 begin
209 // ////////////////////////////////////////////////////////////////////////// //
210 constructor TGxRect.Create (ax, ay, aw, ah: Integer); begin x := ax; y := ay; w := aw; h := ah; end;
216 begin
220 function TGxRect.toString (): AnsiString; begin result := formatstrf('(%s,%s;%sx%s)', [x, y, w, h]); end;
223 // ////////////////////////////////////////////////////////////////////////// //
227 // ////////////////////////////////////////////////////////////////////////// //
228 //TODO: overflow checks
229 function intersectRect (var x0, y0, w0, h0: Integer; const x1, y1, w1, h1: Integer): Boolean; inline;
230 var
233 begin
236 // check for intersection
243 // ok, intersects
255 begin