diff options
author | Evgeny Rozaliev <rozaliev@gmail.com> | 2015-06-08 12:26:42 +0300 |
---|---|---|
committer | Evgeny Rozaliev <rozaliev@gmail.com> | 2015-06-08 12:26:42 +0300 |
commit | 7053837ac19d5c6159f492e177d417aa994b7d04 (patch) | |
tree | a117c30bcc620dcbeb3026145d0f3f2192c24587 | |
parent | 84703027d63e22361197a1fc74a4949becf5fccb (diff) | |
download | glutin-7053837ac19d5c6159f492e177d417aa994b7d04.tar.gz glutin-7053837ac19d5c6159f492e177d417aa994b7d04.zip |
[add] content scale
-rw-r--r-- | src/api/ios/delegate.rs | 5 | ||||
-rw-r--r-- | src/api/ios/mod.rs | 17 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/api/ios/delegate.rs b/src/api/ios/delegate.rs index 1d9f90e..62cd89d 100644 --- a/src/api/ios/delegate.rs +++ b/src/api/ios/delegate.rs @@ -13,6 +13,7 @@ use super::ffi::{ nil, CGRect, CGPoint, + CGFloat, UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleHeight }; @@ -25,6 +26,8 @@ pub fn create_delegate_class() { unsafe { let main_screen: id = msg_send![Class::get("UIScreen").unwrap(), mainScreen]; let bounds: CGRect = msg_send![main_screen, bounds]; + let scale: CGFloat = msg_send![main_screen, nativeScale]; + let window: id = msg_send![Class::get("UIWindow").unwrap(), alloc]; let window: id = msg_send![window, initWithFrame:bounds.clone()]; @@ -47,7 +50,7 @@ pub fn create_delegate_class() { let _: () = msg_send![window, addSubview:view]; let _: () = msg_send![window, makeKeyAndVisible]; - let state = Box::new(DelegateState::new(window, view_controller, view, size)); + let state = Box::new(DelegateState::new(window, view_controller, view, size, scale as f32)); let state_ptr: *mut DelegateState = mem::transmute(state); this.set_ivar("glutinState", state_ptr as *mut libc::c_void); diff --git a/src/api/ios/mod.rs b/src/api/ios/mod.rs index fbb0c93..9d1b527 100644 --- a/src/api/ios/mod.rs +++ b/src/api/ios/mod.rs @@ -95,7 +95,8 @@ use self::ffi::{ RTLD_GLOBAL, id, nil, - NSString + NSString, + CGFloat }; @@ -125,18 +126,20 @@ struct DelegateState { window: id, controller: id, view: id, - size: (u32,u32) + size: (u32,u32), + scale: f32 } impl DelegateState { - fn new(window: id, controller:id, view: id, size: (u32,u32)) -> DelegateState { + fn new(window: id, controller:id, view: id, size: (u32,u32), scale: f32) -> DelegateState { DelegateState { events_queue: VecDeque::new(), window: window, controller: controller, view: view, - size: size + size: size, + scale: scale } } } @@ -220,7 +223,10 @@ impl Window { let _: () = msg_send![state.view, setMultipleTouchEnabled:YES]; } + let _: () = msg_send![state.view, setContentScaleFactor:state.scale as CGFloat]; + let layer: id = msg_send![state.view, layer]; + let _: () = msg_send![layer, setContentsScale:state.scale as CGFloat]; let _: () = msg_send![layer, setDrawableProperties: draw_props]; let gl = gles::Gles2::load_with(|symbol| self.get_proc_address(symbol)); @@ -243,7 +249,6 @@ impl Window { if gl.CheckFramebufferStatus(gles::FRAMEBUFFER) != gles::FRAMEBUFFER_COMPLETE { panic!("framebuffer status: {:?}", status); } - } fn create_context() -> id { @@ -326,7 +331,7 @@ impl Window { } pub fn hidpi_factor(&self) -> f32 { - 1.0 + unsafe { (&*self.delegate_state) }.scale } pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { |