mirror of
https://github.com/encounter/rust-sdl2.git
synced 2026-07-10 21:18:41 -07:00
Merge pull request #518 from baskerville/display-dpi
Add SDL_GetDisplayDPI
This commit is contained in:
@@ -160,6 +160,7 @@ extern "C" {
|
||||
pub fn SDL_GetWindowDisplayIndex(window: *mut SDL_Window) -> c_int;
|
||||
pub fn SDL_SetWindowDisplayMode(window: *mut SDL_Window, mode: *const SDL_DisplayMode) -> c_int;
|
||||
pub fn SDL_GetWindowDisplayMode(window: *mut SDL_Window, mode: *mut SDL_DisplayMode) -> c_int;
|
||||
pub fn SDL_GetDisplayDPI(displayIndex: c_int, ddpi: *mut c_float, hdpi: *mut c_float, vdpi: *mut c_float) -> c_int;
|
||||
pub fn SDL_GetWindowPixelFormat(window: *mut SDL_Window) -> uint32_t;
|
||||
pub fn SDL_CreateWindow(title: *const c_char, x: c_int, y: c_int, w: c_int, h: c_int, flags: uint32_t) -> *mut SDL_Window;
|
||||
pub fn SDL_CreateWindowFrom(data: *const c_void) -> *mut SDL_Window;
|
||||
|
||||
@@ -571,6 +571,20 @@ impl VideoSubsystem {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return a triplet `(ddpi, hdpi, vdpi)` containing the diagonal, horizontal and vertical
|
||||
/// dots/pixels-per-inch of a display
|
||||
pub fn display_dpi(&self, display_index: i32) -> Result<(f32, f32, f32), String> {
|
||||
let mut ddpi = 0.0;
|
||||
let mut hdpi = 0.0;
|
||||
let mut vdpi = 0.0;
|
||||
let result = unsafe { ll::SDL_GetDisplayDPI(display_index as c_int, &mut ddpi, &mut hdpi, &mut vdpi) };
|
||||
if result < 0 {
|
||||
Err(get_error())
|
||||
} else {
|
||||
Ok((ddpi, hdpi, vdpi))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_screen_saver_enabled(&self) -> bool {
|
||||
unsafe { ll::SDL_IsScreenSaverEnabled() == 1 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user