[add] content scale

This commit is contained in:
Evgeny Rozaliev 2015-06-08 12:26:42 +03:00
parent 84703027d6
commit 7053837ac1
2 changed files with 15 additions and 7 deletions

View file

@ -13,6 +13,7 @@ use super::ffi::{
nil, nil,
CGRect, CGRect,
CGPoint, CGPoint,
CGFloat,
UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleWidth,
UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleHeight
}; };
@ -25,6 +26,8 @@ pub fn create_delegate_class() {
unsafe { unsafe {
let main_screen: id = msg_send![Class::get("UIScreen").unwrap(), mainScreen]; let main_screen: id = msg_send![Class::get("UIScreen").unwrap(), mainScreen];
let bounds: CGRect = msg_send![main_screen, bounds]; 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![Class::get("UIWindow").unwrap(), alloc];
let window: id = msg_send![window, initWithFrame:bounds.clone()]; 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, addSubview:view];
let _: () = msg_send![window, makeKeyAndVisible]; 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); let state_ptr: *mut DelegateState = mem::transmute(state);
this.set_ivar("glutinState", state_ptr as *mut libc::c_void); this.set_ivar("glutinState", state_ptr as *mut libc::c_void);

View file

@ -95,7 +95,8 @@ use self::ffi::{
RTLD_GLOBAL, RTLD_GLOBAL,
id, id,
nil, nil,
NSString NSString,
CGFloat
}; };
@ -125,18 +126,20 @@ struct DelegateState {
window: id, window: id,
controller: id, controller: id,
view: id, view: id,
size: (u32,u32) size: (u32,u32),
scale: f32
} }
impl DelegateState { 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 { DelegateState {
events_queue: VecDeque::new(), events_queue: VecDeque::new(),
window: window, window: window,
controller: controller, controller: controller,
view: view, 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, setMultipleTouchEnabled:YES];
} }
let _: () = msg_send![state.view, setContentScaleFactor:state.scale as CGFloat];
let layer: id = msg_send![state.view, layer]; 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 _: () = msg_send![layer, setDrawableProperties: draw_props];
let gl = gles::Gles2::load_with(|symbol| self.get_proc_address(symbol)); 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 { if gl.CheckFramebufferStatus(gles::FRAMEBUFFER) != gles::FRAMEBUFFER_COMPLETE {
panic!("framebuffer status: {:?}", status); panic!("framebuffer status: {:?}", status);
} }
} }
fn create_context() -> id { fn create_context() -> id {
@ -326,7 +331,7 @@ impl Window {
} }
pub fn hidpi_factor(&self) -> f32 { pub fn hidpi_factor(&self) -> f32 {
1.0 unsafe { (&*self.delegate_state) }.scale
} }
pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> { pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> {