]> git.tdb.fi Git - libs/gltk.git/blob - source/text.h
0e1afaebd198b3230736d38bf1c198b7cc4dc25c
[libs/gltk.git] / source / text.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2009-2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_TEXT_H_
9 #define MSP_GLTK_TEXT_H_
10
11 #include <string>
12 #include <vector>
13
14 namespace Msp {
15 namespace GLtk {
16
17 class Geometry;
18 class Part;
19 class Style;
20
21 /**
22 Stores and renders text.  Supports multiline text.
23 */
24 class Text
25 {
26 private:
27         struct Line
28         {
29                 unsigned start;
30                 unsigned length;
31                 unsigned width;
32         };
33
34         const Style *style;
35         std::string text;
36         std::vector<Line> lines;
37
38 public:
39         Text();
40         Text(const Style &, const std::string &);
41
42         void set_style(const Style *);
43
44         unsigned get_width() const;
45         unsigned get_height() const;
46
47         void set(const std::string &);
48         void erase(unsigned, unsigned);
49         void insert(unsigned, const std::string &);
50         const std::string &get() const { return text; }
51         unsigned size() const { return text.size(); }
52         unsigned get_n_lines() const { return lines.size(); }
53         unsigned get_line_length(unsigned) const;
54         void offset_to_coords(unsigned, unsigned &, unsigned &) const;
55         unsigned coords_to_offset(unsigned, unsigned) const;
56         Geometry coords_to_geometry(unsigned, unsigned) const;
57
58         void render(const Part &, const Geometry &) const;
59
60         Text &operator=(const std::string &);
61 private:
62         void find_lines();
63 };
64
65 } // namespace GLtk
66 } // namespace Msp
67
68 #endif