ws changes and some cruft removal, slight cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3742 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2002-03-13 13:22:54 +00:00
parent ad6d9e444b
commit dd0277f83d
5 changed files with 99 additions and 102 deletions

View File

@ -1,3 +1,13 @@
2002-03-13 Lars Gullik Bjønnes <larsbj@birdstep.com>
* Painter.C (display): anon helper function, adjust code for this
change.
(pixmap): remove function.
* Painter.h: remove private display variable.
* PainterBase.[Ch]: remove dummy[123] cruft, ws changes
2002-03-13 Angus Leeming <a.leeming@ic.ac.uk> 2002-03-13 Angus Leeming <a.leeming@ic.ac.uk>
* WorkArea.[Ch]: remove figinset_canvas cruft. * WorkArea.[Ch]: remove figinset_canvas cruft.

View File

@ -34,32 +34,42 @@
#include <cmath> #include <cmath>
using std::endl; using std::endl;
using std::max; using std::max;
namespace {
inline
Display * display()
{
return GUIRunTime::x11Display();
}
}
Painter::Painter(WorkArea & wa) Painter::Painter(WorkArea & wa)
: PainterBase(wa) : PainterBase(wa)
{ {}
display = GUIRunTime::x11Display();
}
// Basic drawing routines // Basic drawing routines
PainterBase & Painter::point(int x, int y, LColor::color c) PainterBase & Painter::point(int x, int y, LColor::color c)
{ {
XDrawPoint(display, owner.getPixmap(), XDrawPoint(display(), owner.getPixmap(),
lyxColorHandler->getGCForeground(c), x, y); lyxColorHandler->getGCForeground(c), x, y);
return *this; return *this;
} }
PainterBase & Painter::line(int x1, int y1, int x2, int y2, PainterBase & Painter::line(int x1, int y1, int x2, int y2,
LColor::color col, LColor::color col,
enum line_style ls, enum line_style ls,
enum line_width lw) enum line_width lw)
{ {
XDrawLine(display, owner.getPixmap(), XDrawLine(display(), owner.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col), lyxColorHandler->getGCLinepars(ls, lw, col),
x1, y1, x2, y2); x1, y1, x2, y2);
return *this; return *this;
@ -72,16 +82,16 @@ PainterBase & Painter::lines(int const * xp, int const * yp, int np,
enum line_width lw) enum line_width lw)
{ {
boost::scoped_array<XPoint> points(new XPoint[np]); boost::scoped_array<XPoint> points(new XPoint[np]);
for (int i = 0; i < np; ++i) { for (int i = 0; i < np; ++i) {
points[i].x = xp[i]; points[i].x = xp[i];
points[i].y = yp[i]; points[i].y = yp[i];
} }
XDrawLines(display, owner.getPixmap(), XDrawLines(display(), owner.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col), lyxColorHandler->getGCLinepars(ls, lw, col),
points.get(), np, CoordModeOrigin); points.get(), np, CoordModeOrigin);
return *this; return *this;
} }
@ -91,7 +101,7 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
enum line_style ls, enum line_style ls,
enum line_width lw) enum line_width lw)
{ {
XDrawRectangle(display, owner.getPixmap(), XDrawRectangle(display(), owner.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col), lyxColorHandler->getGCLinepars(ls, lw, col),
x, y, w, h); x, y, w, h);
return *this; return *this;
@ -99,37 +109,37 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h,
PainterBase & Painter::fillRectangle(int x, int y, int w, int h, PainterBase & Painter::fillRectangle(int x, int y, int w, int h,
LColor::color col) LColor::color col)
{ {
XFillRectangle(display, owner.getPixmap(), XFillRectangle(display(), owner.getPixmap(),
lyxColorHandler->getGCForeground(col), x, y, w, h); lyxColorHandler->getGCForeground(col), x, y, w, h);
return *this; return *this;
} }
PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np, PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np,
LColor::color col) LColor::color col)
{ {
boost::scoped_array<XPoint> points(new XPoint[np]); boost::scoped_array<XPoint> points(new XPoint[np]);
for (int i = 0; i < np; ++i) { for (int i = 0; i < np; ++i) {
points[i].x = xp[i]; points[i].x = xp[i];
points[i].y = yp[i]; points[i].y = yp[i];
} }
XFillPolygon(display, owner.getPixmap(), XFillPolygon(display(), owner.getPixmap(),
lyxColorHandler->getGCForeground(col), points.get(), np, lyxColorHandler->getGCForeground(col), points.get(), np,
Nonconvex, CoordModeOrigin); Nonconvex, CoordModeOrigin);
return *this; return *this;
} }
PainterBase & Painter::arc(int x, int y, PainterBase & Painter::arc(int x, int y,
unsigned int w, unsigned int h, unsigned int w, unsigned int h,
int a1, int a2, LColor::color col) int a1, int a2, LColor::color col)
{ {
XDrawArc(display, owner.getPixmap(), XDrawArc(display(), owner.getPixmap(),
lyxColorHandler->getGCForeground(col), lyxColorHandler->getGCForeground(col),
x, y, w, h, a1, a2); x, y, w, h, a1, a2);
return *this; return *this;
@ -138,43 +148,37 @@ PainterBase & Painter::arc(int x, int y,
/// Draw lines from x1,y1 to x2,y2. They are arrays /// Draw lines from x1,y1 to x2,y2. They are arrays
PainterBase & Painter::segments(int const * x1, int const * y1, PainterBase & Painter::segments(int const * x1, int const * y1,
int const * x2, int const * y2, int ns, int const * x2, int const * y2, int ns,
LColor::color col, LColor::color col,
enum line_style ls, enum line_width lw) enum line_style ls, enum line_width lw)
{ {
boost::scoped_array<XSegment> s(new XSegment[ns]); boost::scoped_array<XSegment> s(new XSegment[ns]);
for (int i = 0; i < ns; ++i) { for (int i = 0; i < ns; ++i) {
s[i].x1 = x1[i]; s[i].x1 = x1[i];
s[i].y1 = y1[i]; s[i].y1 = y1[i];
s[i].x2 = x2[i]; s[i].x2 = x2[i];
s[i].y2 = y2[i]; s[i].y2 = y2[i];
} }
XDrawSegments(display, owner.getPixmap(), XDrawSegments(display(), owner.getPixmap(),
lyxColorHandler->getGCLinepars(ls, lw, col), lyxColorHandler->getGCLinepars(ls, lw, col),
s.get(), ns); s.get(), ns);
return *this;
}
PainterBase & Painter::pixmap(int x, int y, int w, int h, Pixmap bitmap)
{
XGCValues val;
val.function = GXcopy;
GC gc = XCreateGC(display, owner.getPixmap(),
GCFunction, &val);
XCopyArea(display, bitmap, owner.getPixmap(), gc,
0, 0, w, h, x, y);
XFreeGC(display, gc);
return *this; return *this;
} }
PainterBase & Painter::image(int x, int y, int w, int h, PainterBase & Painter::image(int x, int y, int w, int h,
grfx::GImage const & image) grfx::GImage const & image)
{ {
return pixmap(x, y, w, h, image.getPixmap()); XGCValues val;
val.function = GXcopy;
GC gc = XCreateGC(display(), owner.getPixmap(),
GCFunction, &val);
XCopyArea(display(), image.getPixmap(), owner.getPixmap(), gc,
0, 0, w, h, x, y);
XFreeGC(display(), gc);
return *this;
} }
@ -192,7 +196,7 @@ PainterBase & Painter::text(int x, int y, char c, LyXFont const & f)
PainterBase & Painter::text(int x, int y, char const * s, size_t ls, PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
LyXFont const & f) LyXFont const & f)
{ {
if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) { if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) {
boost::scoped_array<XChar2b> xs(new XChar2b[ls]); boost::scoped_array<XChar2b> xs(new XChar2b[ls]);
@ -213,11 +217,11 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
text(x , y, xs.get(), ls, font); text(x , y, xs.get(), ls, font);
return *this; return *this;
} }
GC gc = lyxColorHandler->getGCForeground(f.realColor()); GC gc = lyxColorHandler->getGCForeground(f.realColor());
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
lyxfont::XSetFont(display, gc, f); lyxfont::XSetFont(display(), gc, f);
XDrawString(display, owner.getPixmap(), gc, x, y, s, ls); XDrawString(display(), owner.getPixmap(), gc, x, y, s, ls);
} else { } else {
LyXFont smallfont(f); LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
@ -225,19 +229,19 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
for (size_t i = 0; i < ls; ++i) { for (size_t i = 0; i < ls; ++i) {
char const c = uppercase(s[i]); char const c = uppercase(s[i]);
if (c != s[i]) { if (c != s[i]) {
lyxfont::XSetFont(display, gc, smallfont); lyxfont::XSetFont(display(), gc, smallfont);
XDrawString(display, owner.getPixmap(), gc, XDrawString(display(), owner.getPixmap(), gc,
tmpx, y, &c, 1); tmpx, y, &c, 1);
tmpx += lyxfont::XTextWidth(smallfont, &c, 1); tmpx += lyxfont::XTextWidth(smallfont, &c, 1);
} else { } else {
lyxfont::XSetFont(display, gc, f); lyxfont::XSetFont(display(), gc, f);
XDrawString(display, owner.getPixmap(), gc, XDrawString(display(), owner.getPixmap(), gc,
tmpx, y, &c, 1); tmpx, y, &c, 1);
tmpx += lyxfont::XTextWidth(f, &c, 1); tmpx += lyxfont::XTextWidth(f, &c, 1);
} }
} }
} }
if (f.underbar() == LyXFont::ON) { if (f.underbar() == LyXFont::ON) {
underline(f, x, y, lyxfont::width(s, ls, f)); underline(f, x, y, lyxfont::width(s, ls, f));
} }
@ -247,12 +251,12 @@ PainterBase & Painter::text(int x, int y, char const * s, size_t ls,
PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls, PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
LyXFont const & f) LyXFont const & f)
{ {
GC gc = lyxColorHandler->getGCForeground(f.realColor()); GC gc = lyxColorHandler->getGCForeground(f.realColor());
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
lyxfont::XSetFont(display, gc, f); lyxfont::XSetFont(display(), gc, f);
XDrawString16(display, owner.getPixmap(), gc, x, y, s, ls); XDrawString16(display(), owner.getPixmap(), gc, x, y, s, ls);
} else { } else {
LyXFont smallfont(f); LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE); smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
@ -266,13 +270,13 @@ PainterBase & Painter::text(int x, int y, XChar2b const * s, int ls,
c.byte2 = uppercase(s[i].byte2); c.byte2 = uppercase(s[i].byte2);
} }
if (c.byte2 != s[i].byte2) { if (c.byte2 != s[i].byte2) {
lyxfont::XSetFont(display, gc, smallfont); lyxfont::XSetFont(display(), gc, smallfont);
XDrawString16(display, owner.getPixmap(), gc, XDrawString16(display(), owner.getPixmap(), gc,
tmpx, y, &c, 1); tmpx, y, &c, 1);
tmpx += lyxfont::XTextWidth16(smallfont, &c, 1); tmpx += lyxfont::XTextWidth16(smallfont, &c, 1);
} else { } else {
lyxfont::XSetFont(display, gc, f); lyxfont::XSetFont(display(), gc, f);
XDrawString16(display, owner.getPixmap(), gc, XDrawString16(display(), owner.getPixmap(), gc,
tmpx, y, &c, 1); tmpx, y, &c, 1);
tmpx += lyxfont::XTextWidth16(f, &c, 1); tmpx += lyxfont::XTextWidth16(f, &c, 1);
} }

