module gui.gui; import bcd.xcb.xcb; import std.stdio; class GUI{ xcb_connection_t* conn; xcb_screen_t* screen; Button[xcb_window_t] buttons; //xcb_get_geometry_reply_t attr; xcb_generic_event_t *event; //int xdiff, ydiff, xorig, yorig, xpress, ypress; //ubyte func; this(){ int screen_num; conn = xcb_connect(null, &screen_num); /* Get the preferred screen. */ xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(xcb_get_setup(conn)); while(screen_num--) xcb_screen_next(&screen_iter); screen = screen_iter.data; } Window addWindow(uint width, uint height){ return new Window(screen.root, this, 0, 0, width, height); } void loop(){ loop: event = xcb_wait_for_event(conn); switch(event.response_type){ case XCB_BUTTON_PRESS: break; case XCB_BUTTON_RELEASE: xcb_button_press_event_t* e = cast(xcb_button_release_event_t* )event; if(e.event in buttons){ buttons[e.event].Operation; } break; default: break; } goto loop; } } struct geometry{ uint width; uint height; } class Window{ xcb_window_t id; GUI gui; this(xcb_window_t parent, GUI g, int x, int y, uint width, uint height){ gui = g; id = xcb_generate_id(gui.conn); xcb_create_window(gui.conn, /* connection */ 0, /* depth */ id, /* window id */ parent, /* parent window */ 0, 0, /* x, y */ width, height, /* width, height */ 0, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ gui.screen.root_visual, /* visual */ 0, /* masks */ null); //cast(uint*)[pixmap, XCB_EVENT_MASK_EXPOSURE]); } void map(){ xcb_map_window(gui.conn, id); xcb_flush(gui.conn); } void unmap(){ writefln("1"); } void resize(uint width, uint height){ xcb_configure_window(gui.conn, id, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, cast(uint*)[width, height]); } geometry getGeometry(){ xcb_get_geometry_reply_t* attr = xcb_get_geometry_reply(gui.conn, xcb_get_geometry(gui.conn, id), null); geometry g; g.width = attr.width; g.height = attr.height; return g; } Container addContainer(int x1, int y1, uint width, uint height){ return new Container(this, x1, y1, width, height); } Container addContainer(float x1, float y1, float x2, float y2){ return new Container(this, x1, y1, x2, y2); } Button addButton(int x1, int y1, uint width, uint height){ return new Button(this, x1, y1, width, height); } Button addButton(float x1, float y1, float x2, float y2){ return new Button(this, x1, y1, x2, y2); } } class Container : Window{ bool relative = false; Window parent; float w1,w2,h1,h2; this(Window p, int x1, int y1, uint width, uint height){ gui = p.gui; parent = p; super(parent.id, p.gui, x1, y1, width, height); } this(Window p, float x1, float y1, float x2, float y2){ relative = true; w1 = x1; w2 = x2; h1 = y1; h2 = y2; geometry geom = parent.getGeometry(); int x3, y3; x3 = cast(int)(geom.width * x1); y3 = cast(int)(geom.height * y1); uint height,width; width = cast(uint)(geom.width*x2 - x3); height = cast(uint)(geom.height*y2 - y3); this(p, x3, y3, width, height); } } class Button : Container{ void delegate() Operation; this(Window p, int x1, int y1, uint width, uint height){ super(p, x1, y1, width, height); p.gui.buttons[id] = this; } this(Window p, float x1, float y1, float x2, float y2){ super(p, x1, y1, x2, y2); p.gui.buttons[id] = this; } } void main(){ GUI gui = new GUI(); Window w = gui.addWindow(150,150); Button b = w.addButton(.1,.1,.9,.9); b.Operation = &w.unmap; w.map(); gui.loop(); }