pub struct VideoSubsystem { /* private fields */ }Implementations§
Source§impl VideoSubsystem
impl VideoSubsystem
pub fn clipboard(&self) -> ClipboardUtil
Source§impl VideoSubsystem
impl VideoSubsystem
pub fn text_input(&self) -> TextInputUtil
Source§impl VideoSubsystem
impl VideoSubsystem
Sourcepub fn window(&self, title: &str, width: u32, height: u32) -> WindowBuilder
pub fn window(&self, title: &str, width: u32, height: u32) -> WindowBuilder
Initializes a new WindowBuilder; a convenience method that calls WindowBuilder::new().
Examples found in repository?
12fn main() {
13 //sdlh is "sdl handle"
14 let sdlh = sdl2_mt::init();
15
16 // create_window() allows you to run arbitrary code to create a window
17 // and then return the drawable Canvas from that window.
18 let window = sdlh.create_window(Box::new(|_sdl, video_subsystem| {
19 let canvas = video_subsystem.window("2D plot", 720, 720)
20 .position_centered()
21 .resizable()
22 .build()
23 .unwrap()
24 .into_canvas()
25 .software()
26 .build()
27 .unwrap();
28
29 Some(canvas)
30 })).unwrap().unwrap();
31
32 sleep(Duration::from_millis(20));
33
34 // example of running arbitrary code on the UI thread
35 sdlh.run_on_ui_thread(Box::new(move |_sdl, windows| {
36 let canvas = windows.get_mut(&window).unwrap();
37 canvas.set_draw_color(Color::RGBA(128, 128, 128, 255));
38 canvas.clear();
39 canvas.present();
40 })).unwrap();
41
42 // create a channel we can use to easily break the loop
43 // from inside the closure.
44 let (tx, rx) = mpsc::channel();
45 while rx.try_recv().is_err() {
46 let tx = tx.clone();
47
48 // handle any new UI events that have happened
49 sdlh.handle_ui_events(Box::new(move |_sdl, windows, event| {
50 match event {
51 &Quit { .. } | &KeyDown { keycode: Some(Keycode::Escape), .. } => {
52 // send a message to rx to cancel the loop
53 tx.send(()).unwrap();
54 },
55
56 &KeyDown { keycode: Some(keycode), .. } => {
57 use sdl2_mt::video::WindowPos::Positioned;
58 let mut canvas = windows.get_mut(&window).unwrap();
59 let (mut x, mut y) = canvas.window().position();
60 match keycode {
61 Keycode::Up => y -= 5,
62 Keycode::Down => y += 5,
63 Keycode::Left => x -= 5,
64 Keycode::Right => x += 5,
65 _ => {}
66 }
67 canvas.window_mut().set_position(Positioned(x), Positioned(y));
68 },
69
70 &Window { win_event: WindowEvent::Resized(new_w, new_h), .. } => {
71 let mut canvas = windows.get_mut(&window).unwrap();
72 canvas.set_draw_color(Color::RGBA(128, (new_h % 256) as u8, (new_w % 256) as u8, 255));
73 canvas.clear();
74 canvas.present();
75 },
76 // false means "this event handler function did not handle this event"
77 // in a multithreaded application, you might have an event handler per window.
78 // this makes it easier to juggle events between handlers.
79 _ => return false
80 }
81 // true means we handled this event
82 true
83 })).unwrap();
84
85 // keep the CPU usage down
86 sleep(Duration::from_millis(15));
87 }
88
89 // not strictly necessary, since when the main thread exits in Rust the entire program is killed.
90 // the exit() function has the effect of terminating the SDL2 UI thread.
91 sdlh.exit().unwrap();
92}pub fn current_video_driver(&self) -> &'static str
pub fn num_video_displays(&self) -> Result<i32, String>
Sourcepub fn display_name(&self, display_index: i32) -> Result<String, String>
pub fn display_name(&self, display_index: i32) -> Result<String, String>
Get the name of the display at the index display_name.
Will return an error if the index is out of bounds or if SDL experienced a failure; inspect the returned string for further info.
pub fn display_bounds(&self, display_index: i32) -> Result<Rect, String>
pub fn num_display_modes(&self, display_index: i32) -> Result<i32, String>
pub fn display_mode( &self, display_index: i32, mode_index: i32, ) -> Result<DisplayMode, String>
pub fn desktop_display_mode( &self, display_index: i32, ) -> Result<DisplayMode, String>
pub fn current_display_mode( &self, display_index: i32, ) -> Result<DisplayMode, String>
pub fn closest_display_mode( &self, display_index: i32, mode: &DisplayMode, ) -> Result<DisplayMode, String>
Sourcepub fn display_dpi(&self, display_index: i32) -> Result<(f32, f32, f32), String>
pub fn display_dpi(&self, display_index: i32) -> Result<(f32, f32, f32), String>
Return a triplet (ddpi, hdpi, vdpi) containing the diagonal, horizontal and vertical
dots/pixels-per-inch of a display
pub fn is_screen_saver_enabled(&self) -> bool
pub fn enable_screen_saver(&self)
pub fn disable_screen_saver(&self)
Sourcepub fn gl_load_library_default(&self) -> Result<(), String>
pub fn gl_load_library_default(&self) -> Result<(), String>
Loads the default OpenGL library.
This should be done after initializing the video driver, but before creating any OpenGL windows. If no OpenGL library is loaded, the default library will be loaded upon creation of the first OpenGL window.
If a different library is already loaded, this function will return an error.
Sourcepub fn gl_load_library<P>(&self, path: P) -> Result<(), String>
pub fn gl_load_library<P>(&self, path: P) -> Result<(), String>
Loads the OpenGL library using a platform-dependent OpenGL library name (usually a file path).
This should be done after initializing the video driver, but before creating any OpenGL windows. If no OpenGL library is loaded, the default library will be loaded upon creation of the first OpenGL window.
If a different library is already loaded, this function will return an error.
Sourcepub fn gl_unload_library(&self)
pub fn gl_unload_library(&self)
Unloads the current OpenGL library.
To completely unload the library, this should be called for every successful load of the OpenGL library.
Sourcepub fn gl_get_proc_address(&self, procname: &str) -> *const ()
pub fn gl_get_proc_address(&self, procname: &str) -> *const ()
Gets the pointer to the named OpenGL function.
This is useful for OpenGL wrappers such as gl-rs.
pub fn gl_extension_supported(&self, extension: &str) -> bool
pub fn gl_get_current_window_id(&self) -> Result<u32, String>
Sourcepub fn gl_release_current_context(&self) -> Result<(), String>
pub fn gl_release_current_context(&self) -> Result<(), String>
Releases the thread’s current OpenGL context, i.e. sets the current OpenGL context to nothing.
pub fn gl_set_swap_interval(&self, interval: i32) -> bool
pub fn gl_get_swap_interval(&self) -> i32
Trait Implementations§
Source§impl Clone for VideoSubsystem
impl Clone for VideoSubsystem
Source§fn clone(&self) -> VideoSubsystem
fn clone(&self) -> VideoSubsystem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more