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