]> git.lyx.org Git - lyx.git/blob - src/mathed/textpainter.C
Make Helge happy: no more crash on arrow up/down in math macro
[lyx.git] / src / mathed / textpainter.C
1 /**
2  * \file textpainter.C
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 #include "support/std_ostream.h"
15
16
17 TextPainter::TextPainter(int xmax, int ymax)
18         : xmax_(xmax), ymax_(ymax), data_(xmax_ * (ymax_ + 1), ' ')
19 {}
20
21
22 char & TextPainter::at(int x, int y)
23 {
24         return data_[y * xmax_ + x];
25 }
26
27
28 char TextPainter::at(int x, int y) const
29 {
30         return data_[y * xmax_ + x];
31 }
32
33
34 void TextPainter::draw(int x, int y, char const * str)
35 {
36         //cerr << "drawing string '" << str << "' at " << x << ',' << y << endl;
37         for (int i = 0; *str && x + i < xmax_; ++i, ++str)
38                 at(x + i, y) = *str;
39         //show();
40 }
41
42
43 void TextPainter::horizontalLine(int x, int y, int n, char c)
44 {
45         for (int i = 0; i < n && i + x < xmax_; ++i)
46                 at(x + i, y) = c;
47 }
48
49
50 void TextPainter::verticalLine(int x, int y, int n, char c)
51 {
52         for (int i = 0; i < n && i + y < ymax_; ++i)
53                 at(x, y + i) = c;
54 }
55
56
57 void TextPainter::draw(int x, int y, char c)
58 {
59         //cerr << "drawing char '" << c << "' at " << x << ',' << y << endl;
60         at(x, y) = c;
61         //show();
62 }
63
64
65 void TextPainter::show(std::ostream & os, int offset) const
66 {
67         os << '\n';
68         for (int j = 0; j <= ymax_; ++j) {
69                 for (int i = 0; i < offset; ++i)
70                         os << ' ';
71                 for (int i = 0; i < xmax_; ++i)
72                         os << at(i, j);
73                 os << '\n';
74         }
75 }