diff options
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | src/api/android/mod.rs | 23 | ||||
-rw-r--r-- | src/api/ios/mod.rs | 37 | ||||
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/platform/ios/mod.rs | 11 |
5 files changed, 51 insertions, 30 deletions
@@ -28,7 +28,10 @@ khronos_api = "0.0.7" clock_ticks = "0.0.5" [target.arm-linux-androideabi.dependencies.android_glue] -version = "0" +version = "0.1" + +[target.i386-apple-ios.dependencies] +objc = "0.1" [target.x86_64-apple-ios.dependencies] objc = "0.1" diff --git a/src/api/android/mod.rs b/src/api/android/mod.rs index be5a79f..12d0bea 100644 --- a/src/api/android/mod.rs +++ b/src/api/android/mod.rs @@ -8,8 +8,7 @@ use std::sync::mpsc::{Receiver, channel}; use {CreationError, Event, MouseCursor}; use CreationError::OsError; use events::ElementState::{Pressed, Released}; -use events::Event::{MouseInput, MouseMoved}; -use events::MouseButton; +use events::{Touch, TouchPhase}; use std::collections::VecDeque; @@ -70,15 +69,19 @@ impl<'a> Iterator for PollEventsIterator<'a> { fn next(&mut self) -> Option<Event> { match self.window.event_rx.try_recv() { - Ok(event) => { - match event { - android_glue::Event::EventDown => Some(MouseInput(Pressed, MouseButton::Left)), - android_glue::Event::EventUp => Some(MouseInput(Released, MouseButton::Left)), - android_glue::Event::EventMove(x, y) => Some(MouseMoved((x as i32, y as i32))), - _ => None, - } + Ok(android_glue::Event::EventMotion(motion)) => { + Some(Event::Touch(Touch { + phase: match motion.action { + android_glue::MotionAction::Down => TouchPhase::Started, + android_glue::MotionAction::Move => TouchPhase::Moved, + android_glue::MotionAction::Up => TouchPhase::Ended, + android_glue::MotionAction::Cancel => TouchPhase::Cancelled, + }, + location: (motion.x as f64, motion.y as f64), + id: motion.pointer_id as u64, + })) } - Err(_) => { + _ => { None } } diff --git a/src/api/ios/mod.rs b/src/api/ios/mod.rs index 0163f45..ef34955 100644 --- a/src/api/ios/mod.rs +++ b/src/api/ios/mod.rs @@ -64,6 +64,7 @@ use std::collections::VecDeque; use std::ptr; +use std::io; use std::mem; use std::ffi::CString; @@ -71,7 +72,8 @@ use libc; use objc::runtime::{Class, BOOL, YES, NO }; use native_monitor::NativeMonitorId; -use { Api, PixelFormat, CreationError, BuilderAttribs, GlContext, CursorState, MouseCursor, Event }; +use { Api, PixelFormat, CreationError, GlContext, CursorState, MouseCursor, Event }; +use { PixelFormatRequirements, GlAttributes, WindowAttributes, ContextError }; use CreationError::OsError; mod delegate; @@ -102,6 +104,7 @@ use self::ffi::{ static mut jmpbuf: [libc::c_int;27] = [0;27]; +#[derive(Clone)] pub struct MonitorID; pub struct Window { @@ -172,7 +175,7 @@ impl MonitorID { impl Window { - pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> { + pub fn new(builder: &WindowAttributes, _: &PixelFormatRequirements, _: &GlAttributes<&Window>) -> Result<Window, CreationError> { unsafe { if setjmp(mem::transmute(&mut jmpbuf)) != 0 { let app: id = msg_send![Class::get("UIApplication").unwrap(), sharedApplication]; @@ -200,7 +203,7 @@ impl Window { Err(CreationError::OsError(format!("Couldn't create UIApplication"))) } - unsafe fn init_context(&mut self, builder: BuilderAttribs) { + unsafe fn init_context(&mut self, builder: &WindowAttributes) { let draw_props: id = msg_send![Class::get("NSDictionary").unwrap(), alloc]; let draw_props: id = msg_send![draw_props, initWithObjects: @@ -215,11 +218,11 @@ impl Window { ].as_ptr() count: 2 ]; - self.make_current(); + let _ = self.make_current(); let state = &mut *self.delegate_state; - if builder.window.multitouch { + if builder.multitouch { let _: () = msg_send![state.view, setMultipleTouchEnabled:YES]; } @@ -265,10 +268,6 @@ impl Window { } } - pub fn is_closed(&self) -> bool { - false - } - pub fn set_title(&self, _: &str) { } @@ -345,8 +344,13 @@ impl Window { } impl GlContext for Window { - unsafe fn make_current(&self) { - let _:BOOL = msg_send![Class::get("EAGLContext").unwrap(), setCurrentContext: self.eagl_context]; + unsafe fn make_current(&self) -> Result<(), ContextError> { + let res: BOOL = msg_send![Class::get("EAGLContext").unwrap(), setCurrentContext: self.eagl_context]; + if res == YES { + Ok(()) + } else { + Err(ContextError::IoError(io::Error::new(io::ErrorKind::Other, "EAGLContext::setCurrentContext unsuccessful"))) + } } fn is_current(&self) -> bool { @@ -362,8 +366,15 @@ impl GlContext for Window { } } - fn swap_buffers(&self) { - unsafe { let _:BOOL = msg_send![self.eagl_context, presentRenderbuffer: gles::RENDERBUFFER]; } + fn swap_buffers(&self) -> Result<(), ContextError> { + unsafe { + let res: BOOL = msg_send![self.eagl_context, presentRenderbuffer: gles::RENDERBUFFER]; + if res == YES { + Ok(()) + } else { + Err(ContextError::IoError(io::Error::new(io::ErrorKind::Other, "EAGLContext.presentRenderbuffer unsuccessful"))) + } + } } fn get_api(&self) -> Api { @@ -362,7 +362,7 @@ pub struct PixelFormat { pub multisampling: Option<u16>, pub srgb: bool, } - + /// VERY UNSTABLE! Describes how the backend should choose a pixel format. #[derive(Clone, Debug)] #[allow(missing_docs)] @@ -526,7 +526,8 @@ pub struct WindowAttributes { /// The default is `true`. pub decorations: bool, - /// ??? TODO: document me + /// [iOS only] Enable multitouch, see [UIView#multipleTouchEnabled] + /// (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instp/UIView/multipleTouchEnabled) pub multitouch: bool, } diff --git a/src/platform/ios/mod.rs b/src/platform/ios/mod.rs index 7cbdd84..95fa7e1 100644 --- a/src/platform/ios/mod.rs +++ b/src/platform/ios/mod.rs @@ -1,9 +1,11 @@ #![cfg(target_os = "ios")] use libc::c_void; -use BuilderAttribs; +use GlAttributes; use CreationError; use PixelFormat; +use PixelFormatRequirements; +use ContextError; pub use api::ios::*; @@ -11,16 +13,17 @@ pub struct HeadlessContext(i32); impl HeadlessContext { /// See the docs in the crate root file. - pub fn new(_builder: BuilderAttribs) -> Result<HeadlessContext, CreationError> { + pub fn new(_: (u32, u32), _: &PixelFormatRequirements, _: &GlAttributes<&HeadlessContext>) + -> Result<HeadlessContext, CreationError> { unimplemented!() } /// See the docs in the crate root file. - pub unsafe fn make_current(&self) { + pub unsafe fn make_current(&self) -> Result<(), ContextError> { unimplemented!() } - pub fn swap_buffers(&self) { + pub fn swap_buffers(&self) -> Result<(), ContextError> { unimplemented!() } |