mirror of
				https://gitlab.com/klmp200/LO27.git
				synced 2025-10-31 04:33:03 +00:00 
			
		
		
		
	Ajout d'une gui et correction de l'apply rules
This commit is contained in:
		| @@ -7,7 +7,7 @@ INCLUDEDIR=-I/usr/include -I. -I../LibMatrix | ||||
|  | ||||
| #Library variables | ||||
| LIBTARGET=libGui.so | ||||
| LIBSOURCE=pixel | ||||
| LIBSOURCE=gui | ||||
| LIBSOURCECFILE=$(LIBSOURCE:=.c) | ||||
| LIBSOURCEOFILE=$(LIBSOURCE:=.o) | ||||
|  | ||||
|   | ||||
| @@ -2,15 +2,17 @@ | ||||
| * @Author: klmp200 | ||||
| * @Date:   2016-12-27 19:59:21 | ||||
| * @Last Modified by:   klmp200 | ||||
| * @Last Modified time: 2016-12-29 00:03:19 | ||||
| * @Last Modified time: 2016-12-29 02:51:25 | ||||
| */ | ||||
| 
 | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <SDL2/SDL.h> | ||||
| #include <pixel.h> | ||||
| #include <gui.h> | ||||
| #include <matrix.h> | ||||
| #include <CellElement.h> | ||||
| #include <termios.h> | ||||
| #include <unistd.h> | ||||
| 
 | ||||
| void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){ | ||||
| 
 | ||||
| @@ -88,3 +90,51 @@ int NewWindowFromMatrix(Matrix m){ | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| bool YesOrNo(char message[]){ | ||||
| 	char response; | ||||
| 
 | ||||
| 	printf("%s (Y/n)\n", message); | ||||
| 	response = getchar(); | ||||
| 	ClearBuffer(); | ||||
| 
 | ||||
| 	if (response == 'n'){ | ||||
| 		return false; | ||||
| 	} else { | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void ClearBuffer(){ | ||||
| 	char c; | ||||
| 	while ((c = getchar()) != '\n' && c != EOF) { } | ||||
| } | ||||
| 
 | ||||
| void DisplayMatrixGUI(Matrix m, bool useSDL){ | ||||
| 	if (useSDL){ | ||||
| 		printf("Press ENTER or the red cross to exit the window and continue.\n"); | ||||
| 		NewWindowFromMatrix(m); | ||||
| 	} else { | ||||
| 		BasicPrintMatrix(m); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| int SafeNumberInput(int min, int max){ | ||||
| 	char str[30]; | ||||
| 	int input; | ||||
| 
 | ||||
| 	fgets(str, 29, stdin); | ||||
| 	ClearBuffer(); | ||||
| 
 | ||||
| 	input = atoi(str); | ||||
| 
 | ||||
| 	while (input < min || input > max){ | ||||
| 		printf("The number should be between %d and %d\n", min, max); | ||||
| 		fgets(str, 29, stdin); | ||||
| 		ClearBuffer(); | ||||
| 		input = atoi(str); | ||||
| 	} | ||||
| 
 | ||||
| 	return input; | ||||
| } | ||||
| @@ -45,4 +45,33 @@ void WaitUntilEnter(SCREEN * screen); | ||||
| */ | ||||
| int NewWindowFromMatrix(Matrix m); | ||||
| 
 | ||||
| /**
 | ||||
| * Display a message and ask for yes or no to the user | ||||
| * @param message the message to display | ||||
| * @return bool the answer | ||||
| */ | ||||
| bool YesOrNo(char message[]); | ||||
| 
 | ||||
| /**
 | ||||
| * Display matrix choosing the right function | ||||
| * @param m a Matrix | ||||
| * @param useSDL a bool | ||||
| * @return | ||||
| */ | ||||
| void DisplayMatrixGUI(Matrix m, bool useSDL); | ||||
| 
 | ||||
| /**
 | ||||
| * Get a number from the user safely | ||||
| * @param min the minimal authorized number | ||||
| * @param max the maximal authorized number | ||||
| * @return int the input number | ||||
| */ | ||||
| int SafeNumberInput(int min, int max); | ||||
| 
 | ||||
| /**
 | ||||
| * Clears the buffer of stdin | ||||
| * @return | ||||
| */ | ||||
| void ClearBuffer(); | ||||
| 
 | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user