]> git.lyx.org Git - lyx.git/blob - src/mathed/math_sqrtinset.C
mathed34.diff
[lyx.git] / src / mathed / math_sqrtinset.C
1 #include <config.h>
2
3 #include "math_sqrtinset.h"
4 #include "math_iter.h"
5 #include "LColor.h"
6 #include "Painter.h"
7 #include "support.h"
8 #include "support/LOstream.h"
9
10 using std::ostream;
11
12 MathSqrtInset::MathSqrtInset(short st)
13         : MathParInset(st, "sqrt", LM_OT_SQRT) {}
14
15
16 MathedInset * MathSqrtInset::Clone()
17 {   
18         return new MathSqrtInset(*this);
19 }
20
21
22 bool MathSqrtInset::Inside(int x, int y) 
23 {
24         return x >= xo() - hmax_
25                 && x <= xo() + width - hmax_
26                 && y <= yo() + descent
27                 && y >= yo() - ascent;
28 }
29
30
31 void
32 MathSqrtInset::draw(Painter & pain, int x, int y)
33
34         MathParInset::draw(pain, x + hmax_ + 2, y); 
35         int const h = ascent;
36         int const d = descent;
37         int const h2 = Height() / 2;
38         int const w2 = (Height() > 4 * hmax_) ? hmax_ : hmax_ / 2; 
39         int xp[4];
40         int yp[4];
41         xp[0] = x + hmax_ + wbody_; yp[0] = y - h;
42         xp[1] = x + hmax_;          yp[1] = y - h;
43         xp[2] = x + w2;             yp[2] = y + d;
44         xp[3] = x;                  yp[3] = y + d - h2;
45         pain.lines(xp, yp, 4, LColor::mathline);
46 }
47
48
49 void
50 MathSqrtInset::Metrics()
51 {
52         MathParInset::Metrics();
53         ascent += 4;
54         descent += 2;
55         int a;
56         int b;
57         hmax_ = mathed_char_height(LM_TC_VAR, size(), 'I', a, b);
58         if (hmax_ < 10) hmax_ = 10;
59         wbody_ = width + 4;
60         width += hmax_ + 4;
61 }
62
63
64 void MathSqrtInset::Write(ostream & os, bool fragile)
65 {
66         os << '\\' << name << '{';
67         MathParInset::Write(os, fragile); 
68         os << '}';
69 }