]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
Painter and scrollbar API patches
[lyx.git] / src / frontends / Painter.C
1 /**
2  * \file Painter.C
3  * Copyright 1998-2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author unknown
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "Painter.h"
17 #include "lyxfont.h"
18 #include "WorkArea.h"
19 #include "frontends/font_metrics.h"
20  
21 using std::max;
22  
23 Painter & Painter::button(int x, int y, int w, int h)
24 {
25         fillRectangle(x, y, w, h, LColor::buttonbg);
26         buttonFrame(x, y, w, h);
27         return * this;
28 }
29
30
31 Painter & Painter::buttonFrame(int x, int y, int w, int h)
32 {
33         //  Width of a side of the button
34         int const d = 2;
35
36         fillRectangle(x, y, w, d, LColor::top);
37         fillRectangle(x, (y + h - d), w, d, LColor::bottom);
38  
39         // Now a couple of trapezoids
40         int x1[4], y1[4];
41  
42         x1[0] = x + d;   y1[0] = y + d;
43         x1[1] = x + d;   y1[1] = (y + h - d);
44         x1[2] = x;     y1[2] = y + h;
45         x1[3] = x;     y1[3] = y;
46         fillPolygon(x1, y1, 4, LColor::left);
47
48         x1[0] = (x + w - d); y1[0] = y + d;
49         x1[1] = (x + w - d); y1[1] = (y + h - d);
50         x1[2] = x + w; y1[2] = (y + h - d);
51         x1[3] = x + w; y1[3] = y;
52         fillPolygon(x1, y1, 4, LColor::right);
53
54         return *this;
55 }
56
57
58 Painter & Painter::rectText(int x, int baseline, 
59         string const & str, 
60         LyXFont const & font,
61         LColor::color back,
62         LColor::color frame)
63 {
64         int width;
65         int ascent;
66         int descent;
67
68         font_metrics::rectText(str, font, width, ascent, descent);
69  
70         rectangle(x, baseline - ascent, width, ascent + descent, frame);
71         fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
72                       ascent + descent - 1, back);
73         text(x + 3, baseline, str, font);
74         return *this;
75 }
76
77
78 Painter & Painter::buttonText(int x, int baseline,
79         string const & str, 
80         LyXFont const & font)
81 {
82         int width;
83         int ascent;
84         int descent;
85
86         font_metrics::buttonText(str, font, width, ascent, descent);
87  
88         button(x, baseline - ascent, width, descent + ascent);
89         text(x + 4, baseline, str, font);
90         return *this;
91 }
92
93
94 void Painter::underline(LyXFont const & f, int x, int y, int width)
95 {
96         int const below = max(font_metrics::maxDescent(f) / 2, 2);
97         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
98  
99         if (height < 2) {
100                 line(x, y + below, x + width, y + below, f.color());
101         } else {
102                 fillRectangle(x, y + below, width, below + height,
103                               f.color());
104         }
105 }