Skip to content
Verified Commit 5adee9b5 authored by snooxx 💤's avatar snooxx 💤
Browse files

KGamePopupItem: Fix incorrect positioning relative to canvas

`KGamePopupItem` can be used to show popup messages overlayed over the
game's canvas, appearing as specified in one of the four corners or in
the center. While this worked fine for `Position::TopLeft`, positioning
for the other locations could be wrong, e.g. too far off from the right
border, cut off, or not perfectly centered. In particular positioning
relative to the edges of the canvas also incorrectly depended on canvas
size and aspect ratio, while the popup message should always be placed
adjacent to the respective edges of the canvas.

This is because dimensions in physical/screen pixels are used in
calculations to determine the position, while drawing is tied to scene
coordinates, which can have different scaling depending on how the
canvas has been scaled to fit within the viewport.

By properly mapping on-screen dimensions of the popup message to scene
coordinates via `mapToScene`, popup messages show up in their correct
locations again. Note that popup messages are not supposed to scale
along with the rest of the game content, to keep them readable
regardless of screen size.

This patch is also required to be able to properly test later HiDPI fixes.

Test Plan:

In KBlocks, change `KBlocksScene::showMessage` to use `TopLeft`,
`TopRight`, `BottomLeft`, `BottomRight` and `Center`. Starting a new
game and pausing/resuming now shows popup messages which are not
cut off, properly adjacent to the canvas border, and perfectly centered.
parent f9e1f89a
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment