mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2024-12-23 11:21:30 +11:00
Implemented set_position for Mac
This commit is contained in:
parent
b576ab3139
commit
001bca8f74
|
@ -20,8 +20,6 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
window.set_position(10, 10);
|
||||
|
||||
while window.is_open() && !window.is_key_down(Key::Escape) {
|
||||
for i in buffer.iter_mut() {
|
||||
noise = seed;
|
||||
|
|
|
@ -93,6 +93,26 @@ int mfb_update(void* window, void* buffer)
|
|||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static float transformY(float y)
|
||||
{
|
||||
float b = CGDisplayBounds(CGMainDisplayID()).size.height;
|
||||
float t = b - y;
|
||||
return t;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void mfb_set_position(void* window, int x, int y)
|
||||
{
|
||||
OSXWindow* win = (OSXWindow*)window;
|
||||
const NSRect contentRect = [[win contentView] frame];
|
||||
const NSRect dummyRect = NSMakeRect(x, transformY(y + contentRect.size.height), 0, 0);
|
||||
const NSRect frameRect = [win frameRectForContentRect:dummyRect];
|
||||
[win setFrameOrigin:frameRect.origin];
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int mfb_should_close(void* window)
|
||||
{
|
||||
OSXWindow* win = (OSXWindow*)window;
|
||||
|
|
|
@ -146,6 +146,7 @@ extern {
|
|||
fn mfb_open(name: *const c_char, width: u32, height: u32, scale: i32) -> *mut c_void;
|
||||
fn mfb_close(window: *mut c_void);
|
||||
fn mfb_update(window: *mut c_void, buffer: *const c_uchar);
|
||||
fn mfb_set_position(window: *mut c_void, x: i32, y: i32);
|
||||
fn mfb_set_key_callback(window: *mut c_void, target: *mut c_void, cb: unsafe extern fn(*mut c_void, i32, i32));
|
||||
fn mfb_should_close(window: *mut c_void) -> i32;
|
||||
fn mfb_get_screen_size() -> u32;
|
||||
|
@ -202,7 +203,8 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_position(&mut self, _: isize, _: isize) {
|
||||
pub fn set_position(&mut self, x: isize, y: isize) {
|
||||
unsafe { mfb_set_position(self.window_handle, x as i32, y as i32) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in a new issue