Skip to content

Commit

Permalink
fet: 3 pages continous scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-n8hgeg5e committed Mar 12, 2020
1 parent 6b23aeb commit b90b938
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
54 changes: 41 additions & 13 deletions src/ApvlvCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,21 @@ namespace apvlv
{
if (!mReady)
return;

gdouble val = gtk_adjustment_get_value (mVaj);
gdouble sub = gtk_adjustment_get_upper(mVaj) - gtk_adjustment_get_lower(mVaj);
mVrate = sub / mLines;
gdouble page_size = sub/3;
gdouble screen_size = gtk_adjustment_get_page_size(mVaj);
mVrate = page_size / mLines;
logs(" val=%lf,sub=%lf",val,sub);
logs(" pageSize=%lf, screen_size=%lf",page_size,screen_size);

if (val - mVrate * times > gtk_adjustment_get_lower(mVaj))
{
gtk_adjustment_set_value (mVaj, val - mVrate * times);
}
else if (val > gtk_adjustment_get_lower(mVaj))
else if ( val > gtk_adjustment_get_lower(mVaj) )
{
// set to min scroll value
gtk_adjustment_set_value (mVaj, gtk_adjustment_get_lower(mVaj));
}
else
Expand All @@ -241,13 +245,20 @@ namespace apvlv
{
if (mContinuous)
{
showpage (mPagenum - 1,
((gtk_adjustment_get_upper(mVaj) / 2) - mVrate * times) / (sub -
gtk_adjustment_get_page_size(mVaj)));
/* set to pos so that one page is hidden above
* this is the same pos as in the previous case
* So one scroll step does nothing visible.
* This is still useful because scrolling overshoots most times because of the
* reload lag.
* TODO: add more pages and start loading in background somehow prior the transition is reached.
full_scroll = sub - screen_size
hide one page -> page_size/full_scroll = page_size/(sub-screen_size)
*/
showpage (mPagenum - 1, page_size/(sub - screen_size));
}
else
{
showpage (mPagenum - 1, 1.0);
showpage (mPagenum + 1, 0.0);
}
}
}
Expand All @@ -259,26 +270,43 @@ namespace apvlv
{
if (!mReady)
return;

gdouble val = gtk_adjustment_get_value (mVaj);
gdouble sub = gtk_adjustment_get_upper(mVaj) - gtk_adjustment_get_lower(mVaj);
mVrate = sub / mLines;
gdouble page_size = sub/3;
gdouble screen_size = gtk_adjustment_get_page_size(mVaj);
mVrate = page_size / mLines;
logs(" val=%lf,sub=%lf",val,sub);
logs(" pageSize=%lf, screen_size=%lf",page_size,screen_size);

if (val + mVrate * times + gtk_adjustment_get_page_size(mVaj) < gtk_adjustment_get_upper(mVaj))
if (val + mVrate * times + screen_size < sub)
{
gtk_adjustment_set_value (mVaj, val + mVrate * times);
}
else if (val + gtk_adjustment_get_page_size(mVaj) < gtk_adjustment_get_upper(mVaj))
else if ( val + screen_size < sub )
{
gtk_adjustment_set_value (mVaj, gtk_adjustment_get_upper(mVaj) - gtk_adjustment_get_page_size(mVaj));
// not enough for one step, set to full scroll val
// full_scroll = sub - screen_size
gtk_adjustment_set_value (mVaj, sub - screen_size);
}
else
{
if (mAutoScrollPage)
{
if (mContinuous)
{
showpage (mPagenum + 1, (sub - gtk_adjustment_get_page_size(mVaj)) / 2 / sub);
/* set to pos so that one page is hidden below
* this is the same pos as in the previous case
* so one scroll step does nothing visible
* this is still useful because scrolling overshoots most times because of the
* reload lag.
* TODO: add more pages and start loading in background somehow prior the transition is reached.
full_scroll = sub - screen_size
abs_pos = full_scroll - page_size = sub - screen_size - page_size
rel_pos = abs_pos/full_scroll = (sub - screen_size - page_size) / (sub - screen_size)
= 1 - page_size/(sub - screen_size)
*/
showpage (mPagenum + 1, 1 - page_size/( sub - screen_size )) ;
}
else
{
Expand Down
35 changes: 24 additions & 11 deletions src/ApvlvDoc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace apvlv

ApvlvDoc::ApvlvDoc (ApvlvView *view, DISPLAY_TYPE type, int w, int h, const char *zm, bool cache): ApvlvCore(view)
{
mCurrentCache1 = mCurrentCache2 = nullptr;
mCurrentCache1 = mCurrentCache2 = mCurrentCache3 = nullptr;

mReady = false;

Expand Down Expand Up @@ -132,6 +132,8 @@ namespace apvlv
{
mImg2 = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (vbox), mImg2, TRUE, TRUE, 0);
mImg3 = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (vbox), mImg3, TRUE, TRUE, 0);
}
}
else if (type == 1)
Expand Down Expand Up @@ -165,6 +167,8 @@ namespace apvlv
delete mCurrentCache1;
if (mCurrentCache2)
delete mCurrentCache2;
if (mCurrentCache3)
delete mCurrentCache3;

savelastposition (filename ());
mPositions.clear ();
Expand Down Expand Up @@ -245,8 +249,8 @@ namespace apvlv
word =
cache->getword (x,
cache ==
mCurrentCache2 ? y - mCurrentCache1->getheight () -
gParams->valuei ("continuouspad") : y);
mCurrentCache2 ? y - mCurrentCache1->getheight () - mCurrentCache3->getheight () -
2 * gParams->valuei ("continuouspad") : y);
if (word != nullptr)
{
pos = word->pos;
Expand All @@ -260,8 +264,8 @@ namespace apvlv
line =
cache->getline (x,
cache ==
mCurrentCache2 ? y - mCurrentCache1->getheight () -
gParams->valuei ("continuouspad") : y);
mCurrentCache2 ? y - mCurrentCache1->getheight () - mCurrentCache3->getheight () -
2 * gParams->valuei ("continuouspad") : y);
if (line != nullptr)
{
pos = line->pos;
Expand Down Expand Up @@ -912,10 +916,16 @@ namespace apvlv
delete mCurrentCache2;
mCurrentCache2 = nullptr;
}
if (mCurrentCache3 != nullptr)
{
delete mCurrentCache3;
mCurrentCache3 = nullptr;
}

if (mContinuous == true)
{
mCurrentCache2 = new ApvlvDocCache (mFile);
mCurrentCache3 = new ApvlvDocCache (mFile);
}

loadlastposition (filename);
Expand Down Expand Up @@ -1031,7 +1041,7 @@ namespace apvlv
if (rp < 0)
return;

//debug ("show page: %d", rp);
//debug ("show page: %d | %lf", rp,s);
mAdjInchg = true;

if (mAutoScrollPage && mContinuous && !mAutoScrollDoc)
Expand Down Expand Up @@ -1091,6 +1101,11 @@ namespace apvlv
mRotatevalue, false);
buf = mCurrentCache2->getbuf (true);
gtk_image_set_from_pixbuf (GTK_IMAGE (mImg2), buf);

