[colobot] 272/390: Fixed remapping virtual keys, closes #415

Didier Raboud odyx at moszumanska.debian.org
Fri Jun 12 14:21:53 UTC 2015


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch upstream/latest
in repository colobot.

commit e179847358e954325657832023100ec32abe80c0
Author: krzys-h <krzys_h at interia.pl>
Date:   Wed Mar 18 21:29:33 2015 +0100

    Fixed remapping virtual keys, closes #415
---
 src/CMakeLists.txt |  1 +
 src/app/app.cpp    | 11 ++---------
 src/common/key.cpp | 37 +++++++++++++++++++++++++++++++++++++
 src/common/key.h   |  3 +++
 src/ui/key.cpp     |  9 +++++----
 5 files changed, 48 insertions(+), 13 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a17df8f..9c1a0dd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -70,6 +70,7 @@ set(BASE_SOURCES
     common/event.cpp
     common/image.cpp
     common/iman.cpp
+    common/key.cpp
     common/logger.cpp
     common/misc.cpp
     common/pathman.cpp
diff --git a/src/app/app.cpp b/src/app/app.cpp
index b6fc6ed..42e4a07 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -1189,17 +1189,10 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent)
     {
         virtualEvent.type = sourceEvent.type;
         virtualEvent.key = sourceEvent.key;
+        virtualEvent.key.key = GetVirtualKey(sourceEvent.key.key);
         virtualEvent.key.virt = true;
 
-        if (sourceEvent.key.key == KEY(LCTRL) || sourceEvent.key.key == KEY(RCTRL))
-            virtualEvent.key.key = VIRTUAL_KMOD(CTRL);
-        else if (sourceEvent.key.key == KEY(LSHIFT) || sourceEvent.key.key == KEY(RSHIFT))
-            virtualEvent.key.key = VIRTUAL_KMOD(SHIFT);
-        else if (sourceEvent.key.key == KEY(LALT) || sourceEvent.key.key == KEY(RALT))
-            virtualEvent.key.key = VIRTUAL_KMOD(ALT);
-        else if (sourceEvent.key.key == KEY(LMETA) || sourceEvent.key.key == KEY(RMETA))
-            virtualEvent.key.key = VIRTUAL_KMOD(META);
-        else
+        if(virtualEvent.key.key == sourceEvent.key.key)
             virtualEvent.type = EVENT_NULL;
     }
     else if ((sourceEvent.type == EVENT_JOY_BUTTON_DOWN) || (sourceEvent.type == EVENT_JOY_BUTTON_UP))
diff --git a/src/common/key.cpp b/src/common/key.cpp
new file mode 100644
index 0000000..a184b04
--- /dev/null
+++ b/src/common/key.cpp
@@ -0,0 +1,37 @@
+/*
+ * This file is part of the Colobot: Gold Edition source code
+ * Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
+ * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://gnu.org/licenses
+ */
+
+#include "common/key.h"
+
+unsigned int GetVirtualKey(unsigned int key)
+{
+    if(key == KEY(LCTRL) || key == KEY(RCTRL))
+        return VIRTUAL_KMOD(CTRL);
+    if(key == KEY(LSHIFT) || key == KEY(RSHIFT))
+        return VIRTUAL_KMOD(SHIFT);
+    if(key == KEY(LALT) || key == KEY(RALT))
+        return VIRTUAL_KMOD(ALT);
+    if(key == KEY(LMETA) || key == KEY(RMETA))
+        return VIRTUAL_KMOD(META);
+
+    if(key == KEY(KP_ENTER))
+    	return KEY(RETURN);
+
+    return key;
+}
\ No newline at end of file
diff --git a/src/common/key.h b/src/common/key.h
index c16bfe0..ec6a225 100644
--- a/src/common/key.h
+++ b/src/common/key.h
@@ -58,6 +58,9 @@ enum VirtualKmod
 // So it is the same as other macros
 #define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
 
+//! Converts individual codes to virtual keys if needed
+unsigned int GetVirtualKey(unsigned int key);
+
 // Virtual key code generated on joystick button presses
 // num is number of joystick button
 #define VIRTUAL_JOY(num) (SDLK_LAST + 200 + num)
diff --git a/src/ui/key.cpp b/src/ui/key.cpp
index 9243825..b537de1 100644
--- a/src/ui/key.cpp
+++ b/src/ui/key.cpp
@@ -70,22 +70,23 @@ bool CKey::EventProcess(const Event &event)
     if (event.type == EVENT_KEY_DOWN && m_catch)
     {
         m_catch = false;
+        unsigned int key = GetVirtualKey(event.key.key);
 
-        if (TestKey(event.key.key)) // impossible ?
+        if (TestKey(key)) // impossible ?
         {
             m_sound->Play(SOUND_TZOING);
         }
         else
         {
-            if (event.key.key == m_binding.primary || event.key.key == m_binding.secondary)
+            if (key == m_binding.primary || key == m_binding.secondary)
             {
                 m_binding.secondary = KEY_INVALID;
-                m_binding.primary = event.key.key;
+                m_binding.primary = key;
             }
             else
             {
                 m_binding.secondary = m_binding.primary;
-                m_binding.primary = event.key.key;
+                m_binding.primary = key;
             }
             m_sound->Play(SOUND_CLICK);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list