winit-sonoma-fix/src/lib.rs

109 lines
2.3 KiB
Rust
Raw Normal View History

2014-07-27 18:55:37 +10:00
#![feature(unsafe_destructor)]
2014-07-30 21:11:49 +10:00
#![feature(globs)]
2014-07-27 18:55:37 +10:00
extern crate libc;
2014-07-30 21:11:49 +10:00
pub use events::*;
2014-07-27 20:59:45 +10:00
pub use hints::{Hints, ClientAPI, Profile};
2014-07-27 18:55:37 +10:00
#[cfg(windows)]
2014-07-27 20:59:45 +10:00
use winimpl = win32;
2014-07-27 23:10:58 +10:00
#[cfg(unix)]
use winimpl = x11;
2014-07-27 18:55:37 +10:00
#[cfg(windows)]
mod win32;
2014-07-27 23:10:58 +10:00
#[cfg(unix)]
mod x11;
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
mod events;
mod hints;
2014-07-27 18:55:37 +10:00
2014-07-28 04:38:27 +10:00
pub struct MonitorID(uint);
2014-07-27 20:59:45 +10:00
pub struct Window {
2014-07-27 23:11:59 +10:00
window: winimpl::Window,
nosend: std::kinds::marker::NoSend,
2014-07-27 20:59:45 +10:00
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
impl Window {
#[inline]
2014-07-28 04:38:27 +10:00
pub fn new(dimensions: Option<(uint, uint)>, title: &str,
hints: &Hints, monitor: Option<MonitorID>)
2014-07-27 20:59:45 +10:00
-> Result<Window, String>
{
2014-07-28 04:38:27 +10:00
let win = try!(winimpl::Window::new(dimensions, title, hints, monitor));
2014-07-27 23:11:59 +10:00
Ok(Window{
window: win,
nosend: std::kinds::marker::NoSend,
})
2014-07-27 20:59:45 +10:00
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
/// Returns true if the window has been closed by the user.
#[inline]
pub fn should_close(&self) -> bool {
self.window.should_close()
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
/// Modifies the title of the window.
#[inline]
pub fn set_title(&self, title: &str) {
self.window.set_title(title)
}
2014-07-27 18:55:37 +10:00
/// Returns the position of the window relative to the top-left hand corner of the screen.
///
/// Returns `None` if the window no longer exists.
2014-07-27 20:59:45 +10:00
#[inline]
pub fn get_position(&self) -> Option<(int, int)> {
2014-07-27 20:59:45 +10:00
self.window.get_position()
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
#[inline]
pub fn set_position(&self, x: uint, y: uint) {
self.window.set_position(x, y)
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
#[inline]
pub fn get_inner_size(&self) -> Option<(uint, uint)> {
self.window.get_inner_size()
2014-07-27 20:59:45 +10:00
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
#[inline]
pub fn get_outer_size(&self) -> Option<(uint, uint)> {
self.window.get_outer_size()
}
#[inline]
pub fn set_inner_size(&self, x: uint, y: uint) {
self.window.set_inner_size(x, y)
2014-07-27 20:59:45 +10:00
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
// TODO: return iterator
#[inline]
pub fn poll_events(&self) -> Vec<Event> {
self.window.poll_events()
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
// TODO: return iterator
#[inline]
pub fn wait_events(&self) -> Vec<Event> {
self.window.wait_events()
}
#[inline]
pub fn make_current(&self) {
self.window.make_current()
}
#[inline]
pub fn get_proc_address(&self, addr: &str) -> *const () {
self.window.get_proc_address(addr)
}
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
#[inline]
pub fn swap_buffers(&self) {
self.window.swap_buffers()
2014-07-27 18:55:37 +10:00
}
}