[aseprite] 223/308: Add key modifiers in Skia/Win port to avoid calling she::is_key_pressed()

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:45:13 UTC 2016


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

thansen pushed a commit to branch master
in repository aseprite.

commit 228c96b9437e03af62afb27bc581105e0cee943f
Author: David Capello <davidcapello at gmail.com>
Date:   Fri Feb 12 12:21:53 2016 -0300

    Add key modifiers in Skia/Win port to avoid calling she::is_key_pressed()
    
    Related to #954
---
 src/she/win/vk.cpp   | 33 ++++++++++++++++++++++++++-------
 src/she/win/window.h | 10 ++++++++++
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/src/she/win/vk.cpp b/src/she/win/vk.cpp
index b624202..f7f96af 100644
--- a/src/she/win/vk.cpp
+++ b/src/she/win/vk.cpp
@@ -1,5 +1,5 @@
 // SHE library
-// Copyright (C) 2012-2015  David Capello
+// Copyright (C) 2012-2016  David Capello
 //
 // This file is released under the terms of the MIT license.
 // Read LICENSE.txt for more information.
@@ -14,7 +14,8 @@
 
 namespace she {
 
-KeyScancode win32vk_to_scancode(int vk) {
+KeyScancode win32vk_to_scancode(int vk)
+{
   static KeyScancode keymap[256] = {
     // 0x00
     kKeyNil, // 0x00
@@ -34,9 +35,9 @@ KeyScancode win32vk_to_scancode(int vk) {
     kKeyNil, // 0x0E - Undefined
     kKeyNil, // 0x0F - Undefined
     // 0x10
-    kKeyNil, // 0x10 - VK_SHIFT
-    kKeyNil, // 0x11 - VK_CONTROL
-    kKeyNil, // 0x12 - VK_MENU
+    kKeyLShift, // 0x10 - VK_SHIFT
+    kKeyLControl, // 0x11 - VK_CONTROL
+    kKeyAlt, // 0x12 - VK_MENU
     kKeyPause, // 0x13 - VK_PAUSE
     kKeyCapsLock, // 0x14 - VK_CAPITAL
     kKeyKana, // 0x15 - VK_KANA
@@ -294,7 +295,25 @@ KeyScancode win32vk_to_scancode(int vk) {
   return keymap[vk];
 }
 
-static int scancode_to_win32vk(KeyScancode scancode) {
+KeyModifiers get_modifiers_from_last_win32_message()
+{
+  int modifiers = kKeyNoneModifier;
+  if ((GetKeyState(VK_LSHIFT) & 0x8000) ||
+      (GetKeyState(VK_RSHIFT) & 0x8000))
+    modifiers |= kKeyShiftModifier;
+  if ((GetKeyState(VK_LCONTROL) & 0x8000) ||
+      (GetKeyState(VK_RCONTROL) & 0x8000))
+    modifiers |= kKeyCtrlModifier;
+  if ((GetKeyState(VK_LMENU) & 0x8000) ||
+      (GetKeyState(VK_RMENU) & 0x8000))
+    modifiers |= kKeyAltModifier;
+  if (GetKeyState(VK_SPACE) & 0x8000)
+    modifiers |= kKeySpaceModifier;
+  return (KeyModifiers)modifiers;
+}
+
+static int scancode_to_win32vk(KeyScancode scancode)
+{
   static int initialized = false;
   static int keymap[kKeyScancodes];
 
@@ -319,7 +338,7 @@ bool is_key_pressed(KeyScancode scancode)
 {
   int vk = scancode_to_win32vk(scancode);
   if (vk)
-    return (GetKeyState(vk) & 0xf000 ? true: false);
+    return (GetAsyncKeyState(vk) & 0x8000 ? true: false);
   else
     return false;
 }
diff --git a/src/she/win/window.h b/src/she/win/window.h
index 174e125..22da38d 100644
--- a/src/she/win/window.h
+++ b/src/she/win/window.h
@@ -27,6 +27,7 @@
 namespace she {
 
   KeyScancode win32vk_to_scancode(int vk);
+  KeyModifiers get_modifiers_from_last_win32_message();
 
   #define SHE_WND_CLASS_NAME L"Aseprite.Window"
 
@@ -290,6 +291,7 @@ namespace she {
           }
 
           Event ev;
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setPosition(gfx::Point(
               GET_X_LPARAM(lparam) / m_scale,
               GET_Y_LPARAM(lparam) / m_scale));
@@ -320,6 +322,7 @@ namespace she {
 
             Event ev;
             ev.setType(Event::MouseLeave);
+            ev.setModifiers(get_modifiers_from_last_win32_message());
             queueEvent(ev);
           }
           break;
@@ -329,6 +332,7 @@ namespace she {
         case WM_MBUTTONDOWN: {
           Event ev;
           ev.setType(Event::MouseDown);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setPosition(gfx::Point(
               GET_X_LPARAM(lparam) / m_scale,
               GET_Y_LPARAM(lparam) / m_scale));
@@ -345,6 +349,7 @@ namespace she {
         case WM_MBUTTONUP: {
           Event ev;
           ev.setType(Event::MouseUp);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setPosition(gfx::Point(
               GET_X_LPARAM(lparam) / m_scale,
               GET_Y_LPARAM(lparam) / m_scale));
@@ -366,6 +371,7 @@ namespace she {
         case WM_RBUTTONDBLCLK: {
           Event ev;
           ev.setType(Event::MouseDoubleClick);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setPosition(gfx::Point(
               GET_X_LPARAM(lparam) / m_scale,
               GET_Y_LPARAM(lparam) / m_scale));
@@ -385,6 +391,7 @@ namespace she {
 
           Event ev;
           ev.setType(Event::MouseWheel);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setPosition(gfx::Point(pos.x, pos.y) / m_scale);
 
           int z = ((short)HIWORD(wparam)) / WHEEL_DELTA;
@@ -407,6 +414,7 @@ namespace she {
 
           Event ev;
           ev.setType(Event::MouseWheel);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setPosition(gfx::Point(pos.x, pos.y) / m_scale);
 
           int bar = (msg == WM_HSCROLL ? SB_HORZ: SB_VERT);
@@ -465,6 +473,7 @@ namespace she {
 
           Event ev;
           ev.setType(Event::KeyDown);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setScancode(win32vk_to_scancode(vk));
           ev.setRepeat(lparam & 0xffff);
 
@@ -485,6 +494,7 @@ namespace she {
         case WM_KEYUP: {
           Event ev;
           ev.setType(Event::KeyUp);
+          ev.setModifiers(get_modifiers_from_last_win32_message());
           ev.setScancode(win32vk_to_scancode(wparam));
           ev.setUnicodeChar(0);
           ev.setRepeat(lparam & 0xffff);

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



More information about the Pkg-games-commits mailing list