View File

@ -26,7 +26,6 @@ class LyXFont;
class WorkArea; class WorkArea;
/** An inplementation for the X Window System. Xlib. /** An inplementation for the X Window System. Xlib.
Classes similar to this one can be made for gtk+, Qt, etc. Classes similar to this one can be made for gtk+, Qt, etc.
*/ */
class Painter : public PainterBase { class Painter : public PainterBase {
@ -79,9 +78,6 @@ public:
PainterBase & image(int x, int y, int w, int h, PainterBase & image(int x, int y, int w, int h,
grfx::GImage const & image); grfx::GImage const & image);
/// For the figinset
PainterBase & pixmap(int x, int y, int w, int h, Pixmap bitmap);
/// Draw a string at position x, y (y is the baseline) /// Draw a string at position x, y (y is the baseline)
PainterBase & text(int x, int y, PainterBase & text(int x, int y,
string const & str, LyXFont const & f); string const & str, LyXFont const & f);
@ -93,16 +89,13 @@ public:
/// Draw a char at position x, y (y is the baseline) /// Draw a char at position x, y (y is the baseline)
PainterBase & text(int x, int y, char c, LyXFont const & f); PainterBase & text(int x, int y, char c, LyXFont const & f);
/// Draw a wide string at position x, y /// Draw a wide string at position x, y
PainterBase & text(int x, int y, XChar2b const * str, int l, PainterBase & text(int x, int y, XChar2b const * str, int l,
LyXFont const & f); LyXFont const & f);
private: private:
/// Check the font, and if set, draw an underline /// Check the font, and if set, draw an underline
void underline(LyXFont const & f, int x, int y, int width); void underline(LyXFont const & f, int x, int y, int width);
///
Display * display;
}; };
#endif #endif

