add imgui menu
This commit is contained in:
parent
917f90defa
commit
205f78fd84
4 changed files with 91 additions and 17 deletions
BIN
resources/Roboto-Regular.ttf
Normal file
BIN
resources/Roboto-Regular.ttf
Normal file
Binary file not shown.
|
@ -23,6 +23,9 @@ impl EventHandler for Game {
|
|||
) -> GameResult {
|
||||
self.mouse_pos = (x, y);
|
||||
self.imgui.update_mouse_pos(x, y);
|
||||
if self.imgui.want_capture_mouse() {
|
||||
return Ok(());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -34,6 +37,10 @@ impl EventHandler for Game {
|
|||
y: f32,
|
||||
) -> GameResult {
|
||||
self.imgui.update_mouse_down(btn);
|
||||
if self.imgui.want_capture_mouse() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// TODO: figure out if the UI handled anything, and then whether or not to keep going into
|
||||
// letting the rest of the code handle the mouse press or not
|
||||
match btn {
|
||||
|
@ -85,6 +92,11 @@ impl EventHandler for Game {
|
|||
}
|
||||
|
||||
fn mouse_wheel_event(&mut self, _: &mut Context, x: f32, y: f32) -> GameResult {
|
||||
self.imgui.update_scroll(x, y);
|
||||
if self.imgui.want_capture_mouse() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.seek_by_steps(-y as i32);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -92,6 +104,9 @@ impl EventHandler for Game {
|
|||
fn key_up_event(&mut self, _: &mut Context, keycode: KeyCode, keymods: KeyMods) -> GameResult {
|
||||
use KeyCode::*;
|
||||
self.imgui.update_key_up(keycode, keymods);
|
||||
if self.imgui.want_capture_keyboard() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match keycode {
|
||||
Space => self.toggle_playing(),
|
||||
|
@ -114,6 +129,9 @@ impl EventHandler for Game {
|
|||
) -> GameResult {
|
||||
use KeyCode::*;
|
||||
self.imgui.update_key_down(keycode, keymods);
|
||||
if self.imgui.want_capture_keyboard() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.keymap.insert(keycode);
|
||||
match keycode {
|
||||
|
|
|
@ -22,7 +22,7 @@ use ggez::{
|
|||
Context,
|
||||
};
|
||||
use image::io::Reader as ImageReader;
|
||||
use imgui::Window;
|
||||
use imgui::{Window, MenuItem};
|
||||
use imgui_winit_support::WinitPlatform;
|
||||
use libosu::{
|
||||
beatmap::Beatmap,
|
||||
|
@ -417,19 +417,6 @@ impl Game {
|
|||
|
||||
self.draw_seeker(ctx)?;
|
||||
|
||||
let mut show = true;
|
||||
self.imgui.render(ctx, 1.0, |ui| {
|
||||
// Window
|
||||
Window::new("Hello world")
|
||||
.size([300.0, 600.0], imgui::Condition::FirstUseEver)
|
||||
.position([50.0, 50.0], imgui::Condition::FirstUseEver)
|
||||
.build(&ui, || {
|
||||
// Your window stuff here!
|
||||
ui.text("Hi from this label!");
|
||||
});
|
||||
ui.show_demo_window(&mut show);
|
||||
});
|
||||
|
||||
// draw whatever tool user is using
|
||||
let (mx, my) = self.mouse_pos;
|
||||
let pos_x = (mx - PLAYFIELD_BOUNDS.x) / PLAYFIELD_BOUNDS.w * 512.0;
|
||||
|
@ -533,6 +520,54 @@ impl Game {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
let mut show = true;
|
||||
self.imgui.render(ctx, 1.0, |ui| {
|
||||
if let Some(menu_bar) = ui.begin_main_menu_bar() {
|
||||
if let Some(menu) = ui.begin_menu("File") {
|
||||
MenuItem::new("Save <C-s>").build(ui);
|
||||
MenuItem::new("Create Difficulty").build(ui);
|
||||
ui.separator();
|
||||
MenuItem::new("Revert to Saved <C-l>").build(ui);
|
||||
MenuItem::new("Export...").build(ui);
|
||||
ui.separator();
|
||||
MenuItem::new("Open Song Folder").build(ui);
|
||||
MenuItem::new("Exit <Esc>").build(ui);
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("Edit") {
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("View") {
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("Compose") {
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("Design") {
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("Timing") {
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("Web") {
|
||||
menu.end();
|
||||
}
|
||||
if let Some(menu) = ui.begin_menu("Help") {
|
||||
menu.end();
|
||||
}
|
||||
menu_bar.end();
|
||||
}
|
||||
// Window
|
||||
// Window::new("Hello world")
|
||||
// .size([300.0, 600.0], imgui::Condition::FirstUseEver)
|
||||
// .position([50.0, 50.0], imgui::Condition::FirstUseEver)
|
||||
// .build(&ui, || {
|
||||
// // Your window stuff here!
|
||||
// ui.text("Hi from this label!");
|
||||
// });
|
||||
// ui.show_demo_window(&mut show);
|
||||
});
|
||||
|
||||
graphics::present(ctx)?;
|
||||
self.frame += 1;
|
||||
if self.is_playing {
|
||||
|
|
|
@ -27,7 +27,7 @@ use ggez::Context;
|
|||
use gfx_core::{handle::RenderTargetView, memory::Typed};
|
||||
use gfx_device_gl;
|
||||
|
||||
use imgui::{Context as ImContext, Key, Ui, Window};
|
||||
use imgui::{Context as ImContext, FontId, Key, Ui, Window, FontSource};
|
||||
use imgui_gfx_renderer::*;
|
||||
|
||||
use std::time::Instant;
|
||||
|
@ -44,6 +44,7 @@ struct MouseState {
|
|||
pub struct ImGuiWrapper {
|
||||
pub imgui: ImContext,
|
||||
pub renderer: Renderer<gfx_core::format::Rgba8, gfx_device_gl::Resources>,
|
||||
font: FontId,
|
||||
last_frame: Instant,
|
||||
mouse_state: MouseState,
|
||||
}
|
||||
|
@ -55,6 +56,13 @@ impl ImGuiWrapper {
|
|||
imgui.set_ini_filename(None);
|
||||
let (factory, gfx_device, _, _, _) = graphics::gfx_objects(ctx);
|
||||
|
||||
// Font
|
||||
let font = imgui.fonts().add_font(&[FontSource::TtfData {
|
||||
data: include_bytes!("../resources/Roboto-Regular.ttf"),
|
||||
size_pixels: 16.0,
|
||||
config: None,
|
||||
}]);
|
||||
|
||||
// Shaders
|
||||
let shaders = {
|
||||
let version = gfx_device.get_info().shading_language;
|
||||
|
@ -74,10 +82,10 @@ impl ImGuiWrapper {
|
|||
};
|
||||
|
||||
// Renderer
|
||||
let mut renderer = Renderer::init(&mut imgui, &mut *factory, shaders).unwrap();
|
||||
let renderer = Renderer::init(&mut imgui, &mut *factory, shaders).unwrap();
|
||||
|
||||
{
|
||||
let mut io = imgui.io_mut();
|
||||
let io = imgui.io_mut();
|
||||
io[Key::Tab] = KeyCode::Tab as _;
|
||||
io[Key::LeftArrow] = KeyCode::Left as _;
|
||||
io[Key::RightArrow] = KeyCode::Right as _;
|
||||
|
@ -106,6 +114,7 @@ impl ImGuiWrapper {
|
|||
Self {
|
||||
imgui,
|
||||
renderer,
|
||||
font,
|
||||
last_frame: Instant::now(),
|
||||
mouse_state: MouseState::default(),
|
||||
}
|
||||
|
@ -130,7 +139,9 @@ impl ImGuiWrapper {
|
|||
self.imgui.io_mut().delta_time = delta_s;
|
||||
|
||||
let ui = self.imgui.frame();
|
||||
let font = ui.push_font(self.font);
|
||||
run_ui(&ui);
|
||||
font.pop();
|
||||
|
||||
// Render
|
||||
let (factory, _, encoder, _, render_target) = graphics::gfx_objects(ctx);
|
||||
|
@ -214,4 +225,14 @@ impl ImGuiWrapper {
|
|||
self.mouse_state.wheel += y;
|
||||
self.mouse_state.wheel_h += x;
|
||||
}
|
||||
|
||||
pub fn want_capture_mouse(&self) -> bool {
|
||||
let io = self.imgui.io();
|
||||
io.want_capture_mouse
|
||||
}
|
||||
|
||||
pub fn want_capture_keyboard(&self) -> bool {
|
||||
let io = self.imgui.io();
|
||||
io.want_capture_keyboard
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue