1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
15 {$INCLUDE ../../shared/a_modes.inc}
20 procedure r_Touch_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
21 procedure r_Touch_Draw
;
30 e_input
, g_options
, g_system
,
34 function GetKeyName (key
: Integer): String;
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';
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
:= '>';
72 if (key
> 0) and (key
< e_MaxInputKeys
) then
73 result
:= e_KeyNames
[key
]
75 result
:= '<' + IntToStr(key
) + '>'
79 procedure r_Touch_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
84 procedure S (xx
, yy
, ww
, hh
: Single);
95 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(SDL2_NODPI)}
96 if SDL_GetDisplayDPI(0, @dpi
, nil, nil) <> 0 then
102 sz
:= Trunc(g_touch_size
* dpi
); sw
:= gWinSizeX
; sh
:= gWinSizeY
;
103 x
:= 0; y
:= Round(sh
* g_touch_offset
/ 100);
106 if sys_IsTextInputActive() then
108 VK_HIDEKBD
: S(sw
- (sz
/2), 0, sz
/ 2, sz
/ 2);
110 else if g_touch_alt
then
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
);
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);
167 procedure r_Touch_Draw
;
168 var i
, x
, y
, w
, h
: Integer; founded
: Boolean;
170 if g_touch_enabled
then
172 for i
:= VK_FIRSTKEY
to VK_LASTKEY
do
174 r_Touch_GetKeyRect(i
, x
, y
, w
, h
, founded
);
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)