Fix setting small ViewOffsets. Refactor neighbouring code, enable a slight MouseAutoScroll by default

* make ViewX,ViewY,ViewOffsetX and Y private, add getters and setters that update variables that are dependent on these
issue1247
Tobias Zwick 2015-01-03 22:51:02 +01:00
parent b64d379579
commit 5e188aafb3
10 changed files with 169 additions and 112 deletions

View File

@ -240,7 +240,7 @@ void C4ConfigControls::CompileFunc(StdCompiler *pComp)
{
#ifndef USE_CONSOLE
pComp->Value(mkNamingAdapt(UserSets, "UserSets", C4PlayerControlAssignmentSets()));
pComp->Value(mkNamingAdapt(MouseAScroll, "MouseAutoScroll", 0));
pComp->Value(mkNamingAdapt(MouseAutoScroll, "MouseAutoScroll", 33));
pComp->Value(mkNamingAdapt(GamepadGuiControl, "GamepadGuiControl", 0, false, true));
#endif
}

View File

@ -227,7 +227,7 @@ class C4ConfigControls
{
public:
int32_t GamepadGuiControl;
int32_t MouseAScroll; // auto scroll strength
int32_t MouseAutoScroll; // auto scroll strength
C4PlayerControlAssignmentSets UserSets;
void CompileFunc(StdCompiler *pComp);

View File

@ -74,11 +74,11 @@ bool C4Viewport::ViewPositionByScrollBars()
// Vertical
scroll.fMask=SIF_POS;
GetScrollInfo(pWindow->hWindow,SB_VERT,&scroll);
ViewY=float(scroll.nPos);
SetViewY(float(scroll.nPos));
// Horizontal
scroll.fMask=SIF_POS;
GetScrollInfo(pWindow->hWindow,SB_HORZ,&scroll);
ViewX=float(scroll.nPos);
SetViewX(float(scroll.nPos));
return true;
}
@ -92,14 +92,14 @@ bool C4Viewport::ScrollBarsByViewPosition()
scroll.nMin=0;
scroll.nMax = GBackHgt * Zoom;
scroll.nPage=ViewHgt;
scroll.nPos=int(ViewY * Zoom);
scroll.nPos=int(GetViewY() * Zoom);
SetScrollInfo(pWindow->hWindow,SB_VERT,&scroll,true);
// Horizontal
scroll.fMask=SIF_ALL;
scroll.nMin=0;
scroll.nMax=GBackWdt * Zoom;
scroll.nPage=ViewWdt;
scroll.nPos = int(ViewX * Zoom);
scroll.nPos = int(GetViewX() * Zoom);
SetScrollInfo(pWindow->hWindow,SB_HORZ,&scroll,true);
return true;
}
@ -134,7 +134,7 @@ bool C4Viewport::ScrollBarsByViewPosition()
GtkAdjustment* adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->h_scrollbar));
gtk_adjustment_configure(adjustment,
ViewX, // value
GetViewX(), // value
0, // lower
GBackWdt, // upper
ViewportScrollSpeed, // step_increment
@ -144,7 +144,7 @@ bool C4Viewport::ScrollBarsByViewPosition()
adjustment = gtk_range_get_adjustment(GTK_RANGE(pWindow->v_scrollbar));
gtk_adjustment_configure(adjustment,
ViewY, // value
GetViewY(), // value
0, // lower
GBackHgt, // upper
ViewportScrollSpeed, // step_increment
@ -199,5 +199,5 @@ void C4ViewportWindow::Close()
}
void C4ViewportWindow::EditCursorMove(int X, int Y, uint32_t state)
{
Console.EditCursor.Move(cvp->ViewX + X / cvp->Zoom, cvp->ViewY + Y / cvp->Zoom, state);
Console.EditCursor.Move(cvp->GetViewX() + X / cvp->Zoom, cvp->GetViewY() + Y / cvp->Zoom, state);
}

View File

@ -40,7 +40,7 @@
void C4Viewport::DropFile(const char* fileName, float x, float y)
{
Game.DropFile(fileName, ViewX+x/Zoom, ViewY+y/Zoom);
Game.DropFile(fileName, GetViewX()+x/Zoom, GetViewY()+y/Zoom);
}
bool C4Viewport::UpdateOutputSize()
@ -63,6 +63,7 @@ bool C4Viewport::UpdateOutputSize()
#endif
OutX=rect.x; OutY=rect.y;
ViewWdt=rect.Wdt; ViewHgt=rect.Hgt;
ScrollView(0,0);
// Scroll bars
ScrollBarsByViewPosition();
// Reset menus
@ -89,11 +90,12 @@ void C4Viewport::Clear()
if (pFoW) { delete pFoW; pFoW = NULL; }
if (pWindow) { delete pWindow->pSurface; pWindow->Clear(); delete pWindow; pWindow = NULL; }
Player=NO_OWNER;
ViewX=ViewY=0;
viewX=viewY=0;
targetViewX=targetViewY=0;
ViewWdt=ViewHgt=0;
OutX=OutY=ViewWdt=ViewHgt=0;
DrawX=DrawY=0;
ViewOffsX = ViewOffsY = 0;
viewOffsX = viewOffsY = 0;
}
void C4Viewport::DrawOverlay(C4TargetFacet &cgo, const ZoomData &GameZoom)
@ -286,7 +288,7 @@ void C4Viewport::Draw(C4TargetFacet &cgo0, bool fDrawOverlay)
gui_cgo.X = DrawX; gui_cgo.Y = DrawY; gui_cgo.Zoom = fGUIZoom;
gui_cgo.Wdt = int(float(ViewWdt)/fGUIZoom); gui_cgo.Hgt = int(float(ViewHgt)/fGUIZoom);
gui_cgo.TargetX = ViewX; gui_cgo.TargetY = ViewY;
gui_cgo.TargetX = GetViewX(); gui_cgo.TargetY = GetViewY();
last_gui_draw_cgo = gui_cgo;
@ -339,7 +341,7 @@ void C4Viewport::Execute()
C4TargetFacet cgo;
C4Window * w = pWindow;
if (!w) w = &FullScreen;
cgo.Set(w->pSurface,DrawX,DrawY,int32_t(ceilf(float(ViewWdt)/Zoom)),int32_t(ceilf(float(ViewHgt)/Zoom)),ViewX,ViewY,Zoom);
cgo.Set(w->pSurface,DrawX,DrawY,int32_t(ceilf(float(ViewWdt)/Zoom)),int32_t(ceilf(float(ViewHgt)/Zoom)),GetViewX(),GetViewY(),Zoom);
pDraw->PrepareRendering(w->pSurface);
// Draw
Draw(cgo, true);
@ -461,8 +463,6 @@ void C4Viewport::AdjustPosition()
assert(Zoom>0);
assert(ZoomTarget>0);
float PrefViewX = ViewX + ViewWdt / (Zoom * 2) - ViewOffsX;
float PrefViewY = ViewY + ViewHgt / (Zoom * 2) - ViewOffsY;
if(Zoom != ZoomTarget)
{
@ -486,50 +486,59 @@ void C4Viewport::AdjustPosition()
// View position
if (PlayerLock && ValidPlr(Player))
{
float ScrollRange = Min(ViewWdt/(10*Zoom),ViewHgt/(10*Zoom));
float ExtraBoundsX = 0, ExtraBoundsY = 0;
float scrollRange, extraBoundsX, extraBoundsY;
scrollRange = extraBoundsX = extraBoundsY = 0;
// target view position (landscape coordinates)
float targetCenterViewX = fixtof(pPlr->ViewX);
float targetCenterViewY = fixtof(pPlr->ViewY);
if (pPlr->ViewMode == C4PVM_Scrolling)
{
ScrollRange=0;
ExtraBoundsX=ExtraBoundsY=ViewportScrollBorder;
extraBoundsX = extraBoundsY = ViewportScrollBorder;
}
else
{
scrollRange = Min(ViewWdt/(10*Zoom),ViewHgt/(10*Zoom));
// if view is close to border, allow scrolling
if (fixtof(pPlr->ViewX) < ViewportScrollBorder) ExtraBoundsX = Min<float>(ViewportScrollBorder - fixtof(pPlr->ViewX), ViewportScrollBorder);
else if (fixtof(pPlr->ViewX) >= GBackWdt - ViewportScrollBorder) ExtraBoundsX = Min<float>(fixtof(pPlr->ViewX) - GBackWdt, 0) + ViewportScrollBorder;
if (fixtof(pPlr->ViewY) < ViewportScrollBorder) ExtraBoundsY = Min<float>(ViewportScrollBorder - fixtof(pPlr->ViewY), ViewportScrollBorder);
else if (fixtof(pPlr->ViewY) >= GBackHgt - ViewportScrollBorder) ExtraBoundsY = Min<float>(fixtof(pPlr->ViewY) - GBackHgt, 0) + ViewportScrollBorder;
if (targetCenterViewX < ViewportScrollBorder) extraBoundsX = Min<float>(ViewportScrollBorder - targetCenterViewX, ViewportScrollBorder);
else if (targetCenterViewX >= GBackWdt - ViewportScrollBorder) extraBoundsX = Min<float>(targetCenterViewX - GBackWdt, 0) + ViewportScrollBorder;
if (targetCenterViewY < ViewportScrollBorder) extraBoundsY = Min<float>(ViewportScrollBorder - targetCenterViewY, ViewportScrollBorder);
else if (targetCenterViewY >= GBackHgt - ViewportScrollBorder) extraBoundsY = Min<float>(targetCenterViewY - GBackHgt, 0) + ViewportScrollBorder;
}
ExtraBoundsX = Max(ExtraBoundsX, (ViewWdt/Zoom - GBackWdt) / 2+1);
ExtraBoundsY = Max(ExtraBoundsY, (ViewHgt/Zoom - GBackHgt) / 2+1);
// calc target view position
float TargetViewX = fixtof(pPlr->ViewX) /* */;
float TargetViewY = fixtof(pPlr->ViewY) /* */;
extraBoundsX = Max(extraBoundsX, (ViewWdt/Zoom - GBackWdt)/2 + 1);
extraBoundsY = Max(extraBoundsY, (ViewHgt/Zoom - GBackHgt)/2 + 1);
// add mouse auto scroll
if (pPlr->MouseControl && ::MouseControl.InitCentered && Config.Controls.MouseAScroll)
if (pPlr->MouseControl && ::MouseControl.InitCentered && Config.Controls.MouseAutoScroll)
{
TargetViewX += (::MouseControl.VpX - ViewWdt / 2) / Zoom;
TargetViewY += (::MouseControl.VpY - ViewHgt / 2) / Zoom;
float strength = Config.Controls.MouseAutoScroll/100.0f;
targetCenterViewX += strength*(::MouseControl.VpX - ViewWdt/2.0f)/Zoom;
targetCenterViewY += strength*(::MouseControl.VpY - ViewHgt/2.0f)/Zoom;
}
// scroll range
TargetViewX = BoundBy(PrefViewX, TargetViewX - ScrollRange, TargetViewX + ScrollRange);
TargetViewY = BoundBy(PrefViewY, TargetViewY - ScrollRange, TargetViewY + ScrollRange);
targetCenterViewX = BoundBy(targetCenterViewX, targetCenterViewX - scrollRange, targetCenterViewX + scrollRange);
targetCenterViewY = BoundBy(targetCenterViewY, targetCenterViewY - scrollRange, targetCenterViewY + scrollRange);
// bounds
TargetViewX = BoundBy(TargetViewX, ViewWdt / (Zoom * 2) - ExtraBoundsX, GBackWdt - ViewWdt / (Zoom * 2) + ExtraBoundsX);
TargetViewY = BoundBy(TargetViewY, ViewHgt / (Zoom * 2) - ExtraBoundsY, GBackHgt - ViewHgt / (Zoom * 2) + ExtraBoundsY);
targetCenterViewX = BoundBy(targetCenterViewX, ViewWdt/Zoom/2 - extraBoundsX, GBackWdt - ViewWdt/Zoom/2 + extraBoundsX);
targetCenterViewY = BoundBy(targetCenterViewY, ViewHgt/Zoom/2 - extraBoundsY, GBackHgt - ViewHgt/Zoom/2 + extraBoundsY);
targetViewX = targetCenterViewX - ViewWdt/Zoom/2 + viewOffsX;
targetViewY = targetCenterViewY - ViewHgt/Zoom/2 + viewOffsY;
// smooth
ViewX = PrefViewX + (TargetViewX - PrefViewX) / BoundBy<int32_t>(Config.General.ScrollSmooth, 1, 50);
ViewY = PrefViewY + (TargetViewY - PrefViewY) / BoundBy<int32_t>(Config.General.ScrollSmooth, 1, 50);
// apply offset
ViewX -= ViewWdt / (Zoom * 2) - ViewOffsX;
ViewY -= ViewHgt / (Zoom * 2) - ViewOffsY;
int32_t smooth = BoundBy<int32_t>(Config.General.ScrollSmooth, 1, 50);
ScrollView((targetViewX - viewX) / smooth, (targetViewY - viewY) / smooth);
}
UpdateBordersX();
UpdateBordersY();
// NO_OWNER can't scroll
if (fIsNoOwnerViewport) { ViewOffsX=0; ViewOffsY=0; }
// clip at borders, update vars
UpdateViewPosition();
if (fIsNoOwnerViewport) { viewOffsX=0; viewOffsY=0; }
#ifdef WITH_DEVELOPER_MODE
//ScrollBarsByViewPosition();
#endif
@ -539,41 +548,20 @@ void C4Viewport::CenterPosition()
{
// center viewport position on map
// set center position
ViewX = (GBackWdt-ViewWdt/Zoom)/2;
ViewY = (GBackHgt-ViewHgt/Zoom)/2;
// clips and updates
UpdateViewPosition();
SetViewX(GBackWdt/2 + ViewWdt/Zoom/2);
SetViewY(GBackHgt/2 + ViewHgt/Zoom/2);
}
void C4Viewport::UpdateViewPosition()
void C4Viewport::UpdateBordersX()
{
// no-owner viewports should not scroll outside viewing area
if (fIsNoOwnerViewport)
{
if (!Application.isEditor && GBackWdt<ViewWdt / Zoom)
{
ViewX = (GBackWdt-ViewWdt / Zoom)/2;
}
else
{
ViewX = Min(ViewX, GBackWdt-ViewWdt / Zoom);
ViewX = Max(ViewX, 0.0f);
}
if (!Application.isEditor && GBackHgt<ViewHgt / Zoom)
{
ViewY = (GBackHgt-ViewHgt / Zoom)/2;
}
else
{
ViewY = Min(ViewY, GBackHgt-ViewHgt / Zoom);
ViewY = Max(ViewY, 0.0f);
}
}
// update borders
BorderLeft = int32_t(Max(-ViewX * Zoom, 0.0f));
BorderTop = int32_t(Max(-ViewY * Zoom, 0.0f));
BorderRight = int32_t(Max(ViewWdt - GBackWdt * Zoom + ViewX * Zoom, 0.0f));
BorderBottom = int32_t(Max(ViewHgt - GBackHgt * Zoom + ViewY * Zoom, 0.0f));
BorderLeft = int32_t(Max(-GetViewX() * Zoom, 0.0f));
BorderRight = int32_t(Max(ViewWdt - GBackWdt * Zoom + GetViewX() * Zoom, 0.0f));
}
void C4Viewport::UpdateBordersY()
{
BorderTop = int32_t(Max(-GetViewY() * Zoom, 0.0f));
BorderBottom = int32_t(Max(ViewHgt - GBackHgt * Zoom + GetViewY() * Zoom, 0.0f));
}
void C4Viewport::Default()
@ -581,7 +569,8 @@ void C4Viewport::Default()
pWindow=NULL;
pFoW = NULL;
Player=0;
ViewX=ViewY=0;
viewX=viewY=0;
targetViewX=targetViewY=0;
ViewWdt=ViewHgt=0;
BorderLeft=BorderTop=BorderRight=BorderBottom=0;
OutX=OutY=ViewWdt=ViewHgt=0;
@ -593,7 +582,7 @@ void C4Viewport::Default()
Next=NULL;
PlayerLock=true;
ResetMenuPositions=false;
ViewOffsX = ViewOffsY = 0;
viewOffsX = viewOffsY = 0;
fIsNoOwnerViewport = false;
last_game_draw_cgo.Default();
last_gui_draw_cgo.Default();
@ -670,17 +659,62 @@ void C4Viewport::DrawPlayerStartup(C4TargetFacet &cgo)
pPlr->ColorDw | 0xff000000, ACenter);
}
void C4Viewport::ScrollView(float byX, float byY)
{
SetViewX(viewX + byX);
SetViewY(viewY + byY);
}
void C4Viewport::SetViewX(float x)
{
viewX = x;
if (fIsNoOwnerViewport)
{
if(GBackWdt < ViewWdt / Zoom)
{
viewX = GBackWdt/2 - ViewWdt / Zoom / 2;
}
else
{
viewX = BoundBy(x, 0.0f, GBackWdt - ViewWdt / Zoom);
}
}
UpdateBordersX();
}
void C4Viewport::SetViewY(float y)
{
viewY = y;
if (fIsNoOwnerViewport)
{
if(GBackHgt < ViewHgt / Zoom)
{
viewY = GBackHgt/2 - ViewHgt / Zoom / 2;
}
else
{
viewY = BoundBy(y, 0.0f, GBackHgt - ViewHgt / Zoom);
}
}
UpdateBordersY();
}
void C4Viewport::SetOutputSize(int32_t iDrawX, int32_t iDrawY, int32_t iOutX, int32_t iOutY, int32_t iOutWdt, int32_t iOutHgt)
{
// update view position: Remain centered at previous position
ViewX += (ViewWdt-iOutWdt)/2;
ViewY += (ViewHgt-iOutHgt)/2;
int32_t deltaWidth = ViewWdt-iOutWdt;
int32_t deltaHeight = ViewHgt-iOutHgt;
// update output parameters
DrawX=iDrawX; DrawY=iDrawY;
OutX=iOutX; OutY=iOutY;
ViewWdt=iOutWdt; ViewHgt=iOutHgt;
// update view position: Remain centered at previous position
// scrolling the view must be done after setting the new view width and height
ScrollView(deltaWidth/2, deltaHeight/2);
CalculateZoom();
UpdateViewPosition();
// Reset menus
ResetMenuPositions=true;
// player uses mouse control? then clip the cursor
@ -972,9 +1006,10 @@ int32_t C4ViewportList::GetAudibility(int32_t iX, int32_t iY, int32_t *iPan, int
int32_t iAudible=0; *iPan = 0;
for (C4Viewport *cvp=FirstViewport; cvp; cvp=cvp->Next)
{
float distanceToCenterOfViewport = Distance(cvp->GetViewCenterX(),cvp->GetViewCenterY(),iX,iY);
iAudible = Max( iAudible,
BoundBy<int32_t>(100-100*Distance(cvp->ViewX+cvp->ViewWdt/2,cvp->ViewY+cvp->ViewHgt/2,iX,iY)/C4AudibilityRadius,0,100) );
*iPan += (iX-(cvp->ViewX+cvp->ViewWdt/2)) / 5;
BoundBy<int32_t>(100-100*distanceToCenterOfViewport/C4AudibilityRadius,0,100) );
*iPan += (iX-(cvp->GetViewCenterX())) / 5;
}
*iPan = BoundBy<int32_t>(*iPan, -100, 100);
return iAudible;
@ -1039,7 +1074,7 @@ bool C4ViewportList::FreeScroll(C4Vec2D vScrollBy)
if (Game.FrameCounter-vp_vf < 5)
{ dx += vp_vx; dy += vp_vy; }
vp_vx=dx; vp_vy=dy; vp_vf=Game.FrameCounter;
vp->ViewX+=dx; vp->ViewY+=dy;
vp->ScrollView(dx, dy);
return true;
}

