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, either version 3 of the License, or
6 * (at your option) any later version.
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.
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/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 procedure g_Touch_ShowKeyboard(yes
: Boolean);
25 procedure g_Touch_HandleEvent(const ev
: TSDL_TouchFingerEvent
);
26 procedure g_Touch_Draw
;
32 e_log
, e_graphics
, e_input
, g_options
, g_game
, g_main
, g_weapons
, g_console
;
38 keyFinger
: array [VK_FIRSTKEY
..VK_LASTKEY
] of Integer;
40 procedure GetKeyRect(key
: Word; out x
, y
, w
, h
: Integer; out founded
: Boolean);
45 if SDL_GetDisplayDPI(0, @dpi
, nil, nil) <> 0 then
49 sz
:= Trunc(size
* dpi
);
50 sw
:= gScreenWidth
; sh
:= gScreenHeight
;
53 w
:= sz
div 2; h
:= sz
div 3;
55 VK_CONSOLE
: begin x
:= 0; y
:= 0 end;
56 VK_ESCAPE
: begin x
:= sw
- w
- 1; y
:= 0 end;
57 VK_CHAT
: begin x
:= sw
div 2 - w
- 4; y
:= 0 end;
58 VK_TEAM
: begin x
:= sw
div 2 + 0 + 4; y
:= 0 end;
62 VK_LEFT
: begin x
:= 0; y
:= sh
- h
- 1 end;
63 VK_RIGHT
: begin x
:= w
; y
:= sh
- h
- 1 end;
67 VK_OPEN
: begin h
:= sz
; x
:= sw
- 1*w
- 1; y
:= sh
- 1*h
- 1 end;
68 VK_JUMP
: begin h
:= sz
; x
:= sw
- 1*w
- 1; y
:= sh
- 2*h
- 1 end;
69 VK_UP
: begin h
:= sz
div 2; x
:= sw
- 2*w
- 1; y
:= sh
- 2*sz
- 1 end;
70 VK_FIRE
: begin h
:= sz
; x
:= sw
- 2*w
- 1; y
:= sh
- sz
div 2 - sz
- 1 end;
71 VK_DOWN
: begin h
:= sz
div 2; x
:= sw
- 2*w
- 1; y
:= sh
- sz
div 2 - 1 end;
72 VK_PREV
: begin h
:= sz
div 2; x
:= 0; y
:= sh
- 3*sz
- 1 end;
73 VK_NEXT
: begin h
:= sz
div 2; x
:= sw
- w
- 1; y
:= sh
- 3*sz
- 1 end;
82 x
:= 0; y
:= 0; w
:= sz
; h
:= sz
;
84 VK_LEFT
: begin x
:= 0; y
:= sh
div 2 - h
div 2; end;
85 VK_RIGHT
: begin x
:= w
; y
:= sh
div 2 - h
div 2; end;
86 VK_UP
: begin x
:= sw
- w
- 1; y
:= sh
div 2 - h
div 2 - h
; end;
87 VK_DOWN
: begin x
:= sw
- w
- 1; y
:= sh
div 2 - h
div 2 + h
; end;
88 VK_FIRE
: begin x
:= sw
- 1*w
- 1; y
:= sh
div 2 - h
div 2; end;
89 VK_OPEN
: begin x
:= sw
- 3*w
- 1; y
:= sh
div 2 - h
div 2; end;
90 VK_JUMP
: begin x
:= sw
- 2*w
- 1; y
:= sh
div 2 - h
div 2; end;
92 w
:= sz
div 2; h
:= sz
div 2;
94 VK_0
: begin x
:= sw
div 2 - w
div 2 - 5*w
- 1; y
:= sh
- 1*h
- 1; end;
95 VK_1
: begin x
:= sw
div 2 - w
div 2 - 4*w
- 1; y
:= sh
- 1*h
- 1; end;
96 VK_2
: begin x
:= sw
div 2 - w
div 2 - 3*w
- 1; y
:= sh
- 1*h
- 1; end;
97 VK_3
: begin x
:= sw
div 2 - w
div 2 - 2*w
- 1; y
:= sh
- 1*h
- 1; end;
98 VK_4
: begin x
:= sw
div 2 - w
div 2 - 1*w
- 1; y
:= sh
- 1*h
- 1; end;
99 VK_5
: begin x
:= sw
div 2 - w
div 2 + 0*w
- 1; y
:= sh
- 1*h
- 1; end;
100 VK_6
: begin x
:= sw
div 2 - w
div 2 + 1*w
- 1; y
:= sh
- 1*h
- 1; end;
101 VK_7
: begin x
:= sw
div 2 - w
div 2 + 2*w
- 1; y
:= sh
- 1*h
- 1; end;
102 VK_8
: begin x
:= sw
div 2 - w
div 2 + 3*w
- 1; y
:= sh
- 1*h
- 1; end;
103 VK_9
: begin x
:= sw
div 2 - w
div 2 + 4*w
- 1; y
:= sh
- 1*h
- 1; end;
104 VK_A
: begin x
:= sw
div 2 - w
div 2 + 5*w
- 1; y
:= sh
- 1*h
- 1; end;
105 VK_CHAT
: begin x
:= sw
div 2 - w
div 2 - 2*w
- 1; y
:= sh
- 2*h
- 1; end;
106 VK_ESCAPE
: begin x
:= sw
div 2 - w
div 2 - 1*w
- 1; y
:= sh
- 2*h
- 1; end;
107 VK_CONSOLE
: begin x
:= sw
div 2 - w
div 2 + 0*w
- 1; y
:= sh
- 2*h
- 1; end;
108 VK_STATUS
: begin x
:= sw
div 2 - w
div 2 + 1*w
- 1; y
:= sh
- 2*h
- 1; end;
109 VK_TEAM
: begin x
:= sw
div 2 - w
div 2 + 2*w
- 1; y
:= sh
- 2*h
- 1; end;
117 function GetKeyName(key
: Word): String;
120 VK_LEFT
: result
:= 'LEFT';
121 VK_RIGHT
: result
:= 'RIGHT';
122 VK_UP
: result
:= 'UP';
123 VK_DOWN
: result
:= 'DOWN';
124 VK_FIRE
: result
:= 'FIRE';
125 VK_OPEN
: result
:= 'OPEN';
126 VK_JUMP
: result
:= 'JUMP';
127 VK_CHAT
: result
:= 'CHAT';
128 VK_ESCAPE
: result
:= 'ESC';
139 VK_A
: result
:= '10';
140 VK_B
: result
:= '11';
141 VK_C
: result
:= '12';
142 VK_D
: result
:= '13';
143 VK_E
: result
:= '14';
144 VK_F
: result
:= '15';
145 VK_CONSOLE
: result
:= 'CON';
146 VK_STATUS
: result
:= 'STAT';
147 VK_TEAM
: result
:= 'TEAM';
148 VK_PREV
: result
:= '<PREV';
149 VK_NEXT
: result
:= 'NEXT>';
151 if (key
> 0) and (key
< e_MaxInputKeys
) then
152 result
:= e_KeyNames
[key
]
154 result
:= '<' + IntToStr(key
) + '>'
158 procedure DrawRect(x
, y
, w
, h
: Integer);
160 e_DrawQuad(x
, y
, x
+ w
, y
+ h
, 0, 255, 0, 63);
163 function IntersectControl(ctl
, xx
, yy
: Integer): Boolean;
168 GetKeyRect(ctl
, x
, y
, w
, h
, founded
);
169 result
:= founded
and (xx
>= x
) and (yy
>= y
) and (xx
<= x
+ w
) and (yy
<= y
+ h
);
172 procedure g_Touch_ShowKeyboard(yes
: Boolean);
185 procedure g_Touch_HandleEvent(const ev
: TSDL_TouchFingerEvent
);
187 x
, y
, i
, finger
: Integer;
191 if SDL_IsTextInputActive() = SDL_True
then
194 finger
:= ev
.fingerId
+ 2;
195 x
:= Trunc(ev
.x
* gScreenWidth
);
196 y
:= Trunc(ev
.y
* gScreenHeight
);
198 for i
:= VK_FIRSTKEY
to VK_LASTKEY
do
200 if IntersectControl(i
, x
, y
) then
202 if ev
.type_
= SDL_FINGERUP
then
204 else if ev
.type_
= SDL_FINGERMOTION
then
205 keyFinger
[i
] := finger
206 else if ev
.type_
= SDL_FINGERDOWN
then
208 KeyPress(i
); // Menu events
209 keyFinger
[i
] := finger
;
212 else if keyFinger
[i
] = finger
then
214 if ev
.type_
= SDL_FINGERUP
then
216 else if ev
.type_
= SDL_FINGERMOTION
then
220 e_KeyUpDown(i
, keyFinger
[i
] <> 0);
224 procedure g_Touch_Draw
;
226 i
, x
, y
, w
, h
: Integer;
232 if SDL_IsTextInputActive() = SDL_True
then
235 for i
:= VK_FIRSTKEY
to VK_LASTKEY
do
237 GetKeyRect(i
, x
, y
, w
, h
, founded
);
240 DrawRect(x
, y
, w
, h
);
241 e_TextureFontPrint(x
, y
, GetKeyName(i
), gStdFont
)
252 conRegVar('touch_enable', @enabled
, 'enable/disable virtual buttons', 'draw buttons');
253 conRegVar('touch_size', @size
, 0.1, 10, 'size of virtual buttons', 'button size');
254 conRegVar('touch_alt', @jab
, 'althernative virtual buttons layout', 'althernative layout');