1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998-2000 The LyX Team
8 *======================================================*/
15 #pragma implementation
18 #include "PainterBase.h"
23 int PainterBase::dummy1 = 0;
24 int PainterBase::dummy2 = 0;
25 int PainterBase::dummy3 = 0;
27 int PainterBase::paperMargin()
33 int PainterBase::paperWidth()
35 return owner.workWidth();
39 int PainterBase::width(string const & s, LyXFont const & f)
41 return f.stringWidth(s);
45 int PainterBase::width(char const * s, int l, LyXFont const & f)
47 return f.textWidth(s, l);
51 int PainterBase::width(char c, LyXFont const & f)
57 PainterBase & PainterBase::circle(int x, int y, unsigned int d,
58 LColor::color col = LColor::foreground)
60 return ellipse(x, y, d, d, col);
64 PainterBase & PainterBase::ellipse(int x, int y,
65 unsigned int w, unsigned int h,
66 LColor::color col = LColor::foreground)
68 return arc(x, y, w, h, 0, 0, col);
72 PainterBase & PainterBase::button(int x, int y, int w, int h)
74 fillRectangle(x, y, w, h, LColor::buttonbg);
75 buttonFrame(x, y, w, h);
80 PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
82 // Width of a side of the button
85 fillRectangle(x, y, w, d, LColor::top);
86 fillRectangle(x, (y+h-d), w, d, LColor::bottom);
88 // Now a couple of trapezoids
91 x1[0] = x+d; y1[0] = y+d;
92 x1[1] = x+d; y1[1] = (y+h-d);
93 x1[2] = x; y1[2] = y+h;
95 fillPolygon(x1, y1, 4, LColor::left);
97 x1[0] = (x+w-d); y1[0] = y+d;
98 x1[1] = (x+w-d); y1[1] = (y+h-d);
99 x1[2] = x+w; y1[2] = (y+h-d);
100 x1[3] = x+w; y1[3] = y;
101 fillPolygon(x1, y1, 4, LColor::right);
107 PainterBase & PainterBase::rectText(int x, int baseline,
109 LyXFont const & font,
111 LColor::color frame, bool draw,
112 int & width, int & ascent, int & descent)
114 static int const d = 2;
115 width = this->width(str, font) + d * 2 + 2;
116 ascent = font.maxAscent() + d;
117 descent = font.maxDescent() + d;
119 if (!draw) return *this;
121 rectangle(x, baseline - ascent, width, ascent + descent, frame);
122 fillRectangle(x + 1, baseline - ascent + 1, width - 1,
123 ascent + descent - 1, back);
124 text(x + d, baseline, str, font);
129 PainterBase & PainterBase::buttonText(int x, int baseline,
131 LyXFont const & font, bool draw,
132 int & width, int & ascent, int & descent)
134 width = this->width(str, font) + 8;
135 ascent = font.maxAscent() + 3;
136 descent = font.maxDescent() + 3;
138 if (!draw) return *this;
140 button(x, baseline - ascent, width, descent + ascent);
141 text(x + 4, baseline, str, font);