View File

@ -28,11 +28,9 @@ class C4Viewport
public:
C4Viewport();
~C4Viewport();
// "landscape" coordinates
float ViewX,ViewY;
int32_t ViewOffsX, ViewOffsY;
// "display" coordinates
int32_t ViewWdt,ViewHgt;
// position of landscape border (left,top,right, bottom) in viewport. 0 if there is not border
int32_t BorderLeft, BorderTop, BorderRight, BorderBottom;
int32_t DrawX,DrawY;
// facets used for last drawing operations
@ -48,7 +46,6 @@ public:
void Execute();
void ClearPointers(C4Object *pObj);
void SetOutputSize(int32_t iDrawX, int32_t iDrawY, int32_t iOutX, int32_t iOutY, int32_t iOutWdt, int32_t iOutHgt);
void UpdateViewPosition(); // update view position: Clip properly; update border variables
void CalculateZoom();
void ChangeZoom(float by_factor);
void SetZoom(float to_zoom, bool direct=false);
@ -67,6 +64,31 @@ public:
C4Viewport *GetNext() { return Next; }
int32_t GetPlayer() { return Player; }
void CenterPosition();
public:
/** Return x-position of upper left corner of viewport in landscape coordinates */
float GetViewX() { return viewX; }
/** Return y-position of upper left corner of viewport in landscape coordinates */
float GetViewY() { return viewY; }
/** Return x-position of the center of viewport in landscape coordinates */
float GetViewCenterX() { return viewX + ViewWdt/Zoom/2; }
/** Return y-position of the center of viewport in landscape coordinates */
float GetViewCenterY() { return viewY + ViewHgt/Zoom/2; }
/** Scroll the viewport by x,y */
void ScrollView(float byX, float byY);
/** Set the view position. */
void SetViewX(float x);
void SetViewY(float y);
/** Set the view offset of the normal viewport center. Used by C4Script function SetViewOffset. */
void SetViewOffset(int32_t x, int32_t y) { viewOffsX = x; viewOffsY = y; }
private:
float viewX,viewY; // current view position in landscape coordinates (upper left corner)
float targetViewX, targetViewY; // target view position for smooth scrolling
int32_t viewOffsX, viewOffsY; // desired view offset in landscape coordinates
void UpdateBordersX();
void UpdateBordersY();
protected:
float Zoom;
float ZoomTarget;

