| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
#include <stdarg.h> |
| 23 |
#include <string.h> |
| 24 |
|
| 25 |
#include "maths.h" |
| 26 |
#include "pstypes.h" |
| 27 |
#include "gr.h" |
| 28 |
#include "event.h" |
| 29 |
#include "ui.h" |
| 30 |
#include "key.h" |
| 31 |
#include "window.h" |
| 32 |
#include "compiler-range_for.h" |
| 33 |
#include "d_range.h" |
| 34 |
|
| 35 |
namespace dcx { |
| 36 |
|
| 37 |
constexpr std::array<const char *, 256> KeyDesc{{ |
| 38 |
"","{Esc}","{1}","{2}","{3}","{4}","{5}","{6}","{7}","{8}","{9}","{0}","{-}", \ |
| 39 |
"{=}","{Backspace}","{Tab}","{Q}","{W}","{E}","{R}","{T}","{Y}","{U}","{I}","{O}", \ |
| 40 |
"{P}","{[}","{]}","{Enter}","{LeftCtrl}","{A}","{S}","{D}","{F}", \ |
| 41 |
"{G}","{H}","{J}","{K}","{L}","{;}","{'}","{`}", \ |
| 42 |
"{RightShift}","{\\}","{Z}","{X}","{C}","{V}","{B}","{N}","{M}","{,}", \ |
| 43 |
"{.}","{/}","{LeftShift}","{Pad*}","{LeftAlt}","{Spacebar}", \ |
| 44 |
"{CapsLock}","{F1}","{F2}","{F3}","{F4}","{F5}","{F6}","{F7}","{F8}","{F9}", \ |
| 45 |
"{F10}","{NumLock}","{ScrollLock}","{Pad7}","{Pad8}","{Pad9}","{Pad-}", \ |
| 46 |
"{Pad4}","{Pad5}","{Pad6}","{Pad+}","{Pad1}","{Pad2}","{Pad3}","{Pad0}", \ |
| 47 |
"{Pad.}","","","","{F11}","{F12}","","","","","","","","","", \ |
| 48 |
"","","","","","","","","","","","","","","","","","","","", \ |
| 49 |
"","","","","","","","","","","","","","","","","","","","", \ |
| 50 |
"","","","","","","","","","","","","","","","","","", \ |
| 51 |
"{PadEnter}","{RightCtrl}","","","","","","","","","","","","","", \ |
| 52 |
"","","","","","","","","","","{Pad/}","","","{RightAlt}","", \ |
| 53 |
"","","","","","","","","","","","","","{Home}","{Up}","{PageUp}", \ |
| 54 |
"","{Left}","","{Right}","","{End}","{Down}","{PageDown}","{Insert}", \ |
| 55 |
"{Delete}","","","","","","","","","","","","","","","","","", \ |
| 56 |
"","","","","","","","","","","","","","","","","","","","", \ |
| 57 |
"","","","","","","" |
| 58 |
}}; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
void GetKeyDescription(char (&text)[100], uint_fast32_t keypress) |
| 64 |
{ |
| 65 |
const char *Ctrl = keypress & KEY_CTRLED ? "{Ctrl}" : ""; |
| 66 |
const char *Alt = keypress & KEY_ALTED ? "{Alt}" : ""; |
| 67 |
const char *Shift = keypress & KEY_SHIFTED ? "{Shift}" : ""; |
| 68 |
snprintf(text, sizeof(text), "%s%s%s%s", Ctrl, Alt, Shift, KeyDesc[keypress & 255 ]); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
int DecodeKeyText( const char * text ) |
| 73 |
{ |
| 74 |
int code{0}; |
| 75 |
|
| 76 |
if (strstr(text, "{Ctrl}") ) |
| 77 |
code |= KEY_CTRLED; |
| 78 |
if (strstr(text, "{Alt}") ) |
| 79 |
code |= KEY_ALTED; |
| 80 |
if (strstr(text, "{Shift}") ) |
| 81 |
code |= KEY_SHIFTED; |
| 82 |
|
| 83 |
range_for (const int i, xrange(256u)) |
| 84 |
{ |
| 85 |
if ( strlen(KeyDesc[i])>0 && strstr(text, KeyDesc[i]) ) |
| 86 |
{ |
| 87 |
code |= i; |
| 88 |
return code; |
| 89 |
} |
| 90 |
} |
| 91 |
return -1; |
| 92 |
} |
| 93 |
|
| 94 |
} |