slopstates.hpp 2.3KB

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