mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
[add] content scale
This commit is contained in:
parent
84703027d6
commit
7053837ac1
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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<(), ()> {
|
||||||
|
|
Loading…
Reference in a new issue