From: Mikko Rasa Date: Wed, 18 Jul 2007 09:26:44 +0000 (+0000) Subject: More code for Window X-Git-Tag: 0.9~33 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e9455430a6e765b6184532f160f6fde4a67b4a2f;p=libs%2Fgltk.git More code for Window --- diff --git a/source/window.cpp b/source/window.cpp index 81f8ce1..2ec55b9 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -38,8 +38,32 @@ Window::~Window() XCloseDisplay(display); } +void Window::show() +{ + XMapWindow(display, window); +} + +void Window::tick() +{ + while(1) + { + int pending=XPending(display); + if(pending==0) + break; + + for(int i=0; ivisual, 0, 0); + + XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|MotionMask|KeyPressMask|KeyReleaseMask); +} + +void Window::process_event(const XEvent &event) +{ + switch(event.type) + { + case ButtonPress: + signal_button_press.emit(event.button.x, event.button.y, event.button.button, event.button.state); + break; + case ButtonRelease: + signal_button_release.emit(event.button.x, event.button.y, event.button.button, event.button.state); + break; + case PointerMotion: + signal_pointer_motion.emit(event.motion.x, event.motion.y); + break; + case KeyPress: + { + char buf[16]; + XLookupString(event.key, buf, sizeof(buf), 0, 0); + // XXX Handle the result according to locale + signal_key_press.emit(event.key.keycode, event.key.state, buf[0]); + } + break; + case KeyRelease: + signal_key_release.emit(event.key.keycode, event.key.state); + break; + default:; + } } } // namespace GLtk diff --git a/source/window.h b/source/window.h index 3990acf..2b2b064 100644 --- a/source/window.h +++ b/source/window.h @@ -22,14 +22,28 @@ struct DisplayOptions class Window { public: + sigc::signal signal_button_press; + sigc::signal signal_button_release; + sigc::signal signal_pointer_motion; + sigc::signal signal_key_press; + sigc::signal signal_key_release; + Window(unsigned, unsigned); Window(const DisplayOptions &); ~Window(); + + unsigned get_width() const { return options.width; } + unsigned get_height() const { return options.height; } + void show(); + void add(Widget &); + void tick(); private: Display *display; + DisplayOptions options; ::Window window; void init(const DisplayOptions &); + void process_event(const XEvent &); }; } // namespace GLtk