Skip to content

Commit

Permalink
fix(window): use Window instead of window
Browse files Browse the repository at this point in the history
  • Loading branch information
realstealthninja committed Aug 28, 2024
1 parent 4aab690 commit c15872a
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
* @author [stealthninja](https://github.com/realstealthninja)
*/

#include "window.hpp" /// For milch::function

#include <X11/Xlib.h> /// for XLib functions
#include "window.hpp" /// For milch::function
#include "color.hpp"
#include "shapes.hpp"

/**
* @brief namespace containing all functions of milch
* @namespace milch
*/
namespace milch {
window::window(unsigned int width, unsigned int height):
Window::Window(size_t width, size_t height):
width(width),
height(height),
title("my window"),
title("my Window"),
win(XCreateWindow(
this->display,
DefaultRootWindow(this->display),
Expand All @@ -33,47 +36,51 @@ namespace milch {
0, nullptr
)) {
this->gc = XCreateGC(this->display, this->win, 0, nullptr);
XStoreName(this->display, this->win, "my window");
this->color_map = XDefaultColormap(this->display, 0);

XStoreName(this->display, this->win, "my Window");
set_background_color(milch::color(255,255,225));
XSetErrorHandler(error_handler);
}
window::window(unsigned int width,
unsigned int height,
Window::Window(size_t width,
size_t height,
const std::string& title,
const milch::color &background_color,
const milch::color &foreground_color): window(width, height) {
const milch::color &foreground_color): Window(width, height) {
set_background_color(background_color);
set_foreground_color(foreground_color);
XStoreName(this->display, this->win, title.c_str());


}

void window::show_window() const {
void Window::show_window() const {
if (!this->win) return;
XMapWindow(this->display, this->win);
XFlush(this->display);
}

window::~window() {
Window::~Window() {
if (!this->win) return;
XFreeGC(this->display, this->gc);
XDestroyWindow(this->display, this->win);
XCloseDisplay(this->display);

}

void window::set_background_color(const milch::color& color) const {
Colormap map = XDefaultColormap(this->display, 0);
void Window::set_background_color(const milch::color& color) const {
XColor clr = color.to_xlib_color();
XAllocColor(this->display, map, &clr);

XAllocColor(this->display, this->color_map, &clr);
XSetWindowBackground(this->display, this->win, clr.pixel);
XClearWindow(this->display, this->win);
XFlush(this->display);
}

void window::set_foreground_color(const color &color) const {
Colormap map = XDefaultColormap(this->display, 0);
void Window::set_foreground_color(const color &color) const {
XColor clr = color.to_xlib_color();
XAllocColor(this->display, map, &clr);

XAllocColor(this->display, this->color_map, &clr);
XSetForeground(this->display, this->gc, clr.pixel);
XClearWindow(this->display, this->win);
XFlush(this->display);
Expand All @@ -92,15 +99,15 @@ namespace milch {
return this->win;
}

window::operator GC() const {
Window::operator GC() const {
return this->gc;
}

window::operator Display*() const {
Window::operator Display*() const {
return this->display;
}

window::window(window &w) {
Window::Window(Window &w) {
w.width = this->width;
w.height = this->height;
w.display = this->display;
Expand All @@ -109,7 +116,7 @@ namespace milch {
w.title = this->title;
}

void window::draw_line(shapes::point a, shapes::point b, int width_of_line) const {
void Window::draw_line(shapes::point a, shapes::point b, int width_of_line) const {
XGCValues values;
values.line_width = width_of_line;
XChangeGC(this->display, this->gc, GCLineWidth, &values);
Expand Down

0 comments on commit c15872a

Please sign in to comment.