Fix pastes not being centred on the cursor

This commit hopefully concludes hammering at old pasting code.
This commit is contained in:
Tamás Bálint Misius 2023-06-08 12:21:23 +02:00
parent 6fb893a8de
commit eea0c54a36
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
2 changed files with 13 additions and 16 deletions

View File

@ -214,9 +214,7 @@ GameView::GameView():
selectPoint1(0, 0),
selectPoint2(0, 0),
currentMouse(0, 0),
mousePosition(0, 0),
placeSaveThumb(nullptr),
placeSaveOffset(0, 0)
mousePosition(0, 0)
{
int currentX = 1;
@ -1181,7 +1179,16 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
Vec2<int> GameView::PlaceSavePos() const
{
return c->NormaliseBlockCoord(selectPoint2 + placeSaveOffset * CELL + Vec2(1, 1) * CELL / 2);
auto [ trQuoX, trRemX ] = floorDiv(placeSaveTranslate.X, CELL);
auto [ trQuoY, trRemY ] = floorDiv(placeSaveTranslate.Y, CELL);
auto usefulSize = placeSaveThumb->Size();
if (trRemX) usefulSize.X -= CELL;
if (trRemY) usefulSize.Y -= CELL;
auto cursorCell = (usefulSize - Vec2{ CELL, CELL }) / 2 - Vec2{ trQuoX, trQuoY } * CELL; // stamp coordinates
auto unaligned = selectPoint2 - cursorCell;
auto quoX = floorDiv(unaligned.X, CELL).first;
auto quoY = floorDiv(unaligned.Y, CELL).first;
return { quoX, quoY };
}
void GameView::OnMouseUp(int x, int y, unsigned button)
@ -1204,7 +1211,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
{
if (placeSaveThumb && y <= WINDOWH-BARSIZE)
{
c->PlaceSave(PlaceSavePos() / CELL);
c->PlaceSave(PlaceSavePos());
}
}
else
@ -1942,13 +1949,6 @@ void GameView::NotifyTransformedPlaceSaveChanged(GameModel *sender)
if (sender->GetTransformedPlaceSave())
{
placeSaveThumb = SaveRenderer::Ref().Render(sender->GetTransformedPlaceSave(), true, true, sender->GetRenderer());
auto [ quoX, remX ] = floorDiv(placeSaveTranslate.X, CELL);
auto [ quoY, remY ] = floorDiv(placeSaveTranslate.Y, CELL);
placeSaveOffset = Vec2{ quoX, quoY };
auto usefulSize = placeSaveThumb->Size() / CELL;
if (remX) usefulSize.X -= 1;
if (remY) usefulSize.Y -= 1;
placeSaveOffset -= usefulSize / 2;
selectMode = PlaceSave;
selectPoint2 = mousePosition;
}
@ -2164,7 +2164,7 @@ void GameView::OnDraw()
{
if(placeSaveThumb && selectPoint2.X!=-1)
{
auto rect = RectSized(PlaceSavePos(), placeSaveThumb->Size());
auto rect = RectSized(PlaceSavePos() * CELL, placeSaveThumb->Size());
ren->BlendImage(placeSaveThumb->Data(), 0x80, rect);
ren->XorDottedRect(rect);
}

View File

@ -118,7 +118,6 @@ private:
ui::Point mousePosition;
std::unique_ptr<VideoBuffer> placeSaveThumb;
ui::Point placeSaveOffset;
Mat2<int> placeSaveTransform = Mat2<int>::Identity;
Vec2<int> placeSaveTranslate = Vec2<int>::Zero;
void TranslateSave(Vec2<int> addToTranslate);
@ -163,8 +162,6 @@ public:
bool AltBehaviour(){ return altBehaviour; }
SelectMode GetSelectMode() { return selectMode; }
void BeginStampSelection();
ui::Point GetPlaceSaveOffset() { return placeSaveOffset; }
void SetPlaceSaveOffset(ui::Point offset) { placeSaveOffset = offset; }
ByteString TakeScreenshot(int captureUI, int fileType);
int Record(bool record);