diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e3e125..f0a30a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,15 @@ set_target_properties(versioned_map PROPERTIES LINKER_LANGUAGE C) include(CTest) +option(BUILD_TREE_VIS "Build tree visualization" OFF) +if(BUILD_TREE_VIS) + find_package(SDL2 REQUIRED) + find_package(SDL2_ttf REQUIRED) + add_executable(tree_vis TreeVis.cpp) + target_link_libraries(tree_vis PRIVATE SDL2::SDL2) + target_link_libraries(tree_vis PRIVATE SDL2_ttf::SDL2_ttf) +endif() + if(BUILD_TESTING) add_executable(rootset_test RootSet.cpp) target_compile_definitions(rootset_test PRIVATE ENABLE_ROOTSET_TESTS) diff --git a/TreeVis.cpp b/TreeVis.cpp new file mode 100644 index 0000000..c0be9c8 --- /dev/null +++ b/TreeVis.cpp @@ -0,0 +1,53 @@ +#include +#include + +int main(int argc, char *argv[]) { + SDL_Init(SDL_INIT_VIDEO); + + TTF_Init(); + + SDL_Window *window = + SDL_CreateWindow("Hello World", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED | SDL_WINDOW_ALLOW_HIGHDPI, 1920, + 1080, SDL_WINDOW_SHOWN); + + SDL_Renderer *renderer = + SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + + TTF_Font *font = + TTF_OpenFont("../third_party/scientifica/ttf/scientifica.ttf", 72); + + bool running = true; + while (running) { + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + running = false; + } + } + + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + + auto *surface = TTF_RenderUTF8_Solid(font, "Hello World", {0, 255, 0}); + SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_Rect dst = {0, 0, 0, 0}; + SDL_QueryTexture(texture, NULL, NULL, &dst.w, &dst.h); + SDL_RenderCopy(renderer, texture, NULL, &dst); + + SDL_DestroyTexture(texture); + SDL_FreeSurface(surface); + + SDL_RenderPresent(renderer); + } + + TTF_CloseFont(font); + + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + + TTF_Quit(); + SDL_Quit(); + + return 0; +} diff --git a/third_party/scientifica/ttf/scientifica.ttf b/third_party/scientifica/ttf/scientifica.ttf new file mode 100644 index 0000000..1753d31 Binary files /dev/null and b/third_party/scientifica/ttf/scientifica.ttf differ diff --git a/third_party/scientifica/ttf/scientificaBold.ttf b/third_party/scientifica/ttf/scientificaBold.ttf new file mode 100644 index 0000000..0cd01a7 Binary files /dev/null and b/third_party/scientifica/ttf/scientificaBold.ttf differ diff --git a/third_party/scientifica/ttf/scientificaItalic.ttf b/third_party/scientifica/ttf/scientificaItalic.ttf new file mode 100644 index 0000000..ef29a47 Binary files /dev/null and b/third_party/scientifica/ttf/scientificaItalic.ttf differ