Skip to content

Commit

Permalink
proof of concept to fix SDL double input
Browse files Browse the repository at this point in the history
  • Loading branch information
barbeque-squared committed Dec 2, 2023
1 parent 4c253db commit 006a275
Show file tree
Hide file tree
Showing 40 changed files with 189 additions and 144 deletions.
21 changes: 20 additions & 1 deletion src/base/UMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ interface
procedure Main;
procedure MainLoop;
procedure CheckEvents;
procedure StartTextInput;
procedure StopTextInput;
procedure SetTextInput(enabled: boolean);

type
TMainThreadExecProc = procedure(Data: Pointer);
Expand Down Expand Up @@ -299,6 +302,21 @@ procedure Main;
{$ENDIF}
end;

procedure StartTextInput;
begin
SDL_StartTextInput;
end;

procedure StopTextInput;
begin
SDL_StopTextInput;
end;

procedure SetTextInput(enabled: boolean);
begin
if enabled then StartTextInput else StopTextInput;
end;

procedure MainLoop;
var
Delay: integer;
Expand All @@ -309,7 +327,8 @@ procedure MainLoop;
I,J: Integer;
begin
Max_FPS := Ini.MaxFramerateGet;
SDL_StartTextInput;
// need to explicitly stop this because it appears to be started by default
SDL_StopTextInput;
Done := false;
J := 1;
CountSkipTime();
Expand Down
6 changes: 3 additions & 3 deletions src/screens/UScreenAbout.pas
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ function TScreenAbout.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Press
if (PressedDown) then
begin // Key Down
// check normal keys
case UCS4UpperCase(CharCode) of
Ord('C'):
case PressedKey of
SDLK_C:
begin
FadeTo(@ScreenCredits, SoundLib.Start);
Exit;
end;

