Skip to content

Commit

Permalink
- adapt the bunny scroller to widescreen images.
Browse files Browse the repository at this point in the history
This only concerns the actual horizontal scroller. The vertical one still needs work and the "The End" screen only works if the second picture of the scroller is the full widescreen image because this page is done as a regular single image page which does not know anything about widescreen asset replacements.
  • Loading branch information
coelckers committed Oct 24, 2020
1 parent 30e71c7 commit e1af278
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 33 deletions.
10 changes: 9 additions & 1 deletion src/common/2d/v_draw.cpp
Expand Up @@ -410,7 +410,15 @@ void CalcFullscreenScale(DrawParms *parms, double srcwidth, double srcheight, in
}
}

DEFINE_ACTION_FUNCTION(_Screen, GetFullscreenRect)
void GetFullscreenRect(double width, double height, int fsmode, DoubleRect* rect)
{
DrawParms parms;
parms.viewport.width = twod->GetWidth();
parms.viewport.height = twod->GetHeight();
CalcFullscreenScale(&parms, width, height, fsmode, *rect);
}

DEFINE_ACTION_FUNCTION_NATIVE(_Screen, GetFullscreenRect, GetFullscreenRect)
{
PARAM_PROLOGUE;
PARAM_FLOAT(virtw);
Expand Down
2 changes: 2 additions & 0 deletions src/common/2d/v_draw.h
Expand Up @@ -254,6 +254,8 @@ template<class T>
void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms);
bool SetTextureParms(F2DDrawer *drawer, DrawParms* parms, FGameTexture* img, double x, double y);

void GetFullscreenRect(double width, double height, int fsmode, DoubleRect* rect);

void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char* string, int tag_first, ...);
void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char32_t* string, int tag_first, ...);
void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...);
Expand Down
107 changes: 75 additions & 32 deletions src/intermission/intermission.cpp
Expand Up @@ -713,55 +713,98 @@ void DIntermissionScreenScroller::Drawer ()
{
auto tex = TexMan.GetGameTexture(mFirstPic);
auto tex2 = TexMan.GetGameTexture(mSecondPic);
if (mTicker >= mScrollDelay && mTicker < mScrollDelay + mScrollTime && tex != NULL && tex2 != NULL)
//if (mTicker >= mScrollDelay && mTicker < mScrollDelay + mScrollTime && tex != nullptr && tex2 != nullptr)
{
// These must round down to the nearest full pixel to cover seams between the two textures.
int fwidth = (int)tex->GetDisplayWidth();
int fheight = (int)tex->GetDisplayHeight();
int fwidth2 = (int)tex2->GetDisplayWidth();
int fheight2 = (int)tex2->GetDisplayHeight();

double xpos1 = 0, ypos1 = 0, xpos2 = 0, ypos2 = 0;

switch (mScrollDir)
if (mScrollDir == SCROLL_Left || mScrollDir == SCROLL_Right)
{
case SCROLL_Up:
ypos1 = double(mTicker - mScrollDelay) * fheight / mScrollTime;
ypos2 = ypos1 - fheight;
break;

case SCROLL_Down:
ypos1 = -double(mTicker - mScrollDelay) * fheight / mScrollTime;
ypos2 = ypos1 + fheight;
break;

case SCROLL_Left:
default:
xpos1 = double(mTicker - mScrollDelay) * fwidth / mScrollTime;
xpos2 = xpos1 - fwidth;
break;

case SCROLL_Right:
xpos1 = -double(mTicker - mScrollDelay) * fwidth / mScrollTime;
xpos2 = xpos1 + fwidth;
break;
// guesstimate the intended aspect ratio.
int aheight = fheight == 200 ? 240 : fheight == 400 ? 480 : fheight;
int awidth = aheight * 4 / 3;
int atotalwidth = fwidth + fwidth2;
int sidespace = (atotalwidth - 2*awidth);
// Now set a clipping rectangle for the intended viewport
double displayratio = atotalwidth / double(aheight) - 4./3.;
double displaywidth = aheight * displayratio;
DoubleRect drect;
GetFullscreenRect(displaywidth, aheight, FSMode_ScaleToFit43, &drect);
twod->SetClipRect(int(drect.left), int(drect.top), int(drect.width), int(drect.height));

int ticker = clamp(mTicker - mScrollDelay, 0, mScrollTime);

switch (mScrollDir)
{
case SCROLL_Left:
default:
xpos2 = -awidth + double(ticker) * awidth / mScrollTime;
xpos1 = xpos2 + fwidth2;
break;

case SCROLL_Right:
xpos1 = -double(ticker) * awidth / mScrollTime;
xpos2 = xpos1 + fwidth;
break;
}
double scale = drect.height / aheight;
xpos1 *= scale;
xpos2 *= scale;

DrawTexture(twod, tex, xpos1 + drect.left, drect.top,
DTA_DestWidthF, fwidth * scale,
DTA_DestHeightF, aheight * scale,
DTA_Masked, false,
TAG_DONE);
DrawTexture(twod, tex2, xpos2 + drect.left, drect.top,
DTA_DestWidthF, fwidth2 * scale,
DTA_DestHeightF, aheight * scale,
DTA_Masked, false,
TAG_DONE);


twod->ClearClipRect();
}
else
{
switch (mScrollDir)
{
case SCROLL_Up:
default:
ypos1 = double(mTicker - mScrollDelay) * fheight / mScrollTime;
ypos2 = ypos1 - fheight;
break;

DrawTexture(twod, tex, xpos1, ypos1,
DTA_VirtualWidth, fwidth,
DTA_VirtualHeight, fheight,
DTA_Masked, false,
TAG_DONE);
DrawTexture(twod, tex2, xpos2, ypos2,
DTA_VirtualWidth, fwidth,
DTA_VirtualHeight, fheight,
DTA_Masked, false,
TAG_DONE);
case SCROLL_Down:
ypos1 = -double(mTicker - mScrollDelay) * fheight / mScrollTime;
ypos2 = ypos1 + fheight;
break;
}

DrawTexture(twod, tex, xpos1, ypos1,
DTA_VirtualWidth, fwidth,
DTA_VirtualHeight, fheight,
DTA_Masked, false,
TAG_DONE);
DrawTexture(twod, tex2, xpos2, ypos2,
DTA_VirtualWidth, fwidth,
DTA_VirtualHeight, fheight,
DTA_Masked, false,
TAG_DONE);
}
mBackground = mSecondPic;
}
/*
else
{
Super::Drawer();
}
*/
}


Expand Down

0 comments on commit e1af278

Please sign in to comment.