X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fwindow.cpp;fp=source%2Fwindow.cpp;h=75a88dce6f3331e82917ea161de7bc604a67b5e7;hb=1fbd1b60d9fffe40febe499315347762da007269;hp=0000000000000000000000000000000000000000;hpb=13a47981754ff9e44627dd44caa68b685ee3fdbf;p=libs%2Fgui.git diff --git a/source/window.cpp b/source/window.cpp new file mode 100644 index 0000000..75a88dc --- /dev/null +++ b/source/window.cpp @@ -0,0 +1,149 @@ +/* $Id$ + +This file is part of libmspgbase +Copyright © 2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#include +#include +#include "window.h" + +using namespace std; + +#include + +namespace Msp { + +DisplayOptions::DisplayOptions(): + width(640), + height(480), + fullscreen(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) +{ + options.width=w; + options.height=h; + + init(); +} + +Window::Window(const DisplayOptions &dopt): + options(dopt) +{ + init(); +} + +Window::~Window() +{ + if(window) + XDestroyWindow(display, window); + if(display) + XCloseDisplay(display); +} + +void Window::show() +{ + XMapRaised(display, window); +} + +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); + // XXX Handle the result according to locale + signal_key_press.emit(event.xkey.keycode, event.xkey.state, buf[0]); + } + break; + case KeyRelease: + signal_key_release.emit(event.xkey.keycode, event.xkey.state); + break; + case ConfigureNotify: + options.width=event.xconfigure.width; + options.height=event.xconfigure.height; + break; + default:; + } +} + +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 Msp