View File

@ -2094,8 +2094,7 @@ static bool FnSetViewOffset(C4PropList * _this, long iPlayer, long iX, long iY)
C4Viewport *pView = ::Viewports.GetViewport(iPlayer);
if (!pView) return 1; // sync safety
// set
pView->ViewOffsX = iX;
pView->ViewOffsY = iY;
pView->SetViewOffset(iX, iY);
// ok
return 1;
}

View File

@ -209,7 +209,7 @@ void C4MouseControl::Move(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFl
// get view position
C4Rect rcViewport = Viewport->GetOutputRect();
fctViewport.Set(NULL, rcViewport.x, rcViewport.y, rcViewport.Wdt, rcViewport.Hgt);
ViewX=Viewport->ViewX; ViewY=Viewport->ViewY;
ViewX=Viewport->GetViewX(); ViewY=Viewport->GetViewY();
fctViewportGame = Viewport->last_game_draw_cgo;
fctViewportGUI = Viewport->last_gui_draw_cgo;
// First time viewport attachment: center mouse
@ -900,9 +900,7 @@ void C4MouseControl::ScrollView(float iX, float iY, float ViewWdt, float ViewHgt
else if (Viewport)
{
// no player: Scroll fullscreen viewport
Viewport->ViewX = Viewport->ViewX+iX;
Viewport->ViewY = Viewport->ViewY+iY;
Viewport->UpdateViewPosition();
Viewport->ScrollView(iX, iY);
}
}

View File

@ -1647,8 +1647,8 @@ bool C4Object::ActivateMenu(int32_t iMenu, int32_t iMenuSelect,
Menu->SetPermanent(true);
Menu->SetAlignment(C4MN_Align_Free);
C4Viewport *pViewport = ::Viewports.GetViewport(Controller); // Hackhackhack!!!
if (pViewport) Menu->SetLocation((pTarget->GetX() + pTarget->Shape.GetX() + pTarget->Shape.Wdt + 10 - pViewport->ViewX) * pViewport->GetZoom(),
(pTarget->GetY() + pTarget->Shape.GetY() - pViewport->ViewY) * pViewport->GetZoom());
if (pViewport) Menu->SetLocation((pTarget->GetX() + pTarget->Shape.GetX() + pTarget->Shape.Wdt + 10 - pViewport->GetViewX()) * pViewport->GetZoom(),
(pTarget->GetY() + pTarget->Shape.GetY() - pViewport->GetViewY()) * pViewport->GetZoom());
// Add info item
fctSymbol.Create(C4PictureSize, C4PictureSize); pTarget->Def->Draw(fctSymbol, false, pTarget->Color, pTarget);
Menu->Add(pTarget->GetName(), fctSymbol, "", C4MN_Item_NoCount, NULL, pTarget->GetInfoString().getData());

View File

@ -209,9 +209,9 @@ bool C4Video::AdjustPosition()
C4Player *pPlr = ::Players.Get(pViewport->GetPlayer());
if (!pPlr) return false;
// Set camera position
X = int32_t(fixtof(pPlr->ViewX) - pViewport->ViewX + pViewport->DrawX - Width/2);
X = int32_t(fixtof(pPlr->ViewX) - pViewport->GetViewX() + pViewport->DrawX - Width/2);
X = BoundBy( X, 0, pViewport->ViewWdt - Width );
Y = int32_t(fixtof(pPlr->ViewY) - pViewport->ViewY + pViewport->DrawY - Height/2);
Y = int32_t(fixtof(pPlr->ViewY) - pViewport->GetViewY() + pViewport->DrawY - Height/2);
Y = BoundBy( Y, 0, pViewport->ViewHgt - Height );
// Success
return true;
@ -295,7 +295,7 @@ void C4Video::Draw()
if ( (pViewport = ::Viewports.GetFirstViewport()) )
{
C4TargetFacet cgo;
cgo.Set(Surface,pViewport->DrawX,pViewport->DrawY,pViewport->ViewWdt,pViewport->ViewHgt,pViewport->ViewX,pViewport->ViewY);
cgo.Set(Surface,pViewport->DrawX,pViewport->DrawY,pViewport->ViewWdt,pViewport->ViewHgt,pViewport->GetViewX(),pViewport->GetViewY());
Draw(cgo);
}
}

View File

@ -303,10 +303,11 @@ LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
}
//----------------------------------------------------------------------------------------------------------------------------------
case WM_USER_DROPDEF:
Game.DropDef(C4ID(lParam),cvp->ViewX+float(LOWORD(wParam))/cvp->Zoom,cvp->ViewY+float(HIWORD(wParam)/cvp->Zoom));
Game.DropDef(C4ID(lParam),cvp->GetViewX()+float(LOWORD(wParam))/cvp->Zoom,cvp->GetViewY()+float(HIWORD(wParam)/cvp->Zoom));
break;
//----------------------------------------------------------------------------------------------------------------------------------
case WM_SIZE:
case WM_SIZING:
cvp->UpdateOutputSize();
break;
//----------------------------------------------------------------------------------------------------------------------------------
@ -317,11 +318,12 @@ LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
case WM_HSCROLL:
switch (LOWORD(wParam))
{
case SB_THUMBTRACK: case SB_THUMBPOSITION: cvp->ViewX=float(HIWORD(wParam))/cvp->Zoom; break;
case SB_LINELEFT: cvp->ViewX-=ViewportScrollSpeed; break;
case SB_LINERIGHT: cvp->ViewX+=ViewportScrollSpeed; break;
case SB_PAGELEFT: cvp->ViewX-=cvp->ViewWdt; break;
case SB_PAGERIGHT: cvp->ViewX+=cvp->ViewWdt; break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION: cvp->SetViewX(float(HIWORD(wParam))/cvp->Zoom); break;
case SB_LINELEFT: cvp->ScrollView(-ViewportScrollSpeed, 0.0f); break;
case SB_LINERIGHT: cvp->ScrollView(+ViewportScrollSpeed, 0.0f); break;
case SB_PAGELEFT: cvp->ScrollView(-cvp->ViewWdt/cvp->Zoom, 0.0f); break;
case SB_PAGERIGHT: cvp->ScrollView(+cvp->ViewWdt/cvp->Zoom, 0.0f); break;
}
cvp->Execute();
cvp->ScrollBarsByViewPosition();
@ -330,11 +332,12 @@ LRESULT APIENTRY ViewportWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
case WM_VSCROLL:
switch (LOWORD(wParam))
{
case SB_THUMBTRACK: case SB_THUMBPOSITION: cvp->ViewY = float(HIWORD(wParam))/cvp->Zoom; break;
case SB_LINEUP: cvp->ViewY-=ViewportScrollSpeed; break;
case SB_LINEDOWN: cvp->ViewY+=ViewportScrollSpeed; break;
case SB_PAGEUP: cvp->ViewY-=cvp->ViewWdt; break;
case SB_PAGEDOWN: cvp->ViewY+=cvp->ViewWdt; break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION: cvp->SetViewY(float(HIWORD(wParam))/cvp->Zoom); break;
case SB_LINEUP: cvp->ScrollView(0.0f,-ViewportScrollSpeed); break;
case SB_LINEDOWN: cvp->ScrollView(0.0f,+ViewportScrollSpeed); break;
case SB_PAGEUP: cvp->ScrollView(0.0f,-cvp->ViewWdt/cvp->Zoom); break;
case SB_PAGEDOWN: cvp->ScrollView(0.0f,+cvp->ViewWdt/cvp->Zoom); break;
}
cvp->Execute();
cvp->ScrollBarsByViewPosition();