From dd0277f83dafec2937d9bba30b36169ca1aa1677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Wed, 13 Mar 2002 13:22:54 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 10 ++++ src/Painter.C | 124 ++++++++++++++++++++++++---------------------- src/Painter.h | 11 +--- src/PainterBase.C | 23 ++++----- src/PainterBase.h | 33 +++++------- 5 files changed, 99 insertions(+), 102 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 98a298caff..7576954914 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2002-03-13 Lars Gullik Bjønnes + + * 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 * WorkArea.[Ch]: remove figinset_canvas cruft. diff --git a/src/Painter.C b/src/Painter.C index db10023d73..e3a83a6e77 100644 --- a/src/Painter.C +++ b/src/Painter.C @@ -34,32 +34,42 @@ #include + using std::endl; using std::max; +namespace { + +inline +Display * display() +{ + return GUIRunTime::x11Display(); +} + +} + + Painter::Painter(WorkArea & wa) : PainterBase(wa) -{ - display = GUIRunTime::x11Display(); -} +{} // Basic drawing routines PainterBase & Painter::point(int x, int y, LColor::color c) { - XDrawPoint(display, owner.getPixmap(), + XDrawPoint(display(), owner.getPixmap(), lyxColorHandler->getGCForeground(c), x, y); return *this; } PainterBase & Painter::line(int x1, int y1, int x2, int y2, - LColor::color col, - enum line_style ls, - enum line_width lw) + LColor::color col, + enum line_style ls, + enum line_width lw) { - XDrawLine(display, owner.getPixmap(), + XDrawLine(display(), owner.getPixmap(), lyxColorHandler->getGCLinepars(ls, lw, col), x1, y1, x2, y2); return *this; @@ -72,16 +82,16 @@ PainterBase & Painter::lines(int const * xp, int const * yp, int np, enum line_width lw) { boost::scoped_array points(new XPoint[np]); - + for (int i = 0; i < np; ++i) { points[i].x = xp[i]; points[i].y = yp[i]; } - - XDrawLines(display, owner.getPixmap(), + + XDrawLines(display(), owner.getPixmap(), lyxColorHandler->getGCLinepars(ls, lw, col), points.get(), np, CoordModeOrigin); - + return *this; } @@ -91,7 +101,7 @@ PainterBase & Painter::rectangle(int x, int y, int w, int h, enum line_style ls, enum line_width lw) { - XDrawRectangle(display, owner.getPixmap(), + XDrawRectangle(display(), owner.getPixmap(), lyxColorHandler->getGCLinepars(ls, lw, col), x, y, w, h); 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, - LColor::color col) + LColor::color col) { - XFillRectangle(display, owner.getPixmap(), + XFillRectangle(display(), owner.getPixmap(), lyxColorHandler->getGCForeground(col), x, y, w, h); return *this; } PainterBase & Painter::fillPolygon(int const * xp, int const * yp, int np, - LColor::color col) + LColor::color col) { boost::scoped_array points(new XPoint[np]); - + for (int i = 0; i < np; ++i) { points[i].x = xp[i]; points[i].y = yp[i]; } - - XFillPolygon(display, owner.getPixmap(), + + XFillPolygon(display(), owner.getPixmap(), lyxColorHandler->getGCForeground(col), points.get(), np, Nonconvex, CoordModeOrigin); - + return *this; } PainterBase & Painter::arc(int x, int y, - unsigned int w, unsigned int h, - int a1, int a2, LColor::color col) + unsigned int w, unsigned int h, + int a1, int a2, LColor::color col) { - XDrawArc(display, owner.getPixmap(), + XDrawArc(display(), owner.getPixmap(), lyxColorHandler->getGCForeground(col), x, y, w, h, a1, a2); return *this; @@ -138,43 +148,37 @@ PainterBase & Painter::arc(int x, int y, /// Draw lines from x1,y1 to x2,y2. They are arrays PainterBase & Painter::segments(int const * x1, int const * y1, - int const * x2, int const * y2, int ns, - LColor::color col, - enum line_style ls, enum line_width lw) + int const * x2, int const * y2, int ns, + LColor::color col, + enum line_style ls, enum line_width lw) { boost::scoped_array s(new XSegment[ns]); - + for (int i = 0; i < ns; ++i) { s[i].x1 = x1[i]; s[i].y1 = y1[i]; s[i].x2 = x2[i]; s[i].y2 = y2[i]; } - XDrawSegments(display, owner.getPixmap(), + XDrawSegments(display(), owner.getPixmap(), lyxColorHandler->getGCLinepars(ls, lw, col), 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; } 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, - LyXFont const & f) + LyXFont const & f) { if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) { boost::scoped_array 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); return *this; } - + GC gc = lyxColorHandler->getGCForeground(f.realColor()); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { - lyxfont::XSetFont(display, gc, f); - XDrawString(display, owner.getPixmap(), gc, x, y, s, ls); + lyxfont::XSetFont(display(), gc, f); + XDrawString(display(), owner.getPixmap(), gc, x, y, s, ls); } else { LyXFont smallfont(f); 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) { char const c = uppercase(s[i]); if (c != s[i]) { - lyxfont::XSetFont(display, gc, smallfont); - XDrawString(display, owner.getPixmap(), gc, + lyxfont::XSetFont(display(), gc, smallfont); + XDrawString(display(), owner.getPixmap(), gc, tmpx, y, &c, 1); tmpx += lyxfont::XTextWidth(smallfont, &c, 1); } else { - lyxfont::XSetFont(display, gc, f); - XDrawString(display, owner.getPixmap(), gc, + lyxfont::XSetFont(display(), gc, f); + XDrawString(display(), owner.getPixmap(), gc, tmpx, y, &c, 1); tmpx += lyxfont::XTextWidth(f, &c, 1); } } } - + if (f.underbar() == LyXFont::ON) { 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, - LyXFont const & f) + LyXFont const & f) { GC gc = lyxColorHandler->getGCForeground(f.realColor()); if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { - lyxfont::XSetFont(display, gc, f); - XDrawString16(display, owner.getPixmap(), gc, x, y, s, ls); + lyxfont::XSetFont(display(), gc, f); + XDrawString16(display(), owner.getPixmap(), gc, x, y, s, ls); } else { LyXFont smallfont(f); 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); } if (c.byte2 != s[i].byte2) { - lyxfont::XSetFont(display, gc, smallfont); - XDrawString16(display, owner.getPixmap(), gc, + lyxfont::XSetFont(display(), gc, smallfont); + XDrawString16(display(), owner.getPixmap(), gc, tmpx, y, &c, 1); tmpx += lyxfont::XTextWidth16(smallfont, &c, 1); } else { - lyxfont::XSetFont(display, gc, f); - XDrawString16(display, owner.getPixmap(), gc, + lyxfont::XSetFont(display(), gc, f); + XDrawString16(display(), owner.getPixmap(), gc, tmpx, y, &c, 1); tmpx += lyxfont::XTextWidth16(f, &c, 1); } diff --git a/src/Painter.h b/src/Painter.h index f020d53313..6f33849815 100644 --- a/src/Painter.h +++ b/src/Painter.h @@ -26,7 +26,6 @@ class LyXFont; class WorkArea; /** An inplementation for the X Window System. Xlib. - Classes similar to this one can be made for gtk+, Qt, etc. */ class Painter : public PainterBase { @@ -79,9 +78,6 @@ public: PainterBase & image(int x, int y, int w, int h, 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) PainterBase & text(int x, int y, string const & str, LyXFont const & f); @@ -93,16 +89,13 @@ public: /// Draw a char at position x, y (y is the baseline) PainterBase & text(int x, int y, char c, LyXFont const & f); - + /// Draw a wide string at position x, y PainterBase & text(int x, int y, XChar2b const * str, int l, - LyXFont const & f); + LyXFont const & f); private: /// Check the font, and if set, draw an underline void underline(LyXFont const & f, int x, int y, int width); - - /// - Display * display; }; #endif diff --git a/src/PainterBase.C b/src/PainterBase.C index 1c5e21473f..ba7c818121 100644 --- a/src/PainterBase.C +++ b/src/PainterBase.C @@ -18,9 +18,6 @@ #include "WorkArea.h" #include "font.h" -int PainterBase::dummy1 = 0; -int PainterBase::dummy2 = 0; -int PainterBase::dummy3 = 0; 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 int d = 2; - + fillRectangle(x, y, w, d, LColor::top); fillRectangle(x, (y+h-d), w, d, LColor::bottom); - + // Now a couple of trapezoids int x1[4], y1[4]; - - x1[0] = x+d; y1[0] = y+d; - x1[1] = x+d; y1[1] = (y+h-d); - x1[2] = x; y1[2] = y+h; + + x1[0] = x + d; y1[0] = y + d; + x1[1] = x + d; y1[1] = (y + h - d); + x1[2] = x; y1[2] = y + h; x1[3] = x; y1[3] = y; fillPolygon(x1, y1, 4, LColor::left); - x1[0] = (x+w-d); y1[0] = y+d; - x1[1] = (x+w-d); y1[1] = (y+h-d); - x1[2] = x+w; y1[2] = (y+h-d); - x1[3] = x+w; y1[3] = y; + x1[0] = (x + w - d); y1[0] = y + d; + x1[1] = (x + w - d); y1[1] = (y + h - d); + x1[2] = x + w; y1[2] = (y + h - d); + x1[3] = x + w; y1[3] = y; fillPolygon(x1, y1, 4, LColor::right); return *this; diff --git a/src/PainterBase.h b/src/PainterBase.h index 303bb157fb..d397100e1a 100644 --- a/src/PainterBase.h +++ b/src/PainterBase.h @@ -36,13 +36,6 @@ namespace grfx { */ class PainterBase { -protected: - /// - static int dummy1; - /// - static int dummy2; - /// - static int dummy3; public: /// enum line_width { @@ -51,7 +44,7 @@ public: /// line_thick }; - + /// enum line_style { /// @@ -61,13 +54,13 @@ public: /// line_onoffdash }; - + /// explicit PainterBase(WorkArea & wa) : owner(wa) {} /// virtual ~PainterBase() {} - + /* Screen geometry */ /// int paperMargin() const; @@ -82,7 +75,7 @@ public: LColor::color = LColor::foreground, enum line_style = line_solid, enum line_width = line_thin) = 0; - + /** Draw the lines between the lines in xp and yp. xp and yp are arrays of points, and np is the number of them. */ @@ -91,13 +84,13 @@ public: LColor::color = LColor::foreground, enum line_style = line_solid, enum line_width = line_thin) = 0; - + /// Here xp and yp are arrays of points virtual PainterBase & fillPolygon( int const * xp, int const * yp, int np, LColor::color = LColor::foreground) = 0; - + /// Draw lines from x1,y1 to x2,y2. They are arrays virtual PainterBase & segments( int const * x1, int const * y1, @@ -117,7 +110,7 @@ public: virtual PainterBase & circle( int x, int y, unsigned int d, LColor::color = LColor::foreground); - + /// Draw an ellipse virtual PainterBase & ellipse( int x, int y, @@ -143,7 +136,7 @@ public: /// A filled rectangle with the shape of a 3D button virtual PainterBase & button(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) virtual PainterBase & text(int x, int y, string const & str, LyXFont const & f) = 0; - + /** Draw a string at position x, y (y is the baseline) This is just for fast drawing */ 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) virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0; - + /** Draws a string and encloses it inside a rectangle. */ PainterBase & rectText(int x, int baseline, string const & string, LyXFont const & font, LColor::color back, LColor::color frame); - + /** Draw a string and encloses it inside a button frame. */ PainterBase & buttonText(int x, int baseline, string const & s, LyXFont const & font);