The Battle for Wesnoth  1.15.0-dev
text_surface.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 by Chris Beck<render787@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "font_id.hpp" // for text_chunk
18 #include "color.hpp"
19 
20 #include <SDL_ttf.h>
21 
22 #include <string>
23 #include <vector>
24 
25 /***
26  * Note: This is specific to the SDL_TTF codepath.
27  */
28 class surface;
29 
30 namespace font {
31 
33 {
34 public:
35  text_surface(const std::string& str, int size, color_t color, int style);
36  text_surface(int size, color_t color, int style);
37  void set_text(const std::string& str);
38 
39  void measure() const;
40  std::size_t width() const;
41  std::size_t height() const;
42 #ifdef HAVE_FRIBIDI
43  bool is_rtl() const { return is_rtl_; } // Right-To-Left alignment
44 #endif
45  const std::vector<surface>& get_surfaces() const;
46 
47  bool operator==(const text_surface& t) const;
48  bool operator!=(const text_surface& t) const { return !operator==(t); }
49 private:
50  int hash_;
53  int style_;
54  mutable int w_, h_;
56  mutable bool initialized_;
57  mutable std::vector<text_chunk> chunks_;
58  mutable std::vector<surface> surfs_;
59 #ifdef HAVE_FRIBIDI
60  bool is_rtl_;
61  void bidi_cvt();
62 #endif
63  void hash();
64 };
65 
66 } // end namespace font
std::vector< char_t > string
Note: Specific to sdl_ttf.
bool operator!=(const text_surface &t) const
std::vector< text_chunk > chunks_
std::size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
std::size_t width() const
void measure() const
text_surface(const std::string &str, int size, color_t color, int style)
void set_text(const std::string &str)
const std::vector< surface > & get_surfaces() const
std::vector< surface > surfs_
std::size_t height() const
double t
Definition: astarsearch.cpp:64
bool operator==(const text_surface &t) const