@@ -835,7 +835,7 @@ void C4Viewport::Clear()
835
835
DrawX = DrawY = 0 ;
836
836
Regions.Clear ();
837
837
dViewX = dViewY = -31337 ;
838
- ViewOffsX = ViewOffsY = 0 ;
838
+ ViewOffsets. clear () ;
839
839
previousViewRootSection = nullptr ;
840
840
}
841
841
@@ -1247,8 +1247,15 @@ void C4Viewport::AdjustPosition()
1247
1247
// calc target view position
1248
1248
int32_t iTargetViewX = pPlr->ViewX - ViewWdt / 2 ;
1249
1249
int32_t iTargetViewY = pPlr->ViewY - ViewHgt / 2 ;
1250
+ // get view offset
1251
+ std::int32_t viewOffsetX{0 };
1252
+ std::int32_t viewOffsetY{0 };
1253
+ if (const auto it = ViewOffsets.find (&viewRootSection); it != ViewOffsets.end ())
1254
+ {
1255
+ std::tie (viewOffsetX, viewOffsetY) = it->second ;
1256
+ }
1250
1257
// add mouse auto scroll
1251
- int32_t iPrefViewX = ViewX - ViewOffsX , iPrefViewY = ViewY - ViewOffsY ;
1258
+ int32_t iPrefViewX = ViewX - viewOffsetX , iPrefViewY = ViewY - viewOffsetY ;
1252
1259
if (pPlr->MouseControl && Game.MouseControl .InitCentered && Config.General .MouseAScroll )
1253
1260
{
1254
1261
int32_t iAutoScrollBorder = (std::min)((std::min)(ViewWdt / 10 , ViewHgt / 10 ), C4SymbolSize);
@@ -1298,12 +1305,12 @@ void C4Viewport::AdjustPosition()
1298
1305
dViewY = itofix (ViewY);
1299
1306
}
1300
1307
// apply offset
1301
- ViewX += ViewOffsX ; ViewY += ViewOffsY ;
1308
+ ViewX += viewOffsetX ; ViewY += viewOffsetY ;
1302
1309
// store previous section
1303
1310
previousViewRootSection = &viewRootSection;
1304
1311
}
1305
1312
// NO_OWNER can't scroll
1306
- if (fIsNoOwnerViewport ) { ViewOffsX = 0 ; ViewOffsY = 0 ; }
1313
+ if (fIsNoOwnerViewport ) { ViewOffsets. clear () ; }
1307
1314
// clip at borders, update vars
1308
1315
UpdateViewPosition ();
1309
1316
}
@@ -1339,6 +1346,23 @@ C4Section &C4Viewport::GetViewRootSection()
1339
1346
return *Game.Sections .front ();
1340
1347
}
1341
1348
1349
+ void C4Viewport::SetViewOffset (C4Section §ion, const std::int32_t x, const std::int32_t y)
1350
+ {
1351
+ if (fIsNoOwnerViewport )
1352
+ {
1353
+ return ;
1354
+ }
1355
+
1356
+ if (x == 0 && y == 0 )
1357
+ {
1358
+ ViewOffsets.erase (§ion.GetRootSection ());
1359
+ }
1360
+ else
1361
+ {
1362
+ ViewOffsets.insert_or_assign (§ion.GetRootSection (), std::pair{x, y});
1363
+ }
1364
+ }
1365
+
1342
1366
void C4Viewport::UpdateViewPosition ()
1343
1367
{
1344
1368
C4Section §ion{GetViewRootSection ()};
@@ -1383,7 +1407,7 @@ void C4Viewport::Default()
1383
1407
SetRegions = nullptr ;
1384
1408
Regions.Default ();
1385
1409
dViewX = dViewY = -31337 ;
1386
- ViewOffsX = ViewOffsY = 0 ;
1410
+ ViewOffsets. clear () ;
1387
1411
fIsNoOwnerViewport = false ;
1388
1412
}
1389
1413
@@ -1626,6 +1650,8 @@ void C4Viewport::ClearSectionPointers(C4Section §ion)
1626
1650
{
1627
1651
previousViewRootSection = nullptr ;
1628
1652
}
1653
+
1654
+ ViewOffsets.erase (§ion);
1629
1655
}
1630
1656
1631
1657
void C4Viewport::DrawMouseButtons (C4FacetEx &cgo)
0 commit comments