mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-05 10:48:03 +00:00
88 lines
1.7 KiB
C
88 lines
1.7 KiB
C
/*
|
|
* @Author: klmp200
|
|
* @Date: 2016-12-27 19:59:21
|
|
* @Last Modified by: klmp200
|
|
* @Last Modified time: 2016-12-28 23:57:29
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <SDL2/SDL.h>
|
|
#include <pixel.h>
|
|
#include <matrix.h>
|
|
#include <CellElement.h>
|
|
|
|
void SetPixel(SDL_Renderer *renderer, int x, int y, bool value){
|
|
|
|
if (value){
|
|
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
|
} else {
|
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
|
}
|
|
SDL_RenderDrawPoint(renderer, x, y);
|
|
}
|
|
|
|
void DisplayMatrixSDL(SCREEN *screen, Matrix m){
|
|
int i;
|
|
int j;
|
|
|
|
SDL_SetRenderDrawColor(screen->renderer, 0, 0, 0, 0);
|
|
SDL_RenderClear(screen->renderer);
|
|
|
|
for (i=0;i<m.rowCount;i++){
|
|
for (j=0;j<m.colCount;j++){
|
|
SetPixel(screen->renderer, i, j, GetCellValue(m, j, i));
|
|
}
|
|
}
|
|
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;
|
|
}
|