]> git.lyx.org Git - lyx.git/blob - src/PainterBase.C
Fix the line-delete-forward bug?
[lyx.git] / src / PainterBase.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998-2000 The LyX Team
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "PainterBase.h"
17 #include "lyxfont.h"
18 #include "WorkArea.h"
19 #include "font.h"
20
21 int PainterBase::dummy1 = 0;
22 int PainterBase::dummy2 = 0;
23 int PainterBase::dummy3 = 0;
24
25 int PainterBase::paperMargin() const
26 {
27         return 20;
28 }
29
30
31 int PainterBase::paperWidth() const
32 {
33         return owner.workWidth();
34 }
35
36
37 PainterBase & PainterBase::circle(int x, int y, unsigned int d,
38                                   LColor::color col)
39 {
40         return ellipse(x, y, d, d, col);
41 }
42
43
44 PainterBase & PainterBase::ellipse(int x, int y,
45                                    unsigned int w, unsigned int h,
46                                    LColor::color col)
47 {
48         return arc(x, y, w, h, 0, 0, col);
49 }
50
51
52 PainterBase & PainterBase::button(int x, int y, int w, int h)
53 {
54         fillRectangle(x, y, w, h, LColor::buttonbg);
55         buttonFrame(x, y, w, h);
56         return * this;
57 }
58
59
60 PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
61 {
62         //  Width of a side of the button
63         int d = 2;
64
65         fillRectangle(x, y, w, d, LColor::top);
66         fillRectangle(x, (y+h-d), w, d, LColor::bottom);
67  
68         // Now a couple of trapezoids
69         int x1[4], y1[4];
70  
71         x1[0] = x+d;   y1[0] = y+d;
72         x1[1] = x+d;   y1[1] = (y+h-d);
73         x1[2] = x;     y1[2] = y+h;
74         x1[3] = x;     y1[3] = y;
75         fillPolygon(x1, y1, 4, LColor::left);
76
77         x1[0] = (x+w-d); y1[0] = y+d;
78         x1[1] = (x+w-d); y1[1] = (y+h-d);
79         x1[2] = x+w; y1[2] = (y+h-d);
80         x1[3] = x+w; y1[3] = y;
81         fillPolygon(x1, y1, 4, LColor::right);
82
83         return *this;
84 }
85
86
87 PainterBase & PainterBase::rectText(int x, int baseline, 
88                                     string const & str, 
89                                     LyXFont const & font,
90                                     LColor::color back,
91                                     LColor::color frame, bool draw,
92                                     int & width, int & ascent, int & descent)
93 {
94         static int const d = 2;
95         width = lyxfont::width(str, font) + d * 2 + 2;
96         ascent = lyxfont::maxAscent(font) + d;
97         descent = lyxfont::maxDescent(font) + d;
98
99         if (!draw) return *this;
100
101         rectangle(x, baseline - ascent, width, ascent + descent, frame);
102         fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
103                       ascent + descent - 1, back);
104         text(x + d, baseline, str, font);
105         return *this;
106 }
107
108
109 PainterBase & PainterBase::buttonText(int x, int baseline,
110                                       string const & str, 
111                                       LyXFont const & font, bool draw,
112                                       int & width, int & ascent, int & descent)
113 {
114         width = lyxfont::width(str, font) + 8;
115         ascent = lyxfont::maxAscent(font) + 3;
116         descent = lyxfont::maxDescent(font) + 3;
117
118         if (!draw) return *this;
119
120         button(x, baseline - ascent, width, descent + ascent);
121         text(x + 4, baseline, str, font);
122         return *this;
123 }