X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fwindow.cpp;h=f867faf6e58e3a775c08248f943eb17c1159b71e;hb=2d1312772711709fc44cb1a39283329864c25100;hp=ee5bec90d93f6165c742e13316fca7d621d79d10;hpb=efdfd047fac06547a5a9173f25dea42aeef0a93f;p=libs%2Fgui.git diff --git a/source/window.cpp b/source/window.cpp index ee5bec9..f867faf 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -9,38 +9,35 @@ Distributed under the LGPL #include #include #include +#include "display.h" #include "window.h" using namespace std; namespace Msp { +namespace Graphics { -DisplayOptions::DisplayOptions(): +WindowOptions::WindowOptions(): width(640), height(480), - fullscreen(false) + fullscreen(false), + resizable(false) { } -/** -Initializes the class but does not open the window. Intended for use by -derived classes. -*/ -Window::Window(): - display(0), - window(0) -{ } - -Window::Window(unsigned w, unsigned h) +Window::Window(Display &dpy, unsigned w, unsigned h, bool fs): + display(dpy) { options.width=w; options.height=h; + options.fullscreen=fs; init(); } -Window::Window(const DisplayOptions &dopt): - options(dopt) +Window::Window(Display &dpy, const WindowOptions &opts): + display(dpy), + options(opts) { init(); } @@ -48,9 +45,9 @@ Window::Window(const DisplayOptions &dopt): Window::~Window() { if(window) - XDestroyWindow(display, window); - if(display) - XCloseDisplay(display); + XDestroyWindow(display.get_display(), window); + + display.remove_window(this); } void Window::set_title(const string &title) @@ -61,123 +58,79 @@ void Window::set_title(const string &title) prop.encoding=XA_STRING; prop.format=8; prop.nitems=title.size(); - XSetWMName(display, window, &prop); + XSetWMName(display.get_display(), window, &prop); + display.check_error(); } void Window::show() { - XMapRaised(display, window); + XMapRaised(display.get_display(), window); + display.check_error(); } void Window::hide() { - XUnmapWindow(display, window); -} - -void Window::tick() -{ - while(1) - { - int pending=XPending(display); - if(pending==0) - break; - - for(int i=0; i(&event.xkey), buf, sizeof(buf), 0, 0); + XLookupString(const_cast(&ev.xkey), buf, sizeof(buf), 0, 0); // XXX Handle the result according to locale - signal_key_press.emit(event.xkey.keycode, event.xkey.state, buf[0]); + signal_key_press.emit(ev.xkey.keycode, ev.xkey.state, buf[0]); } break; case KeyRelease: - signal_key_release.emit(event.xkey.keycode, event.xkey.state); + signal_key_release.emit(ev.xkey.keycode, ev.xkey.state); break; case ConfigureNotify: - options.width=event.xconfigure.width; - options.height=event.xconfigure.height; + options.width=ev.xconfigure.width; + options.height=ev.xconfigure.height; signal_resize.emit(options.width, options.height); break; case ClientMessage: - if(event.xclient.data.l[0]==static_cast(wm_delete_window)) + if(ev.xclient.data.l[0]==static_cast(wm_delete_window)) signal_close.emit(); break; case EnterNotify: - XSetInputFocus(display, window, RevertToParent, CurrentTime); + XSetInputFocus(display.get_display(), window, RevertToParent, CurrentTime); break; default:; } - - on_event(event); -} - -int Window::x_error_handler(Display *display, XErrorEvent *error) -{ - char buf[128]; - XGetErrorText(display, error->error_code, buf, sizeof(buf)); - /*string request_code=lexical_cast(error->request_code); - char buf2[1024]; - XGetErrorDatabaseText(display, "XRequest", request_code.c_str(), buf, buf2, sizeof(buf2));*/ - throw Exception(buf); } +} // namespace Graphics } // namespace Msp