Started with implementing get_size()

Currently Mac is implemented with stub versions for Linux and Windows
This commit is contained in:
Daniel Collin 2016-05-01 09:54:34 +02:00
parent 3565e1cb3f
commit f540aae1b9
5 changed files with 73 additions and 17 deletions

View file

@ -251,6 +251,21 @@ impl Window {
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
/// The coordinate system is as 0, 0 as the upper left corner

View file

@ -95,5 +95,32 @@
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

View file

@ -280,6 +280,10 @@ impl Window {
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)> {
let sx = self.shared_data.scroll_x;
let sy = self.shared_data.scroll_y;

View file

@ -233,6 +233,11 @@ impl Window {
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)> {
let s = self.shared_data.scale as f32;
let w = self.shared_data.width as f32;

View file

@ -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)> {
let s = self.scale_factor as f32;
let w = self.width as f32;