From 42e41dde1603ac222b44070073f774185544eebd Mon Sep 17 00:00:00 2001 From: marouault Date: Mon, 14 Feb 2022 10:07:11 +0100 Subject: [PATCH] Input processor start textinput --- Pontu/entryPoints/main.c | 6 +++--- Pontu/include/engine/InputProcessor.h | 4 ++++ Pontu/include/engine/TextInput.h | 3 ++- Pontu/include/engine/arrayTextInput.h | 9 +++++++++ Pontu/src/engine/InputProcessor.c | 25 ++++++++++++++++++++++++- Pontu/src/view/GameInterface.c | 4 ++-- 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 Pontu/include/engine/arrayTextInput.h diff --git a/Pontu/entryPoints/main.c b/Pontu/entryPoints/main.c index d2e981f..a669351 100644 --- a/Pontu/entryPoints/main.c +++ b/Pontu/entryPoints/main.c @@ -73,16 +73,16 @@ int main(int argc, char *argv[]) { }*/ generalState = GS_Game; - gameView(&generalState, window, renderer, players, nbPlayers, &fontHandler); + //gameView(&generalState, window, renderer, players, nbPlayers, &fontHandler); //Pour tester le endGameMenu directement generalState = GS_EndOfGameMenu; - /*players[0].eliminationTurn = 10; + players[0].eliminationTurn = 10; players[0].rank = 3; players[1].eliminationTurn = 15; players[1].rank = 2; players[2].eliminationTurn = 0; - players[2].rank = 1;*/ + players[2].rank = 1; endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers); break; diff --git a/Pontu/include/engine/InputProcessor.h b/Pontu/include/engine/InputProcessor.h index 594923f..d8a6691 100644 --- a/Pontu/include/engine/InputProcessor.h +++ b/Pontu/include/engine/InputProcessor.h @@ -10,6 +10,8 @@ #include "engine/Button.h" #include "engine/arrayButton.h" +#include "engine/TextInput.h" +#include "engine/arrayTextInput.h" #include "engine/InputElement.h" /** @@ -19,6 +21,8 @@ typedef struct { struct array_P_Button tabButton; + struct array_TextInput tabTextInput; + TextInput* selectedTextInput; } InputProcessor; diff --git a/Pontu/include/engine/TextInput.h b/Pontu/include/engine/TextInput.h index e6641ca..cd8556e 100644 --- a/Pontu/include/engine/TextInput.h +++ b/Pontu/include/engine/TextInput.h @@ -27,7 +27,8 @@ typedef struct { char* value; - int cursorPosition; + Sint32 cursorPosition; + SDL_Rect size; bool isActive; SDL_Color textColor; diff --git a/Pontu/include/engine/arrayTextInput.h b/Pontu/include/engine/arrayTextInput.h new file mode 100644 index 0000000..f4a63d5 --- /dev/null +++ b/Pontu/include/engine/arrayTextInput.h @@ -0,0 +1,9 @@ +#ifndef ARRAY_TEXT_INPUT_INCLUDED +#define ARRAY_TEXT_INPUT_INCLUDED + +#include "engine/TextInput.h" +#include "engine/ArrayUtils.h" + +GENERATE_DYNAMIC_ARRAY(TextInput) + +#endif //ARRAY_TEXT_INPUT_INCLUDED diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index 065f9a4..ec68542 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -2,7 +2,8 @@ InputProcessor createInputProcessor() { InputProcessor inputProcessor = { - .tabButton = array_P_Button_Create() + .tabButton = array_P_Button_Create(), + .tabTextInput = array_TextInput_Create() }; return inputProcessor; } @@ -33,6 +34,22 @@ InputElement proccessInput(InputProcessor *inputProcessor) b->onClick(b); } } + bool textInputClicked = false; + for (size_t i = 0; itabTextInput.size; ++i) { + TextInput* ti = &inputProcessor->tabTextInput.elems[i]; + if (SDL_PointInRect(&mousePoint, &ti->size)) { + if (inputProcessor->selectedTextInput == NULL) { + SDL_StartTextInput(); + } + inputProcessor->selectedTextInput = ti; + textInputClicked = true; + break; + } + } + if (!textInputClicked) { + inputProcessor->selectedTextInput = NULL; + SDL_StopTextInput(); + } return createInputElementNone(); } case SDL_MOUSEMOTION: @@ -50,6 +67,12 @@ InputElement proccessInput(InputProcessor *inputProcessor) if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { return createInputElementResizeWindow(event.window.data1, event.window.data2); } + break; + case SDL_TEXTINPUT: + + break; + case SDL_TEXTEDITING: + break; } diff --git a/Pontu/src/view/GameInterface.c b/Pontu/src/view/GameInterface.c index e98f63a..9312bea 100644 --- a/Pontu/src/view/GameInterface.c +++ b/Pontu/src/view/GameInterface.c @@ -50,9 +50,9 @@ struct array_TextLabel createGameInterfaceLabels(SDL_Renderer* renderer, FontHan struct array_TextLabel labels = array_TextLabel_Create(); // Label : Nb Turn - TextLabel nbTurnLabel = createTextLabel("Turn : ",&positonNbTurnLabel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY); + TextLabel nbTurnLabel = createTextLabel("Turn : ",&positonNbTurnLabel,1,&colorLabel,fontHandler->fonts[FONT_retro],renderer,positionX,positionY); // Label : Time of the game - TextLabel timeLabel = createTextLabel("Time : ",&positionTimeLablel,1,&colorLabel,fontHandler.fonts[FONT_retro],renderer,positionX,positionY); + TextLabel timeLabel = createTextLabel("Time : ",&positionTimeLablel,1,&colorLabel,fontHandler->fonts[FONT_retro],renderer,positionX,positionY); //Add TextLabel to the array array_TextLabel_AddElement(&labels, nbTurnLabel);