summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0e06274)
raw | patch | inline | side by side (parent: 0e06274)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Thu, 27 Jan 2022 19:20:14 +0000 (22:20 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 9 Jun 2023 07:57:19 +0000 (10:57 +0300) |
15 files changed:
src/game/Doom2DF.lpr | patch | blob | history | |
src/game/g_console.pas | patch | blob | history | |
src/game/g_game.pas | patch | blob | history | |
src/game/g_gui.pas | patch | blob | history | |
src/game/g_menu.pas | patch | blob | history | |
src/game/g_options.pas | patch | blob | history | |
src/game/opengl/r_game.pas | patch | blob | history | |
src/game/opengl/r_render.pas | patch | blob | history | |
src/game/opengl/r_touch.pas | [moved from src/game/sdl2/g_touch.pas with 55% similarity] | patch | blob | history |
src/game/sdl/g_system.pas | patch | blob | history | |
src/game/sdl/g_touch.pas | [deleted file] | patch | blob | history |
src/game/sdl2/g_system.pas | patch | blob | history | |
src/game/stub/g_system.pas | patch | blob | history | |
src/game/stub/g_touch.pas | [deleted file] | patch | blob | history |
src/shared/a_modes.inc | patch | blob | history |
diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr
index 1db010902c294eb9f71d319085a669ce632d0c03..4131108e19b11ac7d89c6547fa12c116aaff096f 100644 (file)
--- a/src/game/Doom2DF.lpr
+++ b/src/game/Doom2DF.lpr
{$IFNDEF HEADLESS}
{$IFDEF USE_SYSSTUB}
g_system in 'stub/g_system.pas',
- g_touch in 'stub/g_touch.pas',
{$ENDIF}
{$IFDEF USE_SDL}
g_system in 'sdl/g_system.pas',
- g_touch in 'sdl/g_touch.pas',
{$ENDIF}
{$IFDEF USE_SDL2}
g_system in 'sdl2/g_system.pas',
- g_touch in 'sdl2/g_touch.pas',
{$ENDIF}
{$ENDIF}
r_textures in 'opengl/r_textures.pas',
r_weapons in 'opengl/r_weapons.pas',
r_window in 'opengl/r_window.pas',
+ {$IFDEF ENABLE_TOUCH}
+ r_touch in 'opengl/r_touch.pas',
+ {$ENDIF}
{$IFDEF ENABLE_MENU}
g_gui in 'g_gui.pas',
g_menu in 'g_menu.pas',
g_Language_Set(gLanguage);
{$IFNDEF HEADLESS}
r_Render_Initialize;
- g_Touch_Init;
{$ENDIF}
DebugOptions;
g_Net_InitLowLevel;
diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index 13bf81f55870bc559f01d47e663b715cb83874ec..c872e8effe25e17125e80dd9d2d196cddd69fa75 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
{$IFDEF ENABLE_MENU}
g_gui, g_menu,
{$ENDIF}
- {$IFNDEF HEADLESS}
- g_touch,
+ {$IFDEF ENABLE_TOUCH}
+ g_system,
{$ENDIF}
g_textures, e_input, g_game, g_gfx, g_player, g_items,
SysUtils, g_basic, g_options, Math, e_res,
gChatShow := False;
gConsoleShow := not gConsoleShow;
InputReady := False;
- {$IFNDEF HEADLESS}
- g_Touch_ShowKeyboard(gConsoleShow or gChatShow);
+ {$IFDEF ENABLE_TOUCH}
+ sys_ShowKeyboard(gConsoleShow or gChatShow);
{$ENDIF}
end;
InputReady := False;
Line := '';
CPos := 1;
- {$IFNDEF HEADLESS}
- g_Touch_ShowKeyboard(gConsoleShow or gChatShow);
+ {$IFDEF ENABLE_TOUCH}
+ sys_ShowKeyboard(gConsoleShow or gChatShow);
{$ENDIF}
end;
'unbindall':
for i := 0 to e_MaxInputKeys - 1 do
g_Console_BindKey(i, '');
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_TOUCH}
'showkeyboard':
- g_Touch_ShowKeyboard(True);
+ sys_ShowKeyboard(True);
'hidekeyboard':
- g_Touch_ShowKeyboard(False);
+ sys_ShowKeyboard(False);
{$ENDIF}
'togglemenu':
begin
diff --git a/src/game/g_game.pas b/src/game/g_game.pas
index 2debca1f909544d3fe6dc55b70cee0347675ebc5..c15aeaae6fa4750e39c3169fe78ad73f98129958 100644 (file)
--- a/src/game/g_game.pas
+++ b/src/game/g_game.pas
{$IFDEF ENABLE_MENU}
g_gui,
{$ENDIF}
- {$IFNDEF HEADLESS}
- g_touch,
- {$ENDIF}
SysUtils, Classes, MAPDEF,
g_base, g_basic, g_player, g_res_downloader,
g_sound, utils, md5, mempool, xprofiler,
diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas
index 5da0d5a561cac1763cb0c5f95d41f12b8b81d4f4..fe15869bee62b7ab781b7d04015caf5a7285c987 100644 (file)
--- a/src/game/g_gui.pas
+++ b/src/game/g_gui.pas
uses
{$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
- g_base, r_graphics, e_input, e_log, g_playermodel, g_basic, g_touch, MAPDEF, utils;
+ g_base, r_graphics, e_input, e_log, g_playermodel, g_basic, MAPDEF, utils;
const
MAINMENU_HEADER_COLOR: TRGB = (R:255; G:255; B:255);
implementation
uses
+ {$IFDEF ENABLE_TOUCH}
+ g_system,
+ {$ENDIF}
g_sound, SysUtils, e_res, r_textures,
g_game, Math, StrUtils, g_player, g_options, g_console, r_playermodel,
g_map, g_weapons, xdynrec, wadreader;
end;
g_GUIGrabInput := (@FOnEnterEvent = nil) and (FWindow.FActiveControl = Self);
- g_Touch_ShowKeyboard(g_GUIGrabInput)
+
+ {$IFDEF ENABLE_TOUCH}
+ sys_ShowKeyboard(g_GUIGrabInput)
+ {$ENDIF}
end;
procedure TGUIEdit.SetText(Text: string);
diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas
index 80f27318b471b0e32b9e70c3f05267cf835b25c4..2824c922d1b982d37d46c3f189be158c252eac86 100644 (file)
--- a/src/game/g_menu.pas
+++ b/src/game/g_menu.pas
e_log, SysUtils, CONFIG, g_playermodel, DateUtils,
MAPDEF, Math, g_saveload,
g_language, e_res,
- g_net, g_netmsg, g_netmaster, g_items, e_input, g_touch,
+ g_net, g_netmsg, g_netmaster, g_items, e_input,
utils, wadreader, g_system, r_render, r_game;
diff --git a/src/game/g_options.pas b/src/game/g_options.pas
index aba27649cbc0eb14e6481865e16a59b8b3a9ca67..dea1ca3a37b144e754637d37282bc945e2089566 100644 (file)
--- a/src/game/g_options.pas
+++ b/src/game/g_options.pas
g_dbg_aimline_on: Boolean = false;
g_dbg_input: Boolean = False;
+ var (* touch *)
+ g_touch_enabled: Boolean = False;
+ g_touch_size: Single = 1.0;
+ g_touch_offset: Single = 50.0;
+ g_touch_fire: Boolean = True;
+ g_touch_alt: Boolean = False;
+
{--- Read-only dirs ---}
GameWAD: string;
DataDirs: SSArray;
conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
conRegVar('g_lastmap', @gsMap, '', '');
- conRegVar('d_input', @g_dbg_input, '', '')
+ conRegVar('d_input', @g_dbg_input, '', '');
+
+ (* touch *)
+ conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons');
+ conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
+ conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size');
+ conRegVar('touch_offset', @g_touch_offset, 0, 100, '', '');
+ conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout');
end.
index ed21eaabcee583c62290f99a732b6f161d681635..734eb1dc6f8f0052e950fd047e5d1e52843f92e0 100644 (file)
{$ENDIF}
SysUtils, Classes, Math,
g_base, g_basic, r_graphics,
- g_system, g_touch,
+ g_system,
MAPDEF, xprofiler, utils, wadreader, CONFIG,
e_input, e_sound,
g_language, g_console, g_triggers, g_player, g_options, g_monsters, g_map, g_panel,
e_SetRendertarget(False);
e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
e_BlitFramebuffer(gWinSizeX, gWinSizeY);
-
- // draw the overlay stuff on top of it
-
- g_Touch_Draw;
end;
end.
index a9c46397bc9a158690c79cd568da0fbe8b4df969..2e356dd1b68d4e3ab8ffce0c8cb976a501c48e47 100644 (file)
function r_Render_GetGibRect (m, id: Integer): TRectWH;
procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
+{$IFDEF ENABLE_TOUCH}
+ // touch screen button location and size
+ procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
+{$ENDIF}
+
procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
implementation
uses
{$INCLUDE ../../nogl/noGLuses.inc}
+ {$IFDEF ENABLE_TOUCH}
+ r_touch,
+ {$ENDIF}
SysUtils, Classes, Math,
e_log, g_system, utils,
g_game, g_options, g_console,
procedure r_Render_Draw;
begin
r_Game_Draw;
+ {$IFDEF ENABLE_TOUCH}
+ r_Touch_Draw;
+ {$ENDIF}
end;
procedure r_Render_Resize (w, h: Integer);
r_GFX_OnceAnim(AnimType, X, Y)
end;
+{$IFDEF ENABLE_TOUCH}
+ procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
+ begin
+ r_Touch_GetKeyRect (key, x, y, w, h, founded)
+ end;
+{$ENDIF}
+
procedure r_Render_DrawLoading (force: Boolean);
begin
r_Window_DrawLoading(force)
similarity index 55%
rename from src/game/sdl2/g_touch.pas
rename to src/game/opengl/r_touch.pas
index 645176010962aafa8b105f8389d3116f3cf3660b..812ce9eeaeb421026191ff77a54ef6f95b986507 100644 (file)
rename from src/game/sdl2/g_touch.pas
rename to src/game/opengl/r_touch.pas
index 645176010962aafa8b105f8389d3116f3cf3660b..812ce9eeaeb421026191ff77a54ef6f95b986507 100644 (file)
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
-{$INCLUDE ../shared/a_modes.inc}
-unit g_touch;
+{$INCLUDE ../../shared/a_modes.inc}
+unit r_touch;
interface
- uses
- SDL2;
-
- var
- g_touch_enabled: Boolean = False;
- g_touch_size: Single = 1.0;
- g_touch_offset: Single = 50.0;
- g_touch_fire: Boolean = True;
- g_touch_alt: Boolean = False;
-
- procedure g_Touch_Init;
- procedure g_Touch_ShowKeyboard(yes: Boolean);
- procedure g_Touch_HandleEvent(const ev: TSDL_TouchFingerEvent);
- procedure g_Touch_Draw;
+ procedure r_Touch_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
+ procedure r_Touch_Draw;
implementation
uses
- {$IFDEF ENABLE_MENU}
- g_gui,
+ {$IFDEF USE_SDL2}
+ SDL2,
{$ENDIF}
SysUtils,
- e_log, r_graphics, r_game, e_input, g_options, g_game, g_weapons, g_console
+ e_input, g_options, g_system,
+ r_game, r_graphics
;
- var
- angleFire: Boolean;
- keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer;
+ function GetKeyName (key: Integer): String;
+ begin
+ case key of
+ VK_SHOWKBD: result := 'KBD';
+ VK_HIDEKBD: result := 'KBD';
+ VK_LEFT: result := 'LEFT';
+ VK_RIGHT: result := 'RIGHT';
+ VK_UP: result := 'UP';
+ VK_DOWN: result := 'DOWN';
+ VK_FIRE: result := 'FIRE';
+ VK_OPEN: result := 'OPEN';
+ VK_JUMP: result := 'JUMP';
+ VK_CHAT: result := 'CHAT';
+ VK_ESCAPE: result := 'ESC';
+ VK_0: result := '0';
+ VK_1: result := '1';
+ VK_2: result := '2';
+ VK_3: result := '3';
+ VK_4: result := '4';
+ VK_5: result := '5';
+ VK_6: result := '6';
+ VK_7: result := '7';
+ VK_8: result := '8';
+ VK_9: result := '9';
+ VK_A: result := '10';
+ VK_B: result := '11';
+ VK_C: result := '12';
+ VK_D: result := '13';
+ VK_E: result := '14';
+ VK_F: result := '15';
+ VK_CONSOLE: result := 'CON';
+ VK_STATUS: result := 'STAT';
+ VK_TEAM: result := 'TEAM';
+ VK_PREV: result := '<PREW';
+ VK_NEXT: result := 'NEXT>';
+ VK_LSTRAFE: result := '<';
+ VK_RSTRAFE: result := '>';
+ else
+ if (key > 0) and (key < e_MaxInputKeys) then
+ result := e_KeyNames[key]
+ else
+ result := '<' + IntToStr(key) + '>'
+ end
+ end;
- procedure GetKeyRect(key: Integer; out x, y, w, h: Integer; out founded: Boolean);
+ procedure r_Touch_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
var
sw, sh, sz: Integer;
dpi: Single;
begin
founded := false;
- {$IFNDEF SDL2_NODPI}
+ {$IF DEFINED(USE_SDL2) AND NOT DEFINED(SDL2_NODPI)}
if SDL_GetDisplayDPI(0, @dpi, nil, nil) <> 0 then
dpi := 96;
{$ELSE}
x := 0; y := Round(sh * g_touch_offset / 100);
w := sz; h := sz;
- if SDL_IsTextInputActive() = SDL_True then
+ if sys_IsTextInputActive() then
case key of
VK_HIDEKBD: S(sw - (sz/2), 0, sz / 2, sz / 2);
end
end
end;
- function GetKeyName(key: Integer): String;
- begin
- case key of
- VK_SHOWKBD: result := 'KBD';
- VK_HIDEKBD: result := 'KBD';
- VK_LEFT: result := 'LEFT';
- VK_RIGHT: result := 'RIGHT';
- VK_UP: result := 'UP';
- VK_DOWN: result := 'DOWN';
- VK_FIRE: result := 'FIRE';
- VK_OPEN: result := 'OPEN';
- VK_JUMP: result := 'JUMP';
- VK_CHAT: result := 'CHAT';
- VK_ESCAPE: result := 'ESC';
- VK_0: result := '0';
- VK_1: result := '1';
- VK_2: result := '2';
- VK_3: result := '3';
- VK_4: result := '4';
- VK_5: result := '5';
- VK_6: result := '6';
- VK_7: result := '7';
- VK_8: result := '8';
- VK_9: result := '9';
- VK_A: result := '10';
- VK_B: result := '11';
- VK_C: result := '12';
- VK_D: result := '13';
- VK_E: result := '14';
- VK_F: result := '15';
- VK_CONSOLE: result := 'CON';
- VK_STATUS: result := 'STAT';
- VK_TEAM: result := 'TEAM';
- VK_PREV: result := '<PREW';
- VK_NEXT: result := 'NEXT>';
- VK_LSTRAFE: result := '<';
- VK_RSTRAFE: result := '>';
- else
- if (key > 0) and (key < e_MaxInputKeys) then
- result := e_KeyNames[key]
- else
- result := '<' + IntToStr(key) + '>'
- end
- end;
-
- function IntersectControl(ctl, xx, yy: Integer): Boolean;
- var
- x, y, w, h: Integer;
- founded: Boolean;
- begin
- GetKeyRect(ctl, x, y, w, h, founded);
- result := founded and (xx >= x) and (yy >= y) and (xx <= x + w) and (yy <= y + h);
- end;
-
- procedure g_Touch_Init;
- begin
-{$IFNDEF HEADLESS}
- g_Touch_ShowKeyboard(FALSE);
- g_touch_enabled := SDL_GetNumTouchDevices() > 0
-{$ENDIF}
- end;
-
- procedure g_Touch_ShowKeyboard(yes: Boolean);
+ procedure r_Touch_Draw;
+ var i, x, y, w, h: Integer; founded: Boolean;
begin
-{$IFNDEF HEADLESS}
- if g_dbg_input then
- e_LogWritefln('g_Touch_ShowKeyboard(%s)', [yes]);
- (* on desktop we always receive text (needed for cheats) *)
- if yes or (SDL_HasScreenKeyboardSupport() = SDL_FALSE) then
- SDL_StartTextInput
- else
- SDL_StopTextInput
-{$ENDIF}
- end;
-
- procedure g_Touch_HandleEvent(const ev: TSDL_TouchFingerEvent);
- var
- x, y, i, finger: Integer;
-
- procedure KeyUp (finger, i: Integer);
- begin
- if g_dbg_input then
- e_LogWritefln('Input Debug: g_touch.KeyUp, finger=%s, key=%s', [finger, i]);
-
- keyFinger[i] := 0;
- e_KeyUpDown(i, False);
- g_Console_ProcessBind(i, False);
-
- (* up/down + fire hack *)
-{$IFDEF ENABLE_MENU}
- if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and (g_ActiveWindow = nil) and angleFire then
-{$ELSE}
- if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and angleFire then
-{$ENDIF}
- begin
- if (i = VK_UP) or (i = VK_DOWN) then
- begin
- angleFire := False;
- keyFinger[VK_FIRE] := 0;
- e_KeyUpDown(VK_FIRE, False);
- g_Console_ProcessBind(VK_FIRE, False)
- end
- end
- end;
-
- procedure KeyDown (finger, i: Integer);
+ if g_touch_enabled then
begin
- if g_dbg_input then
- e_LogWritefln('Input Debug: g_touch.KeyDown, finger=%s, key=%s', [finger, i]);
-
- keyFinger[i] := finger;
- e_KeyUpDown(i, True);
- g_Console_ProcessBind(i, True);
-
- (* up/down + fire hack *)
-{$IFDEF ENABLE_MENU}
- if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and (g_ActiveWindow = nil) then
-{$ELSE}
- if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then
-{$ENDIF}
+ for i := VK_FIRSTKEY to VK_LASTKEY do
begin
- if i = VK_UP then
+ r_Touch_GetKeyRect(i, x, y, w, h, founded);
+ if founded then
begin
- angleFire := True;
- keyFinger[VK_FIRE] := -1;
- e_KeyUpDown(VK_FIRE, True);
- g_Console_ProcessBind(VK_FIRE, True)
+ e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 31);
+ e_TextureFontPrintEx(x, y, GetKeyName(i), gStdFont, 255, 255, 255, 1, True)
end
- else if i = VK_DOWN then
- begin
- angleFire := True;
- keyFinger[VK_FIRE] := -1;
- e_KeyUpDown(VK_FIRE, True);
- g_Console_ProcessBind(VK_FIRE, True)
- end
- end
- end;
-
- procedure KeyMotion (finger, i: Integer);
- begin
- if keyFinger[i] <> finger then
- begin
- KeyUp(finger, i);
- KeyDown(finger, i)
- end
- end;
-
- begin
- if not g_touch_enabled then
- Exit;
-
- finger := ev.fingerId + 2;
- x := Trunc(ev.x * gWinSizeX);
- y := Trunc(ev.y * gWinSizeY);
-
- for i := VK_FIRSTKEY to VK_LASTKEY do
- begin
- if IntersectControl(i, x, y) then
- begin
- if ev.type_ = SDL_FINGERUP then
- KeyUp(finger, i)
- else if ev.type_ = SDL_FINGERMOTION then
- KeyMotion(finger, i)
- else if ev.type_ = SDL_FINGERDOWN then
- keyDown(finger, i)
- end
- else if keyFinger[i] = finger then
- begin
- if ev.type_ = SDL_FINGERUP then
- KeyUp(finger, i)
- else if ev.type_ = SDL_FINGERMOTION then
- KeyUp(finger, i)
- end
- end
- end;
-
- procedure g_Touch_Draw;
- var i, x, y, w, h: Integer; founded: Boolean;
- begin
-{$IFNDEF HEADLESS}
- if not g_touch_enabled then
- Exit;
-
- for i := VK_FIRSTKEY to VK_LASTKEY do
- begin
- GetKeyRect(i, x, y, w, h, founded);
- if founded then
- begin
- e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 31);
- e_TextureFontPrintEx(x, y, GetKeyName(i), gStdFont, 255, 255, 255, 1, True)
end
end
-{$ENDIF}
end;
-initialization
- conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons');
- conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
- conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size');
- conRegVar('touch_offset', @g_touch_offset, 0, 100, '', '');
- conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout');
end.
index 0067bbca54da5798197c71d9c6a709906e9f2090..8fdb42ca5b93ea3ea61ef2f14ff832f9ea53c07d 100644 (file)
function sys_HandleInput (): Boolean;
procedure sys_RequestQuit;
+{$IFDEF ENABLE_TOUCH}
+ function sys_IsTextInputActive (): Boolean;
+ procedure sys_ShowKeyboard (yes: Boolean);
+{$ENDIF}
+
(* --- Init --- *)
procedure sys_Init;
procedure sys_Final;
end;
{$ENDIF}
+{$IFDEF ENABLE_TOUCH}
+ procedure sys_ShowKeyboard (yes: Boolean);
+ begin
+ // stub
+ end;
+
+ function sys_IsTextInputActive (): Boolean;
+ begin
+ Result := false
+ end;
+{$ENDIF}
+
function Key2Stub (key: Integer): Integer;
var x: Integer;
begin
diff --git a/src/game/sdl/g_touch.pas b/src/game/sdl/g_touch.pas
--- a/src/game/sdl/g_touch.pas
+++ /dev/null
@@ -1,53 +0,0 @@
-(* Copyright (C) Doom 2D: Forever Developers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License ONLY.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *)
-{$INCLUDE ../shared/a_modes.inc}
-unit g_touch;
-
-interface
-
- var
- g_touch_enabled: Boolean = False;
- g_touch_size: Single = 1.0;
- g_touch_offset: Single = 50.0;
- g_touch_fire: Boolean = True;
- g_touch_alt: Boolean = False;
-
- procedure g_Touch_Init;
- procedure g_Touch_ShowKeyboard(yes: Boolean);
- procedure g_Touch_Draw;
-
-implementation
-
- uses g_console;
-
- procedure g_Touch_Init;
- begin
- end;
-
- procedure g_Touch_ShowKeyboard(yes: Boolean);
- begin
- end;
-
- procedure g_Touch_Draw;
- begin
- end;
-
-initialization
- conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons');
- conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
- conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size');
- conRegVar('touch_offset', @g_touch_offset, 0, 100, '', '');
- conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout');
-end.
index 89127adcc894bec838c4ddbbd63ab0153d8bbb37..bc60586efecc3ccee0b8fecc7421d4bd3256ae59 100644 (file)
function sys_HandleInput (): Boolean;
procedure sys_RequestQuit;
+{$IFDEF ENABLE_TOUCH}
+ function sys_IsTextInputActive (): Boolean;
+ procedure sys_ShowKeyboard (yes: Boolean);
+{$ENDIF}
+
(* --- Init --- *)
procedure sys_Init;
procedure sys_Final;
implementation
uses
- SysUtils, SDL2, Math, ctypes,
- e_log, e_input, e_sound,
{$IFDEF ENABLE_HOLMES}
sdlcarcass,
{$ENDIF}
- g_touch, g_options, g_console, g_game, g_basic
+ {$IFNDEF HEADLESS}
+ r_render,
+ {$ENDIF}
+ {$IFDEF ENABLE_MENU}
+ g_gui,
+ {$ENDIF}
+ SysUtils, SDL2, Math, ctypes,
+ e_log, e_input, e_sound,
+ g_options, g_console, g_game, g_basic
;
const
JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean;
JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer;
+ var (* touch *)
+ angleFire: Boolean;
+ keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer;
+
(* --------- Graphics --------- *)
function GetTitle (): AnsiString;
end
end;
+ (* --------- Touch --------- *)
+
+{$IFDEF ENABLE_TOUCH}
+ function sys_IsTextInputActive (): Boolean;
+ begin
+ Result := SDL_IsTextInputActive() = SDL_True
+ end;
+
+ procedure sys_ShowKeyboard (yes: Boolean);
+ begin
+ {$IFNDEF HEADLESS}
+ if g_dbg_input then
+ e_LogWritefln('g_Touch_ShowKeyboard(%s)', [yes]);
+ (* on desktop we always receive text (needed for cheats) *)
+ if yes or (SDL_HasScreenKeyboardSupport() = SDL_FALSE) then
+ SDL_StartTextInput
+ else
+ SDL_StopTextInput
+ {$ENDIF}
+ end;
+
+ procedure HandleTouch (const ev: TSDL_TouchFingerEvent);
+ var
+ x, y, i, finger: Integer;
+
+ function IntersectControl(ctl, xx, yy: Integer): Boolean;
+ var x, y, w, h: Integer; founded: Boolean;
+ begin
+ r_Render_GetKeyRect(ctl, x, y, w, h, founded);
+ result := founded and (xx >= x) and (yy >= y) and (xx <= x + w) and (yy <= y + h);
+ end;
+
+ procedure KeyUp (finger, i: Integer);
+ begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: g_touch.KeyUp, finger=%s, key=%s', [finger, i]);
+
+ keyFinger[i] := 0;
+ e_KeyUpDown(i, False);
+ g_Console_ProcessBind(i, False);
+
+ (* up/down + fire hack *)
+{$IFDEF ENABLE_MENU}
+ if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and (g_ActiveWindow = nil) and angleFire then
+{$ELSE}
+ if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and angleFire then
+{$ENDIF}
+ begin
+ if (i = VK_UP) or (i = VK_DOWN) then
+ begin
+ angleFire := False;
+ keyFinger[VK_FIRE] := 0;
+ e_KeyUpDown(VK_FIRE, False);
+ g_Console_ProcessBind(VK_FIRE, False)
+ end
+ end
+ end;
+
+ procedure KeyDown (finger, i: Integer);
+ begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: g_touch.KeyDown, finger=%s, key=%s', [finger, i]);
+
+ keyFinger[i] := finger;
+ e_KeyUpDown(i, True);
+ g_Console_ProcessBind(i, True);
+
+ (* up/down + fire hack *)
+{$IFDEF ENABLE_MENU}
+ if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and (g_ActiveWindow = nil) then
+{$ELSE}
+ if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then
+{$ENDIF}
+ begin
+ if i = VK_UP then
+ begin
+ angleFire := True;
+ keyFinger[VK_FIRE] := -1;
+ e_KeyUpDown(VK_FIRE, True);
+ g_Console_ProcessBind(VK_FIRE, True)
+ end
+ else if i = VK_DOWN then
+ begin
+ angleFire := True;
+ keyFinger[VK_FIRE] := -1;
+ e_KeyUpDown(VK_FIRE, True);
+ g_Console_ProcessBind(VK_FIRE, True)
+ end
+ end
+ end;
+
+ procedure KeyMotion (finger, i: Integer);
+ begin
+ if keyFinger[i] <> finger then
+ begin
+ KeyUp(finger, i);
+ KeyDown(finger, i)
+ end
+ end;
+
+ begin
+ if not g_touch_enabled then
+ Exit;
+
+ finger := ev.fingerId + 2;
+ x := Trunc(ev.x * gWinSizeX);
+ y := Trunc(ev.y * gWinSizeY);
+
+ for i := VK_FIRSTKEY to VK_LASTKEY do
+ begin
+ if IntersectControl(i, x, y) then
+ begin
+ if ev.type_ = SDL_FINGERUP then
+ KeyUp(finger, i)
+ else if ev.type_ = SDL_FINGERMOTION then
+ KeyMotion(finger, i)
+ else if ev.type_ = SDL_FINGERDOWN then
+ keyDown(finger, i)
+ end
+ else if keyFinger[i] = finger then
+ begin
+ if ev.type_ = SDL_FINGERUP then
+ KeyUp(finger, i)
+ else if ev.type_ = SDL_FINGERMOTION then
+ KeyUp(finger, i)
+ end
+ end
+ end;
+{$ENDIF} // TOUCH
+
(* --------- Input --------- *)
function HandleWindow (var ev: TSDL_WindowEvent): Boolean;
SDL_JOYDEVICEADDED: HandleJoyAdd(ev.jdevice);
SDL_JOYDEVICEREMOVED: HandleJoyRemove(ev.jdevice);
SDL_TEXTINPUT: HandleTextInput(ev.text);
- SDL_FINGERMOTION, SDL_FINGERDOWN, SDL_FINGERUP: g_Touch_HandleEvent(ev.tfinger);
+ {$IFDEF ENABLE_TOUCH}
+ SDL_FINGERMOTION, SDL_FINGERDOWN, SDL_FINGERUP: HandleTouch(ev.tfinger);
+ {$ENDIF}
{$IFDEF ENABLE_HOLMES}
SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, SDL_MOUSEMOTION: fuiOnSDLEvent(ev);
{$ENDIF}
e_LogWritefln('SDL: Init subsystem failed: %s', [SDL_GetError()]);
{$ENDIF}
SDL_ShowCursor(SDL_DISABLE);
+ {$IFDEF ENABLE_TOUCH}
+ sys_ShowKeyboard(FALSE);
+ g_touch_enabled := SDL_GetNumTouchDevices() > 0;
+ {$ELSE}
+ g_touch_enabled := False;
+ {$ENDIF}
end;
procedure sys_Final;
index a1e3473e9b613c0b4b624957ae78da2b47840e59..6202cb43dc1c95636fd242e62da2ea71c6feb0bb 100644 (file)
function sys_HandleInput (): Boolean;
procedure sys_RequestQuit;
+{$IFDEF ENABLE_TOUCH}
+ function sys_IsTextInputActive (): Boolean;
+ procedure sys_ShowKeyboard (yes: Boolean);
+{$ENDIF}
+
(* --- Init --- *)
procedure sys_Init;
procedure sys_Final;
(* --------- Input --------- *)
+{$IFDEF ENABLE_TOUCH}
+ function sys_IsTextInputActive (): Boolean;
+ begin
+ Result := false
+ end;
+
+ procedure sys_ShowKeyboard (yes: Boolean);
+ begin
+ end;
+{$ENDIF}
+
function sys_HandleInput (): Boolean;
begin
result := false
diff --git a/src/game/stub/g_touch.pas b/src/game/stub/g_touch.pas
+++ /dev/null
@@ -1,53 +0,0 @@
-(* Copyright (C) Doom 2D: Forever Developers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3 of the License ONLY.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *)
-{$INCLUDE ../shared/a_modes.inc}
-unit g_touch;
-
-interface
-
- var
- g_touch_enabled: Boolean = False;
- g_touch_size: Single = 1.0;
- g_touch_offset: Single = 50.0;
- g_touch_fire: Boolean = True;
- g_touch_alt: Boolean = False;
-
- procedure g_Touch_Init;
- procedure g_Touch_ShowKeyboard(yes: Boolean);
- procedure g_Touch_Draw;
-
-implementation
-
- uses g_console;
-
- procedure g_Touch_Init;
- begin
- end;
-
- procedure g_Touch_ShowKeyboard(yes: Boolean);
- begin
- end;
-
- procedure g_Touch_Draw;
- begin
- end;
-
-initialization
- conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons');
- conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
- conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size');
- conRegVar('touch_offset', @g_touch_offset, 0, 100, '', '');
- conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout');
-end.
diff --git a/src/shared/a_modes.inc b/src/shared/a_modes.inc
index 43b773baf80e7de79fe0f506e7a8dd2a4bef36fc..909a81373e8e31313174124b661a1ccb4d314ccb 100644 (file)
--- a/src/shared/a_modes.inc
+++ b/src/shared/a_modes.inc
{$UNDEF ENABLE_MENU}
{$DEFINE DISABLE_MENU}
{$ENDIF}
+ {$IFDEF ENABLE_TOUCH}
+ {$WARNING Touch screen in headless mode has no sense. Disabled.}
+ {$UNDEF ENABLE_TOUCH}
+ {$DEFINE DISABLE_TOUCH}
+ {$ENDIF}
{$ENDIF}
{$IF DEFINED(ENABLE_MENU) AND DEFINED(DISABLE_MENU)}
{$ENDIF}
{$ENDIF}
+{$IF DEFINED(ENABLE_TOUCH) AND DEFINED(DISABLE_TOUCH)}
+ {$ERROR Select ENABLE_TOUCH or DISABLE_TOUCH}
+{$ELSEIF NOT DEFINED(ENABLE_TOUCH) AND NOT DEFINED(DISABLE_TOUCH)}
+ // defaut ENABLE/DISABLE touch
+ {$IFDEF HEADLESS}
+ {$DEFINE DISABLE_TOUCH}
+ {$ELSE}
+ {$DEFINE ENABLE_TOUCH}
+ {$ENDIF}
+{$ENDIF}
+
{$IF DEFINED(USE_SYSSTUB)}
{$IF DEFINED(USE_SDL) OR DEFINED(USE_SDL2)}
{$ERROR Only one system driver must be selected!}