From 5772cc53806b384a3e8db5398aa17b4f6e311883 Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Tue, 3 Dec 2019 15:24:03 +0100 Subject: [PATCH] Merge dev -> master (#111) * Deprecated update_with_buffer and added a temporary (update_with_buffer_size) for now. This will later be removed and the update_with_buffer is requiring the size to bu suplied * Reparation for 0.14 release * Missed one case --- CHANGELOG.md | 14 ++++++++++++++ Cargo.toml | 2 +- README.md | 6 +++--- examples/julia.rs | 2 +- examples/menu.rs | 3 +-- examples/mouse.rs | 2 +- examples/multi.rs | 4 ++-- examples/noise.rs | 12 +++++------- examples/title_cursor.rs | 2 +- src/lib.rs | 40 +++++++++++++++++++++++++++++++++++++++- 10 files changed, 68 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1620cd8..412ef99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ This project follows semantic versioning. +### v0.14 (2019-12-03) + +- [changed] Deprecated update_with_buffer on favor of update_with_buffer_size. The idea is that a size in of the buffer will be more robust and allow for aspect scaling as well. +- [changed] Improved macOS resizing support. +- [changed] Better modifier handling on macOS. +- [changed] Moved CI over to Github Actions +- [changed] Formatted all code with rustfmt +- [changed] Documentation improvments (Thanks Gary Guo & Arif Roktim!) +- [fixed] 'attempt to subtract with overflow' bug (Thanks Venceslas!) +- [fixed] Window close handling & missing Alt keys for X11 (Thanks Gary Guo!) +- [added] Juila example added (Thanks mishazawa!) +- [added] Add support for raspberry pi (Thanks Florian Blasius!) +- [added] Added support for raw-window-handle trait + ### v0.13 (2019-08-30) - [changed] unix: replaced scale functions with macro and added missing invocations (Thanks Johannes Stölp!) diff --git a/Cargo.toml b/Cargo.toml index b1a734c..6563687 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minifb" -version = "0.13.0" +version = "0.14.0" license = "MIT/Apache-2.0" authors = ["Daniel Collin "] description = "Cross-platform window setup with optional bitmap rendering" diff --git a/README.md b/README.md index bd86334..b93d1e5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Usage ```toml # Cargo.toml [dependencies] -minifb = "0.13" +minifb = "0.14" ``` Example @@ -43,14 +43,14 @@ fn main() { } // We unwrap here as we want this code to exit if it fails. Real applications may want to handle this in a different way - window.update_with_buffer(&buffer).unwrap(); + window.update_with_buffer_size(&buffer, WIDTH, HEIGHT).unwrap(); } } ``` Status ------ -Currently Mac, Redox, Linux and Windows (64-bit and 32-bit) are the current supported platforms. X11 (Linux/FreeBSD/etc) support has been tested on Ubuntu (x64). Bug report(s) for other OSes/CPUs are welcome! +Currently macOS, Redox, Linux and Windows (64-bit and 32-bit) are the current supported platforms. X11 (Linux/FreeBSD/etc) support has been tested on Ubuntu (x64). Bug report(s) for other OSes/CPUs are welcome! Build instructions diff --git a/examples/julia.rs b/examples/julia.rs index adcd5f9..64c9d24 100644 --- a/examples/julia.rs +++ b/examples/julia.rs @@ -58,7 +58,7 @@ fn main() { angle += 0.1; // We unwrap here as we want this code to exit if it fails - window.update_with_buffer(&buffer).unwrap(); + window.update_with_buffer_size(&buffer, WIDTH, HEIGHT).unwrap(); } } diff --git a/examples/menu.rs b/examples/menu.rs index d8de747..fc5d816 100644 --- a/examples/menu.rs +++ b/examples/menu.rs @@ -29,7 +29,6 @@ fn main() { WIDTH, HEIGHT, WindowOptions { - resize: true, scale: Scale::X2, ..WindowOptions::default() }, @@ -113,6 +112,6 @@ fn main() { }); // We unwrap here as we want this code to exit if it fails - window.update_with_buffer(&buffer).unwrap(); + window.update_with_buffer_size(&buffer, WIDTH, HEIGHT).unwrap(); } } diff --git a/examples/mouse.rs b/examples/mouse.rs index e895700..ea0e3f0 100644 --- a/examples/mouse.rs +++ b/examples/mouse.rs @@ -65,6 +65,6 @@ fn main() { }); // We unwrap here as we want this code to exit if it fails - window.update_with_buffer(&buffer).unwrap(); + window.update_with_buffer_size(&buffer, width, height).unwrap(); } } diff --git a/examples/multi.rs b/examples/multi.rs index bc0b723..8fe1902 100644 --- a/examples/multi.rs +++ b/examples/multi.rs @@ -34,8 +34,8 @@ fn main() { && !orig.is_key_down(Key::Escape) && !double.is_key_down(Key::Escape) { - orig.update_with_buffer(&buffer).unwrap(); - double.update_with_buffer(&buffer).unwrap(); + orig.update_with_buffer_size(&buffer, width, height).unwrap(); + double.update_with_buffer_size(&buffer, width, height).unwrap(); pos += 7; pos *= 13; pos %= buffer.len(); diff --git a/examples/noise.rs b/examples/noise.rs index de1e8a3..359f388 100644 --- a/examples/noise.rs +++ b/examples/noise.rs @@ -32,12 +32,10 @@ fn main() { let mut size = (0, 0); while window.is_open() && !window.is_key_down(Key::Escape) { - { - let new_size = window.get_size(); - if new_size != size { - size = new_size; - buffer.resize(size.0 * size.1 / 2 / 2, 0); - } + let new_size = window.get_size(); + if new_size != size { + size = new_size; + buffer.resize(size.0 * size.1 / 2 / 2, 0); } for i in buffer.iter_mut() { @@ -63,6 +61,6 @@ fn main() { }); // We unwrap here as we want this code to exit if it fails - window.update_with_buffer(&buffer).unwrap(); + window.update_with_buffer_size(&buffer, new_size.0, new_size.0).unwrap(); } } diff --git a/examples/title_cursor.rs b/examples/title_cursor.rs index 7dd90a9..db4377f 100644 --- a/examples/title_cursor.rs +++ b/examples/title_cursor.rs @@ -130,6 +130,6 @@ fn main() { } // We unwrap here as we want this code to exit if it fails - window.update_with_buffer(&buffer).unwrap(); + window.update_with_buffer_size(&buffer, WIDTH, HEIGHT).unwrap(); } } diff --git a/src/lib.rs b/src/lib.rs index bcd03ac..df413cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,7 +145,7 @@ pub struct WindowOptions { pub title: bool, /// If it should be possible to resize the window (default: false) pub resize: bool, - /// Scale of the window that used in conjunction with update_with_buffer (default: X1) + /// Scale of the window that used in conjunction with update_with_buffer_size (default: X1) pub scale: Scale, } @@ -243,10 +243,48 @@ impl Window { /// window.update_with_buffer(&buffer).unwrap(); /// ``` #[inline] + #[deprecated( + since = "0.14.0", + note = "Please use the update_with_buffer_size instead. This function will be replaced with args given in update_with_buffer_size in the future." + )] pub fn update_with_buffer(&mut self, buffer: &[u32]) -> Result<()> { self.0.update_with_buffer(buffer) } + /// + /// Updates the window with a 32-bit pixel buffer. The encoding for each pixel is `0RGB`: + /// The upper 8-bits are ignored, the next 8-bits are for the red channel, the next 8-bits + /// afterwards for the green channel, and the lower 8-bits for the blue channel. + /// + /// Notice that the buffer needs to be at least the size of the created window. + /// + /// # Examples + /// + /// ```no_run + /// # use minifb::*; + /// fn from_u8_rgb(r: u8, g: u8, b: u8) -> u32 { + /// let (r, g, b) = (r as u32, g as u32, b as u32); + /// (r << 16) | (g << 8) | b + /// } + /// let window_width = 600; + /// let window_height = 400; + /// let buffer_width = 600; + /// let buffer_height = 400; + /// + /// let azure_blue = from_u8_rgb(0, 127, 255); + /// + /// let mut buffer: Vec = vec![azure_blue; buffer_width * buffer_height]; + /// + /// let mut window = Window::new("Test", window_width, window_height, WindowOptions::default()).unwrap(); + /// + /// window.update_with_buffer_size(&buffer, buffer_width, buffer_height).unwrap(); + /// ``` + #[inline] + pub fn update_with_buffer_size(&mut self, buffer: &[u32], _width: usize, _height: usize) -> Result<()> { + // currently width / height isn't used but will be soon + self.0.update_with_buffer(buffer) + } + /// /// Updates the window (this is required to call in order to get keyboard/mouse input, etc) ///