DEADSOFTWARE

FlexUI: don't change window size in "fit to screen" mode if size was already set
[d2df-sdl.git] / src / gx / gh_ui_common.pas
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}
18 unit gh_ui_common;
20 interface
23 // ////////////////////////////////////////////////////////////////////////// //
24 type
25 TLaySize = record
26 public
27 w, h: Integer;
29 private
30 function getIdx (idx: Integer): Integer; inline;
31 procedure setIdx (idx, v: Integer); inline;
33 public
34 constructor Create (aw, ah: Integer);
36 function toString (): AnsiString;
38 function equals (constref a: TLaySize): Boolean; inline;
39 public
40 property item[idx: Integer]: Integer read getIdx write setIdx; default;
41 end;
43 TLayPos = record
44 public
45 x, y: Integer;
47 private
48 function getIdx (idx: Integer): Integer; inline;
49 procedure setIdx (idx, v: Integer); inline;
51 public
52 constructor Create (ax, ay: Integer);
54 function toString (): AnsiString;
56 function equals (constref a: TLayPos): Boolean; inline;
58 public
59 property item[idx: Integer]: Integer read getIdx write setIdx; default;
60 end;
62 TLayMargins = record
63 public
64 top, right, bottom, left: Integer;
66 public
67 constructor Create (atop, aright, abottom, aleft: Integer);
69 function toString (): AnsiString;
71 function horiz (): Integer; inline;
72 function vert (): Integer; inline;
73 end;
76 implementation
78 uses
79 utils;
82 // ////////////////////////////////////////////////////////////////////////// //
83 constructor TLaySize.Create (aw, ah: Integer); begin w := aw; h := ah; end;
84 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;
85 procedure TLaySize.setIdx (idx, v: Integer); inline; begin if (idx = 0) then w := v else if (idx = 1) then h := v; end;
86 function TLaySize.toString (): AnsiString; begin result := formatstrf('[%d,%d]', [w, h]); end;
87 function TLaySize.equals (constref a: TLaySize): Boolean; inline; begin result := (w = a.w) and (h = a.h); end;
89 constructor TLayPos.Create (ax, ay: Integer); begin x := ax; y := ay; end;
90 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;
91 procedure TLayPos.setIdx (idx, v: Integer); inline; begin if (idx = 0) then x := v else if (idx = 1) then y := v; end;
92 function TLayPos.toString (): AnsiString; begin result := formatstrf('(%d,%d)', [x, y]); end;
93 function TLayPos.equals (constref a: TLayPos): Boolean; inline; begin result := (x = a.x) and (y = a.y); end;
95 constructor TLayMargins.Create (atop, aright, abottom, aleft: Integer);
96 begin
97 if (atop < 0) then atop := 0;
98 if (aright < 0) then aright := 0;
99 if (abottom < 0) then abottom := 0;
100 if (aleft < 0) then aleft := 0;
101 left := aleft;
102 right := aright;
103 top := atop;
104 bottom := abottom;
105 end;
106 function TLayMargins.toString (): AnsiString; begin result := formatstrf('(%s,%s,%s,%s)', [top, right, bottom, left]); end;
107 function TLayMargins.horiz (): Integer; inline; begin result := left+right; end;
108 function TLayMargins.vert (): Integer; inline; begin result := top+bottom; end;
111 end.