Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle actual size/fit to screen #23

Closed
Davejkane opened this issue May 8, 2019 · 7 comments · Fixed by #37
Closed

Toggle actual size/fit to screen #23

Davejkane opened this issue May 8, 2019 · 7 comments · Fixed by #37
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@Davejkane
Copy link
Owner

  • Add ToggleFit to Action enum in ui.rs
  • Add actual_size boolean to program
  • Match z key to ToggleFit in event_action function in ui.rs
  • Match Action::ToggleFit to toggle_fit function in run in program.rs
  • in toggle_fit function flip the actual_size boolean
  • When changing image in Next, Prev, Move, First, Last etc, reset the actual_size boolean. It should be true when both images are small than window, and false when any dimension is larger than the corresponding window dimension.
  • Add new action to README.
@Davejkane Davejkane added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels May 8, 2019
@Davejkane Davejkane added this to the 0.3 milestone May 8, 2019
@gurgalex
Copy link
Collaborator

gurgalex commented May 9, 2019

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

@Davejkane
Copy link
Owner Author

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
Copy link
Collaborator

gurgalex commented May 10, 2019

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
Copy link
Owner Author

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

@gurgalex gurgalex self-assigned this May 10, 2019
@Davejkane
Copy link
Owner Author

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
Copy link
Collaborator

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

@gurgalex
Copy link
Collaborator

gurgalex commented May 11, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants