mangling some more complicated font names.
* lyx_gui.C: use Gtk::Main instead of while() loop:
fix eating CPU even when idle
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)
2006-02-12 John Spray <spray@lyx.org>
* GMenubar.C: assume backend strings in latin1 (bug 1954)
namespace frontend {
GPainter::GPainter(GWorkArea & xwa)
namespace frontend {
GPainter::GPainter(GWorkArea & xwa)
- : Painter(), owner_(xwa)
+ : Painter(), owner_(xwa), currentcolor_(LColor::magenta)
-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::start()
+{
+ pixmap_ = owner_.getPixmap();
+ colorhandler_ = &(owner_.getColorHandler());
+ gc_ = owner_.getGC();
+ gc_->set_foreground(*(colorhandler_->getGdkColor(currentcolor_)));
-void GPainter::setLineParam(Glib::RefPtr<Gdk::GC> gc,
- line_style ls, line_width lw)
+inline void GPainter::setLineParam(line_style ls, line_width lw)
{
int width = 0;
switch (lw) {
{
int width = 0;
switch (lw) {
style = Gdk::LINE_ON_OFF_DASH;
break;
}
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)
{
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);
line_style ls,
line_width lw)
{
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);
line_style ls,
line_width lw)
{
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]);
}
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);
line_style ls,
line_width lw)
{
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)
{
}
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)
{
}
void GPainter::fillPolygon(int const * xp, int const * yp,
int np, LColor_color col)
{
- setForeground(owner_.getGC(), 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]);
}
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)
{
}
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);
}
false, x, y, w, h, a1, a2);
}
graphics::LyXGdkImage const & image =
static_cast<graphics::LyXGdkImage const &>(i);
Glib::RefPtr<Gdk::Pixbuf> const & pixbuf = image.pixbuf();
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);
}
pixmap->draw_pixbuf (gc, pixbuf, 0, 0, x, y, w, h,
Gdk::RGB_DITHER_NONE, 0, 0);
}
XftFont * font = getXftFont(f);
XftColor * xftClr = owner_.getColorHandler().
getXftColor(f.realColor());
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,
XftDraw * draw = owner_.getXftDraw();
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
XftDrawString32(draw, xftClr, font, x, y,
namespace frontend {
class GWorkArea;
namespace frontend {
class GWorkArea;
/**
* GPainter - a painter implementation for Gtkmm
/**
* GPainter - a painter implementation for Gtkmm
/// return the height of the work area in pixels
virtual int paperHeight() const;
/// 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(
XftColor * getXftColor(LColor_color clr);
/// draw a line from point to point
virtual void line(
XChar2b const * str, size_t l,
LyXFont const & f);
XChar2b const * str, size_t l,
LyXFont const & f);
private:
/// our owner who we paint upon
GWorkArea & owner_;
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
};
} // namespace frontend