slopstates.hpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "keyboard.hpp"
  24. #include "slop.hpp"
  25. #include "rectangle.hpp"
  26. namespace slop {
  27. class SlopMemory;
  28. class SlopOptions;
  29. class SlopState {
  30. public:
  31. virtual ~SlopState();
  32. virtual void onEnter( SlopMemory& memory );
  33. virtual void onExit( SlopMemory& memory );
  34. virtual void update( SlopMemory& memory, double dt );
  35. virtual void draw( SlopMemory& memory, glm::mat4 matrix );
  36. };
  37. class SlopStart : SlopState {
  38. private:
  39. bool setStartPos;
  40. glm::vec2 startPos;
  41. public:
  42. virtual void onEnter( SlopMemory& memory );
  43. virtual void update( SlopMemory& memory, double dt );
  44. virtual void draw( SlopMemory& memory, glm::mat4 matrix );
  45. };
  46. class SlopStartDrag : SlopState {
  47. private:
  48. glm::vec2 startPoint;
  49. float repeatTimer;
  50. float multiplier;
  51. public:
  52. SlopStartDrag( glm::vec2 point );
  53. virtual void onEnter( SlopMemory& memory );
  54. virtual void update( SlopMemory& memory, double dt );
  55. virtual void draw( SlopMemory& memory, glm::mat4 matrix );
  56. };
  57. class SlopEndDrag : SlopState {
  58. public:
  59. virtual void onEnter( SlopMemory& memory );
  60. };
  61. class SlopMemory {
  62. private:
  63. SlopState* state;
  64. SlopState* nextState;
  65. public:
  66. SlopMemory( SlopOptions* options, Rectangle* rect );
  67. ~SlopMemory();
  68. Window selectedWindow;
  69. bool running;
  70. float tolerance;
  71. bool nodecorations;
  72. Rectangle* rectangle;
  73. void setState( SlopState* state );
  74. void update( double dt );
  75. void draw( glm::mat4& matrix );
  76. };
  77. }
  78. #endif // N_SLOPSTATES_H_