]> git.lyx.org Git - features.git/commitdiff
speed up math drawing
authorAndré Pönitz <poenitz@gmx.net>
Tue, 12 Mar 2002 14:59:08 +0000 (14:59 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 12 Mar 2002 14:59:08 +0000 (14:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3729 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/mathed/Makefile.am
src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/math_atom.C
src/mathed/math_atom.h
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_iterator.C
src/mathed/math_iterator.h
src/mathed/math_support.C
src/mathed/math_xdata.C
src/mathed/math_xdata.h

index 2ece17bdb985088da009b17b12cfaa5ce2a11473..b81cd36295513c55250903104647797c1ab37772 100644 (file)
@@ -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 \
index 36d717c72ec227dd1056bb56e31e3de5cb45cd9d..fc759f77446e45bf82129a0703c30767ed2d166a 100644 (file)
@@ -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);
index 5eaa8f93ed5352ab11309cfefebce837f7b2a481..d7298a06b29ff81a056e0265a65d08409e1a9533 100644 (file)
@@ -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);
 
index 0e70a9b043ab4b38e0ace37a8225cf8badcd6179..8e423064bac79325f49e4ae6008fee08cd7db078 100644 (file)
 
 #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();
-}
index 8e78a4b0c8188047d3d1a070946aa27a4c0b65f4..2c79655c8a40d8f389134193dd702071fcaddb4b 100644 (file)
@@ -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:
        ///
index fe08e2802abef5f44d6e656c29a8a89e6d22c2b6..2fe623fc359354393c68764250c23ff392d4e9ff 100644 (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()
 {
        // rebreak
index 3561d2089eccb53984ac5cdfd2aaaa1424c98869..433810c2298eeb8d651825c2c79cf74aaa048848 100644 (file)
@@ -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
index 3d6406c799c2faa4f9b33aafff4db283ff77a6e4..7bb18450978d7f36039891f06bc870dd928fcea7 100644 (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
 {
        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_;
 }
 
index 7b484b030b41be4c37166a333024513a6c3c0510..29998f4ac4d95fe06c3211f821b2757ab882d395 100644 (file)
@@ -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
index 78dc7cefd1b134ac66c2960992ec0badf618ad18..9ea3366ef31ade6ddc29950ea469dd571e285f62 100644 (file)
@@ -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);
 }
 
 
index cab9a2c337f78aae32f2360e4e2ae0a1db0e6249..3a1faff1fc95ef251b74eac8a197c9d94a94b61c 100644 (file)
@@ -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);
index ee5b1d73a9ed7e83124b37c2bc241fd27c2bece9..3a6739591b4329503d47d1cd123e7e961351af0e 100644 (file)
@@ -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