From 02b119e206a043dce19315b9412e2fe9e0d3e6f7 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 1 Nov 2021 11:14:01 -0400 Subject: [PATCH] Add bindings for convenience color functions --- src/python/magnum/math.vector.h | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/python/magnum/math.vector.h b/src/python/magnum/math.vector.h index a21b4d8..08bf40e 100644 --- a/src/python/magnum/math.vector.h +++ b/src/python/magnum/math.vector.h @@ -544,7 +544,15 @@ template void color3(py::class_, Math::Vector3>& c) return Degd(self.hue()); }, "Hue") .def("saturation", &Math::Color3::saturation, "Saturation") - .def("value", &Math::Color3::value, "Value"); + .def("value", &Math::Color3::value, "Value") + + /* Color Convenience */ + .def_static("red", &Math::Color3::red, py::arg("red") = Math::Implementation::fullChannel()) + .def_static("green", &Math::Color3::green, py::arg("green") = Math::Implementation::fullChannel()) + .def_static("blue", &Math::Color3::blue, py::arg("blue") = Math::Implementation::fullChannel()) + .def_static("cyan", &Math::Color3::cyan, py::arg("red") = T(0)) + .def_static("magenta", &Math::Color3::magenta, py::arg("green") = T(0)) + .def_static("yellow", &Math::Color3::yellow, py::arg("yellow") = T(0)); } /* Needs to be separate to make it a priority over buffer protocol */ @@ -604,7 +612,27 @@ template void color4(py::class_, Math::Vector4>& c) .def_property("rgb", static_cast(Math::Color4::*)() const>(&Math::Color4::rgb), [](Math::Color4& self, const Math::Color3& value) { self.rgb() = value; }, - "RGB part of the vector"); + "RGB part of the vector") + + /* Color Convenience */ + .def_static("red", &Math::Color4::red, + py::arg("red") = Math::Implementation::fullChannel(), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("green", &Math::Color4::green, + py::arg("green") = Math::Implementation::fullChannel(), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("blue", &Math::Color4::blue, + py::arg("blue") = Math::Implementation::fullChannel(), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("cyan", &Math::Color4::cyan, + py::arg("red") = T(0), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("magenta", &Math::Color4::magenta, + py::arg("green") = T(0), + py::arg("alpha") = Math::Implementation::fullChannel()) + .def_static("yellow", &Math::Color4::yellow, + py::arg("yellow") = T(0), + py::arg("alpha") = Math::Implementation::fullChannel()); } }