From d1704107a585423264def88c85465e88ceb853e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Bergstr=C3=B6m?= <davbe125@student.liu.se>
Date: Mon, 6 Aug 2018 08:39:14 +0200
Subject: [PATCH] Add white as default argument to draw functions

---
 python-api-src/lib_color.cpp     | 22 ++++++++++++++++++++++
 python-api-src/lib_map_tools.cpp | 11 +++++------
 python-api-src/library.cpp       | 17 +----------------
 python-api-src/library.h         |  1 +
 4 files changed, 29 insertions(+), 22 deletions(-)
 create mode 100644 python-api-src/lib_color.cpp

diff --git a/python-api-src/lib_color.cpp b/python-api-src/lib_color.cpp
new file mode 100644
index 000000000..7fa2179b5
--- /dev/null
+++ b/python-api-src/lib_color.cpp
@@ -0,0 +1,22 @@
+#include "library.h"
+
+namespace py = pybind11;
+
+void define_color(py::module & m)
+{
+    py::class_<sc2::Color> color(m, "Color");
+    color.def(py::init<>());
+    color.def(py::init<int, int, int>(), "r"_a, "g"_a, "b"_a);
+    color.def_readwrite("r", &sc2::Color::r, "Red");
+    color.def_readwrite("g", &sc2::Color::g, "Green");
+    color.def_readwrite("b", &sc2::Color::b, "Blue");
+    color.attr("WHITE") = sc2::Colors::White;
+    color.attr("RED") = sc2::Colors::Red;
+    color.attr("GREEN") = sc2::Colors::Green;
+    color.attr("YELLOW") = sc2::Colors::Yellow;
+    color.attr("BLUE") = sc2::Colors::Blue;
+    color.attr("TEAL") = sc2::Colors::Teal;
+    color.attr("PURPLE") = sc2::Colors::Purple;
+    color.attr("BLACK") = sc2::Colors::Black;
+    color.attr("GRAY") = sc2::Colors::Gray;
+}
\ No newline at end of file
diff --git a/python-api-src/lib_map_tools.cpp b/python-api-src/lib_map_tools.cpp
index c89b19fd5..402ea9ebe 100644
--- a/python-api-src/lib_map_tools.cpp
+++ b/python-api-src/lib_map_tools.cpp
@@ -9,12 +9,11 @@ void define_map_tools(py::module & m)
         .def_property_readonly("width", &MapTools::width, "The width of the map")
         .def_property_readonly("height", &MapTools::height, "The height of the map")
         //.def("terrainHeight", &MapTools::terrainHeight, py::const_)
-        .def("draw_line", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawLine, py::const_), py::arg("start"), py::arg("stop"), py::arg("color"))
-        //.def("draw_line", py::overload_cast<CCPositionType, CCPositionType, CCPositionType, CCPositionType, const CCColor &>(&MapTools::drawLine, py::const_)); // TODO: Default argument??
-        .def("draw_box", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawBox, py::const_), py::arg("top_left"), py::arg("bottom_right"), py::arg("color"))
-        .def("draw_circle", py::overload_cast<const CCPosition &, CCPositionType, const CCColor &>(&MapTools::drawCircle, py::const_), py::arg("center"), py::arg("radius"), py::arg("color"))
-        .def("draw_text", &MapTools::drawText, "position"_a, "text"_a, "color"_a)
-        .def("draw_text_screen", &MapTools::drawTextScreen, "percentage_x"_a, "percentage_y"_a, "text"_a, "color"_a);
+        .def("draw_line", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawLine, py::const_), py::arg("start"), py::arg("stop"), py::arg("color") = white)
+        .def("draw_box", py::overload_cast<const CCPosition &, const CCPosition &, const CCColor &>(&MapTools::drawBox, py::const_), py::arg("top_left"), py::arg("bottom_right"), py::arg("color") = white)
+        .def("draw_circle", py::overload_cast<const CCPosition &, CCPositionType, const CCColor &>(&MapTools::drawCircle, py::const_), py::arg("center"), py::arg("radius"), py::arg("color") = white)
+        .def("draw_text", &MapTools::drawText, "position"_a, "text"_a, "color"_a = white)
+        .def("draw_text_screen", &MapTools::drawTextScreen, "percentage_x"_a, "percentage_y"_a, "text"_a, "color"_a = white);
 
         /*
         TODO: Left to implement
diff --git a/python-api-src/library.cpp b/python-api-src/library.cpp
index 05cf271cc..efa1fe9a2 100644
--- a/python-api-src/library.cpp
+++ b/python-api-src/library.cpp
@@ -13,6 +13,7 @@ PYBIND11_MODULE(library, m)
     define_point(m);
     define_base_location(m);
     define_tech_tree(m);
+    define_color(m);
     define_map_tools(m);
     define_building_placer(m);
 
@@ -89,22 +90,6 @@ PYBIND11_MODULE(library, m)
         .value("CheatMoney", sc2::Difficulty::CheatMoney)
         .value("CheatInsane", sc2::Difficulty::CheatInsane);
 
-    py::class_<sc2::Color> color(m, "Color");
-    color.def(py::init<>());
-    color.def(py::init<int, int, int>(), "r"_a, "g"_a, "b"_a);
-    color.def_readwrite("r", &sc2::Color::r, "Red");
-    color.def_readwrite("g", &sc2::Color::g, "Green");
-    color.def_readwrite("b", &sc2::Color::b, "Blue");
-    color.attr("WHITE") = sc2::Colors::White;
-    color.attr("RED") = sc2::Colors::Red;
-    color.attr("GREEN") = sc2::Colors::Green;
-    color.attr("YELLOW") = sc2::Colors::Yellow;
-    color.attr("BLUE") = sc2::Colors::Blue;
-    color.attr("TEAL") = sc2::Colors::Teal;
-    color.attr("PURPLE") = sc2::Colors::Purple;
-    color.attr("BLACK") = sc2::Colors::Black;
-    color.attr("GRAY") = sc2::Colors::Gray;
-
     m.def("create_participants", &sc2::CreateParticipant, "Create participant from bot", "race"_a, "bot"_a);
     m.def("create_computer", &sc2::CreateComputer, "Create participant from built-in Starcraft computer", "race"_a, "difficulty"_a);
 
diff --git a/python-api-src/library.h b/python-api-src/library.h
index 7d11d4d80..ec250c5bd 100644
--- a/python-api-src/library.h
+++ b/python-api-src/library.h
@@ -56,5 +56,6 @@ void define_util(pybind11::module &m);
 void define_point(pybind11::module &m);
 void define_base_location(pybind11::module & m);
 void define_tech_tree(pybind11::module & m);
+void define_color(pybind11::module & m);
 void define_map_tools(pybind11::module & m);
 void define_building_placer(pybind11::module & m);
-- 
GitLab