diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-14 03:45:57 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-14 03:45:57 +0200 |
| commit | 854f2f732acc4c1d9fa4126962149cae14f4d4e9 (patch) | |
| tree | b9ed25c54bf261b6e22c755db86811a6ee12836f /src/Interface.cs | |
| parent | 4f1128a8001b90e1d163056ef66763bc3b7b8576 (diff) | |
* 0.crow, 1.crow, 2.crow, 5.crow, 7.crow:
tests
* GraphicObject.cs:
enabled, code clean and naming conventions
* Label.cs, TextBox.cs:
debug
* Interface.cs:
keyboard repeat
Diffstat (limited to 'src/Interface.cs')
| -rw-r--r-- | src/Interface.cs | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/src/Interface.cs b/src/Interface.cs index bee0d8b5..4a0789a2 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -69,9 +69,9 @@ namespace Crow //TODO: shold be declared in graphicObject public static bool FocusOnHover = false; /// <summary> Time to wait in millisecond before starting repeat loop</summary> - public static int DeviceRepeatDelay = 600; + public static int DeviceRepeatDelay = 700; /// <summary> Time interval in millisecond between device event repeat</summary> - public static int DeviceRepeatInterval = 100; + public static int DeviceRepeatInterval = 40; public static bool ReplaceTabsWithSpace = false; /// <summary> Allow rendering of interface in development environment </summary> public static bool DesignerMode = false; @@ -332,6 +332,14 @@ namespace Crow FocusedWidget.onMouseClick (this, new MouseButtonEventArgs (Mouse.X, Mouse.Y, MouseButton.Left, true)); } } + if (keyboardRepeatCount > 0) { + int mc = keyboardRepeatCount; + keyboardRepeatCount -= mc; + for (int i = 0; i < mc; i++) { + _focusedWidget.onKeyDown (this, lastKeyDownEvt); + } + } + if (!Monitor.TryEnter (UpdateMutex)) return; @@ -653,20 +661,6 @@ namespace Crow HoverWidget.onMouseWheel (this, e); return true; } - - volatile bool mouseRepeatOn; - volatile int mouseRepeatCount; - Thread mouseRepeatThread; - void mouseRepeatThreadFunc() - { - mouseRepeatOn = true; - Thread.Sleep (Interface.DeviceRepeatDelay); - while (mouseRepeatOn) { - mouseRepeatCount++; - Thread.Sleep (Interface.DeviceRepeatInterval); - } - mouseRepeatCount = 0; - } #endregion #region Keyboard @@ -674,8 +668,14 @@ namespace Crow Keyboard.SetKeyState((Crow.Key)Key,true); if (_focusedWidget == null) return false; - KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); + KeyboardKeyEventArgs e = lastKeyDownEvt = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); + lastKeyDownEvt.IsRepeat = true; _focusedWidget.onKeyDown (this, e); + + keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc); + keyboardRepeatThread.IsBackground = true; + keyboardRepeatThread.Start (); + return true; } public bool ProcessKeyUp(int Key){ @@ -683,7 +683,14 @@ namespace Crow if (_focusedWidget == null) return false; KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)Key, false, Keyboard); + _focusedWidget.onKeyUp (this, e); + + if (keyboardRepeatThread != null) { + keyboardRepeatOn = false; + keyboardRepeatThread.Abort(); + keyboardRepeatThread.Join (); + } return true; } public bool ProcessKeyPress(char Key){ @@ -695,6 +702,33 @@ namespace Crow } #endregion + #region Device Repeat Events + volatile bool mouseRepeatOn, keyboardRepeatOn; + volatile int mouseRepeatCount, keyboardRepeatCount; + Thread mouseRepeatThread, keyboardRepeatThread; + KeyboardKeyEventArgs lastKeyDownEvt; + void mouseRepeatThreadFunc() + { + mouseRepeatOn = true; + Thread.Sleep (Interface.DeviceRepeatDelay); + while (mouseRepeatOn) { + mouseRepeatCount++; + Thread.Sleep (Interface.DeviceRepeatInterval); + } + mouseRepeatCount = 0; + } + void keyboardRepeatThreadFunc() + { + keyboardRepeatOn = true; + Thread.Sleep (Interface.DeviceRepeatDelay); + while (keyboardRepeatOn) { + keyboardRepeatCount++; + Thread.Sleep (Interface.DeviceRepeatInterval); + } + keyboardRepeatCount = 0; + } + #endregion + #region ILayoutable implementation public void RegisterClip(Rectangle r){ clipping.AddRectangle (r); |