vertical_stripes.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SuperTux
  2. // Copyright (C) 2020 Grzegorz Przybylski <zwatotem@gmail.com>
  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 "object/vertical_stripes.hpp"
  17. #include "editor/editor.hpp"
  18. #include "math/rect.hpp"
  19. #include "math/rectf.hpp"
  20. #include "supertux/sector.hpp"
  21. #include "video/drawing_context.hpp"
  22. #include "video/surface.hpp"
  23. VerticalStripes::VerticalStripes() :
  24. m_visible(false),
  25. m_layer(LAYER_FOREGROUND1 + 10),
  26. m_left_stripe(0,0,0,0),
  27. m_right_stripe(0,0,0,0)
  28. {
  29. }
  30. VerticalStripes::~VerticalStripes()
  31. {
  32. }
  33. void
  34. VerticalStripes::update(float dt_sec)
  35. {
  36. m_visible = !Editor::is_active();
  37. }
  38. void
  39. VerticalStripes::draw(DrawingContext& context)
  40. {
  41. float screen_width = context.get_width();
  42. float level_width = Sector::get().get_width();
  43. if (m_visible && level_width < screen_width)
  44. {
  45. // Drawing two black stripes at each side of a screen
  46. float screen_height = context.get_height();
  47. float level_height = Sector::get().get_height();
  48. Canvas& canvas = context.get_canvas(DrawingTarget::COLORMAP);
  49. float screen_left = (level_width - screen_width) / 2;
  50. float screen_right = level_width - screen_left;
  51. // Level can still be scrolled vertically!
  52. float rect_top = -screen_height;
  53. float rect_bottom = level_height + screen_height;
  54. Rectf left_stripe = Rectf(screen_left, rect_top, 0, rect_bottom);
  55. Rectf right_stripe = Rectf(level_width, rect_top, screen_right, rect_bottom);
  56. canvas.draw_filled_rect(left_stripe, Color(0,0,0), m_layer);
  57. canvas.draw_filled_rect(right_stripe, Color(0,0,0), m_layer);
  58. }
  59. }
  60. /* EOF */