]> git.tdb.fi Git - libs/gltk.git/blob - source/text.h
Add a VSlider to multiline Entries
[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         struct RenderData;
35         struct CoordsToGeomData;
36
37         const Style *style;
38         std::string text;
39         std::vector<Line> lines;
40
41 public:
42         Text();
43         Text(const Style &, const std::string &);
44
45         void set_style(const Style *);
46
47         unsigned get_width() const;
48         unsigned get_height() const;
49
50         void set(const std::string &);
51         void erase(unsigned, unsigned);
52         void insert(unsigned, const std::string &);
53         const std::string &get() const { return text; }
54         unsigned size() const { return text.size(); }
55         unsigned get_n_lines() const { return lines.size(); }
56         unsigned get_line_length(unsigned) const;
57         void offset_to_coords(unsigned, unsigned &, unsigned &) const;
58         unsigned coords_to_offset(unsigned, unsigned) const;
59         Geometry coords_to_geometry(const Part &, const Geometry &, unsigned, unsigned, unsigned) const;
60
61         void render(const Part &, const Geometry &, unsigned = 0) const;
62
63         Text &operator=(const std::string &);
64 private:
65         void find_lines();
66
67         template<typename T, void (Text::*)(unsigned, const Geometry &, T &) const>
68         void process_lines(const Part &, const Geometry &, unsigned, T &) const;
69
70         void render_line(unsigned, const Geometry &, RenderData &) const;
71         void coords_to_geom_line(unsigned, const Geometry &, CoordsToGeomData &) const;
72 };
73
74 } // namespace GLtk
75 } // namespace Msp
76
77 #endif