mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-28 16:11:35 +00:00
Add she::is_key_pressed() and clear_keyboard_buffer()
This commit is contained in:
parent
d1bd775270
commit
7095a82141
@ -1166,7 +1166,7 @@ bool Editor::onProcessMessage(Message* msg)
|
||||
case kFocusLeaveMessage:
|
||||
// As we use keys like Space-bar as modifier, we can clear the
|
||||
// keyboard buffer when we lost the focus.
|
||||
clear_keybuf();
|
||||
she::clear_keyboard_buffer();
|
||||
break;
|
||||
|
||||
case kMouseWheelMessage:
|
||||
|
@ -53,7 +53,6 @@
|
||||
#include "raster/raster.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
@ -320,7 +319,7 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
if (!m_document)
|
||||
break;
|
||||
|
||||
if (mouseMsg->middle() || key[KEY_SPACE]) {
|
||||
if (mouseMsg->middle() || she::is_key_pressed(kKeySpace)) {
|
||||
captureMouse();
|
||||
m_state = STATE_SCROLLING;
|
||||
m_oldPos = static_cast<MouseMessage*>(msg)->position();
|
||||
@ -739,8 +738,8 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
case kKeySpace: {
|
||||
m_scroll = false;
|
||||
|
||||
// We have to clear all the KEY_SPACE in buffer.
|
||||
clear_keybuf();
|
||||
// We have to clear all the kKeySpace keys in buffer.
|
||||
she::clear_keyboard_buffer();
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
|
@ -810,6 +810,16 @@ void error_message(const char* msg)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_key_pressed(KeyScancode scancode)
|
||||
{
|
||||
return key[scancode] ? true: false;
|
||||
}
|
||||
|
||||
void clear_keyboard_buffer()
|
||||
{
|
||||
clear_keybuf();
|
||||
}
|
||||
|
||||
} // namespace she
|
||||
|
||||
// It must be defined by the user program code.
|
||||
|
@ -154,6 +154,9 @@ namespace she {
|
||||
kKeyScancodes = 127
|
||||
};
|
||||
|
||||
bool is_key_pressed(KeyScancode scancode);
|
||||
void clear_keyboard_buffer();
|
||||
|
||||
} // namespace she
|
||||
|
||||
#endif
|
||||
|
@ -14,8 +14,7 @@
|
||||
#include "base/split_string.h"
|
||||
#include "base/string.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
#include <ctype.h>
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -410,16 +409,16 @@ bool Accelerator::checkFromAllegroKeyArray()
|
||||
{
|
||||
KeyModifiers modifiers = kKeyNoneModifier;
|
||||
|
||||
if (key[KEY_LSHIFT] ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyShiftModifier);
|
||||
if (key[KEY_RSHIFT] ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyShiftModifier);
|
||||
if (key[KEY_LCONTROL]) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
|
||||
if (key[KEY_RCONTROL]) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
|
||||
if (key[KEY_ALT] ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyAltModifier);
|
||||
if (key[KEY_COMMAND ]) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCmdModifier);
|
||||
if (she::is_key_pressed(kKeyLShift) ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyShiftModifier);
|
||||
if (she::is_key_pressed(kKeyRShift) ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyShiftModifier);
|
||||
if (she::is_key_pressed(kKeyLControl)) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
|
||||
if (she::is_key_pressed(kKeyRControl)) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCtrlModifier);
|
||||
if (she::is_key_pressed(kKeyAlt) ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyAltModifier);
|
||||
if (she::is_key_pressed(kKeyCommand) ) modifiers = (KeyModifiers)((int)modifiers | (int)kKeyCmdModifier);
|
||||
|
||||
for (KeyCombos::iterator it = m_combos.begin(), end = m_combos.end();
|
||||
it != end; ++it) {
|
||||
if ((it->scancode == 0 || key[it->scancode]) &&
|
||||
if ((it->scancode == 0 || she::is_key_pressed(it->scancode)) &&
|
||||
(it->modifiers == modifiers)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "ui/theme.h"
|
||||
#include "ui/view.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
|
||||
namespace ui {
|
||||
|
||||
using namespace gfx;
|
||||
|
@ -14,8 +14,7 @@
|
||||
#include "ui/manager.h"
|
||||
#include "ui/widget.h"
|
||||
|
||||
#include <allegro/keyboard.h>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace ui {
|
||||
|
||||
@ -23,11 +22,11 @@ Message::Message(MessageType type)
|
||||
: m_type(type)
|
||||
, m_used(false)
|
||||
, m_modifiers((KeyModifiers)
|
||||
((key[KEY_LSHIFT] || key[KEY_RSHIFT] ? kKeyShiftModifier: 0) |
|
||||
(key[KEY_LCONTROL] || key[KEY_RCONTROL] ? kKeyCtrlModifier: 0) |
|
||||
(key[KEY_ALT] ? kKeyAltModifier: 0) |
|
||||
(key[KEY_COMMAND] ? kKeyCmdModifier: 0) |
|
||||
(key[KEY_SPACE] ? kKeySpaceModifier: 0)))
|
||||
((she::is_key_pressed(kKeyLShift) || she::is_key_pressed(kKeyRShift) ? kKeyShiftModifier: 0) |
|
||||
(she::is_key_pressed(kKeyLControl) || she::is_key_pressed(kKeyRControl) ? kKeyCtrlModifier: 0) |
|
||||
(she::is_key_pressed(kKeyAlt) ? kKeyAltModifier: 0) |
|
||||
(she::is_key_pressed(kKeyCommand) ? kKeyCmdModifier: 0) |
|
||||
(she::is_key_pressed(kKeySpace) ? kKeySpaceModifier: 0)))
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user