rust_minifb/examples/multi.rs

32 lines
824 B
Rust
Raw Normal View History

Rewrite linux backend in rust (#70) * x11-rs : don't build libminifb_native.a * x11-rs : commented out all calls to the mfb_xxx functions. * x11-rs : added handle field to Window, type is xlib::Window. Also implemented the get_window_handle() method. * x11-rs : created a DisplayInfo struct with a setup() method. * x11-rs : fleshed out DisplayInfo::setup() method some more. * x11-rs : updated Cargo.toml to require x11_dl "2.16". That is because we need the XContext type, which seems to be unavailable in the 2.14 version. * x11-rs : code to call the XCreateWindow() function. * x11-rs : call XMapRaise() and XFlush() on our window. * x11-rs : more work on Window::new() -- ported more stuff from mfb_open(). * x11-rs : create the 'ximage' field in Window::new(). * x11-rs : removed SharedData struct, moved fields into Window. * x11-rs : ported the set_window_title() method. * x11-rs : ported creating a "draw_buffer" and the 1:1 scaling code. * x11-rs : ported the scale_2x() function. * x11-rs : ported the scale_4x() function. * x11-rs : ported the set_position() method. * x11-rs : ported the mfb_close() code, i.e. Drop trait on a Window. * x11-rs : tidied up code computing "scale" value for a new window. * x11-rs : implemented Drop trait for DisplayInfo. * x11-rs : updated the get_scroll_wheel() method. * x11-rs : tidy up update_with_buffer() and check buffer size. * x11-rs : ported the check_formats() code. * x11-rs : ported the init_cursors() code. * x11-rs : ported the set_cursor_style() code. * x11-rs : ported the raw_get_mouse_pos() code. * x11-rs : moved the code implementing Drop trait for Window. * x11-rs : ported the basic event loop (i.e. raw_process_events). * x11-rs : ported code handling the WM_DELETE_WINDOW client message. * x11-rs : added code file "src/os/unix/key_mapping.rs" This file contains code to map an X keysym to a Unicode char, which is done via a binary search on a large table. I ported the code to Rust and rewrote the binary search as a recursive function. * x11-rs : ported the XkbQueryExtension() code. * x11-rs : fleshed out the process_key() code. * x11-rs : added test code for keysym_to_unicode(), fixed a table entry. * x11-rs : another test value for the key_mapping test code. * x11-rs : ported the update_key_state() code. * x11-rs : ported the char_callback() code. * x11-rs : ported the mouse button handling code. * x11-rs : ported code handling the XConfigureNotify event. * x11-rs : code tidying, silence most compiler warnings. * x11-rs : removed the native C code: X11MiniFB.c * x11-rs : fixed bug in the button handling code. * x11-rs : made the scale_2x() and scale_4x() code faster. * merge error * whitespace * fix cursors: bad string handling * upgrade x11-dl * merge scaling implementations * multi-window example
2019-03-30 18:18:42 +11:00
extern crate minifb;
use minifb::{WindowOptions, Window, Scale, Key};
fn main() {
let width = 640;
let height = 320;
let mut buffer = vec![0u32; width * height];
let mut double = Window::new("Larger", width, height, WindowOptions {
scale: Scale::X2,
..WindowOptions::default()
}).unwrap();
let mut orig = Window::new("Smaller", width, height, WindowOptions {
..WindowOptions::default()
}).unwrap();
Rewrite linux backend in rust (#70) * x11-rs : don't build libminifb_native.a * x11-rs : commented out all calls to the mfb_xxx functions. * x11-rs : added handle field to Window, type is xlib::Window. Also implemented the get_window_handle() method. * x11-rs : created a DisplayInfo struct with a setup() method. * x11-rs : fleshed out DisplayInfo::setup() method some more. * x11-rs : updated Cargo.toml to require x11_dl "2.16". That is because we need the XContext type, which seems to be unavailable in the 2.14 version. * x11-rs : code to call the XCreateWindow() function. * x11-rs : call XMapRaise() and XFlush() on our window. * x11-rs : more work on Window::new() -- ported more stuff from mfb_open(). * x11-rs : create the 'ximage' field in Window::new(). * x11-rs : removed SharedData struct, moved fields into Window. * x11-rs : ported the set_window_title() method. * x11-rs : ported creating a "draw_buffer" and the 1:1 scaling code. * x11-rs : ported the scale_2x() function. * x11-rs : ported the scale_4x() function. * x11-rs : ported the set_position() method. * x11-rs : ported the mfb_close() code, i.e. Drop trait on a Window. * x11-rs : tidied up code computing "scale" value for a new window. * x11-rs : implemented Drop trait for DisplayInfo. * x11-rs : updated the get_scroll_wheel() method. * x11-rs : tidy up update_with_buffer() and check buffer size. * x11-rs : ported the check_formats() code. * x11-rs : ported the init_cursors() code. * x11-rs : ported the set_cursor_style() code. * x11-rs : ported the raw_get_mouse_pos() code. * x11-rs : moved the code implementing Drop trait for Window. * x11-rs : ported the basic event loop (i.e. raw_process_events). * x11-rs : ported code handling the WM_DELETE_WINDOW client message. * x11-rs : added code file "src/os/unix/key_mapping.rs" This file contains code to map an X keysym to a Unicode char, which is done via a binary search on a large table. I ported the code to Rust and rewrote the binary search as a recursive function. * x11-rs : ported the XkbQueryExtension() code. * x11-rs : fleshed out the process_key() code. * x11-rs : added test code for keysym_to_unicode(), fixed a table entry. * x11-rs : another test value for the key_mapping test code. * x11-rs : ported the update_key_state() code. * x11-rs : ported the char_callback() code. * x11-rs : ported the mouse button handling code. * x11-rs : ported code handling the XConfigureNotify event. * x11-rs : code tidying, silence most compiler warnings. * x11-rs : removed the native C code: X11MiniFB.c * x11-rs : fixed bug in the button handling code. * x11-rs : made the scale_2x() and scale_4x() code faster. * merge error * whitespace * fix cursors: bad string handling * upgrade x11-dl * merge scaling implementations * multi-window example
2019-03-30 18:18:42 +11:00
let mut pos = 13;
while orig.is_open() && double.is_open()
&& !orig.is_key_down(Key::Escape)
&& !double.is_key_down(Key::Escape) {
orig.update_with_buffer(&buffer).unwrap();
double.update_with_buffer(&buffer).unwrap();
pos += 7;
pos *= 13;
pos %= buffer.len();
buffer[pos] = 0xff_ff_ff;
}
}