shrinkfade.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "supertux/shrinkfade.hpp"
  17. #include "supertux/globals.hpp"
  18. #include "video/drawing_context.hpp"
  19. #include "video/video_system.hpp"
  20. #include "video/viewport.hpp"
  21. ShrinkFade::ShrinkFade(const Vector& dest, float fade_time, int draw_layer, Direction direction) :
  22. m_draw_layer(draw_layer),
  23. m_dest(dest),
  24. m_fade_time(fade_time),
  25. m_accum_time(0),
  26. m_initial_size(static_cast<float>(SCREEN_HEIGHT > SCREEN_WIDTH ? SCREEN_HEIGHT : SCREEN_WIDTH)),
  27. m_direction(direction)
  28. {
  29. }
  30. void
  31. ShrinkFade::update(float dt_sec)
  32. {
  33. m_accum_time += dt_sec;
  34. if (m_accum_time > m_fade_time)
  35. m_accum_time = m_fade_time;
  36. }
  37. void
  38. ShrinkFade::draw(DrawingContext& context)
  39. {
  40. float progress = m_accum_time / m_fade_time;
  41. float diameter = 2 * m_initial_size * (m_direction == FADEOUT ? (1.0f - progress) : progress);
  42. context.color().draw_inverse_ellipse(m_dest, Vector(1.1f * diameter, diameter),
  43. Color(0, 0, 0), m_draw_layer);
  44. }
  45. bool
  46. ShrinkFade::done() const
  47. {
  48. return m_accum_time >= m_fade_time;
  49. }
  50. /* EOF */