View File

@ -18,9 +18,6 @@
#include "WorkArea.h" #include "WorkArea.h"
#include "font.h" #include "font.h"
int PainterBase::dummy1 = 0;
int PainterBase::dummy2 = 0;
int PainterBase::dummy3 = 0;
int PainterBase::paperMargin() const int PainterBase::paperMargin() const
{ {
@ -67,23 +64,23 @@ PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
{ {
// Width of a side of the button // Width of a side of the button
int d = 2; int d = 2;
fillRectangle(x, y, w, d, LColor::top); fillRectangle(x, y, w, d, LColor::top);
fillRectangle(x, (y+h-d), w, d, LColor::bottom); fillRectangle(x, (y+h-d), w, d, LColor::bottom);
// Now a couple of trapezoids // Now a couple of trapezoids
int x1[4], y1[4]; int x1[4], y1[4];
x1[0] = x+d; y1[0] = y+d; x1[0] = x + d; y1[0] = y + d;
x1[1] = x+d; y1[1] = (y+h-d); x1[1] = x + d; y1[1] = (y + h - d);
x1[2] = x; y1[2] = y+h; x1[2] = x; y1[2] = y + h;
x1[3] = x; y1[3] = y; x1[3] = x; y1[3] = y;
fillPolygon(x1, y1, 4, LColor::left); fillPolygon(x1, y1, 4, LColor::left);
x1[0] = (x+w-d); y1[0] = y+d; x1[0] = (x + w - d); y1[0] = y + d;
x1[1] = (x+w-d); y1[1] = (y+h-d); x1[1] = (x + w - d); y1[1] = (y + h - d);
x1[2] = x+w; y1[2] = (y+h-d); x1[2] = x + w; y1[2] = (y + h - d);
x1[3] = x+w; y1[3] = y; x1[3] = x + w; y1[3] = y;
fillPolygon(x1, y1, 4, LColor::right); fillPolygon(x1, y1, 4, LColor::right);
return *this; return *this;

View File

@ -36,13 +36,6 @@ namespace grfx {
*/ */
class PainterBase { class PainterBase {
protected:
///
static int dummy1;
///
static int dummy2;
///
static int dummy3;
public: public:
/// ///
enum line_width { enum line_width {
@ -51,7 +44,7 @@ public:
/// ///
line_thick line_thick
}; };
/// ///
enum line_style { enum line_style {
/// ///
@ -61,13 +54,13 @@ public:
/// ///
line_onoffdash line_onoffdash
}; };
/// ///
explicit PainterBase(WorkArea & wa) : owner(wa) {} explicit PainterBase(WorkArea & wa) : owner(wa) {}
/// ///
virtual ~PainterBase() {} virtual ~PainterBase() {}
/* Screen geometry */ /* Screen geometry */
/// ///
int paperMargin() const; int paperMargin() const;
@ -82,7 +75,7 @@ public:
LColor::color = LColor::foreground, LColor::color = LColor::foreground,
enum line_style = line_solid, enum line_style = line_solid,
enum line_width = line_thin) = 0; enum line_width = line_thin) = 0;
/** Draw the lines between the lines in xp and yp. /** Draw the lines between the lines in xp and yp.
xp and yp are arrays of points, and np is the xp and yp are arrays of points, and np is the
number of them. */ number of them. */
@ -91,13 +84,13 @@ public:
LColor::color = LColor::foreground, LColor::color = LColor::foreground,
enum line_style = line_solid, enum line_style = line_solid,
enum line_width = line_thin) = 0; enum line_width = line_thin) = 0;
/// Here xp and yp are arrays of points /// Here xp and yp are arrays of points
virtual PainterBase & fillPolygon( virtual PainterBase & fillPolygon(
int const * xp, int const * yp, int const * xp, int const * yp,
int np, int np,
LColor::color = LColor::foreground) = 0; LColor::color = LColor::foreground) = 0;
/// Draw lines from x1,y1 to x2,y2. They are arrays /// Draw lines from x1,y1 to x2,y2. They are arrays
virtual PainterBase & segments( virtual PainterBase & segments(
int const * x1, int const * y1, int const * x1, int const * y1,
@ -117,7 +110,7 @@ public:
virtual PainterBase & circle( virtual PainterBase & circle(
int x, int y, unsigned int d, int x, int y, unsigned int d,
LColor::color = LColor::foreground); LColor::color = LColor::foreground);
/// Draw an ellipse /// Draw an ellipse
virtual PainterBase & ellipse( virtual PainterBase & ellipse(
int x, int y, int x, int y,
@ -143,7 +136,7 @@ public:
/// A filled rectangle with the shape of a 3D button /// A filled rectangle with the shape of a 3D button
virtual PainterBase & button(int x, int y, int w, int h); virtual PainterBase & button(int x, int y, int w, int h);
/// ///
virtual PainterBase & buttonFrame(int x, int y, int w, int h); virtual PainterBase & buttonFrame(int x, int y, int w, int h);
@ -155,22 +148,22 @@ public:
/// Draw a string at position x, y (y is the baseline) /// Draw a string at position x, y (y is the baseline)
virtual PainterBase & text(int x, int y, virtual PainterBase & text(int x, int y,
string const & str, LyXFont const & f) = 0; string const & str, LyXFont const & f) = 0;
/** Draw a string at position x, y (y is the baseline) /** Draw a string at position x, y (y is the baseline)
This is just for fast drawing */ This is just for fast drawing */
virtual PainterBase & text(int x, int y, char const * str, size_t l, virtual PainterBase & text(int x, int y, char const * str, size_t l,
LyXFont const & f) = 0; LyXFont const & f) = 0;
/// Draw a char at position x, y (y is the baseline) /// Draw a char at position x, y (y is the baseline)
virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0; virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0;
/** Draws a string and encloses it inside a rectangle. */ /** Draws a string and encloses it inside a rectangle. */
PainterBase & rectText(int x, int baseline, PainterBase & rectText(int x, int baseline,
string const & string, string const & string,
LyXFont const & font, LyXFont const & font,
LColor::color back, LColor::color back,
LColor::color frame); LColor::color frame);
/** Draw a string and encloses it inside a button frame. */ /** Draw a string and encloses it inside a button frame. */
PainterBase & buttonText(int x, int baseline, string const & s, PainterBase & buttonText(int x, int baseline, string const & s,
LyXFont const & font); LyXFont const & font);