X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Froot.cpp;h=6bc5793df6e0c4b5140660a9f96f8d3095e58c5f;hb=8a0058b5b90bb7e9eacf1646142f4d73b426fd66;hp=f8a4d9f76dcf0ef920fad27bae6f8a9d222d6a99;hpb=131ac8ff2c06f94d40f4bf98d4a6ec0d113cdffc;p=libs%2Fgltk.git diff --git a/source/root.cpp b/source/root.cpp index f8a4d9f..6bc5793 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -1,17 +1,75 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include #include "root.h" namespace Msp { namespace GLtk { -Root::Root(Resources &r, Window &w): +Root::Root(const Resources &r, Graphics::Window &w): + Widget(r), Panel(r), window(w) { set_geometry(Geometry(0, 0, window.get_width(), window.get_height())); + update_style(); + window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event)); window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event)); window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event)); + window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press_event)); + window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release_event)); +} + +void Root::button_press_event(int x, int y, unsigned btn, unsigned) +{ + if(visible) + { + translate_coords(x, y); + button_press(x, y, btn); + } +} + +void Root::button_release_event(int x, int y, unsigned btn, unsigned) +{ + if(visible) + { + translate_coords(x, y); + button_release(x, y, btn); + } +} + +void Root::pointer_motion_event(int x, int y) +{ + if(visible) + { + translate_coords(x, y); + pointer_motion(x, y); + } +} + +void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch) +{ + if(visible) + key_press(Input::key_from_sys(key), mod, ch); +} + +void Root::key_release_event(unsigned key, unsigned mod) +{ + if(visible) + key_release(Input::key_from_sys(key), mod); +} + +void Root::translate_coords(int &x, int &y) +{ + x=x*geom.w/window.get_width(); + y=geom.h-1-y*geom.h/window.get_height(); } } // namespace GLtk