Guest User

Untitled

a guest
Jun 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. class Console
  2. {
  3. public:
  4. typedef std::list<String> InputList;
  5.  
  6. enum Result
  7. {
  8. NOTHING = 0,
  9. ENTERED,
  10. ESCAPED
  11. };
  12.  
  13. static const String& GetInput() { return input; }
  14.  
  15. static Result Query(SDLKey lastKey)
  16. {
  17. if(lastResult == ENTERED || lastResult == ESCAPED)
  18. {
  19. input.clear();
  20. }
  21.  
  22. switch (lastKey)
  23. {
  24. case SDLK_a:
  25. case SDLK_b:
  26. case SDLK_c:
  27. case SDLK_d:
  28. case SDLK_e:
  29. case SDLK_f:
  30. case SDLK_g:
  31. case SDLK_h:
  32. case SDLK_i:
  33. case SDLK_j:
  34. case SDLK_k:
  35. case SDLK_l:
  36. case SDLK_m:
  37. case SDLK_n:
  38. case SDLK_o:
  39. case SDLK_p:
  40. case SDLK_q:
  41. case SDLK_r:
  42. case SDLK_s:
  43. case SDLK_t:
  44. case SDLK_u:
  45. case SDLK_v:
  46. case SDLK_w:
  47. case SDLK_x:
  48. case SDLK_y:
  49. case SDLK_z:
  50. case SDLK_0:
  51. case SDLK_1:
  52. case SDLK_2:
  53. case SDLK_3:
  54. case SDLK_4:
  55. case SDLK_5:
  56. case SDLK_6:
  57. case SDLK_7:
  58. case SDLK_8:
  59. case SDLK_9:
  60. case SDLK_SLASH:
  61. case SDLK_BACKSLASH:
  62. case SDLK_PERIOD:
  63. case SDLK_COMMA:
  64. case SDLK_SPACE:
  65. case SDLK_UNDERSCORE:
  66. case SDLK_MINUS:
  67. input += static_cast<char> (lastKey);
  68. lastResult = NOTHING;
  69. break;
  70. case SDLK_RETURN:
  71. lastResult = ENTERED;
  72. break;
  73. case SDLK_ESCAPE:
  74. lastResult = ESCAPED;
  75. break;
  76. }
  77. return lastResult;
  78. }
  79.  
  80. protected:
  81. static Result lastResult;
  82. static String input;
  83. };
  84.  
  85. if(lastKey == SDLK_RETURN)
  86. lastResult = ENTERED;
  87. else if(lastKey == SDLK_ESCAPE)
  88. lastResult = ESCAPED;
  89. else if(lastKey >= SDLK_SPACE && lastKey <= SDLK_z)
  90. {
  91. input += static_cast<char> (lastKey);
  92. lastResult = NOTHING;
  93. }
Add Comment
Please, Sign In to add comment