Davejkane / riv

Riv - The Rust Image Viewer
MIT License
99 stars 10 forks source link

Toggle actual size/fit to screen #23

Closed Davejkane closed 5 years ago

Davejkane commented 5 years ago
gurgalex commented 5 years ago

So, pressing z should either zoom in or out on the image until it fits in the dimensions of the window?

Davejkane commented 5 years ago

Yes, pressing z should toggle between actual size and fit to window. The default for images smaller than the window should be actual size, and the default for images larger than the window should be fit to window.

gurgalex commented 5 years ago

Question. When the image is larger than the display and actual size is desired, should the viewport focus on the center of the image?

I'm heavily leaning toward centered.

22 May be related

Centered

xxxxx
xyyyx
xyyyx
xyyyx
xxxxx

Or

Top-left focus

yyyxx
yyyxx
yyyxx
xxxxx
xxxxx
Davejkane commented 5 years ago

I'd also definitely go with centred. Hadn't even thought of it as an option :)

Davejkane commented 5 years ago

Just a heads up, canvas.copy_ex let's you specify a centre point, which will make this much easier.

https://rust-sdl2.github.io/rust-sdl2/sdl2/render/struct.Canvas.html#method.copy_ex

gurgalex commented 5 years ago

Nice! Just need to get the center point of the texture.

gurgalex commented 5 years ago

From what I've read, the center point for copy_ex is used to specify the point to rotate or flip along. https://docs.rs/sdl2/0.32.2/sdl2/render/struct.Canvas.html#method.copy_ex

Copies a portion of the texture to the current rendering target, optionally rotating it by angle around the given center and also flipping it top-bottom and/or left-right.

So, perhaps what needs to be done manually is:

  1. Compute the texture center point
  2. (tex_slice) Create a rectangle to select only an area as large as the destination dimensions (or an area only as large as the image dimensions)
  3. Center the tex_slice center on the destination area center.