use crate::{ffi::window as ffi, window::ContextSettings};
#[cfg_attr(feature = "ci-headless", doc = "```no_run")]
#[cfg_attr(not(feature = "ci-headless"), doc = "```")]
#[derive(Debug)]
pub struct Context(*mut ffi::sfContext);
impl Context {
#[must_use]
pub fn new() -> Context {
Context(unsafe { ffi::sfContext_create() })
}
pub fn set_active(&mut self, active: bool) -> bool {
unsafe { ffi::sfContext_setActive(self.0, active) }
}
#[must_use]
pub fn settings(&self) -> &ContextSettings {
unsafe { &*ffi::sfContext_getSettings(self.0) }
}
#[must_use]
pub fn active_context_id() -> u64 {
unsafe { ffi::sfContext_getActiveContextId() }
}
}
#[cfg_attr(not(feature = "ci-headless"), test)]
fn test_settings() {
use crate::window::Window;
use std::thread;
let window = Window::new((32, 32), "test", Default::default(), &Default::default());
let win_settings = *window.settings();
thread::spawn(move || {
let context = Context::new();
assert_eq!(context.settings(), &win_settings);
})
.join()
.unwrap();
}
impl Drop for Context {
fn drop(&mut self) {
unsafe {
ffi::sfContext_destroy(self.0);
}
}
}
impl Default for Context {
fn default() -> Self {
Context::new()
}
}