mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-17 16:10:05 +00:00
Fix problem mapping "Ctrl++ Pad" key
This commit is contained in:
parent
4733a0151d
commit
8eefdf174e
@ -10,9 +10,10 @@
|
||||
|
||||
#include "ui/accelerator.h"
|
||||
|
||||
#include "base/unique_ptr.h"
|
||||
#include "base/replace_string.h"
|
||||
#include "base/split_string.h"
|
||||
#include "base/string.h"
|
||||
#include "base/unique_ptr.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
@ -54,10 +55,12 @@ Accelerator::Accelerator(const std::string& str)
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens;
|
||||
base::split_string(str, tokens, "+");
|
||||
for (std::string tok : tokens) {
|
||||
tok = base::string_to_lower(tok);
|
||||
std::size_t i, j;
|
||||
for (i=0; i<str.size(); i=j+1) {
|
||||
// i+1 because the first character can be '+' sign
|
||||
for (j=i+1; j<str.size() && str[j] != '+'; ++j)
|
||||
;
|
||||
std::string tok = base::string_to_lower(str.substr(i, j - i));
|
||||
|
||||
if (m_scancode == kKeySpace) {
|
||||
m_modifiers = (KeyModifiers)((int)m_modifiers | (int)kKeySpaceModifier);
|
||||
@ -176,15 +179,15 @@ Accelerator::Accelerator(const std::string& str)
|
||||
m_scancode = kKey8Pad;
|
||||
else if (tok == "9 pad")
|
||||
m_scancode = kKey9Pad;
|
||||
else if (tok == "slash pad")
|
||||
else if (tok == "/ pad" || tok == "slash pad")
|
||||
m_scancode = kKeySlashPad;
|
||||
else if (tok == "asterisk")
|
||||
else if (tok == "* pad" || tok == "asterisk pad" || tok == "asterisk")
|
||||
m_scancode = kKeyAsterisk;
|
||||
else if (tok == "minus pad")
|
||||
else if (tok == "- pad" || tok == "minus pad")
|
||||
m_scancode = kKeyMinusPad;
|
||||
else if (tok == "plus pad")
|
||||
else if (tok == "+ pad" || tok == "plus pad")
|
||||
m_scancode = kKeyPlusPad;
|
||||
else if (tok == "del pad")
|
||||
else if (tok == "del pad" || tok == "delete pad")
|
||||
m_scancode = kKeyDelPad;
|
||||
else if (tok == "enter pad")
|
||||
m_scancode = kKeyEnterPad;
|
||||
@ -219,7 +222,7 @@ bool Accelerator::isEmpty() const
|
||||
|
||||
std::string Accelerator::toString() const
|
||||
{
|
||||
// Same order that Allegro scancodes
|
||||
// Same order that she::KeyScancode
|
||||
static const char* table[] = {
|
||||
NULL,
|
||||
"A",
|
||||
@ -311,7 +314,7 @@ std::string Accelerator::toString() const
|
||||
"* Pad",
|
||||
"- Pad",
|
||||
"+ Pad",
|
||||
"Delete Pad",
|
||||
"Del Pad",
|
||||
"Enter Pad",
|
||||
"PrtScr",
|
||||
"Pause",
|
||||
|
56
src/ui/accelerator_ui_tests.cpp
Normal file
56
src/ui/accelerator_ui_tests.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013, 2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#define TEST_GUI
|
||||
#include "tests/test.h"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
TEST(Accelerator, Parser)
|
||||
{
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyF1, '\0'), Accelerator("F1"));
|
||||
EXPECT_EQ(Accelerator(kKeyAltModifier, kKeyQ, 'q'), Accelerator("Alt+Q"));
|
||||
EXPECT_EQ(Accelerator(kKeyCtrlModifier, kKeyQ, 'q'), Accelerator("Ctrl+Q"));
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyMinus, '-'), Accelerator("-"));
|
||||
EXPECT_EQ(Accelerator(kKeyShiftModifier, kKeyMinus, '-'), Accelerator("Shift+-"));
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyEquals, '='), Accelerator("="));
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyNil, '+'), Accelerator("+"));
|
||||
EXPECT_EQ(Accelerator(kKeyShiftModifier, kKeyNil, '+'), Accelerator("Shift++"));
|
||||
EXPECT_EQ(Accelerator(kKeyCtrlModifier, kKeyNil, '+'), Accelerator("Ctrl++"));
|
||||
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyMinusPad, 0), Accelerator("Minus Pad"));
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyMinusPad, 0), Accelerator("- Pad"));
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyPlusPad, 0), Accelerator("Plus Pad"));
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyPlusPad, 0), Accelerator("+ Pad"));
|
||||
EXPECT_EQ(Accelerator(kKeyCtrlModifier, kKeyPlusPad, 0), Accelerator("Ctrl++ Pad"));
|
||||
}
|
||||
|
||||
TEST(Accelerator, ToString)
|
||||
{
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyF1, '\0').toString(), Accelerator("F1").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyAltModifier, kKeyQ, 'q').toString(), Accelerator("Alt+Q").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyCtrlModifier, kKeyQ, 'q').toString(), Accelerator("Ctrl+Q").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyMinus, '-').toString(), Accelerator("-").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyShiftModifier, kKeyMinus, '-').toString(), Accelerator("Shift+-").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyEquals, '=').toString(), Accelerator("=").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyNil, '+').toString(), Accelerator("+").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyShiftModifier, kKeyNil, '+').toString(), Accelerator("Shift++").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyCtrlModifier, kKeyNil, '+').toString(), Accelerator("Ctrl++").toString());
|
||||
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyMinusPad, 0).toString(), Accelerator("Minus Pad").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyMinusPad, 0).toString(), Accelerator("- Pad").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyPlusPad, 0).toString(), Accelerator("Plus Pad").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyNoneModifier, kKeyPlusPad, 0).toString(), Accelerator("+ Pad").toString());
|
||||
EXPECT_EQ(Accelerator(kKeyCtrlModifier, kKeyPlusPad, 0).toString(), Accelerator("Ctrl++ Pad").toString());
|
||||
|
||||
EXPECT_EQ("- Pad", Accelerator(kKeyNoneModifier, kKeyMinusPad, 0).toString());
|
||||
EXPECT_EQ("- Pad", Accelerator("Minus Pad").toString());
|
||||
EXPECT_EQ("- Pad", Accelerator("- Pad").toString());
|
||||
|
||||
EXPECT_EQ("+ Pad", Accelerator(kKeyNoneModifier, kKeyPlusPad, 0).toString());
|
||||
EXPECT_EQ("+ Pad", Accelerator("Plus Pad").toString());
|
||||
EXPECT_EQ("+ Pad", Accelerator("+ Pad").toString());
|
||||
}
|
@ -468,12 +468,24 @@ void Manager::addToGarbage(Widget* widget)
|
||||
*/
|
||||
void Manager::enqueueMessage(Message* msg)
|
||||
{
|
||||
int c;
|
||||
|
||||
ASSERT(msg != NULL);
|
||||
|
||||
#ifdef REPORT_EVENTS
|
||||
if (msg->type() == kKeyDownMessage ||
|
||||
msg->type() == kKeyUpMessage) {
|
||||
int mods = (int)static_cast<KeyMessage*>(msg)->keyModifiers();
|
||||
TRACE("Key%s scancode=%d unicode=%d mods=%s%s%s\n",
|
||||
(msg->type() == kKeyDownMessage ? "Down": "Up"),
|
||||
static_cast<KeyMessage*>(msg)->scancode(),
|
||||
static_cast<KeyMessage*>(msg)->unicodeChar(),
|
||||
mods & kKeyShiftModifier ? " Shift": "",
|
||||
mods & kKeyCtrlModifier ? " Ctrl": "",
|
||||
mods & kKeyAltModifier ? " Alt": "");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check if this message must be filtered by some widget before
|
||||
c = msg->type();
|
||||
int c = msg->type();
|
||||
if (c >= kFirstRegisteredMessage)
|
||||
c = kFirstRegisteredMessage;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user