slopstates.hpp 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* slopstates.hpp: State machine stuffs.
  2. *
  3. * Copyright (C) 2014: Dalton Nell, Slop Contributors (https://github.com/naelstrof/slop/graphs/contributors).
  4. *
  5. * This file is part of Slop.
  6. *
  7. * Slop is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Slop is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Slop. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef N_SLOPSTATES_H_
  21. #define N_SLOPSTATES_H_
  22. #include "mouse.hpp"
  23. #include "windowhelper.hpp"
  24. #include "slop.hpp"
  25. #ifdef SLOP_LEGACY_MODE
  26. #include "xshaperectangle.hpp"
  27. #else
  28. #include "rectangle.hpp"
  29. #endif
  30. class SlopMemory;
  31. class SlopOptions;
  32. class SlopState {
  33. public:
  34. virtual ~SlopState();
  35. virtual void onEnter( SlopMemory& memory );
  36. virtual void onExit( SlopMemory& memory );
  37. virtual void update( SlopMemory& memory, double dt );
  38. virtual void draw( SlopMemory& memory, glm::mat4 matrix );
  39. };
  40. class SlopStart : SlopState {
  41. private:
  42. bool setStartPos;
  43. glm::vec2 startPos;
  44. public:
  45. virtual void onEnter( SlopMemory& memory );
  46. virtual void update( SlopMemory& memory, double dt );
  47. virtual void draw( SlopMemory& memory, glm::mat4 matrix );
  48. };
  49. class SlopStartDrag : SlopState {
  50. private:
  51. glm::vec2 startPoint;
  52. public:
  53. SlopStartDrag( glm::vec2 point );
  54. virtual void onEnter( SlopMemory& memory );
  55. virtual void update( SlopMemory& memory, double dt );
  56. virtual void draw( SlopMemory& memory, glm::mat4 matrix );
  57. };
  58. class SlopEndDrag : SlopState {
  59. public:
  60. virtual void onEnter( SlopMemory& memory );
  61. };
  62. class SlopMemory {
  63. private:
  64. SlopState* state;
  65. SlopState* nextState;
  66. public:
  67. SlopMemory( SlopOptions* options, Rectangle* rect );
  68. ~SlopMemory();
  69. Window selectedWindow;
  70. bool running;
  71. float tolerance;
  72. bool nodecorations;
  73. Rectangle* rectangle;
  74. void setState( SlopState* state );
  75. void update( double dt );
  76. void draw( glm::mat4& matrix );
  77. };
  78. #endif // N_SLOPSTATES_H_