-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#include "app_handlers.hpp" | ||
|
||
#include "python_object.hpp" | ||
#include "exec.hpp" | ||
#include "script.hpp" | ||
|
||
#include "scene.hpp" | ||
|
||
#include <fmt/core.h> | ||
|
||
namespace bxx::app::handlers | ||
{ | ||
void register_handler(std::string const& target, std::function<void(bxx::python_tuple const&)> func) | ||
{ | ||
// todo: for some bizarre reason this stops working if i don't pass all varargs python-side, | ||
// but everything is still in the first tuple once it reaches C++ | ||
size_t event_idx = lib_register_event([=](bxx::python_tuple const& tuple) { | ||
func(tuple.get<python_tuple>(0)); | ||
return bxx::python_object(); | ||
}); | ||
exec({ | ||
fmt::format("@bpy.app.handlers.persistent"), | ||
fmt::format("def event_{}_{}(*args):",get_script_index(),event_idx), | ||
fmt::format(" fire_event({},{}, args)",get_script_index(),event_idx), | ||
fmt::format("register_app_handler({}, bpy.app.handlers.{}, event_{}_{})", get_script_index(), target, get_script_index(), event_idx, target) | ||
}); | ||
} | ||
|
||
void depsgraph_update_pre(std::function<void(scene)> callback) | ||
{ | ||
register_handler("depsgraph_update_pre", [=](python_tuple const& tup) { | ||
callback(tup.get<python_object>(0)); | ||
}); | ||
} | ||
|
||
void depsgraph_update_post(std::function<void(scene, python_object)> callback) | ||
{ | ||
register_handler("depsgraph_update_post", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0), tup.get<python_object>(1)); | ||
}); | ||
} | ||
void frame_change_pre(std::function<void(scene)> callback) | ||
{ | ||
register_handler("frame_change_pre", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void frame_change_post(std::function<void(scene, python_object)> callback) | ||
{ | ||
register_handler("frame_change_post", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0), tup.get<python_object>(1)); | ||
}); | ||
} | ||
|
||
void load_factory_preferences_post(std::function<void()> callback) | ||
{ | ||
register_handler("load_factory_preferences_post", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void load_factory_startup_post(std::function<void()> callback) | ||
{ | ||
register_handler("load_factory_startup_post", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void load_post(std::function<void()> callback) | ||
{ | ||
register_handler("load_post", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void load_pre(std::function<void()> callback) | ||
{ | ||
register_handler("load_pre", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void redo_pre(std::function<void(scene)> callback) | ||
{ | ||
register_handler("redo_pre", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void redo_post(std::function<void(scene)> callback) | ||
{ | ||
register_handler("redo_post", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void render_cancel(std::function<void()> callback) | ||
{ | ||
register_handler("render_cancel", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void render_complete(std::function<void(scene)> callback) | ||
{ | ||
register_handler("render_complete", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void render_init(std::function<void()> callback) | ||
{ | ||
register_handler("render_init", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void render_post(std::function<void(scene)> callback) | ||
{ | ||
register_handler("render_post", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void render_pre(std::function<void(scene)> callback) | ||
{ | ||
register_handler("render_pre", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void render_stats(std::function<void()> callback) | ||
{ | ||
register_handler("render_stats", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void render_write(std::function<void()> callback) | ||
{ | ||
register_handler("render_write", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void save_post(std::function<void()> callback) | ||
{ | ||
register_handler("save_post", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void save_pre(std::function<void()> callback) | ||
{ | ||
register_handler("save_pre", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
void undo_post(std::function<void(scene)> callback) | ||
{ | ||
register_handler("undo_post", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void undo_pre(std::function<void(scene)> callback) | ||
{ | ||
register_handler("undo_pre", [=](python_tuple const& tup) { | ||
callback(tup.get<scene>(0)); | ||
}); | ||
} | ||
void version_update(std::function<void()> callback) | ||
{ | ||
register_handler("version_update", [=](python_tuple const& tup) { | ||
callback(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include <functional> | ||
|
||
namespace bxx | ||
{ | ||
class python_object; | ||
class python_tuple; | ||
class scene; | ||
namespace app::handlers | ||
{ | ||
void depsgraph_update_pre(std::function<void(scene)> callback); | ||
void depsgraph_update_post(std::function<void(scene, python_object)> callback); | ||
void frame_change_pre(std::function<void(scene)> callback); | ||
void frame_change_post(std::function<void(scene, python_object)> callback); | ||
void load_factory_preferences_post(std::function<void()> callback); | ||
void load_factory_startup_post(std::function<void()> callback); | ||
void load_post(std::function<void()> callback); | ||
void load_pre(std::function<void()> callback); | ||
void redo_pre(std::function<void(scene)> callback); | ||
void redo_post(std::function<void(scene)> callback); | ||
// todo: unknown arguments | ||
void render_cancel(std::function<void()> callback); | ||
void render_complete(std::function<void(scene)> callback); | ||
// todo: unknown arguments | ||
void render_init(std::function<void()> callback); | ||
void render_post(std::function<void(scene)> callback); | ||
void render_pre(std::function<void(scene)> callback); | ||
// todo: unknown arguments | ||
void render_stats(std::function<void()> callback); | ||
// todo: unknown arguments | ||
void render_write(std::function<void()> callback); | ||
void save_post(std::function<void()> callback); | ||
void save_pre(std::function<void()> callback); | ||
void undo_post(std::function<void(scene)> callback); | ||
void undo_pre(std::function<void(scene)> callback); | ||
void version_update(std::function<void()> callback); | ||
void register_handler(std::string const& target, std::function<void(python_tuple const&)> callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters