Skip to content

Commit

Permalink
[Script/LuaOverlay] Separated the Overlay's widget bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Razakhel committed Dec 4, 2023
1 parent 8c9aa31 commit c73022e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 79 deletions.
3 changes: 2 additions & 1 deletion include/RaZ/Script/LuaWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class LuaWrapper {
static void registerMatrixTypes();
static void registerMeshTypes();
static void registerMeshRendererTypes();
static void registerOverlayTypes();
static void registerOverlayBaseTypes();
static void registerOverlayWidgetTypes();
static void registerPhysicsTypes();
static void registerRenderTypes();
static void registerRenderGraphTypes();
Expand Down
93 changes: 93 additions & 0 deletions src/RaZ/Script/LuaOverlayBase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "RaZ/Render/Overlay.hpp"
#include "RaZ/Render/Texture.hpp"
#include "RaZ/Script/LuaWrapper.hpp"
#include "RaZ/Utils/TypeUtils.hpp"

#define SOL_ALL_SAFETIES_ON 1
#include "sol/sol.hpp"

namespace Raz {

using namespace TypeUtils;

void LuaWrapper::registerOverlayBaseTypes() {
sol::state& state = getState();

{
sol::usertype<Overlay> overlay = state.new_usertype<Overlay>("Overlay",
sol::constructors<Overlay()>());
overlay["isEmpty"] = &Overlay::isEmpty;
overlay["addWindow"] = sol::overload([] (Overlay& o, std::string t) { return &o.addWindow(std::move(t)); },
[] (Overlay& o, std::string t, const Vec2f& s) { return &o.addWindow(std::move(t), s); },
PickOverload<std::string, const Vec2f&, const Vec2f&>(&Overlay::addWindow));
overlay["hasKeyboardFocus"] = &Overlay::hasKeyboardFocus;
overlay["hasMouseFocus"] = &Overlay::hasMouseFocus;
overlay["render"] = &Overlay::render;
}

{
sol::usertype<OverlayWindow> overlayWindow = state.new_usertype<OverlayWindow>("OverlayWindow",
sol::constructors<OverlayWindow(std::string),
OverlayWindow(std::string, const Vec2f&),
OverlayWindow(std::string, const Vec2f&, const Vec2f&)>());
overlayWindow["isEnabled"] = &OverlayWindow::isEnabled;
overlayWindow["enable"] = sol::overload([] (OverlayWindow& r) { r.enable(); },
PickOverload<bool>(&OverlayWindow::enable));
overlayWindow["disable"] = &OverlayWindow::disable;
overlayWindow["addLabel"] = &OverlayWindow::addLabel;
overlayWindow["addColoredLabel"] = sol::overload([] (OverlayWindow& w, std::string t, const Color& c) { return &w.addColoredLabel(std::move(t), c); },
PickOverload<std::string, const Color&, float>(&OverlayWindow::addColoredLabel),
[] (OverlayWindow& w, std::string t,
float r, float g, float b) { return &w.addColoredLabel(std::move(t), r, g, b); },
PickOverload<std::string, float, float, float, float>(&OverlayWindow::addColoredLabel));
overlayWindow["addButton"] = &OverlayWindow::addButton;
overlayWindow["addCheckbox"] = &OverlayWindow::addCheckbox;
overlayWindow["addSlider"] = &OverlayWindow::addSlider;
overlayWindow["addTextbox"] = sol::overload([] (OverlayWindow& w, std::string l,
std::function<void(const std::string&)> c) { return &w.addTextbox(std::move(l),
std::move(c)); },
PickOverload<std::string, std::function<void(const std::string&)>,
std::string>(&OverlayWindow::addTextbox));
overlayWindow["addTextArea"] = sol::overload([] (OverlayWindow& w, std::string l,
std::function<void(const std::string&)> c) { return &w.addTextArea(std::move(l), std::move(c)); },
[] (OverlayWindow& w, std::string l, std::function<void(const std::string&)> c,
std::string t) { return &w.addTextArea(std::move(l), std::move(c), std::move(t)); },
PickOverload<std::string, std::function<void(const std::string&)>,
std::string, float>(&OverlayWindow::addTextArea));
overlayWindow["addListBox"] = sol::overload([] (OverlayWindow& w, std::string l, std::vector<std::string> e,
std::function<void(const std::string&, std::size_t)> c) { return &w.addListBox(std::move(l),
std::move(e),
std::move(c)); },
PickOverload<std::string, std::vector<std::string>, std::function<void(const std::string&, std::size_t)>,
std::size_t>(&OverlayWindow::addListBox));
overlayWindow["addDropdown"] = sol::overload([] (OverlayWindow& w, std::string l, std::vector<std::string> e,
std::function<void(const std::string&, std::size_t)> c) { return &w.addDropdown(std::move(l),
std::move(e),
std::move(c)); },
PickOverload<std::string, std::vector<std::string>, std::function<void(const std::string&, std::size_t)>,
std::size_t>(&OverlayWindow::addDropdown));
overlayWindow["addTexture"] = sol::overload(PickOverload<const Texture2D&, unsigned int, unsigned int>(&OverlayWindow::addTexture),
PickOverload<const Texture2D&>(&OverlayWindow::addTexture));
overlayWindow["addProgressBar"] = sol::overload([] (OverlayWindow& w, int min, int max) { return &w.addProgressBar(min, max); },
PickOverload<int, int, bool>(&OverlayWindow::addProgressBar));
overlayWindow["addPlot"] = sol::overload([] (OverlayWindow& w, std::string l, std::size_t c) { return &w.addPlot(std::move(l), c); },
[] (OverlayWindow& w, std::string l, std::size_t c,
std::string x) { return &w.addPlot(std::move(l), c, std::move(x)); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x,
std::string y) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y)); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x, std::string y,
float min) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y), min); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x, std::string y, float min,
float max) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y), min, max); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x, std::string y, float min, float max,
bool lock) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y), min, max, lock); },
PickOverload<std::string, std::size_t, std::string, std::string,
float, float, bool, float>(&OverlayWindow::addPlot));
overlayWindow["addSeparator"] = &OverlayWindow::addSeparator;
overlayWindow["addFrameTime"] = &OverlayWindow::addFrameTime;
overlayWindow["addFpsCounter"] = &OverlayWindow::addFpsCounter;
overlayWindow["render"] = &OverlayWindow::render;
}
}

} // namespace Raz
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ namespace Raz {

using namespace TypeUtils;

void LuaWrapper::registerOverlayTypes() {
void LuaWrapper::registerOverlayWidgetTypes() {
sol::state& state = getState();

{
sol::usertype<Overlay> overlay = state.new_usertype<Overlay>("Overlay",
sol::constructors<Overlay()>());
overlay["isEmpty"] = &Overlay::isEmpty;
overlay["addWindow"] = sol::overload([] (Overlay& o, std::string t) { return &o.addWindow(std::move(t)); },
[] (Overlay& o, std::string t, const Vec2f& s) { return &o.addWindow(std::move(t), s); },
PickOverload<std::string, const Vec2f&, const Vec2f&>(&Overlay::addWindow));
overlay["hasKeyboardFocus"] = &Overlay::hasKeyboardFocus;
overlay["hasMouseFocus"] = &Overlay::hasMouseFocus;
overlay["render"] = &Overlay::render;
}

{
state.new_usertype<OverlayButton>("OverlayButton",
sol::constructors<OverlayButton(std::string, std::function<void()>)>(),
Expand Down Expand Up @@ -195,70 +183,6 @@ void LuaWrapper::registerOverlayTypes() {
PickOverload<const Texture2D&>(&OverlayTexture::setTexture));
}

{
sol::usertype<OverlayWindow> overlayWindow = state.new_usertype<OverlayWindow>("OverlayWindow",
sol::constructors<OverlayWindow(std::string),
OverlayWindow(std::string, const Vec2f&),
OverlayWindow(std::string, const Vec2f&, const Vec2f&)>());
overlayWindow["isEnabled"] = &OverlayWindow::isEnabled;
overlayWindow["enable"] = sol::overload([] (OverlayWindow& r) { r.enable(); },
PickOverload<bool>(&OverlayWindow::enable));
overlayWindow["disable"] = &OverlayWindow::disable;
overlayWindow["addLabel"] = &OverlayWindow::addLabel;
overlayWindow["addColoredLabel"] = sol::overload([] (OverlayWindow& w, std::string t, const Color& c) { return &w.addColoredLabel(std::move(t), c); },
PickOverload<std::string, const Color&, float>(&OverlayWindow::addColoredLabel),
[] (OverlayWindow& w, std::string t,
float r, float g, float b) { return &w.addColoredLabel(std::move(t), r, g, b); },
PickOverload<std::string, float, float, float, float>(&OverlayWindow::addColoredLabel));
overlayWindow["addButton"] = &OverlayWindow::addButton;
overlayWindow["addCheckbox"] = &OverlayWindow::addCheckbox;
overlayWindow["addSlider"] = &OverlayWindow::addSlider;
overlayWindow["addTextbox"] = sol::overload([] (OverlayWindow& w, std::string l,
std::function<void(const std::string&)> c) { return &w.addTextbox(std::move(l),
std::move(c)); },
PickOverload<std::string, std::function<void(const std::string&)>,
std::string>(&OverlayWindow::addTextbox));
overlayWindow["addTextArea"] = sol::overload([] (OverlayWindow& w, std::string l,
std::function<void(const std::string&)> c) { return &w.addTextArea(std::move(l), std::move(c)); },
[] (OverlayWindow& w, std::string l, std::function<void(const std::string&)> c,
std::string t) { return &w.addTextArea(std::move(l), std::move(c), std::move(t)); },
PickOverload<std::string, std::function<void(const std::string&)>,
std::string, float>(&OverlayWindow::addTextArea));
overlayWindow["addListBox"] = sol::overload([] (OverlayWindow& w, std::string l, std::vector<std::string> e,
std::function<void(const std::string&, std::size_t)> c) { return &w.addListBox(std::move(l),
std::move(e),
std::move(c)); },
PickOverload<std::string, std::vector<std::string>, std::function<void(const std::string&, std::size_t)>,
std::size_t>(&OverlayWindow::addListBox));
overlayWindow["addDropdown"] = sol::overload([] (OverlayWindow& w, std::string l, std::vector<std::string> e,
std::function<void(const std::string&, std::size_t)> c) { return &w.addDropdown(std::move(l),
std::move(e),
std::move(c)); },
PickOverload<std::string, std::vector<std::string>, std::function<void(const std::string&, std::size_t)>,
std::size_t>(&OverlayWindow::addDropdown));
overlayWindow["addTexture"] = sol::overload(PickOverload<const Texture2D&, unsigned int, unsigned int>(&OverlayWindow::addTexture),
PickOverload<const Texture2D&>(&OverlayWindow::addTexture));
overlayWindow["addProgressBar"] = sol::overload([] (OverlayWindow& w, int min, int max) { return &w.addProgressBar(min, max); },
PickOverload<int, int, bool>(&OverlayWindow::addProgressBar));
overlayWindow["addPlot"] = sol::overload([] (OverlayWindow& w, std::string l, std::size_t c) { return &w.addPlot(std::move(l), c); },
[] (OverlayWindow& w, std::string l, std::size_t c,
std::string x) { return &w.addPlot(std::move(l), c, std::move(x)); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x,
std::string y) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y)); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x, std::string y,
float min) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y), min); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x, std::string y, float min,
float max) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y), min, max); },
[] (OverlayWindow& w, std::string l, std::size_t c, std::string x, std::string y, float min, float max,
bool lock) { return &w.addPlot(std::move(l), c, std::move(x), std::move(y), min, max, lock); },
PickOverload<std::string, std::size_t, std::string, std::string,
float, float, bool, float>(&OverlayWindow::addPlot));
overlayWindow["addSeparator"] = &OverlayWindow::addSeparator;
overlayWindow["addFrameTime"] = &OverlayWindow::addFrameTime;
overlayWindow["addFpsCounter"] = &OverlayWindow::addFpsCounter;
overlayWindow["render"] = &OverlayWindow::render;
}

state.new_enum<OverlayElementType>("OverlayElementType", {
{ "LABEL", OverlayElementType::LABEL },
{ "COLORED_LABEL", OverlayElementType::COLORED_LABEL },
Expand Down
3 changes: 2 additions & 1 deletion src/RaZ/Script/LuaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void LuaWrapper::registerTypes() {
registerMeshTypes();
registerMeshRendererTypes();
#if !defined(RAZ_NO_OVERLAY)
registerOverlayTypes();
registerOverlayBaseTypes();
registerOverlayWidgetTypes();
#endif
registerPhysicsTypes();
registerRenderTypes();
Expand Down

0 comments on commit c73022e

Please sign in to comment.