]> git.lyx.org Git - lyx.git/blob - src/mathed/TextPainter.cpp
6811c40af25d8c1872f1ba40f82f7c7e9cb62f8f
[lyx.git] / src / mathed / TextPainter.cpp
1 /**
2  * \file TextPainter.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "TextPainter.h"
14
15 #include <ostream>
16
17
18 namespace lyx {
19
20
21 TextPainter::TextPainter(int xmax, int ymax)
22         : xmax_(xmax), ymax_(ymax), data_(xmax_ * (ymax_ + 1), ' ')
23 {}
24
25
26 char_type & TextPainter::at(int x, int y)
27 {
28         return data_[y * xmax_ + x];
29 }
30
31
32 char_type TextPainter::at(int x, int y) const
33 {
34         return data_[y * xmax_ + x];
35 }
36
37
38 void TextPainter::draw(int x, int y, char_type const * str)
39 {
40         //cerr << "drawing string '" << str << "' at " << x << ',' << y << endl;
41         for (int i = 0; *str && x + i < xmax_; ++i, ++str)
42                 at(x + i, y) = *str;
43         //show();
44 }
45
46
47 void TextPainter::horizontalLine(int x, int y, int n, char_type c)
48 {
49         for (int i = 0; i < n && i + x < xmax_; ++i)
50                 at(x + i, y) = c;
51 }
52
53
54 void TextPainter::verticalLine(int x, int y, int n, char_type c)
55 {
56         for (int i = 0; i < n && i + y < ymax_; ++i)
57                 at(x, y + i) = c;
58 }
59
60
61 void TextPainter::draw(int x, int y, char_type c)
62 {
63         //cerr << "drawing char '" << c << "' at " << x << ',' << y << endl;
64         at(x, y) = c;
65         //show();
66 }
67
68
69 void TextPainter::show(odocstream & os, int offset) const
70 {
71         os << '\n';
72         for (int j = 0; j <= ymax_; ++j) {
73                 for (int i = 0; i < offset; ++i)
74                         os << ' ';
75                 for (int i = 0; i < xmax_; ++i)
76                         os << at(i, j);
77                 os << '\n';
78         }
79 }
80
81
82 } // namespace lyx