#[derive(Clone, Copy)]
pub enum Scale {
FitScreen,
X1,
X2,
X4,
X8,
X16,
X32,
}
#[derive(PartialEq, Clone, Copy)]
pub enum KeyRepeat {
Yes,
No,
}
#[derive(PartialEq, Clone, Copy)]
pub enum MouseButton
{
Left,
Middle,
Right,
}
#[derive(PartialEq, Clone, Copy)]
pub enum MouseMode {
Pass,
Clamp,
Discard,
}
extern crate libc;
use std::os::raw;
#[doc(hidden)]
mod error;
pub use self::error::Error;
pub type Result<T> = std::result::Result<T, Error>;
pub mod key;
pub use key::Key as Key;
pub mod os;
mod mouse_handler;
mod key_handler;
mod window_flags;
mod menu;
pub use menu::Menu as Menu;
pub use menu::MENU_KEY_COMMAND;
pub use menu::MENU_KEY_WIN;
pub use menu::MENU_KEY_SHIFT;
pub use menu::MENU_KEY_CTRL;
pub use menu::MENU_KEY_ALT;
#[cfg(target_os = "macos")]
use self::os::macos as imp;
#[cfg(target_os = "windows")]
use self::os::windows as imp;
#[cfg(any(target_os="linux",
target_os="freebsd",
target_os="dragonfly",
target_os="netbsd",
target_os="openbsd"))]
use self::os::unix as imp;
pub struct Window(imp::Window);
pub struct WindowOptions {
pub borderless: bool,
pub title: bool,
pub resize: bool,
pub scale: Scale
}
impl Window {
pub fn new(name: &str, width: usize, height: usize, opts: WindowOptions) -> Result<Window> {
imp::Window::new(name, width, height, opts).map(Window)
}
#[inline]
pub fn get_window_handle(&self) -> *mut raw::c_void {
self.0.get_window_handle()
}
#[inline]
pub fn update_with_buffer(&mut self, buffer: &[u32]) {
self.0.update_with_buffer(buffer)
}
#[inline]
pub fn update(&mut self) {
self.0.update()
}
#[inline]
pub fn is_open(&self) -> bool {
self.0.is_open()
}
#[inline]
pub fn set_position(&mut self, x: isize, y: isize) {
self.0.set_position(x, y)
}
#[inline]
pub fn get_mouse_pos(&self, mode: MouseMode) -> Option<(f32, f32)> {
self.0.get_mouse_pos(mode)
}
#[inline]
pub fn get_mouse_down(&self, button: MouseButton) -> bool {
self.0.get_mouse_down(button)
}
#[inline]
pub fn get_scroll_wheel(&self) -> Option<(f32, f32)> {
self.0.get_scroll_wheel()
}
#[inline]
pub fn get_keys(&self) -> Option<Vec<Key>> {
self.0.get_keys()
}
#[inline]
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Option<Vec<Key>> {
self.0.get_keys_pressed(repeat)
}
#[inline]
pub fn is_key_down(&self, key: Key) -> bool {
self.0.is_key_down(key)
}
#[inline]
pub fn is_key_pressed(&self, key: Key, repeat: KeyRepeat) -> bool {
self.0.is_key_pressed(key, repeat)
}
#[inline]
pub fn set_key_repeat_delay(&mut self, delay: f32) {
self.0.set_key_repeat_delay(delay)
}
#[inline]
pub fn set_key_repeat_rate(&mut self, rate: f32) {
self.0.set_key_repeat_rate(rate)
}
#[inline]
pub fn is_active(&mut self) -> bool {
self.0.is_active()
}
#[inline]
pub fn add_menu(&mut self, menu_name: &str, menu: &Vec<Menu>) -> Result<()> {
self.0.add_menu(menu_name, menu)
}
#[inline]
pub fn update_menu(&mut self, menu_name: &str, menu: &Vec<Menu>) -> Result<()> {
self.0.update_menu(menu_name, menu)
}
#[inline]
pub fn remove_menu(&mut self, menu_name: &str) -> Result<()> {
self.0.remove_menu(menu_name)
}
#[inline]
pub fn is_menu_pressed(&mut self) -> Option<usize> {
self.0.is_menu_pressed()
}
}
#[doc(hidden)]
impl Default for WindowOptions {
fn default() -> WindowOptions {
WindowOptions {
borderless: false,
title: true,
resize: false,
scale: Scale::X1,
}
}
}