Skip to content

Develop a "Viewport" class #2908

Open
Open
@Ghabry

Description

@Ghabry

There are some technical issues with higher resolutions / widescreen that are hard to solve:

When the map is smaller than the screen it should be centered. Centering a map is tricky though: All tiles must be shifted and the events. Additionally ScreenX/ScreenY likely must be adjusted etc. Is a pretty invasive change.

Here comes Viewport or BitmapView to stay in style of Filesystem/FilesystemView (here FsView is a subpath baked by Fs).

A Viewport has the same interface as a Bitmap. It is baked by a Bitmap but all rendering operations happen inside a predefined area of the Bitmap.

E.g. you have a 640x480 bitmap and you create a 320x240 Viewport at 100x200.

Then width() and height() of the viewport will lie and return 320 and 240 and when doing a Blit via the Viewport the Blit operation is redirected to the baking Bitmap at Rect(320, 240, 100, 200).


Makes the code everywhere simpler because the rendering logic and math is central again.


Pretty involved though because all Drawable::Draw methods must be changed to take a Viewport instead :/


Though question is if this could be also using Sprite as this class already does a lot of what we need for this 🤔 . But is not a thin wrapper. Has more stuff.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions