]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/systemkeyboardinput.cpp
Add modifier state enum
[libs/gltk.git] / source / systemkeyboardinput.cpp
index fe803a6ddd2e407abbe1cdbcadaed5ec4ce989da..a99183231f08e66203e5d16112e9cfbacdecbe3c 100644 (file)
@@ -7,7 +7,8 @@ namespace GLtk {
 
 SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
        InputMethod(r),
-       keyboard(k)
+       keyboard(k),
+       modifier_state(0)
 {
        keyboard.signal_button_press.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_press));
        keyboard.signal_button_release.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_release));
@@ -16,8 +17,17 @@ SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
 
 bool SystemKeyboardInput::key_press(unsigned key)
 {
-       // TODO modifiers
-       if(root.key_press(key, 0))
+       if(!root.is_visible())
+               return false;
+
+       if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R)
+               modifier_state |= MOD_SHIFT;
+       else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R)
+               modifier_state |= MOD_CTRL;
+       else if(key==Input::KEY_ALT_L || key==Input::KEY_ALT_R)
+               modifier_state |= MOD_ALT;
+
+       if(root.key_press(key, modifier_state))
                return true;
        
        switch(key)
@@ -37,12 +47,29 @@ bool SystemKeyboardInput::key_press(unsigned key)
 
 bool SystemKeyboardInput::key_release(unsigned key)
 {
-       return root.key_release(key, 0);
+       if(root.is_visible())
+       {
+               bool result = root.key_release(key, modifier_state);
+
+               if(key==Input::KEY_SHIFT_L || key==Input::KEY_SHIFT_R)
+                       modifier_state &= ~MOD_SHIFT;
+               else if(key==Input::KEY_CTRL_L || key==Input::KEY_CTRL_R)
+                       modifier_state &= ~MOD_CTRL;
+               else if(key==Input::KEY_ALT_L || key==Input::KEY_ALT_R)
+                       modifier_state &= ~MOD_ALT;
+
+               return result;
+       }
+       else
+               return false;
 }
 
 bool SystemKeyboardInput::character(StringCodec::unichar ch)
 {
-       return root.character(ch);
+       if(root.is_visible())
+               return root.character(ch);
+       else
+               return false;
 }
 
 } // namespace GLtk