Merge branch 'master' of gitlab.iut-clermont.uca.fr:maribemont/projet-tut

origin/fixingSettings
thmaillarb 3 years ago
commit 9e711c75cc

@ -40,6 +40,8 @@ int main(int argc, char *argv[]) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
SDL_StopTextInput();
FontHandler fontHandler = loadFonts();
AudioHandler audioHandler = newAudioHandler(128, 128, 128);
@ -56,12 +58,12 @@ int main(int argc, char *argv[]) {
SDL_GetWindowSize(window, &windowW, &windowH);
size_t nbPlayers = 3;
size_t nbPlayers = 4;
Player players[] = {
newPlayer("Bépo", PlayerViolet),
newPlayer("Azeryty", PlayerBlue),
newPlayer("Adcsg", PlayerRed),
//newPlayer("qsdfqsdfq", PlayerYellow)
newPlayer("qsdfqsdfq", PlayerYellow)
};
//players[2] = ;
@ -73,9 +75,10 @@ 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].rank = 3;
@ -83,6 +86,7 @@ int main(int argc, char *argv[]) {
players[1].rank = 2;
players[2].eliminationTurn = 0;
players[2].rank = 1;
*/
endGameMenu(&generalState, window, renderer, &fontHandler, players, nbPlayers);
break;

@ -1,6 +1,6 @@
// #include "../test/testTextureLoader.c"
// #include "../test/testFontLoader.c"
#include "../test/testAudioHandler.c"
//#include "../test/testAudioHandler.c"
// #include "../test/testGenerateurTexture.c"
//#include "../test/testGameInterface.c"
//#include "../test/testConnectionMenu.c"
@ -11,6 +11,7 @@
//#include "../test/testConnectionMenu.c"
//#include "../test/testDrawMainMenu.c"
//#include "../test/testSettingsView.c"
#include "../test/testTextInputWithProcessor.c"
//#include "../test/oldMain__ThisCanBeGameMain.c"
/*
This file is meant to be modified (used only to called other tests functions)
@ -18,10 +19,10 @@
int main(int argc, char *argv[]) {
//testTextureLoader();
testAudioHandler();
//testAudioHandler();
//testFontLoader();
//testGenerateurTexture();
//testTextInput();
testTextInputProcessor();
//testButtonTextureLoader();
//testConnectionMenu();
//testMenuEndGame();

@ -43,7 +43,7 @@ typedef struct
* \author Allan Point
* \date 05/01/2022
*/
bool addCharacterToInputTextValueAtCursor(TextInput* textInput, const char charToAdd);
bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAdd);
/**
* \brief Remove a character from the TextInput

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 651 B

@ -41,12 +41,17 @@ InputElement proccessInput(InputProcessor *inputProcessor)
if (inputProcessor->selectedTextInput == NULL) {
SDL_StartTextInput();
}
else {
inputProcessor->selectedTextInput->isActive = false;
}
inputProcessor->selectedTextInput = ti;
textInputClicked = true;
inputProcessor->selectedTextInput->isActive = true;
break;
}
}
if (!textInputClicked) {
inputProcessor->selectedTextInput->isActive = false;
inputProcessor->selectedTextInput = NULL;
SDL_StopTextInput();
}
@ -69,10 +74,10 @@ InputElement proccessInput(InputProcessor *inputProcessor)
}
break;
case SDL_TEXTINPUT:
addStringToInputTextValueAtCursor(inputProcessor->selectedTextInput, event.text.text);
break;
case SDL_TEXTEDITING:
inputProcessor->selectedTextInput->cursorPosition = event.edit.start;
break;
}

@ -1,31 +1,32 @@
#include "engine/TextInput.h"
bool addCharacterToInputTextValueAtCursor(TextInput* textInput, const char charToAdd)
bool addStringToInputTextValueAtCursor(TextInput* textInput, const char* strToAdd)
{
const size_t lenText = strlen(textInput->value);
if(textInput == NULL)
{
return false;
}
if(textInput->cursorPosition > strlen(textInput->value))
if(textInput->cursorPosition > lenText)
{
return false;
textInput->cursorPosition = lenText;
}
char newValue[strlen(textInput->value)+1];
const size_t lenStrToAdd = strlen(strToAdd);
char newValue[lenText+lenStrToAdd+1];
strcpy(newValue, "");
//strcpy(newValue, "");
strncat(newValue, textInput->value, textInput->cursorPosition);
strcat(newValue, &charToAdd);
strcat(newValue, strToAdd);
strcat(newValue, textInput->value+textInput->cursorPosition);
free(textInput->value);
textInput->value = (char*) malloc(strlen(newValue));
textInput->value = (char*) realloc(textInput->value, strlen(newValue));
if(textInput->value == NULL)
{
fprintf(stderr, "WARNING: Can't allocate memory space to TextInput\n");
return false;
}
strcpy(textInput->value, newValue);
textInput->cursorPosition += 1;
textInput->cursorPosition += lenStrToAdd;
return true;
}

@ -16,20 +16,30 @@ void action(P_Button* buttonCaller){
struct array_P_Button createGameInterfaceButtons(SDL_Renderer* renderer, FontHandler* fontHandler) {
SDL_Color menuBorderColor= {0,0,255,255};
SDL_Color menuBackgroundColor = {0,255,0,255};
//SDL_Color menuBackgroundColor = {0,0,255,255};
int sizex=20,sizey=20;
SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler->fonts[FONT_retro], 125, menuBorderColor,menuBorderColor,24,5,&sizex,&sizey,renderer);
SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler->fonts[FONT_retro], 125, menuBorderColor,menuBackgroundColor,24,5,&sizex,&sizey,renderer);
SDL_Texture *menuButtonTexture = createGenericButtonTexture("Menu", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *menuButtonHoverTexture = createGenericButtonTexture("MenuHover", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *settingsButtonTexture = createTextureFromPath(renderer,"rsrc/img/SettingsResized.png");
//SDL_Texture *settingsButtonTexture = createGenericButtonTexture("Settings", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *settingsButtonHoverTexture = createGenericButtonTexture("SettingsHover", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *muteButtonTexture = createTextureFromPath(renderer,"rsrc/img/SoundResized.png");
//SDL_Texture *muteButtonTexture = createGenericButtonTexture("Mute", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
SDL_Texture *muteButtonHoverTexture = createGenericButtonTexture("MuteHover", fontHandler->fonts[FONT_retro], 15, menuBorderColor,menuBackgroundColor,13,5,&sizex,&sizey,renderer);
struct array_P_Button buttons = array_P_Button_Create();
// Menu
array_P_Button_AddElement(&buttons, createButton(menuButtonTexture, menuButtonHoverTexture,20,20,100,50,&action)); //top left corner (rectangle)
// Settings
array_P_Button_AddElement(&buttons, createButton(menuButtonTexture, menuButtonHoverTexture, 750,10,50,50,&action)); //top right corner (square or circle)
array_P_Button_AddElement(&buttons, createButton(settingsButtonTexture, settingsButtonHoverTexture, 750,10,50,50,&action)); //top right corner (square or circle)
// Mute/Unmute
array_P_Button_AddElement(&buttons, createButton(menuButtonTexture, menuButtonHoverTexture, 825,10,50,50,&action)); //top right cornre (square or circle)
array_P_Button_AddElement(&buttons, createButton(muteButtonTexture, muteButtonHoverTexture, 825,10,50,50,&action)); //top right cornre (square or circle)
return buttons;
}

@ -234,7 +234,6 @@ void endGameMenu(GeneralState* generalState, SDL_Window* window, SDL_Renderer* r
switch (inputElement.data.buttonEvent.event) {
case BUTTON_ENTRY:
case BUTTON_EXIT:
fprintf(stderr, "Button changed"); fflush(stderr);
drawButtonOnRenderer(renderer, inputElement.data.buttonEvent.button);
needToPresent = true;
break;

@ -0,0 +1,116 @@
#include <SDL2/SDL.h>
#include <stdio.h>
#include "engine/TextureLoader.h"
#include "engine/FontLoader.h"
#include "engine/TextInput.h"
#include "engine/InputProcessor.h"
void testTextInputProcessor() {
SDL_Rect windowSize = {10, 10, 900, 900};
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
int statut = EXIT_FAILURE;
if(SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "Error : %s\n", SDL_GetError());
return;
}
window = SDL_CreateWindow("Pontu",windowSize.x, windowSize.y, windowSize.w, windowSize.h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
if (!window)
{
fprintf(stderr, "Error : %s\n", SDL_GetError());
return;
}
renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
if(!renderer)
{
fprintf(stderr, "Erreur : %s", SDL_GetError());
return;
}
if(TTF_Init()==-1) {
printf("TTF_Init: %s\n", TTF_GetError());
exit(2);
}
InputProcessor inputProcessor = createInputProcessor();
bool needToPresent = true;
FontHandler fontHandler = loadFonts();
SDL_StopTextInput();
TextInput tI;
array_TextInput_AddElement(&inputProcessor.tabTextInput, tI);
TextInput* textInput = array_TextInput_Last(&inputProcessor.tabTextInput);
SDL_Rect size = {.x=10, .y=10, .w=90, .h=20};
if(!initTextInput(textInput, &size, NULL, fontHandler.fonts[FONT_retro]))
{
fprintf(stderr, "WARNING: can't init TextInput\n");
return;
}
drawTextInputOnRenderer(renderer, textInput);
bool quit = false;
while(!quit)
{
{
InputElement inputElement;
while (InputType_None != (inputElement = proccessInput(&inputProcessor)).type) {
switch (inputElement.type)
{
case InputType_ActivateUI:
switch (inputElement.data.uiAction)
{
case UIAction_Quit:
quit = true;
break;
case UIAction_Validate:
break;
case UIAction_Cancel:
break;
default:
break;
}
break;
case InputType_Window_Resize: {
/*const SDL_Rect rectM = {
.x=inputElement.data.windowSize.w/10,
.y=0,
.w=inputElement.data.windowSize.w*80/100,
.h=inputElement.data.windowSize.h
};*/
break;
}
default:
break;
}
}
}
drawTextInputOnRenderer(renderer, textInput);
needToPresent = true;
if (needToPresent) {
SDL_RenderPresent(renderer);
needToPresent = false;
}
SDL_Delay(10);
}
freeInputProcessor(&inputProcessor);
}
Loading…
Cancel
Save