diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2014-10-09 20:04:02 +0200 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2014-10-09 20:04:02 +0200 |
commit | 093c188b114d879543b98f60b6e9a3489d9cf70f (patch) | |
tree | 4a788e43172cd968c2a2cd1bd7d3102ea6937c80 /src/osx | |
parent | cfb0cb70013772492c1930ced62f48aa6cb372ff (diff) | |
parent | e565bfeb1372b885f8cced6a42596b731cb382b2 (diff) | |
download | glutin-093c188b114d879543b98f60b6e9a3489d9cf70f.tar.gz glutin-093c188b114d879543b98f60b6e9a3489d9cf70f.zip |
Merge pull request #44 from tomaka/headless-rendering
Implement headless rendering
Diffstat (limited to 'src/osx')
-rw-r--r-- | src/osx/mod.rs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/osx/mod.rs b/src/osx/mod.rs index d41c9c7..78d147f 100644 --- a/src/osx/mod.rs +++ b/src/osx/mod.rs @@ -1,4 +1,10 @@ -use {Event, WindowBuilder}; +use Event; + +#[cfg(feature = "window")] +use WindowBuilder; + +#[cfg(feature = "headless")] +use HeadlessRendererBuilder; use cocoa::base::{id, NSUInteger, nil}; use cocoa::appkit::*; @@ -11,6 +17,14 @@ pub struct Window { context: id, } +pub struct HeadlessContext(Window); + +impl Deref<Window> for HeadlessContext { + fn deref(&self) -> &Window { + &self.0 + } +} + pub struct MonitorID; pub fn get_available_monitors() -> Vec<MonitorID> { @@ -31,14 +45,28 @@ impl MonitorID { } } +#[cfg(feature = "window")] impl Window { - pub fn new(_builder: WindowBuilder) -> Result<Window, String> { + pub fn new(builder: WindowBuilder) -> Result<Window, String> { + Window::new_impl(builder.dimensions, builder.title.as_slice(), true) + } +} + +#[cfg(feature = "headless")] +impl HeadlessContext { + pub fn new(builder: HeadlessRendererBuilder) -> Result<HeadlessContext, String> { + Window::new_impl(Some(builder.dimensions), "", false) + .map(|w| HeadlessContext(w)) + } +} +impl Window { + fn new_impl(dimensions: Option<(uint, uint)>, title: &str, visible: bool) -> Result<Window, String> { let app = match Window::create_app() { Some(app) => app, None => { return Err(format!("Couldn't create NSApplication")); }, }; - let window = match Window::create_window(_builder.dimensions.unwrap_or((800, 600)), _builder.title.as_slice()) { + let window = match Window::create_window(dimensions.unwrap_or((800, 600)), title) { Some(window) => window, None => { return Err(format!("Couldn't create NSWindow")); }, }; |