ShortcutsWindow.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * ShortcutsWindow.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 ShortcutElement : 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. ShortcutElement(std::string id, JsonNode keys, int elem, std::function<void(const std::string & id, const std::string & keyName)> func);
  34. ShortcutElement(std::string group, int elem);
  35. };
  36. class ShortcutsWindow : 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<ShortcutElement>> 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. ShortcutsWindow();
  51. };
  52. class ShortcutsEditWindow : 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. public:
  61. ShortcutsEditWindow(const std::string & id, std::function<void(const std::string & id, const std::string & keyName)> func);
  62. };