Skip to content

Commit

Permalink
Simplify API: merge run() and startUp()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Apr 16, 2024
1 parent d2dd328 commit 64a705a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/Editor/PetriEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ Editor::Editor(size_t const width, size_t const height,
m_path(GET_DATA_PATH),
m_simulation(m_net, m_messages),
m_view(*this)
{
m_states.title = title;
}

//------------------------------------------------------------------------------
void Editor::startUp(std::string const& filepath)
{
#ifdef __EMSCRIPTEN__
# define FONT_SIZE 18.0f
Expand All @@ -55,6 +49,8 @@ void Editor::startUp(std::string const& filepath)

std::cout << "Path: " << m_path.toString() << std::endl;

m_states.title = title;

// Set imgui.ini loading/saving location
ImGuiIO &io = ImGui::GetIO();
g_ini_filename = m_path.expand("imgui.ini").c_str();
Expand All @@ -64,7 +60,11 @@ void Editor::startUp(std::string const& filepath)
// Setup fonts
io.Fonts->AddFontFromFileTTF(m_path.expand("font.ttf").c_str(), FONT_SIZE);
reloadFonts();
}

//------------------------------------------------------------------------------
void Editor::run(std::string const& filepath)
{
// Load Petri net file if passed with command line
if (!filepath.empty())
{
Expand All @@ -79,6 +79,9 @@ void Editor::startUp(std::string const& filepath)
m_messages.setError(m_net.error());
}
}

// Start the infinite loop
Application::run();
}

//------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions src/Editor/PetriEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ class Editor: public Application
Editor(size_t const width, size_t const height, std::string const& title);

//-------------------------------------------------------------------------
//! \brief starts up the Petri net editor and call the infinite loop.
//! \param[in] petri_file the path of the Petri net fil to load. Let it
//! dummy if you do not want to open a file.
//! \brief Starts the Petri net editor up, load the Petri file if given not
//! empty. Then call the infinite loop of the GUI.
//! \param[in] petri_file the path of the Petri net fil to load. Pass dummy
//! string if you do not want to load a Petri net file.
//-------------------------------------------------------------------------
void startUp(std::string const& petri_file);
void run(std::string const& petri_file);

private: // Inheritance from Application class

Expand Down
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ int main(int argc, char* argv[])
}

tpne::Editor editor(1024, 768, "Petri Net Editor");
editor.startUp(filename);
editor.run();
editor.run(filename);
}

0 comments on commit 64a705a

Please sign in to comment.