diff --git a/include/window.hpp b/include/window.hpp index b569174..e191e29 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -17,6 +17,8 @@ #include "color.hpp" /// For color #include "shapes.hpp" /// For shapes::point +typedef Window XWindow; + /** * @brief namespace containing all functions of milch * @namespace milch @@ -27,22 +29,28 @@ namespace milch { * @brief class contains functions relating to windows * @class window */ - class window { - public: - unsigned int width{}; ///< window width - unsigned int height{}; ///< window height - std::string title; ///< window's title + class Window { + private: Display *display = XOpenDisplay(nullptr); ///< display struct from XLib GC gc{}; ///< Graphics context of window / display - Window win {}; ///< window struct from XLib + XWindow win {}; ///< window struct from XLib + + Colormap color_map; ///< color map of the given display + + public: + size_t width{}; ///< window width + size_t height{}; ///< window height + std::string title; ///< window's title + + /** * @brief base window constructor creates a window using XLib * @param width of the window * @param height of the window */ - window(unsigned int width, unsigned int height); + Window(size_t width, size_t height); /** * @brief A simple constructor for easier development @@ -50,8 +58,8 @@ namespace milch { * @param height of the window * @param title of the window */ - window(unsigned int width, - unsigned int height, + Window(size_t width, + size_t height, const std::string &title, const milch::color &background_color = milch::color(255,255,255), const milch::color &foreground_color = milch::color(1,1,1)); @@ -59,12 +67,12 @@ namespace milch { /** * @brief copy constructor of window */ - window(window &w); + Window(Window &w); /** * @brief move constructor of window */ - window(window&& w) = default; + Window(Window&& w) = default; /** * @brief Makes the window visible @@ -93,7 +101,10 @@ namespace milch { * @return 0 and exit the program if an erorr occurs */ static int error_handler(Display *d, XErrorEvent *error) { - std::cerr << "ERROR: " << error->error_code << "\n"; + char* buf; + XGetErrorText(d, error->error_code, buf, 256); + + std::cerr << "\033[1;31mERROR\033[0m XLIB " << buf << "\n"; std::cerr.flush(); return 0; } @@ -116,7 +127,7 @@ namespace milch { * @breif conversion of window to Window * @return XLib Window */ - explicit operator Window() const; + explicit operator XWindow() const; /** * @breif conversion of window to graphics context @@ -128,7 +139,7 @@ namespace milch { * @details * deletes all the pointers and alleviates memory */ - ~window(); + ~Window(); }; } // namespace milch