speed up math drawing

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3729 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-03-12 14:59:08 +00:00
parent 3beb3be67c
commit d15da27db8
12 changed files with 71 additions and 67 deletions

View File

@ -24,12 +24,10 @@ libmathed_la_SOURCES = \
math_biginset.h \ math_biginset.h \
math_binominset.C \ math_binominset.C \
math_binominset.h \ math_binominset.h \
math_braceinset.C \
math_braceinset.h \
math_boxinset.C \ math_boxinset.C \
math_boxinset.h \ math_boxinset.h \
math_binaryopinset.C \ math_braceinset.C \
math_binaryopinset.h \ math_braceinset.h \
math_casesinset.C \ math_casesinset.C \
math_casesinset.h \ math_casesinset.h \
math_charinset.C \ math_charinset.C \

View File

@ -335,14 +335,13 @@ void InsetFormula::read(Buffer const *, LyXLex & lex)
void InsetFormula::draw(BufferView * bv, LyXFont const & font, void InsetFormula::draw(BufferView * bv, LyXFont const & font,
int y, float & xx, bool) const int y, float & xx, bool) const
{ {
int x = int(xx);
Painter & pain = bv->painter();
metrics(bv, font); metrics(bv, font);
int x = int(xx);
int w = par_->width(); int w = par_->width();
int h = par_->height(); int h = par_->height();
int a = par_->ascent(); int a = par_->ascent();
Painter & pain = bv->painter();
if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background)) if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background))
pain.fillRectangle(x, y - a, w, h, LColor::mathbg); pain.fillRectangle(x, y - a, w, h, LColor::mathbg);

View File

@ -392,6 +392,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
hideInsetCursor(bv); hideInsetCursor(bv);
mathcursor->normalize(); mathcursor->normalize();
mathcursor->touch();
switch (action) { switch (action) {
// --- Cursor Movements --------------------------------------------- // --- Cursor Movements ---------------------------------------------
@ -721,6 +723,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
} }
mathcursor->normalize(); mathcursor->normalize();
mathcursor->touch();
lyx::Assert(mathcursor); lyx::Assert(mathcursor);

View File

@ -20,14 +20,10 @@
#include "math_atom.h" #include "math_atom.h"
#include "math_inset.h" #include "math_inset.h"
#include "support/LAssert.h"
#include <utility> #include <utility>
using std::swap;
MathAtom::MathAtom() MathAtom::MathAtom()
: nucleus_(0) : nucleus_(0)
{} {}
@ -48,7 +44,7 @@ void MathAtom::operator=(MathAtom const & p)
if (&p == this) if (&p == this)
return; return;
MathAtom tmp(p); MathAtom tmp(p);
swap(tmp.nucleus_, nucleus_); std::swap(tmp.nucleus_, nucleus_);
} }
@ -65,16 +61,3 @@ void MathAtom::reset(MathInset * p)
delete nucleus_; delete nucleus_;
nucleus_ = p; nucleus_ = p;
} }
MathInset * MathAtom::nucleus() const
{
lyx::Assert(nucleus_);
return nucleus_;
}
MathInset * MathAtom::operator->() const
{
return nucleus();
}

View File

@ -47,10 +47,10 @@ public:
void operator=(MathAtom const &); void operator=(MathAtom const &);
/// change inset under the hood /// change inset under the hood
void reset(MathInset * p); void reset(MathInset * p);
/// access to the inset (checked with gprof)
MathInset * nucleus() const { return nucleus_; }
/// access to the inset /// access to the inset
MathInset * nucleus() const; MathInset * operator->() const { return nucleus_; }
/// access to the inset
MathInset * operator->() const;
private: private:
/// ///

View File

