diff --git a/CMakeLists.txt b/CMakeLists.txt index 628c0c6..6edaaa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,29 @@ -cmake_minimum_required(VERSION 3.24) -project(cppout) +cmake_minimum_required(VERSION 4.0) +project(cppout LANGUAGES CXX) -file(GLOB SOURCE_FILES "*/*.cpp") +file(GLOB SOURCE_FILES "src/*.cpp") -find_package(Curses REQUIRED) -include_directories(${CURSES_INCLUDE_DIR}) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include(FetchContent) +FetchContent_Declare(SFML + GIT_REPOSITORY https://github.com/SFML/SFML.git + GIT_TAG 3.1.0 + GIT_SHALLOW ON + EXCLUDE_FROM_ALL + SYSTEM) +FetchContent_MakeAvailable(SFML) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) +add_custom_command( + TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/assets" + "$/assets" + COMMENT "copying assets to build dir" +) + if(MSVC) target_compile_option(${PROJECT_NAME} PRIVATE /W4) else() @@ -18,4 +34,7 @@ else() ) endif() -target_link_libraries(${PROJECT_NAME} ${CURSES_LIBRARIES}) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) +target_link_libraries(${PROJECT_NAME} PRIVATE SFML::Graphics) + +set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME}) diff --git a/assets/NS-R.ttf b/assets/NS-R.ttf new file mode 100644 index 0000000..f27f4ff Binary files /dev/null and b/assets/NS-R.ttf differ diff --git a/src/sorters.hpp b/src/sorters.hpp new file mode 100644 index 0000000..13aadf8 --- /dev/null +++ b/src/sorters.hpp @@ -0,0 +1,12 @@ +#include +#include + +struct SortingData { + std::string name; + int target; + std::vector data; + + SortingData(std::string name, std::vector data) + : name(name), data(data) {} + +}; diff --git a/src/sortui.cpp b/src/sortui.cpp index 39a672d..de9800c 100644 --- a/src/sortui.cpp +++ b/src/sortui.cpp @@ -1,54 +1,101 @@ - // for now juist CLI, print an arr, then print each it +#include +#include +#include +#include +#include #include #include #include +#include #include #include #include #include + +#include +#include + #include "timer.hpp" +#include "sorters.hpp" -struct SortingData { - std::string name; - int target; - std::vector data; - - SortingData(std::string name, std::vector data) - : name(name), data(data) {} - -}; +using namespace std::chrono; +using namespace std; void displaynumbers(SortingData in_arr) { - for (size_t i = 0; i < in_arr.data.size(); ++i) { - printf("array:%d ", in_arr.data[i]); - } - printf("\n"); + for (size_t i = 0; i < in_arr.data.size(); ++i) { + printf("array:%d ", in_arr.data[i]); + } + printf("\n"); } -void stepbubblesort(std::vector &data, size_t step) { - data[step%data.size()]++; - } +void stepbubblesort(vector &data, size_t step) { + data[step%data.size()]++; +} + +vector dataprovider(){ + return vector {9,8,1,2,7,3,6,4,5}; +} + +void setuptimers(TimerManager &mytimermanager, SortingData &mysd){ + + unique_ptr mytimer = make_unique( + "sort1", 0, + [&mysd](Timer &t) { stepbubblesort(mysd.data, t.triggercounter); }, + milliseconds(1000)); + unique_ptr mydisplaytimer = make_unique("display", 0, + [&mysd](Timer &t){displaynumbers(mysd);}, + milliseconds(1000)); + mytimermanager.add_timer(move(mytimer)); + mytimermanager.add_timer(move(mydisplaytimer)); +} + +struct App{ + sf::RenderWindow mywindow; + sf::Font myfont; + sf::Text text; + TimerManager mytimermanager; + SortingData mysortdata; + + sf::Font load_font(const string &filename) { + sf::Font font; + if (!font.openFromFile(filename)){ + fprintf(stderr, "failed to load font"); + std::exit(1); + } + return font; + } + + App():mywindow(sf::VideoMode({800,600}), "mywindow"), + myfont(load_font("assets/NS-R.ttf")), + text(myfont), + mysortdata("arr1", dataprovider()) { + text.setFont(myfont); + text.setString("Hello world"); + text.setCharacterSize(24); + text.setFillColor(sf::Color::Red); + + setuptimers(mytimermanager, mysortdata); + + } + + void run(){ + while (mywindow.isOpen()){ + while (const optional event = mywindow.pollEvent()){ + if (event->is()) + mywindow.close(); + } + + mywindow.clear(sf::Color::Black); + mywindow.draw(text); + mytimermanager.update_timers(); + mywindow.display(); + this_thread::sleep_for(milliseconds(1000)); + } + } +}; int main() { - - std::vector dummydata = {9,8,1,2,7,3,6,4,5}; - SortingData mysd("arr1", dummydata); - std::unique_ptr mytimer = std::make_unique( - "sort1", 0, - [&mysd](Timer &t) { stepbubblesort(mysd.data, t.triggercounter); }, - std::chrono::milliseconds(1000)); - std::unique_ptr mydisplaytimer = std::make_unique("display", 0, [&mysd](Timer &t){displaynumbers(mysd);}, std::chrono::milliseconds(1000)); - - TimerManager mytimermanager; - - - mytimermanager.add_timer(std::move(mytimer)); - mytimermanager.add_timer(std::move(mydisplaytimer)); - - - while (true) { - mytimermanager.update_timers(); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - }; + App myapp; + myapp.run(); }