[Scummvm-cvs-logs] CVS: scummvm/gui EditTextWidget.cpp,1.4,1.5 EditTextWidget.h,1.2,1.3 ListWidget.cpp,1.16,1.17 ListWidget.h,1.11,1.12 dialog.cpp,1.25,1.26 dialog.h,1.16,1.17 newgui.cpp,1.30,1.31 newgui.h,1.17,1.18 widget.h,1.10,1.11
Max Horn
fingolfin at users.sourceforge.net
Fri Nov 22 06:03:09 CET 2002
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv29764
Modified Files:
EditTextWidget.cpp EditTextWidget.h ListWidget.cpp
ListWidget.h dialog.cpp dialog.h newgui.cpp newgui.h widget.h
Log Message:
changed the key input system in NewGUI: pass both the keycode and the ascii value to handleKeyUp/Down. Also, use this to fix the key repeat code (see bug #626225)
Index: EditTextWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- EditTextWidget.cpp 21 Nov 2002 17:24:42 -0000 1.4
+++ EditTextWidget.cpp 22 Nov 2002 14:02:29 -0000 1.5
@@ -29,8 +29,6 @@
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
_type = kEditTextWidget;
- _currentKeyDown = 0;
-
_caretVisible = false;
_caretTime = 0;
}
@@ -54,7 +52,7 @@
// a mouse click should place the caret.
}
-bool EditTextWidget::handleKeyDown(char key, int modifiers)
+bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
bool handled = true;
bool dirty = false;
@@ -63,7 +61,7 @@
if (_caretVisible)
drawCaret(true);
- switch (key) {
+ switch (keycode) {
case '\n': // enter/return
case '\r':
_boss->releaseFocus();
@@ -87,8 +85,8 @@
case 23: // end
break;
default:
- if (isalnum(key) || key == ' ' || key == '-' || key == '_') {
- _label += key;
+ if (isprint((char)ascii)) {
+ _label += (char)ascii;
dirty = true;
} else {
handled = false;
@@ -97,24 +95,8 @@
if (dirty)
draw();
-
-#ifndef _WIN32_WCE
-
- // not done on WinCE because keyboard is emulated and
- // keyup is not generated
-
- _currentKeyDown = key;
-
-#endif
return handled;
-}
-
-bool EditTextWidget::handleKeyUp(char key, int modifiers)
-{
- if (key == _currentKeyDown)
- _currentKeyDown = 0;
- return true;
}
void EditTextWidget::drawWidget(bool hilite)
Index: EditTextWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/EditTextWidget.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- EditTextWidget.h 21 Nov 2002 15:20:51 -0000 1.2
+++ EditTextWidget.h 22 Nov 2002 14:02:29 -0000 1.3
@@ -30,7 +30,6 @@
typedef ScummVM::StringList StringList;
typedef ScummVM::String String;
protected:
- int _currentKeyDown;
String _backupString;
bool _caretVisible;
uint32 _caretTime;
@@ -39,9 +38,7 @@
virtual void handleTickle();
virtual void handleMouseDown(int x, int y, int button, int clickCount);
- virtual bool handleKeyDown(char key, int modifiers);
- virtual bool handleKeyUp(char key, int modifiers);
- //virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
+ virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers);
virtual bool wantsFocus() { return true; };
Index: ListWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ListWidget.cpp 21 Nov 2002 17:24:42 -0000 1.16
+++ ListWidget.cpp 22 Nov 2002 14:02:30 -0000 1.17
@@ -136,7 +136,7 @@
_scrollBar->handleMouseWheel(x, y, direction);
}
-bool ListWidget::handleKeyDown(char key, int modifiers)
+bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
bool handled = true;
bool dirty = false;
@@ -147,7 +147,7 @@
if (_caretVisible)
drawCaret(true);
- switch (key) {
+ switch (keycode) {
case '\n': // enter/return
case '\r':
// enter, confirm edit and exit editmode
@@ -166,8 +166,8 @@
dirty = true;
break;
default:
- if (isalnum(key) || key == ' ' || key == '-' || key == '_') {
- _list[_selectedItem] += key;
+ if (isprint((char)ascii)) {
+ _list[_selectedItem] += (char)ascii;
dirty = true;
} else {
handled = false;
@@ -177,7 +177,7 @@
} else {
// not editmode
- switch (key) {
+ switch (keycode) {
case '\n': // enter
case '\r':
if (_selectedItem >= 0) {
@@ -234,16 +234,16 @@
// not done on WinCE because keyboard is emulated and
// keyup is not generated
- _currentKeyDown = key;
+ _currentKeyDown = keycode;
#endif
return handled;
}
-bool ListWidget::handleKeyUp(char key, int modifiers)
+bool ListWidget::handleKeyUp(uint16 ascii, int keycode, int modifiers)
{
- if (key == _currentKeyDown)
+ if (keycode == _currentKeyDown)
_currentKeyDown = 0;
return true;
}
Index: ListWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ListWidget.h 21 Nov 2002 12:48:50 -0000 1.11
+++ ListWidget.h 22 Nov 2002 14:02:30 -0000 1.12
@@ -74,8 +74,8 @@
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
- virtual bool handleKeyDown(char key, int modifiers);
- virtual bool handleKeyUp(char key, int modifiers);
+ virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers);
+ virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual bool wantsFocus() { return true; };
Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- dialog.cpp 21 Nov 2002 15:20:51 -0000 1.25
+++ dialog.cpp 22 Nov 2002 14:02:31 -0000 1.26
@@ -188,17 +188,17 @@
w->handleMouseWheel(x, y, direction);
}
-void Dialog::handleKeyDown(char key, int modifiers)
+void Dialog::handleKeyDown(uint16 ascii, int keycode, int modifiers)
{
if (_focusedWidget) {
- if (_focusedWidget->handleKeyDown(key, modifiers))
+ if (_focusedWidget->handleKeyDown(ascii, keycode, modifiers))
return;
} else {
// Hotkey handling
Widget *w = _firstWidget;
- key = toupper(key);
+ ascii = toupper(ascii);
while (w) {
- if (w->_type == kButtonWidget && key == toupper(((ButtonWidget *)w)->_hotkey)) {
+ if (w->_type == kButtonWidget && ascii == toupper(((ButtonWidget *)w)->_hotkey)) {
// We first send a mouseDown then a mouseUp.
// FIXME: insert a brief delay between both.
w->handleMouseDown(0, 0, 1, 1);
@@ -210,17 +210,17 @@
}
// ESC closes all dialogs by default
- if (key == 27)
+ if (keycode == 27)
close();
// TODO: tab/shift-tab should focus the next/previous focusable widget
}
-void Dialog::handleKeyUp(char key, int modifiers)
+void Dialog::handleKeyUp(uint16 ascii, int keycode, int modifiers)
{
// Focused widget recieves keyup events
if (_focusedWidget)
- _focusedWidget->handleKeyUp(key, modifiers);
+ _focusedWidget->handleKeyUp(ascii, keycode, modifiers);
}
void Dialog::handleMouseMoved(int x, int y, int button)
Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- dialog.h 21 Nov 2002 15:20:51 -0000 1.16
+++ dialog.h 22 Nov 2002 14:02:32 -0000 1.17
@@ -75,8 +75,8 @@
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
- virtual void handleKeyDown(char key, int modifiers);
- virtual void handleKeyUp(char key, int modifiers);
+ virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
+ virtual void handleKeyUp(uint16 ascii, int keycode, int modifiers);
virtual void handleMouseMoved(int x, int y, int button);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
Index: newgui.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- newgui.cpp 21 Nov 2002 12:48:50 -0000 1.30
+++ newgui.cpp 22 Nov 2002 14:02:32 -0000 1.31
@@ -82,7 +82,7 @@
// Constructor
NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false),
- _stateIsSaved(false), _currentKeyDown(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0)
+ _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0)
{
// Setup some default GUI colors.
// TODO - either use nicer values, or maybe make this configurable?
@@ -94,6 +94,9 @@
// Clear the cursor
memset(_cursor, 0xFF, sizeof(_cursor));
+
+ // Reset key repeat
+ _currentKeyDown.keycode = 0;
}
void NewGui::runLoop()
@@ -132,22 +135,23 @@
while (_system->poll_event(&event)) {
switch(event.event_code) {
case OSystem::EVENT_KEYDOWN:
- activeDialog->handleKeyDown((byte)event.kbd.ascii, event.kbd.flags);
+ activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
#ifndef _WIN32_WCE
// init continuous event stream
// not done on WinCE because keyboard is emulated and
// keyup is not generated
- _currentKeyDown = event.kbd.ascii;
- _currentKeyDownFlags = event.kbd.flags;
+ _currentKeyDown.ascii = event.kbd.ascii;
+ _currentKeyDown.keycode = event.kbd.keycode;
+ _currentKeyDown.flags = event.kbd.flags;
_keyRepeatTime = time + kKeyRepeatInitialDelay;
#endif
break;
case OSystem::EVENT_KEYUP:
- activeDialog->handleKeyUp((byte)event.kbd.ascii, event.kbd.flags);
- if (event.kbd.ascii == _currentKeyDown)
+ activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
+ if (event.kbd.keycode == _currentKeyDown.keycode)
// only stop firing events if it's the current key
- _currentKeyDown = 0;
+ _currentKeyDown.keycode = 0;
break;
case OSystem::EVENT_MOUSEMOVE:
_system->set_mouse_pos(event.mouse.x, event.mouse.y);
@@ -183,12 +187,12 @@
}
// check if event should be sent again (keydown)
- if (_currentKeyDown != 0)
+ if (_currentKeyDown.keycode != 0)
{
if (_keyRepeatTime < time)
{
// fire event
- activeDialog->handleKeyDown(_currentKeyDown, _currentKeyDownFlags);
+ activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);
_keyRepeatTime = time + kKeyRepeatSustainDelay;
}
}
@@ -216,7 +220,7 @@
// _screenPitch = _system->get_width();
_system->grab_overlay(_screen, _screenPitch);
- _currentKeyDown = 0;
+ _currentKeyDown.keycode = 0;
_lastClick.x = _lastClick.y = 0;
_lastClick.time = 0;
_lastClick.count = 0;
Index: newgui.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/newgui.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- newgui.h 21 Nov 2002 12:48:50 -0000 1.17
+++ newgui.h 22 Nov 2002 14:02:32 -0000 1.18
@@ -84,7 +84,11 @@
bool _stateIsSaved;
// for continuous events (keyDown)
- int _currentKeyDown, _currentKeyDownFlags;
+ struct {
+ uint16 ascii;
+ byte flags;
+ int keycode;
+ } _currentKeyDown;
uint32 _keyRepeatTime;
// position and time of last mouse click (used to detect double clicks)
Index: widget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/widget.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- widget.h 21 Nov 2002 15:20:52 -0000 1.10
+++ widget.h 22 Nov 2002 14:02:33 -0000 1.11
@@ -110,8 +110,8 @@
virtual void handleMouseLeft(int button) {}
virtual void handleMouseMoved(int x, int y, int button) {}
virtual void handleMouseWheel(int x, int y, int direction) {}
- virtual bool handleKeyDown(char key, int modifiers) { return false; } // Return true if the event was handled
- virtual bool handleKeyUp(char key, int modifiers) { return false; } // Return true if the event was handled
+ virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled
+ virtual bool handleKeyUp(uint16 ascii, int keycode, int modifiers) { return false; } // Return true if the event was handled
virtual void handleTickle() {}
void draw();
void receivedFocus() { _hasFocus = true; receivedFocusWidget(); }
More information about the Scummvm-git-logs
mailing list