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

Add wrapper functions for getting and setting renderer integer scaling #1112

Merged
merged 3 commits into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum variants directly in your project, you may be affected. If you only used sd

[PR #1150](https://github.com/Rust-SDL2/rust-sdl2/pull/1150) Do not download SDL2 sources when using bundled feature

[PR #1112](https://github.com/Rust-SDL2/rust-sdl2/pull/1150) Add wrapper functions for `SDL_RenderSetIntegerScale` and `SDL_RenderGetIntegerScale`

### v0.34.5

[PR #1100](https://github.com/Rust-SDL2/rust-sdl2/pull/1100) Added binding for `SDL_GetDisplayUsableBounds`
Expand Down
26 changes: 26 additions & 0 deletions src/sdl2/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,32 @@ impl<T: RenderTarget> Canvas<T> {
}
}

/// Sets whether to force integer scales for resolution-independent rendering.
#[doc(alias = "SDL_RenderSetIntegerScale")]
pub fn set_integer_scale(&mut self, scale: bool) -> Result<(), String> {
let ret = unsafe {
sys::SDL_RenderSetIntegerScale(
self.raw(),
if scale {
sys::SDL_bool::SDL_TRUE
} else {
sys::SDL_bool::SDL_FALSE
},
)
};
if ret != 0 {
Err(get_error())
} else {
Ok(())
}
}

/// Gets whether integer scales are forced for resolution-independent rendering.
#[doc(alias = "SDL_RenderGetIntegerScale")]
pub fn integer_scale(&self) -> bool {
unsafe { sys::SDL_RenderGetIntegerScale(self.raw()) == sys::SDL_bool::SDL_TRUE }
}

/// Sets the drawing scale for rendering on the current target.
#[doc(alias = "SDL_RenderSetScale")]
pub fn set_scale(&mut self, scale_x: f32, scale_y: f32) -> Result<(), String> {
Expand Down