mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 19:31:30 +11:00
Added NSView for raw_window_handle on macOS
This commit is contained in:
parent
b310fd372c
commit
acc25a0176
|
@ -150,7 +150,7 @@ static bool create_shaders() {
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void* mfb_open(const char* name, int width, int height, uint32_t flags, int scale)
|
||||
void* mfb_open(const char* name, int width, int height, uint32_t flags, int scale, void** view_handle)
|
||||
{
|
||||
bool prev_init = s_init;
|
||||
|
||||
|
@ -283,6 +283,8 @@ void* mfb_open(const char* name, int width, int height, uint32_t flags, int scal
|
|||
if (!prev_init)
|
||||
[NSApp finishLaunching];
|
||||
|
||||
*view_handle = (void*)view;
|
||||
|
||||
//[pool drain];
|
||||
|
||||
return window;
|
||||
|
|
|
@ -161,6 +161,7 @@ extern "C" {
|
|||
height: u32,
|
||||
flags: u32,
|
||||
scale: i32,
|
||||
view_handle: *mut *const c_void,
|
||||
) -> *mut c_void;
|
||||
fn mfb_set_title(window: *mut c_void, title: *const c_char);
|
||||
fn mfb_close(window: *mut c_void);
|
||||
|
@ -218,6 +219,7 @@ pub struct SharedData {
|
|||
|
||||
pub struct Window {
|
||||
window_handle: *mut c_void,
|
||||
view_handle: *const c_void,
|
||||
scale_factor: usize,
|
||||
pub shared_data: SharedData,
|
||||
key_handler: KeyHandler,
|
||||
|
@ -257,7 +259,7 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Window {
|
|||
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
|
||||
let handle = raw_window_handle::macos::MacOSHandle {
|
||||
ns_window: self.window_handle as *mut _,
|
||||
ns_view: std::ptr::null_mut(),
|
||||
ns_view: self.view_handle as *mut _,
|
||||
..raw_window_handle::macos::MacOSHandle::empty()
|
||||
};
|
||||
raw_window_handle::RawWindowHandle::MacOS(handle)
|
||||
|
@ -276,12 +278,14 @@ impl Window {
|
|||
|
||||
unsafe {
|
||||
let scale_factor = Self::get_scale_factor(width, height, opts.scale) as usize;
|
||||
let mut view_handle = ptr::null();
|
||||
let handle = mfb_open(
|
||||
n.as_ptr(),
|
||||
width as u32,
|
||||
height as u32,
|
||||
window_flags::get_flags(opts),
|
||||
scale_factor as i32,
|
||||
&mut view_handle,
|
||||
);
|
||||
|
||||
if handle == ptr::null_mut() {
|
||||
|
@ -290,6 +294,7 @@ impl Window {
|
|||
|
||||
Ok(Window {
|
||||
window_handle: handle,
|
||||
view_handle,
|
||||
scale_factor,
|
||||
shared_data: SharedData {
|
||||
bg_color: 0,
|
||||
|
|
Loading…
Reference in a new issue