Ord('Q'):
SDLK_Q:
begin
Result := false;
Exit;
Expand Down
4 changes: 2 additions & 2 deletions src/screens/UScreenCredits.pas
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ function TScreenCredits.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
if (PressedDown) then
begin // Key Down
// check normal keys
case UCS4UpperCase(CharCode) of
Ord('Q'):
case PressedKey of
SDLK_Q:
begin
Result := false;
Exit;
Expand Down
4 changes: 2 additions & 2 deletions src/screens/UScreenEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ function TScreenEdit.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Presse
if (PressedDown) then
begin // Key Down
// check normal keys
case UCS4UpperCase(CharCode) of
Ord('Q'):
case PressedKey of
SDLK_Q:
begin
Result := false;
Exit;
Expand Down
4 changes: 2 additions & 2 deletions src/screens/UScreenEditConvert.pas
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ function TScreenEditConvert.ParseInput(PressedKey: cardinal; CharCode: UCS4Char;
if (PressedDown) then
begin // Key Down
// check normal keys
case UCS4UpperCase(CharCode) of
Ord('Q'):
case PressedKey of
SDLK_Q:
begin
Result := false;
Exit;
Expand Down
54 changes: 37 additions & 17 deletions src/screens/UScreenEditSub.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface
UFilesystem,
UGraphicClasses,
UIni,
UMain,
UMenu,
UMenuText,
UMusic,
Expand Down Expand Up @@ -497,14 +498,14 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
if (PressedDown) then // Key Down
begin
// check normal keys
case UCS4UpperCase(CharCode) of
Ord('Q'):
case PressedKey of
SDLK_Q:
begin
Result := false;
Exit;
end;
{
Ord('S'):
SDLK_S:
begin
if SDL_ModState = KMOD_LSHIFT then
begin
Expand Down Expand Up @@ -536,7 +537,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;
}
Ord('S'):
SDLK_S:
begin
// handle medley tags first
if CurrentSong.isDuet then
Expand Down Expand Up @@ -608,7 +609,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;

// set PreviewStart tag
Ord('I'):
SDLK_I:
begin
CopyToUndo;
if SDL_ModState and KMOD_SHIFT <> 0 then
Expand Down Expand Up @@ -699,7 +700,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;

// set Medley tags
Ord('A'):
SDLK_A:
begin
CopyToUndo;
if CurrentSong.Relative then
Expand Down Expand Up @@ -798,7 +799,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;

// jump to Medley tags
Ord('J'):
SDLK_J:
begin
if CurrentSong.Relative then
begin
Expand Down Expand Up @@ -894,7 +895,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
Exit;
end;

Ord('R'): //reload
SDLK_R: //reload
begin
AudioPlayback.Stop;
{$IFDEF UseMIDIPort}
Expand All @@ -906,7 +907,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
Text[TextInfo].Text := Language.Translate('EDIT_INFO_SONG_RELOADED');
end;

Ord('D'):
SDLK_D:
begin
// Divide lengths by 2
if (SDL_ModState = KMOD_LSHIFT) then
Expand Down Expand Up @@ -935,7 +936,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;
end;

Ord('M'):
SDLK_M:
begin
// Multiply lengths by 2
if (SDL_ModState = KMOD_LSHIFT) then
Expand All @@ -948,7 +949,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;
end;

Ord('C'):
SDLK_C:
begin
// Capitalize letter at the beginning of line
if SDL_ModState = 0 then
Expand Down Expand Up @@ -978,7 +979,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
Exit;
end;

Ord('V'):
SDLK_V:
begin
if (SDL_ModState = 0) or (SDL_ModState = KMOD_LALT) then // play current line/remainder of song with video
begin
Expand Down Expand Up @@ -1047,7 +1048,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
ShowInteractiveBackground;
end;

Ord('T'):
SDLK_T:
begin
// Fixes timings between sentences
CopyToUndo;
Expand All @@ -1056,7 +1057,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
Exit;
end;

Ord('P'):
SDLK_P:
begin
if SDL_ModState = 0 then
begin
Expand Down Expand Up @@ -1118,7 +1119,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;

// Golden Note
Ord('G'):
SDLK_G:
begin
CopyToUndo;
if (Tracks[CurrentTrack].Lines[Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].NoteType = ntGolden) then
Expand All @@ -1141,7 +1142,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;

// Freestyle Note
Ord('F'):
SDLK_F:
begin
CopyToUndo;
if (Tracks[CurrentTrack].Lines[Tracks[CurrentTrack].CurrentLine].Notes[CurrentNote[CurrentTrack]].NoteType = ntFreestyle) then
Expand All @@ -1168,7 +1169,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
end;

// undo
Ord('Z'):
SDLK_Z:
begin
if SDL_ModState = KMOD_LCTRL then
begin
Expand Down Expand Up @@ -1468,6 +1469,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
TextPosition := LengthUTF8(BackupEditText);
editLengthText := LengthUTF8(BackupEditText);
TextEditMode := true;
StartTextInput;
end;

SDLK_F5:
Expand All @@ -1479,6 +1481,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
TextPosition := LengthUTF8(BackupEditText);
editLengthText := LengthUTF8(BackupEditText);
BPMEditMode := true;
StartTextInput;
end;

SDLK_SPACE:
Expand Down Expand Up @@ -1533,6 +1536,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := TitleSlideId;
TextPosition := LengthUTF8(BackupEditText);
TitleEditMode := true;
StartTextInput;
end;

if Interaction = ArtistSlideId then
Expand All @@ -1543,6 +1547,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := ArtistSlideId;
TextPosition := LengthUTF8(BackupEditText);
ArtistEditMode := true;
StartTextInput;
end;

if Interaction = LanguageSlideId then
Expand All @@ -1553,6 +1558,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := LanguageSlideId;
TextPosition := LengthUTF8(BackupEditText);
LanguageEditMode := true;
StartTextInput;
end;

if Interaction = EditionSlideId then
Expand All @@ -1563,6 +1569,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := EditionSlideId;
TextPosition := LengthUTF8(BackupEditText);
EditionEditMode := true;
StartTextInput;
end;

if Interaction = GenreSlideId then
Expand All @@ -1573,6 +1580,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := GenreSlideId;
TextPosition := LengthUTF8(BackupEditText);
GenreEditMode := true;
StartTextInput;
end;

if Interaction = YearSlideId then
Expand All @@ -1583,6 +1591,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := YearSlideId;
TextPosition := LengthUTF8(BackupEditText);
YearEditMode := true;
StartTextInput;
end;

if Interaction = CreatorSlideId then
Expand All @@ -1593,6 +1602,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := CreatorSlideId;
TextPosition := LengthUTF8(BackupEditText);
CreatorEditMode := true;
StartTextInput;
end;

// Interaction = 7 // Mp3SlideId
Expand All @@ -1609,6 +1619,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := BPMSlideId;
TextPosition := LengthUTF8(BackupEditText);
BPMEditMode := true;
StartTextInput;
end;

// Interaction = 13 // GAPSlideId
Expand All @@ -1625,6 +1636,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := MedleyStartSlideId;
TextPosition := LengthUTF8(BackupEditText);
P1EditMode := true;
StartTextInput;
end;

if Interaction = MedleyEndSlideId then
Expand All @@ -1635,6 +1647,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := MedleyEndSlideId;
TextPosition := LengthUTF8(BackupEditText);
P2EditMode := true;
StartTextInput;
end;

// Interaction = 20 // StartSlideId
Expand All @@ -1649,6 +1662,7 @@ function TScreenEditSub.ParseInput(PressedKey: cardinal; CharCode: UCS4Char; Pre
CurrentSlideId := LyricSlideId;
TextPosition := LengthUTF8(BackupEditText);
TextEditMode := true;
StartTextInput;
end;

if Interaction = 24 then // UndoButtonId
Expand Down Expand Up @@ -2230,6 +2244,7 @@ function TScreenEditSub.ParseInputEditText(PressedKey: cardinal; CharCode: UCS4C
CreatorEditMode := false;
P1EditMode := false;
P2EditMode := false;
StopTextInput;
editLengthText := 0;
TextPosition := -1;
end;
Expand Down Expand Up @@ -2349,6 +2364,7 @@ function TScreenEditSub.ParseInputEditText(PressedKey: cardinal; CharCode: UCS4C
P1EditMode := false;
P2EditMode := false;
TextEditMode := false;
StopTextInput;
editLengthText := 0;
TextPosition := -1;
CurrentSlideId := -1;
Expand Down Expand Up @@ -2408,6 +2424,7 @@ function TScreenEditSub.ParseInputEditText(PressedKey: cardinal; CharCode: UCS4C
// divide note
DivideNote(false);
TextEditMode := false;
StopTextInput;
EditorLyrics[CurrentTrack].AddLine(CurrentTrack, Tracks[CurrentTrack].CurrentLine);
EditorLyrics[CurrentTrack].Selected := CurrentNote[CurrentTrack];
GoldenRec.KillAll;
Expand Down Expand Up @@ -2449,6 +2466,7 @@ function TScreenEditSub.ParseInputEditBPM(PressedKey: cardinal; CharCode: UCS4Ch
// exit BPM edit mode, restore previous BPM value
SelectsS[CurrentSlideId].TextOpt[0].Text := FloatToStr(CurrentSong.BPM[0].BPM / 4);
BPMEditMode := false;
StopTextInput;
editLengthText := 0;
TextPosition := -1;
end;
Expand All @@ -2472,6 +2490,7 @@ function TScreenEditSub.ParseInputEditBPM(PressedKey: cardinal; CharCode: UCS4Ch
end;

BPMEditMode := false;
StopTextInput;
editLengthText := 0;
TextPosition := -1;
CurrentSlideId := -1;
Expand Down Expand Up @@ -5000,6 +5019,7 @@ procedure TScreenEditSub.OnShow;
P1EditMode := false;
P2EditMode := false;
BPMEditMode := false;
StopTextInput;

editLengthText := 0;
TextPosition := -1;
Expand Down
Loading

0 comments on commit 006a275

Please sign in to comment.