DEADSOFTWARE

gl: interpolate platforms
[d2df-sdl.git] / src / game / renders / opengl / r_touch.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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_touch;
18 interface
20 procedure r_Touch_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
21 procedure r_Touch_Draw;
23 implementation
25 uses
26 {$IFDEF USE_SDL2}
27 SDL2,
28 {$ENDIF}
29 SysUtils,
30 e_input, g_options, g_system, g_game,
31 r_common, r_draw
32 ;
35 function GetKeyName (key: Integer): String;
36 begin
37 case key of
38 VK_SHOWKBD: result := 'KBD';
39 VK_HIDEKBD: result := 'KBD';
40 VK_LEFT: result := 'LEFT';
41 VK_RIGHT: result := 'RIGHT';
42 VK_UP: result := 'UP';
43 VK_DOWN: result := 'DOWN';
44 VK_FIRE: result := 'FIRE';
45 VK_OPEN: result := 'OPEN';
46 VK_JUMP: result := 'JUMP';
47 VK_CHAT: result := 'CHAT';
48 VK_ESCAPE: result := 'ESC';
49 VK_0: result := '0';
50 VK_1: result := '1';
51 VK_2: result := '2';
52 VK_3: result := '3';
53 VK_4: result := '4';
54 VK_5: result := '5';
55 VK_6: result := '6';
56 VK_7: result := '7';
57 VK_8: result := '8';
58 VK_9: result := '9';
59 VK_A: result := '10';
60 VK_B: result := '11';
61 VK_C: result := '12';
62 VK_D: result := '13';
63 VK_E: result := '14';
64 VK_F: result := '15';
65 VK_CONSOLE: result := 'CON';
66 VK_STATUS: result := 'STAT';
67 VK_TEAM: result := 'TEAM';
68 VK_PREV: result := '<PREV';
69 VK_NEXT: result := 'NEXT>';
70 VK_LSTRAFE: result := '<';
71 VK_RSTRAFE: result := '>';
72 else
73 if (key > 0) and (key < e_MaxInputKeys) then
74 result := e_KeyNames[key]
75 else
76 result := '<' + IntToStr(key) + '>'
77 end
78 end;
80 procedure r_Touch_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
81 var
82 sw, sh, sz: Integer;
83 dpi: Single;
85 procedure S (xx, yy, ww, hh: Single);
86 begin
87 x := Trunc(xx);
88 y := Trunc(yy);
89 w := Trunc(ww);
90 h := Trunc(hh);
91 founded := true;
92 end;
94 begin
95 founded := false;
96 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(SDL2_NODPI)}
97 if SDL_GetDisplayDPI(0, @dpi, nil, nil) <> 0 then
98 dpi := 96;
99 {$ELSE}
100 dpi := 96;
101 {$ENDIF}
103 sz := Trunc(g_touch_size * dpi); sw := gWinSizeX; sh := gWinSizeY;
104 x := 0; y := Round(sh * g_touch_offset / 100);
105 w := sz; h := sz;
107 if sys_IsTextInputActive() then
108 case key of
109 VK_HIDEKBD: S(sw - (sz/2), 0, sz / 2, sz / 2);
110 end
111 else if g_touch_alt then
112 case key of
113 (* top ------- x ------------------------------- y w ----- h -- *)
114 VK_CONSOLE: S(0, 0, sz / 2, sz / 2);
115 VK_ESCAPE: S(sw - 1*(sz/2) - 1, 0, sz / 2, sz / 2);
116 VK_SHOWKBD: S(sw - 2*(sz/2) - 1, 0, sz / 2, sz / 2);
117 VK_CHAT: S(sw / 2 - (sz/2) / 2 - (sz/2) - 1, 0, sz / 2, sz / 2);
118 VK_STATUS: S(sw / 2 - (sz/2) / 2 - 1, 0, sz / 2, sz / 2);
119 VK_TEAM: S(sw / 2 - (sz/2) / 2 + (sz/2) - 1, 0, sz / 2, sz / 2);
120 (* left --- x - y -------------- w - h --- *)
121 VK_PREV: S(0, sh - 3.0*sz - 1, sz, sz / 2);
122 VK_LEFT: S(0, sh - 2.0*sz - 1, sz, sz * 2);
123 VK_RIGHT: S(sz, sh - 2.0*sz - 1, sz, sz * 2);
124 (* right - x ------------ y -------------- w - h -- *)
125 VK_NEXT: S(sw - 1*sz - 1, sh - 3.0*sz - 1, sz, sz / 2);
126 VK_UP: S(sw - 2*sz - 1, sh - 2.0*sz - 1, sz, sz / 2);
127 VK_FIRE: S(sw - 2*sz - 1, sh - 1.5*sz - 1, sz, sz);
128 VK_DOWN: S(sw - 2*sz - 1, sh - 0.5*sz - 1, sz, sz / 2);
129 VK_JUMP: S(sw - 1*sz - 1, sh - 2.0*sz - 1, sz, sz);
130 VK_OPEN: S(sw - 1*sz - 1, sh - 1.0*sz - 1, sz, sz);
131 end
132 else
133 case key of
134 (* left ----- x ----- y -------------- w ----- h -- *)
135 VK_ESCAPE: S(0.0*sz, y - 1*sz - sz/2, sz, sz / 2);
136 VK_LSTRAFE: S(0.0*sz, y - 0*sz - sz/2, sz / 2, sz);
137 VK_LEFT: S(0.5*sz, y - 0*sz - sz/2, sz, sz);
138 VK_RIGHT: S(1.5*sz, y - 0*sz - sz/2, sz, sz);
139 VK_RSTRAFE: S(2.5*sz, y - 0*sz - sz/2, sz / 2, sz);
140 (* right - x ------------ y --------------- w - h *)
141 VK_UP: S(sw - 1*sz - 1, y - 1*sz - sz/2, sz, sz);
142 VK_FIRE: S(sw - 1*sz - 1, y - 0*sz - sz/2, sz, sz);
143 VK_DOWN: S(sw - 1*sz - 1, y - -1*sz - sz/2, sz, sz);
144 VK_NEXT: S(sw - 2*sz - 1, y - 1*sz - sz/2, sz, sz);
145 VK_JUMP: S(sw - 2*sz - 1, y - 0*sz - sz/2, sz, sz);
146 VK_PREV: S(sw - 3*sz - 1, y - 1*sz - sz/2, sz, sz);
147 VK_OPEN: S(sw - 3*sz - 1, y - 0*sz - sz/2, sz, sz);
148 (* bottom ---- x -------------------------- y ---------------- w ----- h -- *)
149 VK_CHAT: S(sw/2 - sz/4 - 2*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
150 VK_CONSOLE: S(sw/2 - sz/4 - 1*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
151 VK_STATUS: S(sw/2 - sz/4 - 0*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
152 VK_TEAM: S(sw/2 - sz/4 - -1*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
153 VK_SHOWKBD: S(sw/2 - sz/4 - -2*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
154 VK_0: S(sw/2 - sz/4 - 5*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
155 VK_1: S(sw/2 - sz/4 - 4*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
156 VK_2: S(sw/2 - sz/4 - 3*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
157 VK_3: S(sw/2 - sz/4 - 2*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
158 VK_4: S(sw/2 - sz/4 - 1*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
159 VK_5: S(sw/2 - sz/4 - 0*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
160 VK_6: S(sw/2 - sz/4 - -1*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
161 VK_7: S(sw/2 - sz/4 - -2*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
162 VK_8: S(sw/2 - sz/4 - -3*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
163 VK_9: S(sw/2 - sz/4 - -4*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
164 VK_A: S(sw/2 - sz/4 - -5*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
165 end
166 end;
168 procedure r_Touch_Draw;
169 var i, x, y, w, h: Integer; founded: Boolean;
170 begin
171 if g_touch_enabled then
172 begin
173 for i := VK_FIRSTKEY to VK_LASTKEY do
174 begin
175 r_Touch_GetKeyRect(i, x, y, w, h, founded);
176 if founded then
177 begin
178 r_Draw_Rect(x, y, x + w, y + h, 0, 255, 0, 225);
179 r_Draw_Text(GetKeyName(i), x, y, 255, 255, 255, 225, stdfont);
180 end
181 end
182 end
183 end;
185 end.