mirror of
https://gitlab.com/klmp200/LO27.git
synced 2025-07-11 11:39:22 +00:00
Encapsulation de la SDL
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user