mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +00:00
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:
parent
3beb3be67c
commit
d15da27db8
@ -24,12 +24,10 @@ libmathed_la_SOURCES = \
|
||||
math_biginset.h \
|
||||
math_binominset.C \
|
||||
math_binominset.h \
|
||||
math_braceinset.C \
|
||||
math_braceinset.h \
|
||||
math_boxinset.C \
|
||||
math_boxinset.h \
|
||||
math_binaryopinset.C \
|
||||
math_binaryopinset.h \
|
||||
math_braceinset.C \
|
||||
math_braceinset.h \
|
||||
math_casesinset.C \
|
||||
math_casesinset.h \
|
||||
math_charinset.C \
|
||||
|
@ -335,14 +335,13 @@ void InsetFormula::read(Buffer const *, LyXLex & lex)
|
||||
void InsetFormula::draw(BufferView * bv, LyXFont const & font,
|
||||
int y, float & xx, bool) const
|
||||
{
|
||||
int x = int(xx);
|
||||
|
||||
Painter & pain = bv->painter();
|
||||
|
||||
metrics(bv, font);
|
||||
|
||||
int x = int(xx);
|
||||
int w = par_->width();
|
||||
int h = par_->height();
|
||||
int a = par_->ascent();
|
||||
Painter & pain = bv->painter();
|
||||
|
||||
if (lcolor.getX11Name(LColor::mathbg)!=lcolor.getX11Name(LColor::background))
|
||||
pain.fillRectangle(x, y - a, w, h, LColor::mathbg);
|
||||
|
@ -392,6 +392,8 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
||||
hideInsetCursor(bv);
|
||||
|
||||
mathcursor->normalize();
|
||||
mathcursor->touch();
|
||||
|
||||
switch (action) {
|
||||
|
||||
// --- Cursor Movements ---------------------------------------------
|
||||
@ -721,6 +723,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
|
||||
}
|
||||
|
||||
mathcursor->normalize();
|
||||
mathcursor->touch();
|
||||
|
||||
lyx::Assert(mathcursor);
|
||||
|
||||
|
@ -20,14 +20,10 @@
|
||||
|
||||
#include "math_atom.h"
|
||||
#include "math_inset.h"
|
||||
#include "support/LAssert.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
using std::swap;
|
||||
|
||||
|
||||
MathAtom::MathAtom()
|
||||
: nucleus_(0)
|
||||
{}
|
||||
@ -48,7 +44,7 @@ void MathAtom::operator=(MathAtom const & p)
|
||||
if (&p == this)
|
||||
return;
|
||||
MathAtom tmp(p);
|
||||
swap(tmp.nucleus_, nucleus_);
|
||||
std::swap(tmp.nucleus_, nucleus_);
|
||||
}
|
||||
|
||||
|
||||
@ -65,16 +61,3 @@ void MathAtom::reset(MathInset * p)
|
||||
delete nucleus_;
|
||||
nucleus_ = p;
|
||||
}
|
||||
|
||||
|
||||
MathInset * MathAtom::nucleus() const
|
||||
{
|
||||
lyx::Assert(nucleus_);
|
||||
return nucleus_;
|
||||
}
|
||||
|
||||
|
||||
MathInset * MathAtom::operator->() const
|
||||
{
|
||||
return nucleus();
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ public:
|
||||
void operator=(MathAtom const &);
|
||||
/// change inset under the hood
|
||||
void reset(MathInset * p);
|
||||
/// access to the inset (checked with gprof)
|
||||
MathInset * nucleus() const { return nucleus_; }
|
||||
/// access to the inset
|
||||
MathInset * nucleus() const;
|
||||
/// access to the inset
|
||||
MathInset * operator->() const;
|
||||
MathInset * operator->() const { return nucleus_; }
|
||||
|
||||
private:
|
||||
///
|
||||
|
@ -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()
|
||||
{
|
||||
// rebreak
|
||||
|
@ -185,6 +185,8 @@ public:
|
||||
|
||||
/// make sure cursor position is valid
|
||||
void normalize();
|
||||
/// mark current cursor trace for redraw
|
||||
void touch();
|
||||
///
|
||||
UpdatableInset * asHyperActiveInset() const;
|
||||
|
||||
@ -221,11 +223,6 @@ public:
|
||||
/// returns the normalized anchor of the selection
|
||||
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"
|
||||
MathCursorPos & cursor();
|
||||
/// reference to the last item of the path, i.e. "The Cursor"
|
||||
@ -278,9 +275,13 @@ private:
|
||||
/// write access to cursor cell index
|
||||
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_;
|
||||
///
|
||||
/// text code of last char entered
|
||||
MathTextCodes lastcode_;
|
||||
// Selection stuff
|
||||
/// do we currently select
|
||||
|
@ -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
|
||||
{
|
||||
return cursor_;
|
||||
@ -111,29 +97,32 @@ void MathIterator::operator++()
|
||||
{
|
||||
// move into the current inset if possible
|
||||
// it is impossible for pos() == size()!
|
||||
if (nextInset() && nextInset()->isActive()) {
|
||||
push(nextInset());
|
||||
MathInset * n = nextInset();
|
||||
if (n && n->isActive()) {
|
||||
push(n);
|
||||
return;
|
||||
}
|
||||
|
||||
// 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!
|
||||
++position().pos_;
|
||||
++top.pos_;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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!
|
||||
++position().idx_;
|
||||
position().pos_ = 0;
|
||||
++top.idx_;
|
||||
top.pos_ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise leave array, move on one position
|
||||
// this might yield pos() == size(), but that's a ok.
|
||||
pop();
|
||||
// it certainly invalidates top
|
||||
pop();
|
||||
++position().pos_;
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,10 @@ public:
|
||||
void operator++();
|
||||
/// move on several steps
|
||||
void jump(MathInset::difference_type);
|
||||
/// read access to top most item
|
||||
MathCursorPos const & position() const;
|
||||
/// read access to top most item (inline after running gprof!)
|
||||
MathCursorPos const & position() const { return cursor_.back(); }
|
||||
/// write access to top most item
|
||||
MathCursorPos & position();
|
||||
MathCursorPos & position() { return cursor_.back(); }
|
||||
/// read access to full path
|
||||
MathCursor::cursor_type const & cursor() const;
|
||||
/// read access to top most inset
|
||||
|
@ -609,8 +609,7 @@ int mathed_char_width(MathTextCodes type, MathMetricsInfo const & size,
|
||||
whichFont(font, type, size);
|
||||
if (isBinaryOp(c, type))
|
||||
return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font);
|
||||
else
|
||||
return lyxfont::width(c, font);
|
||||
return lyxfont::width(c, font);
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,13 +18,26 @@ extern MathScriptInset const * asScript(MathArray::const_iterator it);
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
size_ = mi;
|
||||
if (clean_)
|
||||
return;
|
||||
|
||||
size_ = mi;
|
||||
clean_ = true;
|
||||
drawn_ = false;
|
||||
|
||||
if (data_.empty()) {
|
||||
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
|
||||
{
|
||||
xo_ = x;
|
||||
yo_ = y;
|
||||
//if (drawn_ && x == xo_ && y == yo_)
|
||||
// return;
|
||||
|
||||
xo_ = x;
|
||||
yo_ = y;
|
||||
drawn_ = true;
|
||||
|
||||
if (data_.empty()) {
|
||||
pain.rectangle(x, y - ascent_, width_, height(), LColor::mathline);
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
void metrics(MathMetricsInfo const & st) const;
|
||||
/// redraw cell using cache metrics information
|
||||
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
|
||||
int xo() const { return xo_; }
|
||||
@ -86,6 +88,10 @@ public:
|
||||
mutable int yo_;
|
||||
/// cache size information of last drawing
|
||||
mutable MathMetricsInfo size_;
|
||||
/// cached cleaness of cell
|
||||
mutable bool clean_;
|
||||
/// cached draw status of cell
|
||||
mutable bool drawn_;
|
||||
};
|
||||
|
||||
/// output cell on a stream
|
||||
|
Loading…
Reference in New Issue
Block a user