]> git.lyx.org Git - features.git/commitdiff
cached y positions patch from Alfredo
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 12 Apr 2003 23:03:05 +0000 (23:03 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sat, 12 Apr 2003 23:03:05 +0000 (23:03 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6785 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/frontends/ChangeLog
src/frontends/screen.C
src/lyxrow.C
src/lyxrow.h
src/lyxtext.h
src/text.C
src/text2.C

index 3ee0e7681ac415a3fba86a482b7b0433efcf6101..869b8a3d3720a751b5795a6e4dfaf1e5b880de3b 100644 (file)
@@ -1,3 +1,11 @@
+2003-04-11  Alfredo Braunstein  <abraunst@libero.it>
+
+       * lyxrow.[Ch]: add a cached y position to a Row and Row::y()
+       methods to access it.
+       * lyxtext.h:
+       * text.C: Added updateRowPositions to compute all row positions.
+       Make top_y and getRowNearY() to use the cached y position
+
 2003-04-11  John Levon  <levon@movementarian.org>
 
        * text.C (rowBreakPoint): reintroduce the labelEnd
index e9f60c11649226a56ae5c4530e96e98701e6bc36..5e9906ce3f8f9d3f9625094aef5dee0b7fd1568d 100644 (file)
@@ -1,3 +1,8 @@
+2003-04-11  Alfredo Braunstein  <abraunst@libero.it>
+
+       * screen.C (update): add calls to updateRowPositions() before
+       drawOneRow and drawFromTo.
+
 2003-04-10  John Levon  <levon@movementarian.org>
 
        * Toolbar.h:
index 8e7d2cd8721fc410c1eafb2b0dad791be07d9aa6..c6e7b3d323f44ce3c2fab3829404bc2ed593162f 100644 (file)
@@ -257,6 +257,7 @@ void LyXScreen::update(BufferView & bv, int yo, int xo)
        switch (text->refreshStatus()) {
        case LyXText::REFRESH_AREA:
        {
+               text->updateRowPositions();
                int const y = max(int(text->refresh_y - text->top_y()), 0);
                drawFromTo(text, &bv, y, vheight, yo, xo);
                expose(0, y, vwidth, vheight - y);
@@ -264,6 +265,7 @@ void LyXScreen::update(BufferView & bv, int yo, int xo)
        break;
        case LyXText::REFRESH_ROW:
        {
+               text->updateRowPositions();
                // ok I will update the current cursor row
                drawOneRow(text, &bv, text->refresh_row, text->refresh_y,
                           yo, xo);
@@ -412,22 +414,18 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
 {
        lyxerr[Debug::GUI] << "screen: drawFromTo " << y1 << '-' << y2 << endl;
 
-       int y_text = text->top_y() + y1;
-
-       // get the first needed row
-       RowList::iterator row = text->getRowNearY(y_text);
-       RowList::iterator end = text->rows().end();
-
-       // y_text is now the real beginning of the row
-
-       int y = y_text - text->top_y();
+       int const topy = text->top_y();
+       int y_text = topy + y1;
+       RowList::iterator rit = text->getRowNearY(y_text);
+       int y = y_text - topy;
        // y1 is now the real beginning of row on the screen
 
-       while (row != end && y < y2) {
-               RowPainter rp(*bv, *text, row);
-               rp.paint(y + yo, xo, y + text->top_y());
-               y += row->height();
-               ++row;
+       RowList::iterator const rend = text->rows().end();
+       while (rit != rend && y < y2) {
+               RowPainter rp(*bv, *text, rit);
+               rp.paint(y + yo, xo, y + topy);
+               y += rit->height();
+               ++rit;
        }
 
        // maybe we have to clear the screen at the bottom
index 33356ec0d78d20d3fb7314491bfc2e20c1761bc2..682186c71f8f118d0ca034a5d689f5b697ed1806 100644 (file)
@@ -23,17 +23,29 @@ using std::max;
 using std::min;
 
 Row::Row()
-       : pos_(0), fill_(0), height_(0), width_(0),
+       : pos_(0), fill_(0), height_(0), width_(0), y_(0),
          ascent_of_text_(0), baseline_(0)
 {}
 
 
 Row::Row(ParagraphList::iterator pit, pos_type po)
-       : pit_(pit), pos_(po), fill_(0), height_(0), width_(0),
+       : pit_(pit), pos_(po), fill_(0), height_(0), width_(0), y_(0),
          ascent_of_text_(0), baseline_(0)
 {}
 
 
+void Row::y(unsigned int newy)
+{
+       y_ = newy;
+}
+
+
+unsigned int Row::y() const
+{
+       return y_;
+}
+
+
 ParagraphList::iterator Row::par()
 {
        return pit_;
index cbb72cec7cba4170977a119cdd6e64a7c45855c2..7a81db1b2f6ce2c5aa0a190ab757b9c662f05a20 100644 (file)
@@ -61,6 +61,10 @@ public:
        unsigned int baseline() const;
        /// return true if this row is the start of a paragraph
        bool isParStart() const;
+       /// return the cached y position
+       unsigned int y() const;
+       /// cache the y position
+       void y(unsigned int newy);
 private:
        ///
        ParagraphList::iterator pit_;
@@ -73,6 +77,8 @@ private:
        unsigned short height_;
        ///
        unsigned int width_;
+       /// cached y position
+       unsigned int y_;
        /// ascent from baseline including prelude space
        unsigned short ascent_of_text_;
        /// the top of the real text in the row
index 3d45e28352658f8e5f345eb12be5d0588ec1d15b..2a1ec358436683b4a2c81bcae3d8df9600dad8b9 100644 (file)
@@ -88,6 +88,8 @@ private:
         */
        int anchor_row_offset_;
 public:
+       /// update all cached row positions
+       void updateRowPositions();
        /// get the y coord. of the top of the screen (relative to doc start)
        int top_y() const;
        /// set the y coord. of the top of the screen (relative to doc start)
index d3a665d4eb162678d7c270044b9b3f895119f716..ff1b144c2617774ec41e3c49cc950aaa3234b0fe 100644 (file)
@@ -74,25 +74,28 @@ BufferView * LyXText::bv() const
 }
 
 
-int LyXText::top_y() const
+void LyXText::updateRowPositions()
 {
-       if (anchor_row_ == rowlist_.end())
-               return 0;
-
-       int y = 0;
-
-       RowList::iterator rit = rowlist_.begin();
-       RowList::iterator end = rowlist_.end();
-       for (; rit != end && rit != anchor_row_; ++rit) {
+       RowList::iterator rit = rows().begin();
+       RowList::iterator rend = rows().end();
+       for (int y = 0; rit != rend ; ++rit) {
+               rit->y(y);
                y += rit->height();
        }
-       return y + anchor_row_offset_;
+}
+
+
+int LyXText::top_y() const
+{
+       if (isInInset() || anchor_row_ == rowlist_.end() )
+               return 0;
+       return anchor_row_->y() + anchor_row_offset_;
 }
 
 
 void LyXText::top_y(int newy)
 {
-       if (rows().empty())
+       if (rows().empty() || isInInset())
                return;
        lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
 
@@ -2767,20 +2770,41 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
 
 RowList::iterator LyXText::getRowNearY(int & y) const
 {
-       // If possible we should optimize this method. (Lgb)
-       int tmpy = 0;
 
-       RowList::iterator rit = rowlist_.begin();
-       RowList::iterator end = rowlist_.end();
+       RowList::iterator rit = anchor_row_;
+       RowList::iterator const beg = rows().begin();
+       RowList::iterator const end = rows().end();
 
-       while (rit != end &&
-              boost::next(rit) != end &&
-              tmpy + rit->height() <= y) {
-               tmpy += rit->height();
-               ++rit;
+       if (rows().empty()) {
+               y = 0;
+               return end;
+       }
+       if (rit == end)
+               rit = beg;
+
+       int tmpy = rit->y();
+
+       if (tmpy <= y) {
+               while (rit != end && tmpy <= y) {
+                       tmpy += rit->height();
+                       ++rit;
+               }
+               if (rit != beg) {
+                       --rit;
+                       tmpy -= rit->height();
+               }
+       } else {
+               while (rit != beg && tmpy > y) {
+                       --rit;
+                       tmpy -= rit->height();
+               }
+       }
+       if (tmpy < 0 || rit == end) {
+               tmpy = 0;
+               rit = beg;
        }
 
-       // return the real y
+       // return the rel y
        y = tmpy;
 
        return rit;
index ed770d93b03021b335278eb59ea6fb3bf95f63e2..f87adbb30c9d5bf0daac2a534bd95743d3f09862 100644 (file)
@@ -283,7 +283,7 @@ void LyXText::removeRow(RowList::iterator rit)
        if (anchor_row_ == rit) {
                if (rit != rows().begin()) {
                        anchor_row_ = boost::prior(rit);
-                       anchor_row_offset_ += boost::prior(rit)->height();
+                       anchor_row_offset_ += anchor_row_->height();
                } else {
                        anchor_row_ = boost::next(rit);
                        anchor_row_offset_ -= rit->height();