2016-03-05 03:36:28 +11:00
|
|
|
extern crate minifb;
|
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
use minifb::{Window, Key, Scale, WindowOptions, Menu, MenuItem};
|
2016-05-08 17:42:21 +10:00
|
|
|
use minifb::{MENU_KEY_COMMAND, MENU_KEY_CTRL};
|
2016-03-05 03:36:28 +11:00
|
|
|
|
|
|
|
const WIDTH: usize = 640;
|
|
|
|
const HEIGHT: usize = 360;
|
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
/*
|
2016-03-05 03:36:28 +11:00
|
|
|
const MENU_TEST_ID: usize = 1;
|
|
|
|
const OTHER_MENU_ID: usize = 2;
|
|
|
|
const COLOR_0_ID: usize = 3;
|
|
|
|
const COLOR_1_ID: usize = 4;
|
|
|
|
const COLOR_2_ID: usize = 5;
|
|
|
|
const CLOSE_MENU_ID: usize = 6;
|
2016-05-07 20:51:14 +10:00
|
|
|
*/
|
2016-03-05 03:36:28 +11:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut buffer: Vec<u32> = vec![0; WIDTH * HEIGHT];
|
|
|
|
|
|
|
|
let mut window = Window::new("Noise Test - Press ESC to exit",
|
|
|
|
WIDTH,
|
|
|
|
HEIGHT,
|
|
|
|
WindowOptions {
|
|
|
|
resize: true,
|
|
|
|
scale: Scale::X2,
|
|
|
|
..WindowOptions::default()
|
|
|
|
})
|
|
|
|
.expect("Unable to Open Window");
|
|
|
|
|
|
|
|
// Setup a sub menu
|
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
/*
|
2016-03-05 03:36:28 +11:00
|
|
|
let sub_menu = vec![
|
|
|
|
Menu {
|
|
|
|
name: "Color 0",
|
2016-04-29 16:57:55 +10:00
|
|
|
key: Key::F1,
|
2016-03-05 03:36:28 +11:00
|
|
|
id: COLOR_0_ID,
|
|
|
|
..Menu::default()
|
|
|
|
},
|
|
|
|
Menu {
|
|
|
|
name: "Color 1",
|
2016-04-29 16:57:55 +10:00
|
|
|
key: Key::F2,
|
2016-03-05 03:36:28 +11:00
|
|
|
id: COLOR_1_ID,
|
|
|
|
..Menu::default()
|
|
|
|
},
|
|
|
|
Menu {
|
|
|
|
name: "Color 2",
|
2016-04-29 16:57:55 +10:00
|
|
|
key: Key::F12,
|
2016-03-05 03:36:28 +11:00
|
|
|
id: COLOR_2_ID,
|
|
|
|
..Menu::default()
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
// Main menu
|
|
|
|
|
|
|
|
let menu = vec![
|
|
|
|
Menu {
|
|
|
|
name: "Menu Test",
|
|
|
|
key: Key::W,
|
|
|
|
id: MENU_TEST_ID,
|
|
|
|
modifier: MENU_KEY_CTRL,
|
|
|
|
mac_mod: MENU_KEY_COMMAND,
|
|
|
|
..Menu::default()
|
|
|
|
},
|
|
|
|
Menu::separotor(),
|
|
|
|
Menu {
|
|
|
|
name: "Other menu!",
|
|
|
|
key: Key::S,
|
|
|
|
modifier: MENU_KEY_CTRL,
|
|
|
|
mac_mod: MENU_KEY_CTRL,
|
|
|
|
id: OTHER_MENU_ID,
|
|
|
|
..Menu::default()
|
|
|
|
},
|
|
|
|
Menu {
|
|
|
|
name: "Remove Menu",
|
|
|
|
key: Key::R,
|
|
|
|
id: CLOSE_MENU_ID,
|
|
|
|
..Menu::default()
|
|
|
|
},
|
|
|
|
Menu {
|
|
|
|
name: "Select Color",
|
|
|
|
sub_menu: Some(&sub_menu),
|
|
|
|
..Menu::default()
|
|
|
|
}
|
|
|
|
];
|
2016-05-07 20:51:14 +10:00
|
|
|
*/
|
2016-03-05 03:36:28 +11:00
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
//window.add_menu("Test", &menu).expect("Unable to add menu");
|
2016-03-05 03:36:28 +11:00
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
let mut menu = Menu::new("TestMenu").unwrap();
|
|
|
|
|
2016-05-08 17:28:43 +10:00
|
|
|
menu.add_menu_item(&MenuItem::new("Item 1", 1).shortcut(Key::S, 0));
|
|
|
|
menu.add_menu_item(&MenuItem::new("Item 2", 2));
|
|
|
|
menu.add_menu_item(&MenuItem::new("Item 3", 3));
|
|
|
|
|
2016-05-08 17:42:21 +10:00
|
|
|
menu.add_item("Some item", 2).shortcut(Key::Y, MENU_KEY_CTRL).build();
|
2016-05-08 08:25:31 +10:00
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
let _ = window.add_menu(&menu);
|
|
|
|
|
|
|
|
let color_mul = 1;
|
2016-03-05 03:36:28 +11:00
|
|
|
|
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
|
|
|
for y in 0..HEIGHT {
|
|
|
|
for x in 0..WIDTH {
|
|
|
|
buffer[(y * WIDTH) + x] = (((x ^ y) & 0xff) * color_mul) as u32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 20:51:14 +10:00
|
|
|
/*
|
2016-03-05 03:36:28 +11:00
|
|
|
window.is_menu_pressed().map(|menu_id| {
|
|
|
|
match menu_id {
|
|
|
|
COLOR_0_ID => {
|
|
|
|
color_mul = 0xfe0000;
|
|
|
|
}
|
|
|
|
COLOR_1_ID => {
|
|
|
|
color_mul = 0xff00;
|
|
|
|
}
|
|
|
|
COLOR_2_ID => {
|
|
|
|
color_mul = 1;
|
|
|
|
}
|
|
|
|
CLOSE_MENU_ID => {
|
|
|
|
println!("remove menu");
|
2016-05-07 20:51:14 +10:00
|
|
|
//window.remove_menu("Test").expect("Unable to remove menu");
|
2016-03-05 03:36:28 +11:00
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("Menu id {} pressed", menu_id);
|
|
|
|
});
|
2016-05-07 20:51:14 +10:00
|
|
|
*/
|
2016-03-05 03:36:28 +11:00
|
|
|
|
|
|
|
window.get_keys().map(|keys| {
|
|
|
|
for t in keys {
|
|
|
|
match t {
|
|
|
|
Key::W => println!("holding w!"),
|
|
|
|
Key::T => println!("holding t!"),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.update_with_buffer(&buffer);
|
|
|
|
}
|
|
|
|
}
|