💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
1.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "animation.hpp"
  20. animation_base::animation_base():
  21. looped(false),
  22. loop_count(0),
  23. paused(false),
  24. stopped(true),
  25. position(0.0),
  26. speed(1.0),
  27. start_callback(nullptr),
  28. end_callback(nullptr),
  29. loop_callback(nullptr)
  30. {}
  31. void animation_base::seek(double t)
  32. {
  33. position = t;
  34. }
  35. void animation_base::rewind()
  36. {
  37. seek(0.0);
  38. }
  39. void animation_base::loop(bool enabled)
  40. {
  41. looped = enabled;
  42. }
  43. void animation_base::pause()
  44. {
  45. paused = true;
  46. }
  47. void animation_base::play()
  48. {
  49. if (stopped)
  50. {
  51. stopped = false;
  52. if (start_callback)
  53. {
  54. start_callback();
  55. }
  56. }
  57. paused = false;
  58. }
  59. void animation_base::stop()
  60. {
  61. rewind();
  62. stopped = true;
  63. paused = false;
  64. loop_count = 0;
  65. }
  66. void animation_base::set_speed(double speed)
  67. {
  68. this->speed = speed;
  69. }
  70. void animation_base::set_start_callback(std::function<void()> callback)
  71. {
  72. start_callback = callback;
  73. }
  74. void animation_base::set_end_callback(std::function<void()> callback)
  75. {
  76. end_callback = callback;
  77. }
  78. void animation_base::set_loop_callback(std::function<void(int)> callback)
  79. {
  80. loop_callback = callback;
  81. }