Skip to content

Commit

Permalink
Add screenshot while raylib code is currently buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
Lecrapouille committed Nov 12, 2023
1 parent 5bc7828 commit ca5e27c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 21 deletions.
9 changes: 1 addition & 8 deletions external/compile-external-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,4 @@ print-compile raylib
else
call-make PLATFORM=PLATFORM_WEB RAYLIB_RELEASE_PATH=$ARCHI
fi
)

#rm -fr build usr 2> /dev/null
#mkdir -p build
#cd build
#call-cmake -DPLATFORM=Web -DBUILD_SHARED_LIBS=OFF -DBUILD_EXAMPLES=OFF ..
#call-make
#call-make install DESTDIR=.
)
14 changes: 14 additions & 0 deletions src/Editor/Backends/GLFW3/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,22 @@ class Application

Application(size_t const width, size_t const height, std::string const& title);
virtual ~Application();

//--------------------------------------------------------------------------
//! \brief Start a blocking loop for managing its draw and IO events.
//--------------------------------------------------------------------------
void run();

//--------------------------------------------------------------------------
//! \brief Limit the framerate to a maximum fixed frequency.
//--------------------------------------------------------------------------
void framerate(size_t const framerate);

//--------------------------------------------------------------------------
//! \brief Take a screenshot of the game and save it as PNG to the given path.
//--------------------------------------------------------------------------
bool screenshot(std::string const& screenshot_path);

private:

virtual void onStartUp() = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/Editor/Backends/RayLib/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,15 @@ void Application::run()
}

//------------------------------------------------------------------------------
void Application::setFramerate(size_t const framerate)
void Application::framerate(size_t const framerate)
{
m_framerate = framerate;
SetTargetFPS(m_framerate);
}

//------------------------------------------------------------------------------
bool Application::screenshot(std::string const& screenshot_path)
{
TakeScreenshot(screenshot_path.c_str());
return true; // FIXME always ?
}
15 changes: 14 additions & 1 deletion src/Editor/Backends/RayLib/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,21 @@ class Application

Application(size_t const width, size_t const height, std::string const& title);
virtual ~Application();

//--------------------------------------------------------------------------
//! \brief Start a blocking loop for managing its draw and IO events.
//--------------------------------------------------------------------------
void run();
void setFramerate(size_t const framerate);

//--------------------------------------------------------------------------
//! \brief Limit the framerate to a maximum fixed frequency.
//--------------------------------------------------------------------------
void framerate(size_t const framerate);

//--------------------------------------------------------------------------
//! \brief Take a screenshot of the game and save it as PNG to the given path.
//--------------------------------------------------------------------------
bool screenshot(std::string const& screenshot_path);

private:

Expand Down
44 changes: 39 additions & 5 deletions src/Editor/PetriEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static bool do_syslin = false;
static bool do_adjency = false;
static bool do_load = false;
static bool do_save_as = false;
static bool do_screenshot = false;
static Exporter const* do_export_to = nullptr;
static bool show_about = false;
static bool show_help = false;
Expand Down Expand Up @@ -413,7 +414,9 @@ static void menu(Editor& editor)
editor.m_layout_config.grid.enable ^= true;
}
if (ImGui::MenuItem("Take screenshot", nullptr, false))
{}//editor.screenshot();
{
do_screenshot = true;
}
ImGui::Separator();
//if (ImGui::MenuItem("Run", nullptr, false)) TODO
// editor.run();
Expand Down Expand Up @@ -469,6 +472,7 @@ static void menu(Editor& editor)
if (do_load) { editor.load(); }
if (do_save_as) { editor.saveAs(); }
if (do_export_to != nullptr) { editor.exportTo(*do_export_to); }
if (do_screenshot) { editor.screenshot(); }

ImVec2 center = ImGui::GetMainViewport()->GetCenter();

Expand Down Expand Up @@ -1132,11 +1136,11 @@ void Editor::exportTo(Exporter const& exporter)
{
if (ImGuiFileDialog::Instance()->IsOk())
{
std::string error = exporter.exportFct(m_net, ImGuiFileDialog::Instance()->GetFilePathName());
auto const path = ImGuiFileDialog::Instance()->GetFilePathName();
std::string error = exporter.exportFct(m_net, path);
if (error.empty())
{
m_messages.setInfo("saved with success " +
ImGuiFileDialog::Instance()->GetFilePathName());
m_messages.setInfo("saved with success '" + path + "'");
}
else
{
Expand All @@ -1158,6 +1162,36 @@ void Editor::saveAs()
exportTo(exporter);
}

//------------------------------------------------------------------------------
void Editor::screenshot()
{
ImGuiFileDialog::Instance()->OpenDialog("ChooseFileDlgKey",
"Choose the JPEG file to save the screenshot",
".jpg", ".", 1, nullptr,
ImGuiFileDialogFlags_Modal | ImGuiFileDialogFlags_ConfirmOverwrite);

if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey"))
{
if (ImGuiFileDialog::Instance()->IsOk())
{
auto const path = ImGuiFileDialog::Instance()->GetFilePathName();
std::cout << "ghhghgh\n";
if (Application::screenshot(path))
{
m_messages.setInfo("Screenshot taken as file '" + path + "'");
}
else
{
m_messages.setError("Failed to save screenshot to file '" + path + "'");
}
}

// close.
do_screenshot = false;
ImGuiFileDialog::Instance()->Close();
}
}

//------------------------------------------------------------------------------
void Editor::close()
{
Expand Down Expand Up @@ -1348,7 +1382,7 @@ void Editor::onHandleInput()
// update() producing two AnimatedToken carying 1 token that
// will be displayed at the same position instead of a
// single AnimatedToken carying 2 tokens.
setFramerate(m_simulating ? 30 : 60); // FPS
framerate(m_simulating ? 30 : 60); // FPS
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/Editor/PetriEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ class Editor: public Application
bool IsMouseClicked(ImGuiMouseButton& button, bool& dragging);
bool IsMouseReleased(ImGuiMouseButton& key);

/*
void align();
PetriNet::CriticalCycleResult findCriticalCycle();
bool screenshot();
bool changeTypeOfNet(TypeOfNet const type);
*/
void screenshot();
void clear();

std::string getError() const
Expand Down

0 comments on commit ca5e27c

Please sign in to comment.