KeyBindingsWindow.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * KeyBindingsWindow.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../CWindowObject.h"
  12. #include "../../../lib/json/JsonNode.h"
  13. #include "../../../lib/texts/MetaString.h"
  14. class CFilledTexture;
  15. class CButton;
  16. class CLabel;
  17. class TransparentFilledRectangle;
  18. class CSlider;
  19. class CTextBox;
  20. const int MAX_LINES = 11;
  21. const int LINE_HEIGHT = 30;
  22. class KeyBindingElement : public CIntObject
  23. {
  24. private:
  25. std::shared_ptr<CButton> buttonEdit;
  26. std::shared_ptr<CLabel> labelName;
  27. std::shared_ptr<CLabel> labelKeys;
  28. std::shared_ptr<TransparentFilledRectangle> seperationLine; // rectangle is cleaner than line...
  29. MetaString popupText;
  30. std::function<void(const std::string & id, const std::string & keyName)> func;
  31. void showPopupWindow(const Point & cursorPosition) override;
  32. public:
  33. KeyBindingElement(std::string id, JsonNode keys, int elem, std::function<void(const std::string & id, const std::string & keyName)> func);
  34. KeyBindingElement(std::string group, int elem);
  35. };
  36. class KeyBindingsWindow : public CWindowObject
  37. {
  38. private:
  39. std::shared_ptr<CFilledTexture> backgroundTexture;
  40. std::shared_ptr<CButton> buttonOk;
  41. std::shared_ptr<CLabel> labelTitle;
  42. std::shared_ptr<TransparentFilledRectangle> backgroundRect;
  43. std::shared_ptr<CSlider> slider;
  44. std::vector<std::shared_ptr<KeyBindingElement>> listElements;
  45. std::shared_ptr<CButton> buttonReset;
  46. void fillList(int start);
  47. void setKeyBinding(const std::string & id, const std::string & group, const std::string & keyName, bool append);
  48. void resetKeyBinding();
  49. public:
  50. KeyBindingsWindow();
  51. };
  52. class KeyBindingsEditWindow : public CWindowObject
  53. {
  54. private:
  55. std::shared_ptr<CFilledTexture> backgroundTexture;
  56. std::shared_ptr<CTextBox> text;
  57. std::string id;
  58. std::function<void(const std::string & id, const std::string & keyName)> func;
  59. void keyReleased(const std::string & keyName) override;
  60. void notFocusedClick() override;
  61. public:
  62. KeyBindingsEditWindow(const std::string & id, std::function<void(const std::string & id, const std::string & keyName)> func);
  63. };