2016-12-29 15:09:39 +00:00
|
|
|
/*
|
|
|
|
* This is a gui for the cellular automaton library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016-2017 Antoine BARTUCCIO, Jean POREE DE RIDDER
|
|
|
|
*
|
|
|
|
* Licensed under the MIT License,(the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* hhttps://opensource.org/licenses/MIT
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-12-27 19:12:41 +00:00
|
|
|
#ifndef PIXEL_H_INCLUDED
|
|
|
|
#define PIXEL_H_INCLUDED
|
|
|
|
|
|
|
|
#include <SDL2/SDL.h>
|
2016-12-28 22:26:58 +00:00
|
|
|
#include <CellElement.h>
|
2016-12-28 20:39:42 +00:00
|
|
|
#include <matrix.h>
|
2016-12-27 19:12:41 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2016-12-28 20:39:42 +00:00
|
|
|
SDL_Window * window;
|
|
|
|
SDL_Renderer * renderer;
|
|
|
|
int WIDTH;
|
|
|
|
int HEIGHT;
|
|
|
|
SDL_Event event;
|
|
|
|
} SCREEN;
|
2016-12-27 19:12:41 +00:00
|
|
|
|
2016-12-28 20:39:42 +00:00
|
|
|
/**
|
|
|
|
* Set a pixel on a given screen
|
|
|
|
* @param screen the screen to display the pixel
|
|
|
|
* @param x x position
|
|
|
|
* @param y y position
|
|
|
|
* @param value display white if true and black if false
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
void setPixel(SDL_Renderer *renderer, int x, int y, bool value);
|
2016-12-28 20:39:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display an entire matrix on a given screen
|
|
|
|
* @param screen the screen where the matrix should be displayed
|
|
|
|
* @param m a Matrix
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
void displayMatrixSDL(SCREEN *screen, Matrix m);
|
2016-12-27 19:12:41 +00:00
|
|
|
|
2016-12-28 22:59:43 +00:00
|
|
|
/**
|
|
|
|
* Wait until the user press the enter key
|
|
|
|
* @param screen the screen where the renderer is
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
void waitUntilEnter(SCREEN * screen);
|
2016-12-28 22:59:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a matrix in a new SDL window
|
|
|
|
* @param Matrix the matrix to display
|
|
|
|
* @return int error code
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
int newWindowFromMatrix(Matrix m);
|
2016-12-28 22:59:43 +00:00
|
|
|
|
2016-12-29 02:14:07 +00:00
|
|
|
/**
|
|
|
|
* Display a message and ask for yes or no to the user
|
|
|
|
* @param message the message to display
|
|
|
|
* @return bool the answer
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
bool inputYesOrNo(char message[]);
|
2016-12-29 02:14:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display matrix choosing the right function
|
|
|
|
* @param m a Matrix
|
|
|
|
* @param useSDL a bool
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
void displayMatrixGUI(Matrix m, bool useSDL);
|
2016-12-29 02:14:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a number from the user safely
|
|
|
|
* @param min the minimal authorized number
|
|
|
|
* @param max the maximal authorized number
|
|
|
|
* @return int the input number
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
int safeNumberInput(int min, int max);
|
2016-12-29 02:14:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the buffer of stdin
|
|
|
|
*/
|
2017-01-01 15:43:40 +00:00
|
|
|
void clearBuffer();
|
2016-12-29 02:14:07 +00:00
|
|
|
|
2016-12-27 19:12:41 +00:00
|
|
|
#endif
|