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
2015-04-03 17:33:51 +11:00
#[ macro_use ]
extern crate lazy_static ;
2015-04-27 22:25:53 +10:00
#[ macro_use ]
extern crate shared_library ;
2014-07-27 18:55:37 +10:00
extern crate libc ;
2014-12-02 04:24:15 +11:00
#[ cfg(target_os = " windows " ) ]
extern crate winapi ;
2015-01-26 13:52:17 +11:00
#[ cfg(target_os = " windows " ) ]
2015-03-28 21:07:41 +11:00
extern crate kernel32 ;
2015-01-26 13:52:17 +11:00
#[ cfg(target_os = " windows " ) ]
2015-06-24 08:05:37 +10:00
extern crate shell32 ;
#[ cfg(target_os = " windows " ) ]
2015-03-30 14:58:13 +11:00
extern crate gdi32 ;
2015-01-26 13:52:17 +11:00
#[ cfg(target_os = " windows " ) ]
2015-03-30 14:58:13 +11:00
extern crate user32 ;
2015-05-21 02:46:10 +10:00
#[ cfg(target_os = " windows " ) ]
extern crate dwmapi ;
2015-06-05 23:38:21 +10:00
#[ cfg(any(target_os = " macos " , target_os = " ios " )) ]
2015-03-22 16:31:32 +11:00
#[ macro_use ]
extern crate objc ;
#[ cfg(target_os = " macos " ) ]
2015-06-16 07:28:29 +10:00
extern crate cgl ;
#[ cfg(target_os = " macos " ) ]
2014-10-04 23:49:39 +10:00
extern crate cocoa ;
#[ cfg(target_os = " macos " ) ]
extern crate core_foundation ;
2014-11-05 04:03:38 +11:00
#[ cfg(target_os = " macos " ) ]
2015-06-04 14:13:18 +10:00
extern crate core_graphics ;
2016-03-02 13:06:13 +11:00
#[ cfg(any(target_os = " linux " , target_os = " dragonfly " , target_os = " freebsd " , target_os = " openbsd " )) ]
2015-05-07 21:20:25 +10:00
extern crate x11_dl ;
2016-03-02 13:06:13 +11:00
#[ cfg(any(target_os = " linux " , target_os = " freebsd " , target_os = " dragonfly " , target_os = " openbsd " )) ]
2015-12-05 06:39:52 +11:00
#[ macro_use(wayland_env) ]
extern crate wayland_client ;
2014-10-04 23:49:39 +10:00
2014-07-30 21:11:49 +10:00
pub use events ::* ;
2015-09-26 02:04:55 +10:00
pub use window ::{ WindowBuilder , WindowProxy , PollEventsIterator , WaitEventsIterator } ;
2015-09-24 17:11:59 +10:00
pub use window ::{ AvailableMonitorsIter , MonitorId , get_available_monitors , get_primary_monitor } ;
2015-03-19 08:16:35 +11:00
pub use native_monitor ::NativeMonitorId ;
2014-08-13 22:52:12 +10:00
2015-04-24 17:51:23 +10:00
mod api ;
2015-04-02 17:27:32 +11:00
mod platform ;
2014-07-27 20:59:45 +10:00
mod events ;
2015-02-16 19:29:37 +11:00
mod window ;
2014-07-28 04:38:27 +10:00
2015-09-26 02:04:55 +10:00
pub mod os ;
/// Represents an OpenGL context and the Window or environment around it.
///
/// # Example
///
/// ```ignore
/// let window = Window::new().unwrap();
///
/// unsafe { window.make_current() };
///
/// loop {
/// for event in window.poll_events() {
/// match(event) {
/// // process events here
/// _ => ()
/// }
/// }
///
/// // draw everything here
///
/// window.swap_buffers();
/// std::old_io::timer::sleep(17);
/// }
/// ```
pub struct Window {
window : platform ::Window ,
}
2014-11-06 02:42:18 +11:00
/// Error that can happen while creating a window or a headless renderer.
2015-09-20 16:42:32 +10:00
#[ derive(Debug) ]
2014-11-06 02:42:18 +11:00
pub enum CreationError {
OsError ( String ) ,
2015-07-21 03:43:36 +10:00
/// TODO: remove this error
2014-12-29 01:53:24 +11:00
NotSupported ,
2014-11-06 02:42:18 +11:00
}
2015-01-24 12:50:06 +11:00
impl CreationError {
fn to_string ( & self ) -> & str {
2015-02-22 10:07:35 +11:00
match * self {
2015-03-26 05:57:38 +11:00
CreationError ::OsError ( ref text ) = > & text ,
2015-02-22 10:07:35 +11:00
CreationError ::NotSupported = > " Some of the requested attributes are not supported " ,
2014-11-06 02:42:18 +11:00
}
}
}
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 ( )
2015-09-20 16:42:32 +10:00
}
2015-12-19 21:24:09 +11:00
}
2015-04-04 03:36:57 +11:00
#[ derive(Debug, Copy, Clone) ]
2015-01-13 11:22:37 +11:00
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.
2015-01-13 11:22:37 +11:00
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 ,
}
2015-03-27 03:04:01 +11:00
/// Describes how glutin handles the cursor.
2015-04-04 03:36:57 +11:00
#[ derive(Debug, Copy, Clone) ]
2015-03-27 03:04:01 +11:00
pub enum CursorState {
/// Normal cursor behavior.
Normal ,
/// The cursor will be invisible when over the window.
Hide ,
/// Grabs the mouse cursor. The cursor's motion will be confined to this
/// window and the window has exclusive access to further events regarding
/// the cursor.
///
/// This is useful for first-person cameras for example.
Grab ,
}
2015-09-21 17:15:53 +10:00
/// Attributes to use when creating a window.
#[ derive(Clone) ]
pub struct WindowAttributes {
/// The dimensions of the window. If this is `None`, some platform-specific dimensions will be
/// used.
///
/// The default is `None`.
pub dimensions : Option < ( u32 , u32 ) > ,
2015-11-09 22:13:52 +11:00
/// The minimum dimensions a window can be, If this is `None`, the window will have no minimum dimensions (aside from reserved).
2015-11-09 20:42:54 +11:00
///
/// The default is `None`.
pub min_dimensions : Option < ( u32 , u32 ) > ,
2015-11-09 22:13:52 +11:00
/// The maximum dimensions a window can be, If this is `None`, the maximum will have no maximum or will be set to the primary monitor's dimensions by the platform.
2015-11-09 20:42:54 +11:00
///
/// The default is `None`.
pub max_dimensions : Option < ( u32 , u32 ) > ,
2015-09-21 17:15:53 +10:00
/// If `Some`, the window will be in fullscreen mode with the given monitor.
///
/// The default is `None`.
2015-09-24 17:11:59 +10:00
pub monitor : Option < platform ::MonitorId > ,
2015-09-21 17:15:53 +10:00
/// The title of the window in the title bar.
///
/// The default is `"glutin window"`.
pub title : String ,
/// Whether the window should be immediately visible upon creation.
///
/// The default is `true`.
pub visible : bool ,
/// Whether the the window should be transparent. If this is true, writing colors
/// with alpha values different than `1.0` will produce a transparent window.
///
/// The default is `false`.
pub transparent : bool ,
/// Whether the window should have borders and bars.
///
/// The default is `true`.
pub decorations : bool ,
2015-09-22 02:57:35 +10:00
/// [iOS only] Enable multitouch, see [UIView#multipleTouchEnabled]
/// (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instp/UIView/multipleTouchEnabled)
2015-09-21 17:15:53 +10:00
pub multitouch : bool ,
}
impl Default for WindowAttributes {
2015-09-21 22:42:05 +10:00
#[ inline ]
2015-09-21 17:15:53 +10:00
fn default ( ) -> WindowAttributes {
WindowAttributes {
dimensions : None ,
2015-11-09 20:42:54 +11:00
min_dimensions : None ,
max_dimensions : None ,
2015-09-21 17:15:53 +10:00
monitor : None ,
title : " glutin window " . to_owned ( ) ,
visible : true ,
transparent : false ,
decorations : true ,
multitouch : false ,
}
}
}
2015-03-19 08:16:35 +11:00
mod native_monitor {
/// Native platform identifier for a monitor. Different platforms use fundamentally different types
/// to represent a monitor ID.
2015-07-19 21:53:40 +10:00
#[ derive(Clone, PartialEq, Eq) ]
2015-03-19 08:16:35 +11:00
pub enum NativeMonitorId {
/// Cocoa and X11 use a numeric identifier to represent a monitor.
Numeric ( u32 ) ,
/// Win32 uses a Unicode string to represent a monitor.
Name ( String ) ,
/// Other platforms (Android) don't support monitor identification.
Unavailable
}
}