DEADSOFTWARE

gl: draw transpatent weapon with invis
[d2df-sdl.git] / src / game / 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,
31 r_game, r_graphics
32 ;
34 function GetKeyName (key: Integer): String;
35 begin
36 case key of
37 VK_SHOWKBD: result := 'KBD';
38 VK_HIDEKBD: result := 'KBD';
39 VK_LEFT: result := 'LEFT';
40 VK_RIGHT: result := 'RIGHT';
41 VK_UP: result := 'UP';
42 VK_DOWN: result := 'DOWN';
43 VK_FIRE: result := 'FIRE';
44 VK_OPEN: result := 'OPEN';
45 VK_JUMP: result := 'JUMP';
46 VK_CHAT: result := 'CHAT';
47 VK_ESCAPE: result := 'ESC';
48 VK_0: result := '0';
49 VK_1: result := '1';
50 VK_2: result := '2';
51 VK_3: result := '3';
52 VK_4: result := '4';
53 VK_5: result := '5';
54 VK_6: result := '6';
55 VK_7: result := '7';
56 VK_8: result := '8';
57 VK_9: result := '9';
58 VK_A: result := '10';
59 VK_B: result := '11';
60 VK_C: result := '12';
61 VK_D: result := '13';
62 VK_E: result := '14';
63 VK_F: result := '15';
64 VK_CONSOLE: result := 'CON';
65 VK_STATUS: result := 'STAT';
66 VK_TEAM: result := 'TEAM';
67 VK_PREV: result := '<PREW';
68 VK_NEXT: result := 'NEXT>';
69 VK_LSTRAFE: result := '<';
70 VK_RSTRAFE: result := '>';
71 else
72 if (key > 0) and (key < e_MaxInputKeys) then
73 result := e_KeyNames[key]
74 else
75 result := '<' + IntToStr(key) + '>'
76 end
77 end;
79 procedure r_Touch_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
80 var
81 sw, sh, sz: Integer;
82 dpi: Single;
84 procedure S (xx, yy, ww, hh: Single);
85 begin
86 x := Trunc(xx);
87 y := Trunc(yy);
88 w := Trunc(ww);
89 h := Trunc(hh);
90 founded := true;
91 end;
93 begin
94 founded := false;
95 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(SDL2_NODPI)}
96 if SDL_GetDisplayDPI(0, @dpi, nil, nil) <> 0 then
97 dpi := 96;
98 {$ELSE}
99 dpi := 96;
100 {$ENDIF}
102 sz := Trunc(g_touch_size * dpi); sw := gWinSizeX; sh := gWinSizeY;
103 x := 0; y := Round(sh * g_touch_offset / 100);
104 w := sz; h := sz;
106 if sys_IsTextInputActive() then
107 case key of
108 VK_HIDEKBD: S(sw - (sz/2), 0, sz / 2, sz / 2);
109 end
110 else if g_touch_alt then
111 case key of
112 (* top ------- x ------------------------------- y w ----- h -- *)
113 VK_CONSOLE: S(0, 0, sz / 2, sz / 2);
114 VK_ESCAPE: S(sw - 1*(sz/2) - 1, 0, sz / 2, sz / 2);
115 VK_SHOWKBD: S(sw - 2*(sz/2) - 1, 0, sz / 2, sz / 2);
116 VK_CHAT: S(sw / 2 - (sz/2) / 2 - (sz/2) - 1, 0, sz / 2, sz / 2);
117 VK_STATUS: S(sw / 2 - (sz/2) / 2 - 1, 0, sz / 2, sz / 2);
118 VK_TEAM: S(sw / 2 - (sz/2) / 2 + (sz/2) - 1, 0, sz / 2, sz / 2);
119 (* left --- x - y -------------- w - h --- *)
120 VK_PREV: S(0, sh - 3.0*sz - 1, sz, sz / 2);
121 VK_LEFT: S(0, sh - 2.0*sz - 1, sz, sz * 2);
122 VK_RIGHT: S(sz, sh - 2.0*sz - 1, sz, sz * 2);
123 (* right - x ------------ y -------------- w - h -- *)
124 VK_NEXT: S(sw - 1*sz - 1, sh - 3.0*sz - 1, sz, sz / 2);
125 VK_UP: S(sw - 2*sz - 1, sh - 2.0*sz - 1, sz, sz / 2);
126 VK_FIRE: S(sw - 2*sz - 1, sh - 1.5*sz - 1, sz, sz);
127 VK_DOWN: S(sw - 2*sz - 1, sh - 0.5*sz - 1, sz, sz / 2);
128 VK_JUMP: S(sw - 1*sz - 1, sh - 2.0*sz - 1, sz, sz);
129 VK_OPEN: S(sw - 1*sz - 1, sh - 1.0*sz - 1, sz, sz);
130 end
131 else
132 case key of
133 (* left ----- x ----- y -------------- w ----- h -- *)
134 VK_ESCAPE: S(0.0*sz, y - 1*sz - sz/2, sz, sz / 2);
135 VK_LSTRAFE: S(0.0*sz, y - 0*sz - sz/2, sz / 2, sz);
136 VK_LEFT: S(0.5*sz, y - 0*sz - sz/2, sz, sz);
137 VK_RIGHT: S(1.5*sz, y - 0*sz - sz/2, sz, sz);
138 VK_RSTRAFE: S(2.5*sz, y - 0*sz - sz/2, sz / 2, sz);
139 (* right - x ------------ y --------------- w - h *)
140 VK_UP: S(sw - 1*sz - 1, y - 1*sz - sz/2, sz, sz);
141 VK_FIRE: S(sw - 1*sz - 1, y - 0*sz - sz/2, sz, sz);
142 VK_DOWN: S(sw - 1*sz - 1, y - -1*sz - sz/2, sz, sz);
143 VK_NEXT: S(sw - 2*sz - 1, y - 1*sz - sz/2, sz, sz);
144 VK_JUMP: S(sw - 2*sz - 1, y - 0*sz - sz/2, sz, sz);
145 VK_PREV: S(sw - 3*sz - 1, y - 1*sz - sz/2, sz, sz);
146 VK_OPEN: S(sw - 3*sz - 1, y - 0*sz - sz/2, sz, sz);
147 (* bottom ---- x -------------------------- y ---------------- w ----- h -- *)
148 VK_CHAT: S(sw/2 - sz/4 - 2*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
149 VK_CONSOLE: S(sw/2 - sz/4 - 1*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
150 VK_STATUS: S(sw/2 - sz/4 - 0*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
151 VK_TEAM: S(sw/2 - sz/4 - -1*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
152 VK_SHOWKBD: S(sw/2 - sz/4 - -2*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2);
153 VK_0: S(sw/2 - sz/4 - 5*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
154 VK_1: S(sw/2 - sz/4 - 4*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
155 VK_2: S(sw/2 - sz/4 - 3*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
156 VK_3: S(sw/2 - sz/4 - 2*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
157 VK_4: S(sw/2 - sz/4 - 1*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
158 VK_5: S(sw/2 - sz/4 - 0*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
159 VK_6: S(sw/2 - sz/4 - -1*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
160 VK_7: S(sw/2 - sz/4 - -2*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
161 VK_8: S(sw/2 - sz/4 - -3*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
162 VK_9: S(sw/2 - sz/4 - -4*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
163 VK_A: S(sw/2 - sz/4 - -5*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2);
164 end
165 end;
167 procedure r_Touch_Draw;
168 var i, x, y, w, h: Integer; founded: Boolean;
169 begin
170 if g_touch_enabled then
171 begin
172 for i := VK_FIRSTKEY to VK_LASTKEY do
173 begin
174 r_Touch_GetKeyRect(i, x, y, w, h, founded);
175 if founded then
176 begin
177 e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 31);
178 e_TextureFontPrintEx(x, y, GetKeyName(i), gStdFont, 255, 255, 255, 1, True)
179 end
180 end
181 end
182 end;
184 end.