1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2025-07-11 14:09:24 +00:00

Encapsulation de la SDL

This commit is contained in:
2016-12-28 23:59:43 +01:00
parent 430fb4d2c0
commit 23e82f4832
3 changed files with 65 additions and 32 deletions

View File

@ -2,7 +2,7 @@
* @Author: klmp200
* @Date: 2016-12-27 19:59:21
* @Last Modified by: klmp200
* @Last Modified time: 2016-12-28 23:26:39
* @Last Modified time: 2016-12-28 23:57:29
*/
#include <stdio.h>
@ -36,3 +36,52 @@ void DisplayMatrixSDL(SCREEN *screen, Matrix m){
}
SDL_RenderPresent(screen->renderer);
}
void WaitUntilEnter(SCREEN * screen){
int keypress = 0;
while (!keypress){
while(SDL_PollEvent(&screen->event)){
switch (screen->event.type){
case SDL_QUIT:
keypress = 1;
break;
case SDL_KEYDOWN:
switch(screen->event.key.keysym.sym){
case SDLK_RETURN:
keypress = 1;
break;
}
}
}
}
}
int NewWindowFromMatrix(Matrix m){
SCREEN screen;
screen.WIDTH = m.colCount;
screen.HEIGHT = m.rowCount;
if (SDL_Init(SDL_INIT_VIDEO) < 0){
return 1;
}
SDL_CreateWindowAndRenderer(screen.WIDTH, screen.HEIGHT,
SDL_WINDOW_RESIZABLE | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_SHOWN,
&(screen.window), &(screen.renderer));
if (screen.window == NULL || screen.renderer == NULL){
SDL_Quit();
return 1;
}
DisplayMatrixSDL(&screen, m);
WaitUntilEnter(&screen);
SDL_DestroyRenderer(screen.renderer);
SDL_DestroyWindow(screen.window);
return 0;
}

View File

@ -31,4 +31,18 @@ void SetPixel(SDL_Renderer *renderer, int x, int y, bool value);
*/
void DisplayMatrixSDL(SCREEN *screen, Matrix m);
/**
* Wait until the user press the enter key
* @param screen the screen where the renderer is
* @return
*/
void WaitUntilEnter(SCREEN * screen);
/**
* Print a matrix in a new SDL window
* @param Matrix the matrix to display
* @return int error code
*/
int NewWindowFromMatrix(Matrix m);
#endif