DEADSOFTWARE

7143501e947dc2e78f7e8463a6aa380c59e92e93
[d2df-sdl.git] / src / gx / gh_ui_common.pas
1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
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}
17 unit gh_ui_common;
19 interface
22 // ////////////////////////////////////////////////////////////////////////// //
23 type
24 TLaySize = record
25 public
26 w, h: Integer;
28 private
29 function getIdx (idx: Integer): Integer; inline;
30 procedure setIdx (idx, v: Integer); inline;
32 public
33 constructor Create (aw, ah: Integer);
35 function toString (): AnsiString;
37 function equals (constref a: TLaySize): Boolean; inline;
38 public
39 property item[idx: Integer]: Integer read getIdx write setIdx; default;
40 end;
42 TLayPos = record
43 public
44 x, y: Integer;
46 private
47 function getIdx (idx: Integer): Integer; inline;
48 procedure setIdx (idx, v: Integer); inline;
50 public
51 constructor Create (ax, ay: Integer);
53 function toString (): AnsiString;
55 function equals (constref a: TLayPos): Boolean; inline;
57 public
58 property item[idx: Integer]: Integer read getIdx write setIdx; default;
59 end;
62 implementation
64 uses
65 utils;
68 // ////////////////////////////////////////////////////////////////////////// //
69 constructor TLaySize.Create (aw, ah: Integer); begin w := aw; h := ah; end;
70 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;
71 procedure TLaySize.setIdx (idx, v: Integer); inline; begin if (idx = 0) then w := v else if (idx = 1) then h := v; end;
72 function TLaySize.toString (): AnsiString; begin result := formatstrf('[%d,%d]', [w, h]); end;
73 function TLaySize.equals (constref a: TLaySize): Boolean; inline; begin result := (w = a.w) and (h = a.h); end;
75 constructor TLayPos.Create (ax, ay: Integer); begin x := ax; y := ay; end;
76 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;
77 procedure TLayPos.setIdx (idx, v: Integer); inline; begin if (idx = 0) then x := v else if (idx = 1) then y := v; end;
78 function TLayPos.toString (): AnsiString; begin result := formatstrf('(%d,%d)', [x, y]); end;
79 function TLayPos.equals (constref a: TLayPos): Boolean; inline; begin result := (x = a.x) and (y = a.y); end;
82 end.