winit-sonoma-fix/src/lib.rs

244 lines
6.5 KiB
Rust
Raw Normal View History

2014-07-27 18:55:37 +10:00
#![feature(unsafe_destructor)]
2014-07-30 22:13:42 +10:00
#![unstable]
#![allow(unstable)]
2014-07-27 18:55:37 +10:00
2014-08-03 04:49:48 +10:00
//! The purpose of this library is to provide an OpenGL context on as many
//! platforms as possible.
//!
//! # Building a window
2014-09-04 19:38:33 +10:00
//!
2014-08-03 04:49:48 +10:00
//! There are two ways to create a window:
2014-09-04 19:38:33 +10:00
//!
2014-08-03 04:49:48 +10:00
//! - Calling `Window::new()`.
//! - Calling `let builder = WindowBuilder::new()` then `builder.build()`.
//!
//! The first way is the simpliest way and will give you default values.
//!
//! The second way allows you to customize the way your window and GL context
//! will look and behave.
2014-10-05 04:17:02 +11:00
//!
//! # Features
//!
//! This crate has two Cargo features: `window` and `headless`.
//!
//! - `window` allows you to create regular windows and enables the `WindowBuilder` object.
//! - `headless` allows you to do headless rendering, and enables
//! the `HeadlessRendererBuilder` object.
//!
//! By default only `window` is enabled.
2014-08-03 04:49:48 +10:00
2014-11-06 01:22:21 +11:00
extern crate gl_common;
2014-07-27 18:55:37 +10:00
extern crate libc;
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(target_os = "windows")]
extern crate "kernel32-sys" as kernel32;
#[cfg(target_os = "windows")]
extern crate "gdi32-sys" as gdi32;
#[cfg(target_os = "windows")]
extern crate "user32-sys" as user32;
#[cfg(target_os = "macos")]
extern crate cocoa;
#[cfg(target_os = "macos")]
extern crate core_foundation;
#[cfg(target_os = "macos")]
extern crate core_graphics;
2014-07-30 21:11:49 +10:00
pub use events::*;
#[cfg(feature = "headless")]
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
#[cfg(feature = "window")]
pub use window::{WindowBuilder, Window, WindowProxy, PollEventsIterator, WaitEventsIterator};
#[cfg(feature = "window")]
pub use window::{AvailableMonitorsIter, MonitorID, get_available_monitors, get_primary_monitor};
2014-08-13 22:52:12 +10:00
2014-12-05 06:44:12 +11:00
#[cfg(all(not(target_os = "windows"), not(target_os = "linux"), not(target_os = "macos"), not(target_os = "android")))]
use this_platform_is_not_supported;
2014-08-16 00:12:40 +10:00
#[cfg(target_os = "windows")]
2014-10-11 20:06:21 +11:00
#[path="win32/mod.rs"]
mod winimpl;
2014-08-04 02:30:31 +10:00
#[cfg(target_os = "linux")]
2014-10-11 20:06:21 +11:00
#[path="x11/mod.rs"]
mod winimpl;
2014-08-04 02:30:31 +10:00
#[cfg(target_os = "macos")]
2015-01-26 14:28:12 +11:00
#[path="cocoa/mod.rs"]
2014-10-11 20:06:21 +11:00
mod winimpl;
2014-09-12 02:13:50 +10:00
#[cfg(target_os = "android")]
2014-10-11 20:06:21 +11:00
#[path="android/mod.rs"]
mod winimpl;
2014-07-27 18:55:37 +10:00
2014-07-27 20:59:45 +10:00
mod events;
#[cfg(feature = "headless")]
mod headless;
2014-10-05 04:17:02 +11:00
#[cfg(feature = "window")]
mod window;
2014-07-28 04:38:27 +10:00
/// Error that can happen while creating a window or a headless renderer.
2015-01-24 12:50:06 +11:00
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CreationError {
OsError(String),
NotSupported,
}
2015-01-24 12:50:06 +11:00
impl CreationError {
fn to_string(&self) -> &str {
match self {
2014-11-19 16:09:54 +11:00
&CreationError::OsError(ref text) => text.as_slice(),
&CreationError::NotSupported => "Some of the requested attributes are not supported",
}
}
}
2015-01-24 12:50:06 +11:00
impl std::fmt::Display for CreationError {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
formatter.write_str(self.to_string())
}
}
impl std::error::Error for CreationError {
fn description(&self) -> &str {
self.to_string()
}
}
2014-11-19 03:55:26 +11:00
/// All APIs related to OpenGL that you can possibly get while using glutin.
2015-01-24 12:50:06 +11:00
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2014-11-19 03:55:26 +11:00
pub enum Api {
/// The classical OpenGL. Available on Windows, Linux, OS/X.
OpenGl,
/// OpenGL embedded system. Available on Linux, Android.
OpenGlEs,
2015-01-30 04:36:03 +11:00
/// OpenGL for the web. Very similar to OpenGL ES.
WebGl,
2014-11-19 03:55:26 +11:00
}
2015-01-24 12:50:06 +11:00
#[derive(Debug, Copy)]
pub enum MouseCursor {
/// The platform-dependent default cursor.
Default,
/// A simple crosshair.
Crosshair,
/// A hand (often used to indicate links in web browsers).
Hand,
/// Self explanatory.
Arrow,
/// Indicates something is to be moved.
Move,
/// Indicates text that may be selected or edited.
Text,
/// Program busy indicator.
Wait,
/// Help indicator (often rendered as a "?")
Help,
/// Progress indicator. Shows that processing is being done. But in contrast
/// with "Wait" the user may still interact with the program. Often rendered
2015-01-26 14:28:12 +11:00
/// as a spinning beach ball, or an arrow with a watch or hourglass.
Progress,
/// Cursor showing that something cannot be done.
NotAllowed,
ContextMenu,
NoneCursor,
Cell,
VerticalText,
Alias,
Copy,
NoDrop,
Grab,
Grabbing,
AllScroll,
ZoomIn,
ZoomOut,
/// Indicate that some edge is to be moved. For example, the 'SeResize' cursor
/// is used when the movement starts from the south-east corner of the box.
EResize,
NResize,
NeResize,
NwResize,
SResize,
SeResize,
SwResize,
WResize,
EwResize,
NsResize,
NeswResize,
NwseResize,
ColResize,
RowResize,
}
/// Attributes
struct BuilderAttribs<'a> {
#[allow(dead_code)]
headless: bool,
strict: bool,
sharing: Option<&'a winimpl::Window>,
dimensions: Option<(u32, u32)>,
title: String,
monitor: Option<winimpl::MonitorID>,
gl_version: Option<(u32, u32)>,
2014-11-10 02:07:58 +11:00
gl_debug: bool,
vsync: bool,
visible: bool,
2014-11-25 05:35:31 +11:00
multisampling: Option<u16>,
2014-12-29 02:09:28 +11:00
depth_bits: Option<u8>,
stencil_bits: Option<u8>,
color_bits: Option<u8>,
alpha_bits: Option<u8>,
stereoscopy: bool,
}
impl BuilderAttribs<'static> {
fn new() -> BuilderAttribs<'static> {
BuilderAttribs {
headless: false,
strict: false,
2014-11-25 06:13:32 +11:00
sharing: None,
dimensions: None,
2014-10-27 23:10:10 +11:00
title: "glutin window".to_string(),
monitor: None,
gl_version: None,
2014-11-10 02:07:58 +11:00
gl_debug: cfg!(ndebug),
vsync: false,
visible: true,
2014-11-25 05:35:31 +11:00
multisampling: None,
2014-12-29 02:09:28 +11:00
depth_bits: None,
stencil_bits: None,
color_bits: None,
alpha_bits: None,
stereoscopy: false,
}
}
}
impl<'a> BuilderAttribs<'a> {
fn extract_non_static(mut self) -> (BuilderAttribs<'static>, Option<&'a winimpl::Window>) {
let sharing = self.sharing.take();
let new_attribs = BuilderAttribs {
headless: self.headless,
strict: self.strict,
sharing: None,
dimensions: self.dimensions,
title: self.title,
monitor: self.monitor,
gl_version: self.gl_version,
gl_debug: self.gl_debug,
vsync: self.vsync,
visible: self.visible,
multisampling: self.multisampling,
depth_bits: self.depth_bits,
stencil_bits: self.stencil_bits,
color_bits: self.color_bits,
alpha_bits: self.alpha_bits,
stereoscopy: self.stereoscopy,
};
(new_attribs, sharing)
}
}