mCurrentCache3->set (convertindex (mPagenum + 2), mZoomrate,
mRotatevalue, false);
buf = mCurrentCache3->getbuf (true);
gtk_image_set_from_pixbuf (GTK_IMAGE (mImg3), buf);
}
}
else if (mDisplayType == 1)
Expand Down Expand Up @@ -1245,8 +1260,7 @@ namespace apvlv

void ApvlvDoc::scrollup (int times)
{
if (!mReady)
return;
if (!mReady){return;}

if (gParams->valueb ("visualmode") == false)
{
Expand Down Expand Up @@ -1284,8 +1298,7 @@ namespace apvlv

void ApvlvDoc::scrolldown (int times)
{
if (!mReady)
return;
if (!mReady){ return;}

if (gParams->valueb ("visualmode") == false)
{
Expand Down Expand Up @@ -1892,8 +1905,8 @@ namespace apvlv
delete mLinks;
mLinks = nullptr;
}
mInverted = gParams->valueb ("inverted");

mInverted = gParams->valueb ("inverted");
load (this);
}

Expand Down
6 changes: 3 additions & 3 deletions src/ApvlvDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ namespace apvlv
ApvlvDocPositionMap mPositions;
vector < ApvlvDocPosition > mLinkPositions;

ApvlvDocCache *mCurrentCache1, *mCurrentCache2;
ApvlvDocCache *mCurrentCache1, *mCurrentCache2, *mCurrentCache3;
ApvlvDocCache *newcache (int pagenum);
void deletecache (ApvlvDocCache * ac);

DISPLAY_TYPE mDisplayType;
// image viewer
GtkWidget *mImg1, *mImg2;
GtkWidget *mWeb1, *mWeb2;
GtkWidget *mImg1, *mImg2, *mImg3;
GtkWidget *mWeb1, *mWeb2, *mWeb3;
};

}
Expand Down

0 comments on commit b90b938

Please sign in to comment.