mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Try to make GPainter a bit more efficient
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13230 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
61133c4b56
commit
72c40bc700
@ -6,6 +6,8 @@
|
||||
mangling some more complicated font names.
|
||||
* lyx_gui.C: use Gtk::Main instead of while() loop:
|
||||
fix eating CPU even when idle
|
||||
* GPainter.[Ch]: some futile attempts to make painting
|
||||
faster by diminishing function overhead.
|
||||
|
||||
2006-02-12 John Spray <spray@lyx.org>
|
||||
* GMenubar.C: assume backend strings in latin1 (bug 1954)
|
||||
|
@ -55,7 +55,7 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GPainter::GPainter(GWorkArea & xwa)
|
||||
: Painter(), owner_(xwa)
|
||||
: Painter(), owner_(xwa), currentcolor_(LColor::magenta)
|
||||
{
|
||||
}
|
||||
|
||||
@ -72,15 +72,25 @@ int GPainter::paperHeight() const
|
||||
}
|
||||
|
||||
|
||||
void GPainter::setForeground(Glib::RefPtr<Gdk::GC> gc, LColor_color clr)
|
||||
inline void GPainter::setForeground(LColor_color clr)
|
||||
{
|
||||
Gdk::Color * gclr = owner_.getColorHandler().getGdkColor(clr);
|
||||
gc->set_foreground(*gclr);
|
||||
if (clr != currentcolor_) {
|
||||
gc_->set_foreground(*(colorhandler_->getGdkColor(clr)));
|
||||
currentcolor_ = clr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GPainter::setLineParam(Glib::RefPtr<Gdk::GC> gc,
|
||||
line_style ls, line_width lw)
|
||||
void GPainter::start()
|
||||
{
|
||||
pixmap_ = owner_.getPixmap();
|
||||
colorhandler_ = &(owner_.getColorHandler());
|
||||
gc_ = owner_.getGC();
|
||||
gc_->set_foreground(*(colorhandler_->getGdkColor(currentcolor_)));
|
||||
}
|
||||
|
||||
|
||||
inline void GPainter::setLineParam(line_style ls, line_width lw)
|
||||
{
|
||||
int width = 0;
|
||||
switch (lw) {
|
||||
@ -101,15 +111,15 @@ void GPainter::setLineParam(Glib::RefPtr<Gdk::GC> gc,
|
||||
style = Gdk::LINE_ON_OFF_DASH;
|
||||
break;
|
||||
}
|
||||
gc->set_line_attributes(width, style,
|
||||
gc_->set_line_attributes(width, style,
|
||||
Gdk::CAP_NOT_LAST, Gdk::JOIN_MITER);
|
||||
}
|
||||
|
||||
|
||||
void GPainter::point(int x, int y, LColor_color c)
|
||||
{
|
||||
setForeground(owner_.getGC(), c);
|
||||
owner_.getPixmap()->draw_point(owner_.getGC(), x, y);
|
||||
setForeground(c);
|
||||
pixmap_->draw_point(gc_, x, y);
|
||||
}
|
||||
|
||||
|
||||
@ -119,9 +129,9 @@ void GPainter::line(int x1, int y1,
|
||||
line_style ls,
|
||||
line_width lw)
|
||||
{
|
||||
setForeground(owner_.getGC(), col);
|
||||
setLineParam(owner_.getGC(), ls, lw);
|
||||
owner_.getPixmap()->draw_line(owner_.getGC(), x1, y1, x2, y2);
|
||||
setForeground(col);
|
||||
setLineParam(ls, lw);
|
||||
pixmap_->draw_line(gc_, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
|
||||
@ -130,15 +140,15 @@ void GPainter::lines(int const * xp, int const * yp, int np,
|
||||
line_style ls,
|
||||
line_width lw)
|
||||
{
|
||||
setForeground(owner_.getGC(), col);
|
||||
setLineParam(owner_.getGC(), ls, lw);
|
||||
setForeground(col);
|
||||
setLineParam(ls, lw);
|
||||
std::vector<Gdk::Point> points(np);
|
||||
|
||||
for (int i = 0; i < np; ++i) {
|
||||
points[i].set_x(xp[i]);
|
||||
points[i].set_y(yp[i]);
|
||||
}
|
||||
owner_.getPixmap()->draw_lines(owner_.getGC(), points);
|
||||
pixmap_->draw_lines(gc_, points);
|
||||
}
|
||||
|
||||
|
||||
@ -147,39 +157,39 @@ void GPainter::rectangle(int x, int y, int w, int h,
|
||||
line_style ls,
|
||||
line_width lw)
|
||||
{
|
||||
setForeground(owner_.getGC(), col);
|
||||
setLineParam(owner_.getGC(), ls, lw);
|
||||
owner_.getPixmap()->draw_rectangle(owner_.getGC(), false, x, y, w, h);
|
||||
setForeground(col);
|
||||
setLineParam(ls, lw);
|
||||
pixmap_->draw_rectangle(gc_, false, x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
void GPainter::fillRectangle(int x, int y, int w, int h,
|
||||
LColor_color col)
|
||||
{
|
||||
setForeground(owner_.getGC(), col);
|
||||
owner_.getPixmap()->draw_rectangle(owner_.getGC(), true, x, y, w, h);
|
||||
setForeground(col);
|
||||
pixmap_->draw_rectangle(gc_, true, x, y, w, h);
|
||||
}
|
||||
|
||||
|
||||
void GPainter::fillPolygon(int const * xp, int const * yp,
|
||||
int np, LColor_color col)
|
||||
{
|
||||
setForeground(owner_.getGC(), col);
|
||||
setForeground(col);
|
||||
std::vector<Gdk::Point> points(np);
|
||||
|
||||
for (int i = 0; i < np; ++i) {
|
||||
points[i].set_x(xp[i]);
|
||||
points[i].set_y(yp[i]);
|
||||
}
|
||||
owner_.getPixmap()->draw_polygon(owner_.getGC(), true, points);
|
||||
pixmap_->draw_polygon(gc_, true, points);
|
||||
}
|
||||
|
||||
|
||||
void GPainter::arc(int x, int y, unsigned int w, unsigned int h,
|
||||
int a1, int a2, LColor_color col)
|
||||
{
|
||||
setForeground(owner_.getGC(), col);
|
||||
owner_.getPixmap()->draw_arc(owner_.getGC(),
|
||||
setForeground(col);
|
||||
pixmap_->draw_arc(gc_,
|
||||
false, x, y, w, h, a1, a2);
|
||||
}
|
||||
|
||||
@ -190,9 +200,9 @@ void GPainter::image(int x, int y, int w, int h,
|
||||
graphics::LyXGdkImage const & image =
|
||||
static_cast<graphics::LyXGdkImage const &>(i);
|
||||
Glib::RefPtr<Gdk::Pixbuf> const & pixbuf = image.pixbuf();
|
||||
Glib::RefPtr<Gdk::Pixmap> pixmap = owner_.getPixmap();
|
||||
Glib::RefPtr<Gdk::Pixmap> pixmap = pixmap_;
|
||||
|
||||
Glib::RefPtr<Gdk::GC> gc = owner_.getGC();
|
||||
Glib::RefPtr<Gdk::GC> gc = gc_;
|
||||
pixmap->draw_pixbuf (gc, pixbuf, 0, 0, x, y, w, h,
|
||||
Gdk::RGB_DITHER_NONE, 0, 0);
|
||||
}
|
||||
@ -226,7 +236,6 @@ void GPainter::text(int x, int y, wchar_t const * s, int ls, LyXFont const & f)
|
||||
XftFont * font = getXftFont(f);
|
||||
XftColor * xftClr = owner_.getColorHandler().
|
||||
getXftColor(f.realColor());
|
||||
// getXftColor(f.realColor());
|
||||
XftDraw * draw = owner_.getXftDraw();
|
||||
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
|
||||
XftDrawString32(draw, xftClr, font, x, y,
|
||||
|
@ -26,6 +26,7 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class GWorkArea;
|
||||
class ColorHandler;
|
||||
|
||||
/**
|
||||
* GPainter - a painter implementation for Gtkmm
|
||||
@ -39,9 +40,8 @@ public:
|
||||
/// return the height of the work area in pixels
|
||||
virtual int paperHeight() const;
|
||||
|
||||
void setForeground(Glib::RefPtr<Gdk::GC> gc, LColor_color clr);
|
||||
void setLineParam(Glib::RefPtr<Gdk::GC> gc,
|
||||
line_style ls, line_width lw);
|
||||
inline void setForeground(LColor_color clr);
|
||||
inline void setLineParam(line_style ls, line_width lw);
|
||||
XftColor * getXftColor(LColor_color clr);
|
||||
/// draw a line from point to point
|
||||
virtual void line(
|
||||
@ -126,9 +126,16 @@ public:
|
||||
XChar2b const * str, size_t l,
|
||||
LyXFont const & f);
|
||||
|
||||
void start();
|
||||
|
||||
private:
|
||||
/// our owner who we paint upon
|
||||
GWorkArea & owner_;
|
||||
|
||||
Glib::RefPtr<Gdk::GC> gc_;
|
||||
Glib::RefPtr<Gdk::Pixmap> pixmap_;
|
||||
ColorHandler *colorhandler_;
|
||||
LColor_color currentcolor_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
Loading…
Reference in New Issue
Block a user