]> git.lyx.org Git - lyx.git/blob - src/mathed/textpainter.C
fix #1073
[lyx.git] / src / mathed / textpainter.C
1
2 #include "textpainter.h"
3 #include "support/LOstream.h"
4
5
6 TextPainter::TextPainter(int xmax, int ymax)
7         : xmax_(xmax), ymax_(ymax), data_(xmax_ * (ymax_ + 1), ' ')
8 {}
9
10
11 char & TextPainter::at(int x, int y)
12 {
13         return data_[y * xmax_ + x];
14 }
15
16
17 char TextPainter::at(int x, int y) const
18 {
19         return data_[y * xmax_ + x];
20 }
21
22
23 void TextPainter::draw(int x, int y, char const * str)
24 {
25         //cerr << "drawing string '" << str << "' at " << x << ',' << y << endl;
26         for (int i = 0; *str && x + i < xmax_; ++i, ++str)
27                 at(x + i, y) = *str;
28         //show();
29 }
30
31
32 void TextPainter::horizontalLine(int x, int y, int n, char c)
33 {
34         for (int i = 0; i < n && i + x < xmax_; ++i)
35                 at(x + i, y) = c;
36 }
37
38
39 void TextPainter::verticalLine(int x, int y, int n, char c)
40 {
41         for (int i = 0; i < n && i + y < ymax_; ++i)
42                 at(x, y + i) = c;
43 }
44
45
46 void TextPainter::draw(int x, int y, char c)
47 {
48         //cerr << "drawing char '" << c << "' at " << x << ',' << y << endl;
49         at(x, y) = c;
50         //show();
51 }
52
53
54 void TextPainter::show(std::ostream & os, int offset) const
55 {
56         os << '\n';
57         for (int j = 0; j <= ymax_; ++j) {
58                 for (int i = 0; i < offset; ++i)
59                         os << ' ';
60                 for (int i = 0; i < xmax_; ++i)
61                         os << at(i, j);
62                 os << '\n';
63         }
64 }