diff --git a/CMakeLists.txt b/CMakeLists.txt index 201e538..dcb0eb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,10 +65,12 @@ add_executable( fc2d src/tomlcpp.cpp src/error.cpp src/eye.cpp + src/configfile.cpp ) target_link_libraries( fc2d ${OpenCV_LIBS} ${OPENGL_LIBRARIES} ${WEBP_LIBRARIES} FreeGLUT::freeglut GLEW::glew zip Boxer fmt ) add_executable( fc2dconfig src/fc2dconfig.cpp + src/paths.cpp ) target_link_libraries( fc2dconfig ${wxWidgets_LIBRARIES} ) diff --git a/src/configfile.cpp b/src/configfile.cpp new file mode 100644 index 0000000..9e95d3c --- /dev/null +++ b/src/configfile.cpp @@ -0,0 +1,25 @@ +#include +#include + +#include +#include +#include +#include + +bool configFileOpen(struct optData* data) { + auto configFile = toml::parseFile(prefixCustom + "config.toml"); + if (!configFile.table) { + return false; + } + + auto useHaarResult = configFile.table->getBool("use_haar"); + if (useHaarResult.first) { + data->useHaar = useHaarResult.second; + } + auto modelNameResult = configFile.table->getString("model"); + if (modelNameResult.first) { + data->model = modelNameResult.second; + } + + return true; +} diff --git a/src/configfile.hpp b/src/configfile.hpp new file mode 100644 index 0000000..3dd9fd9 --- /dev/null +++ b/src/configfile.hpp @@ -0,0 +1,8 @@ +#ifndef CONFIGFILE_HPP +#define CONFIGFILE_HPP + +#include + +bool configFileOpen(struct optData* optData); + +#endif diff --git a/src/fc2dconfig.cpp b/src/fc2dconfig.cpp index f9711df..c3ad3ab 100644 --- a/src/fc2dconfig.cpp +++ b/src/fc2dconfig.cpp @@ -1,4 +1,8 @@ +#include + #include +#include +#include #include #ifndef WX_PRECOMP @@ -14,13 +18,18 @@ class ConfigurationFrame : public wxFrame { public: ConfigurationFrame(); private: + wxCheckBox* useHaarCheckBox; + wxTextCtrl* modelNameText; void OnExit(wxCommandEvent& event); }; wxIMPLEMENT_APP(ConfigurationApp); bool ConfigurationApp::OnInit() { + initPrefixes(); + // TODO: put config file creation here + ConfigurationFrame* frame = new ConfigurationFrame(); frame->Show(true); return true; @@ -29,11 +38,18 @@ bool ConfigurationApp::OnInit() { ConfigurationFrame::ConfigurationFrame() : wxFrame(NULL, wxID_ANY, "Configure " PROJECT_NAME) { wxPanel* panel = new wxPanel(this, wxID_ANY); + // TODO: load config file and populate values wxStaticText* placeholderText = new wxStaticText(panel, wxID_ANY, "There's nothing here right now, just click OK."); + useHaarCheckBox = new wxCheckBox(panel, wxID_ANY, "Disable DNN face detection"); + // TODO: make this a dropdown with the detected model files + modelNameText = new wxTextCtrl(panel, wxID_ANY, "test"); + // TODO: cancel button to exit without saving settings wxButton* okButton = new wxButton(panel, wxID_OK, "OK"); wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(placeholderText, 0, wxALL | wxALIGN_LEFT, 10); + sizer->Add(useHaarCheckBox, 0, wxALL | wxALIGN_LEFT, 5); + sizer->Add(modelNameText, 0, wxALL | wxALIGN_LEFT, 5); sizer->AddStretchSpacer(1); sizer->Add(okButton, 0, wxALIGN_RIGHT | wxALL, 10); @@ -43,6 +59,12 @@ ConfigurationFrame::ConfigurationFrame() : wxFrame(NULL, wxID_ANY, "Configure " } void ConfigurationFrame::OnExit(wxCommandEvent& event) { - // TODO: write config file here + // write options to config file + std::ofstream configFile; + configFile.open(prefixCustom + "config.toml"); + configFile << "use_haar = " << (useHaarCheckBox->GetValue() ? "true" : "false") << std::endl; + configFile << "model = \"" << modelNameText->GetValue() << "\""<< std::endl; + configFile.close(); + Close(true); } diff --git a/src/main.cpp b/src/main.cpp index bdf7b58..24579c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,18 +4,25 @@ #include #include #include +#include #include #include int main (int argc, char** argv) { -#ifndef _WIN32 - argp_parse(&argp, argc, argv, 0, 0, 0); -#endif - std::cout << PROJECT_NAME " is starting..." << std::endl; initPrefixes(); + + // load config file and apply it + configFileOpen(&optData); + +#ifndef _WIN32 + // parse arguments and apply them + argp_parse(&argp, argc, argv, 0, 0, 0); +#endif + + std::cout << "Custom asset prefix: " << prefixCustom << std::endl; std::cout << "Default asset prefix: " << prefixDefault << std::endl;