aboutsummaryrefslogtreecommitdiff
path: root/src/graphics.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-05-10 16:48:37 +0200
committerCharles <sircharlesaze@gmail.com>2020-05-10 16:48:37 +0200
commitf23764a0ec0b946d9d0c0dd1a2537c0d22849086 (patch)
tree81d0b4dc68e4f34d6e950d0f28f58ca5d3d1e07f /src/graphics.c
parent6d9c284a24555a7df0b37661ff3c5491d6d0449a (diff)
downloadcardioid-f23764a0ec0b946d9d0c0dd1a2537c0d22849086.tar.gz
cardioid-f23764a0ec0b946d9d0c0dd1a2537c0d22849086.tar.bz2
cardioid-f23764a0ec0b946d9d0c0dd1a2537c0d22849086.zip
Dynamic factor, everything to double, removed cardioid struct, window resize
Diffstat (limited to 'src/graphics.c')
-rw-r--r--src/graphics.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/src/graphics.c b/src/graphics.c
deleted file mode 100644
index 2c5ef7e..0000000
--- a/src/graphics.c
+++ /dev/null
@@ -1,104 +0,0 @@
-#include "graphics.h"
-
-#define WINDOW_TITLE "Cardioid"
-
-static const char *g_sdl_error_str;
-
-#ifdef CARDIOID_RELEASE
-# define SDL_CALL(x) x
-#else
-# define SDL_CALL(x) \
- SDL_ClearError(); \
- x; \
- g_sdl_error_str = SDL_GetError(); \
- if (*g_sdl_error_str != '\0') { \
- SDL_Log("[ERROR SDL] %s at %s:%d\n\t"#x, \
- g_sdl_error_str, __FILE__, __LINE__); \
- exit(EXIT_FAILURE); \
-}
-#endif
-
-
-static void update(t_state *state);
-static void event_handler(t_state *state);
-static void draw_lines(t_state *state);
-
-void graphics_init(t_state *state, int width, int height, t_cardioid *cardioid)
-{
- SDL_CALL(SDL_Init(SDL_INIT_VIDEO));
- SDL_CALL(state->window = SDL_CreateWindow(
- WINDOW_TITLE,
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
- width,
- height,
- 0
- ));
- SDL_CALL(state->renderer = SDL_CreateRenderer(state->window, -1, 0));
- state->cardioid = cardioid;
- state->running = true;
-}
-
-void graphics_quit(t_state *state)
-{
- SDL_DestroyRenderer(state->renderer);
- SDL_DestroyWindow(state->window);
- SDL_Quit();
-}
-
-void graphics_run(t_state *state)
-{
- while (state->running)
- {
- event_handler(state);
- update(state);
- SDL_Delay(3);
- }
-}
-
- static
-void update(t_state *state)
-{
- SDL_CALL(SDL_SetRenderDrawColor(state->renderer, 0, 0, 0, 255));
- SDL_CALL(SDL_RenderClear(state->renderer));
- SDL_CALL(SDL_SetRenderDrawColor(state->renderer, 200, 150, 150, 255));
- SDL_CALL(SDL_RenderDrawPoints(state->renderer, state->cardioid->points, state->cardioid->points_num));
- draw_lines(state);
- SDL_CALL(SDL_RenderPresent(state->renderer));
-}
-
- static
-void draw_lines(t_state *state)
-{
- SDL_Point *points = state->cardioid->points;
- SDL_Point *paired;
-
- for (size_t i = 0; i < state->cardioid->points_num; i++)
- {
- paired = &points[i * 10 % state->cardioid->points_num];
- SDL_CALL(SDL_RenderDrawLine(state->renderer, points[i].x, points[i].y, paired->x, paired->y));
- }
-}
-
- static
-void event_handler(t_state *state)
-{
- SDL_Event e;
-
- while (SDL_PollEvent(&e))
- {
- switch (e.type)
- {
- case SDL_QUIT:
- state->running = false;
- break;
- case SDL_KEYDOWN:
- switch (e.key.keysym.sym)
- {
- case SDLK_j: CARDIOID_SUB_POINTS(state->cardioid, 3); break;
- case SDLK_k: CARDIOID_ADD_POINTS(state->cardioid, 3); break;
- }
- break;
- }
- }
-}