1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::sync::Once;
static INIT: Once = Once::new();
static mut CONTEXT: Option<Result<Context, String>> = None;
mod sdl;
use sdl::Context;
pub use sdl::Window;
pub use sdl::WindowInner;
mod event_handler;
pub use event_handler::EventHandler;
pub use event_handler::EventHandlerContext;
fn context() -> Result<&'static Context, &'static str> {
unsafe {
INIT.call_once(|| {
let context = Context::new()
.map_err(|e| format!("failed to initialize global context: {}", e));
CONTEXT = Some(context);
});
match CONTEXT.as_ref().expect("global context not initialized") {
Ok(ref x) => Ok(x),
Err(ref e) => Err(e),
}
}
}
pub fn make_window(name: impl Into<String>) -> Result<Window, String> {
context()?.make_window(name)
}
pub fn make_window_full(options: crate::WindowOptions) -> Result<Window, String> {
context()?.make_window_full(options)
}
pub fn stop() -> Result<(), String> {
let context = context()?;
context.stop()?;
context.join()
}