Skip to content

Commit

Permalink
fix(window): typedef xlib's window
Browse files Browse the repository at this point in the history
  • Loading branch information
realstealthninja committed Aug 28, 2024
1 parent 82b4113 commit 4aab690
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions include/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,44 +29,50 @@ 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
* @param width of the window
* @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));

/**
* @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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand All @@ -128,7 +139,7 @@ namespace milch {
* @details
* deletes all the pointers and alleviates memory
*/
~window();
~Window();
};

} // namespace milch
Expand Down

0 comments on commit 4aab690

Please sign in to comment.