@ -934,6 +934,15 @@ void MathCursor::pullArg(bool goright)
} }
void MathCursor::touch()
{
cursor_type::const_iterator it = Cursor_.begin();
cursor_type::const_iterator et = Cursor_.end();
for ( ; it != et; ++it)
it->xcell().touch();
}
void MathCursor::normalize() void MathCursor::normalize()
{ {
// rebreak // rebreak

View File

@ -185,6 +185,8 @@ public:
/// make sure cursor position is valid /// make sure cursor position is valid
void normalize(); void normalize();
/// mark current cursor trace for redraw
void touch();
/// ///
UpdatableInset * asHyperActiveInset() const; UpdatableInset * asHyperActiveInset() const;
@ -221,11 +223,6 @@ public:
/// returns the normalized anchor of the selection /// returns the normalized anchor of the selection
MathCursorPos normalAnchor() const; MathCursorPos normalAnchor() const;
/// path of positions the cursor had to go if it were leving each inset
cursor_type Cursor_;
/// path of positions the anchor had to go if it were leving each inset
mutable cursor_type Anchor_;
/// reference to the last item of the path, i.e. "The Cursor" /// reference to the last item of the path, i.e. "The Cursor"
MathCursorPos & cursor(); MathCursorPos & cursor();
/// reference to the last item of the path, i.e. "The Cursor" /// reference to the last item of the path, i.e. "The Cursor"
@ -278,9 +275,13 @@ private:
/// write access to cursor cell index /// write access to cursor cell index
idx_type & idx(); idx_type & idx();
/// /// path of positions the cursor had to go if it were leving each inset
cursor_type Cursor_;
/// path of positions the anchor had to go if it were leving each inset
mutable cursor_type Anchor_;
/// pointer to enclsing LyX inset
InsetFormulaBase * formula_; InsetFormulaBase * formula_;
/// /// text code of last char entered
MathTextCodes lastcode_; MathTextCodes lastcode_;
// Selection stuff // Selection stuff
/// do we currently select /// do we currently select

View File

@ -21,20 +21,6 @@ MathIterator::MathIterator(MathInset * p)
//{} //{}
MathCursorPos const & MathIterator::position() const
{
lyx::Assert(cursor_.size());
return cursor_.back();
}
MathCursorPos & MathIterator::position()
{
lyx::Assert(cursor_.size());
return cursor_.back();
}
MathCursor::cursor_type const & MathIterator::cursor() const MathCursor::cursor_type const & MathIterator::cursor() const
{ {
return cursor_; return cursor_;
@ -111,29 +97,32 @@ void MathIterator::operator++()
{ {
// move into the current inset if possible // move into the current inset if possible
// it is impossible for pos() == size()! // it is impossible for pos() == size()!
if (nextInset() && nextInset()->isActive()) { MathInset * n = nextInset();
push(nextInset()); if (n && n->isActive()) {
push(n);
return; return;
} }
// otherwise move on one cell position if possible // otherwise move on one cell position if possible
if (position().pos_ < xcell().data_.size()) { MathCursorPos & top = position();
if (top.pos_ < top.par_->cell(top.idx_).size()) {
// pos() == size() is valid! // pos() == size() is valid!
++position().pos_; ++top.pos_;
return; return;
} }
// otherwise move on one cell if possible // otherwise move on one cell if possible
if (position().idx_ + 1 < par()->nargs()) { if (top.idx_ + 1 < top.par_->nargs()) {
// idx() == nargs() is _not_ valid! // idx() == nargs() is _not_ valid!
++position().idx_; ++top.idx_;
position().pos_ = 0; top.pos_ = 0;
return; return;
} }
// otherwise leave array, move on one position // otherwise leave array, move on one position
// this might yield pos() == size(), but that's a ok. // this might yield pos() == size(), but that's a ok.
pop(); // it certainly invalidates top
pop();
++position().pos_; ++position().pos_;
} }

View File

@ -22,10 +22,10 @@ public:
void operator++(); void operator++();
/// move on several steps /// move on several steps
void jump(MathInset::difference_type); void jump(MathInset::difference_type);
/// read access to top most item /// read access to top most item (inline after running gprof!)
MathCursorPos const & position() const; MathCursorPos const & position() const { return cursor_.back(); }
/// write access to top most item /// write access to top most item
MathCursorPos & position(); MathCursorPos & position() { return cursor_.back(); }
/// read access to full path /// read access to full path
MathCursor::cursor_type const & cursor() const; MathCursor::cursor_type const & cursor() const;
/// read access to top most inset /// read access to top most inset

View File

@ -609,8 +609,7 @@ int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
whichFont(font, type, size); whichFont(font, type, size);
if (isBinaryOp(c, type)) if (isBinaryOp(c, type))
return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font); return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font);
else return lyxfont::width(c, font);
return lyxfont::width(c, font);
} }

View File

@ -18,13 +18,26 @@ extern MathScriptInset const * asScript(MathArray::const_iterator it);
MathXArray::MathXArray() MathXArray::MathXArray()
: width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_() : width_(0), ascent_(0), descent_(0), xo_(0), yo_(0), size_(),
clean_(false), drawn_(false)
{} {}
void MathXArray::touch() const
{
clean_ = false;
drawn_ = false;
}
void MathXArray::metrics(MathMetricsInfo const & mi) const void MathXArray::metrics(MathMetricsInfo const & mi) const
{ {
size_ = mi; if (clean_)
return;
size_ = mi;
clean_ = true;
drawn_ = false;
if (data_.empty()) { if (data_.empty()) {
mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_); mathed_char_dim(LM_TC_VAR, mi, 'I', ascent_, descent_, width_);
@ -58,8 +71,12 @@ void MathXArray::metrics(MathMetricsInfo const & mi) const
void MathXArray::draw(Painter & pain, int x, int y) const void MathXArray::draw(Painter & pain, int x, int y) const
{ {
xo_ = x; //if (drawn_ && x == xo_ && y == yo_)
yo_ = y; // return;
xo_ = x;
yo_ = y;
drawn_ = true;
if (data_.empty()) { if (data_.empty()) {
pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline); pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);

View File

@ -32,6 +32,8 @@ public:
void metrics(MathMetricsInfo const & st) const; void metrics(MathMetricsInfo const & st) const;
/// redraw cell using cache metrics information /// redraw cell using cache metrics information
void draw(Painter & pain, int x, int y) const; void draw(Painter & pain, int x, int y) const;
/// mark cell for re-drawing
void touch() const;
/// access to cached x coordinate of last drawing /// access to cached x coordinate of last drawing
int xo() const { return xo_; } int xo() const { return xo_; }
@ -86,6 +88,10 @@ public:
mutable int yo_; mutable int yo_;
/// cache size information of last drawing /// cache size information of last drawing
mutable MathMetricsInfo size_; mutable MathMetricsInfo size_;
/// cached cleaness of cell
mutable bool clean_;
/// cached draw status of cell
mutable bool drawn_;
}; };
/// output cell on a stream /// output cell on a stream