#include #include #include #include #include #include #include #include #include "chess_board.h" static clock_t start_time, end_time; int begin_game(SDL_Renderer *renderer, SDL_Window *win) { SDL_Rect srcR, destR; srcR.h = 800; srcR.w = 800; destR.h = 800; destR.w = 800; chess_board_resize(renderer, 800, 800); chess_board_init(renderer); srcR.x = 0; srcR.y = 0; destR.x = 0; destR.y = 0; bool run = true; while (run) { clock_t start_t, end_t; SDL_Event event; bool redraw = false; while (SDL_PollEvent(&event)) { /* handle your event here */ if (event.type == SDL_MOUSEBUTTONDOWN) { if (event.button.button == SDL_BUTTON_MIDDLE) // scroll up { run = false; } else if ((event.button.button == SDL_BUTTON_LEFT) || (event.button.button == SDL_BUTTON_RIGHT)) // scroll up { start_time = clock(); click(renderer, event.button.x, event.button.y); end_time = clock(); SDL_RenderPresent(renderer); clock_t t = end_time - start_time; SDL_Log("No. of clicks %ld clicks (%f seconds) to process the incoming click.\n", t, ((float)t) / CLOCKS_PER_SEC); } else { /* Do nothing. */ } } else if (event.type == SDL_QUIT) { run = false; } else if (event.type == SDL_WINDOWEVENT) { switch (event.window.event) { case SDL_WINDOWEVENT_ENTER: case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_RESTORED: redraw = true; break; case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_MAXIMIZED: redraw = true; SDL_GetWindowSize(win, &destR.w, &destR.h); chess_board_resize(renderer, destR.w, destR.h); break; } } else { /* Do nothing. */ } } if (redraw) { start_time = clock(); draw_board(renderer); end_time = clock(); SDL_RenderPresent(renderer); clock_t t = end_time - start_time; SDL_Log("No. of clicks %ld clicks (%f seconds).\n", t, ((float)t) / CLOCKS_PER_SEC); } /* do some other stuff here -- draw your app, etc. */ } return 0; } //g++ main.cpp -o blah `sdl2-config --cflags --libs` /* g++ main.cpp -IC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\include\SDL2 -LC:\Users\Daniel\Documents\Projects\i686-w64-mingw32\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o SDLMain */