From e565bfeb1372b885f8cced6a42596b731cb382b2 Mon Sep 17 00:00:00 2001 From: Tomaka17 Date: Sat, 4 Oct 2014 19:17:02 +0200 Subject: Implement headless rendering --- src/osx/mod.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/osx') 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 for HeadlessContext { + fn deref(&self) -> &Window { + &self.0 + } +} + pub struct MonitorID; pub fn get_available_monitors() -> Vec { @@ -31,14 +45,28 @@ impl MonitorID { } } +#[cfg(feature = "window")] impl Window { - pub fn new(_builder: WindowBuilder) -> Result { + pub fn new(builder: WindowBuilder) -> Result { + Window::new_impl(builder.dimensions, builder.title.as_slice(), true) + } +} + +#[cfg(feature = "headless")] +impl HeadlessContext { + pub fn new(builder: HeadlessRendererBuilder) -> Result { + 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 { 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")); }, }; -- cgit v1.2.3