mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-27 02:56:33 +11:00
Started with implementing get_size()
Currently Mac is implemented with stub versions for Linux and Windows
This commit is contained in:
parent
3565e1cb3f
commit
f540aae1b9
5 changed files with 73 additions and 17 deletions
15
src/lib.rs
15
src/lib.rs
|
@ -251,6 +251,21 @@ impl Window {
|
||||||
self.0.set_position(x, y)
|
self.0.set_position(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns the current size of the window
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// let size = window.get_size();
|
||||||
|
/// println!("width {} height {}", size.0, size.1);
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
#[inline]
|
||||||
|
pub fn get_size(&self) -> (usize, usize) {
|
||||||
|
self.0.get_size()
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Get the current position of the mouse relative to the current window
|
/// Get the current position of the mouse relative to the current window
|
||||||
/// The coordinate system is as 0, 0 as the upper left corner
|
/// The coordinate system is as 0, 0 as the upper left corner
|
||||||
|
|
|
@ -95,5 +95,32 @@
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
- (void)viewDidMoveToWindow
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
|
selector:@selector(windowResized:) name:NSWindowDidResizeNotification
|
||||||
|
object:[self window]];
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
- (void)windowResized:(NSNotification *)notification;
|
||||||
|
{
|
||||||
|
NSSize size = [[self window] frame].size;
|
||||||
|
OSXWindow* window = (OSXWindow*)[self window];
|
||||||
|
window->shared_data->width = (int)size.width;
|
||||||
|
window->shared_data->height = (int)size.height;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -280,6 +280,10 @@ impl Window {
|
||||||
unsafe { mfb_set_position(self.window_handle, x as i32, y as i32) }
|
unsafe { mfb_set_position(self.window_handle, x as i32, y as i32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_size(&self) -> (usize, usize) {
|
||||||
|
(self.shared_data.width as usize, self.shared_data.height as usize)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_scroll_wheel(&self) -> Option<(f32, f32)> {
|
pub fn get_scroll_wheel(&self) -> Option<(f32, f32)> {
|
||||||
let sx = self.shared_data.scroll_x;
|
let sx = self.shared_data.scroll_x;
|
||||||
let sy = self.shared_data.scroll_y;
|
let sy = self.shared_data.scroll_y;
|
||||||
|
|
|
@ -233,6 +233,11 @@ impl Window {
|
||||||
unsafe { mfb_set_position(self.window_handle, x as i32, y as i32) }
|
unsafe { mfb_set_position(self.window_handle, x as i32, y as i32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_size(&self) -> (usize, usize) {
|
||||||
|
(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_mouse_pos(&self, mode: MouseMode) -> Option<(f32, f32)> {
|
pub fn get_mouse_pos(&self, mode: MouseMode) -> Option<(f32, f32)> {
|
||||||
let s = self.shared_data.scale as f32;
|
let s = self.shared_data.scale as f32;
|
||||||
let w = self.shared_data.width as f32;
|
let w = self.shared_data.width as f32;
|
||||||
|
|
|
@ -465,6 +465,11 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_size(&self) -> (usize, usize) {
|
||||||
|
(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_mouse_pos(&self, mode: MouseMode) -> Option<(f32, f32)> {
|
pub fn get_mouse_pos(&self, mode: MouseMode) -> Option<(f32, f32)> {
|
||||||
let s = self.scale_factor as f32;
|
let s = self.scale_factor as f32;
|
||||||
let w = self.width as f32;
|
let w = self.width as f32;
|
||||||
|
|
Loading…
Add table
Reference in a new issue