info_box_line.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef HEADER_SUPERTUX_SUPERTUX_INFO_BOX_LINE_HPP
  17. #define HEADER_SUPERTUX_SUPERTUX_INFO_BOX_LINE_HPP
  18. #include <string>
  19. #include <vector>
  20. #include <memory>
  21. #include "video/color.hpp"
  22. #include "video/font_ptr.hpp"
  23. #include "video/surface_ptr.hpp"
  24. class DrawingContext;
  25. class Rectf;
  26. /**
  27. * Helper class for InfoBox: Represents a line of text
  28. */
  29. class InfoBoxLine final
  30. {
  31. public:
  32. enum LineType { NORMAL, NORMAL_LEFT, SMALL, HEADING, REFERENCE, IMAGE};
  33. enum LineAlignment { LEFT, CENTER, RIGHT };
  34. InfoBoxLine(char format_char, const std::string& text);
  35. void draw(DrawingContext& context, const Rectf& bbox, int layer, LineAlignment alignment = CENTER);
  36. float get_height() const;
  37. static std::vector<std::unique_ptr<InfoBoxLine> > split(const std::string& text, float width);
  38. static bool is_valid_format_char(char format_char)
  39. {
  40. switch (format_char)
  41. {
  42. case ' ':
  43. case '-':
  44. case '*':
  45. case '\t':
  46. case '#':
  47. case '!':
  48. return true;
  49. default:
  50. return false;
  51. }
  52. }
  53. private:
  54. InfoBoxLine::LineType lineType;
  55. FontPtr font;
  56. Color color;
  57. std::string text;
  58. SurfacePtr image;
  59. private:
  60. InfoBoxLine(const InfoBoxLine&) = delete;
  61. InfoBoxLine& operator=(const InfoBoxLine&) = delete;
  62. };
  63. #endif
  64. /* EOF */