💿🐜 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.

88 lines
2.5 KiB

  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 "screen-transition.hpp"
  20. #include "render/material-flags.hpp"
  21. #include <functional>
  22. screen_transition::screen_transition()
  23. {
  24. // Setup material
  25. material.set_flags(MATERIAL_FLAG_TRANSLUCENT | MATERIAL_FLAG_X_RAY);
  26. progress = material.add_property<float>("progress");
  27. // Setup billboard
  28. billboard.set_material(&material);
  29. billboard.set_active(false);
  30. // Add single channel to transition animation
  31. channel = animation.add_channel(0);
  32. // Setup animation start callback to show transition billboard
  33. animation.set_start_callback
  34. (
  35. std::bind(&scene::object_base::set_active, &billboard, true)
  36. );
  37. // Setup animation end callback to hide transition billboard
  38. animation.set_end_callback
  39. (
  40. std::bind(&scene::object_base::set_active, &billboard, false)
  41. );
  42. // Setup animation frame callback to update transition progress material property
  43. animation.set_frame_callback
  44. (
  45. [this](int channel, float progress)
  46. {
  47. this->progress->set_value(progress);
  48. }
  49. );
  50. // Setup animation frame callback to update transition progress material property
  51. animation.set_frame_callback
  52. (
  53. [this](int channel, float progress)
  54. {
  55. this->progress->set_value(progress);
  56. }
  57. );
  58. }
  59. void screen_transition::transition(float duration, bool reverse, ::animation<float>::interpolator_type interpolator)
  60. {
  61. float initial_state = (reverse) ? 1.0f : 0.0f;
  62. float final_state = (reverse) ? 0.0f : 1.0f;
  63. // Build transition animation
  64. channel->remove_keyframes();
  65. channel->insert_keyframe({0.0f, initial_state});
  66. channel->insert_keyframe({duration, final_state});
  67. // Set transition animation interpolator
  68. animation.set_interpolator(interpolator);
  69. // Update tweens
  70. progress->set_value(initial_state);
  71. material.update_tweens();
  72. // Reset and play transition animation
  73. animation.stop();
  74. animation.play();
  75. }