1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-03-22 09:59:25 +00:00

get rid of some warnings

This commit is contained in:
Alula 2022-01-08 06:57:04 +01:00
parent 4d6768c015
commit d484e8a183
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
7 changed files with 36 additions and 3 deletions

View file

@ -60,6 +60,8 @@ pub trait BackendRenderer {
fn imgui_texture_id(&self, texture: &Box<dyn BackendTexture>) -> GameResult<imgui::TextureId>;
fn prepare_imgui(&mut self, ui: &imgui::Ui) -> GameResult;
fn render_imgui(&mut self, draw_data: &DrawData) -> GameResult;
fn supports_vertex_draw(&self) -> bool {

View file

@ -2,7 +2,7 @@ use std::any::Any;
use std::cell::RefCell;
use std::mem;
use imgui::{DrawData, TextureId};
use imgui::{DrawData, TextureId, Ui};
use crate::common::{Color, Rect};
use crate::framework::backend::{
@ -135,6 +135,10 @@ impl BackendRenderer for NullRenderer {
Ok(TextureId::from(0))
}
fn prepare_imgui(&mut self, _ui: &Ui) -> GameResult {
Ok(())
}
fn render_imgui(&mut self, _draw_data: &DrawData) -> GameResult {
Ok(())
}

View file

@ -8,7 +8,7 @@ use std::rc::Rc;
use std::time::Duration;
use imgui::internal::RawWrapper;
use imgui::{ConfigFlags, DrawCmd, DrawData, Key, MouseCursor, TextureId};
use imgui::{ConfigFlags, DrawCmd, DrawData, Key, MouseCursor, TextureId, Ui};
use sdl2::event::{Event, WindowEvent};
use sdl2::keyboard::Scancode;
use sdl2::mouse::{Cursor, SystemCursor};
@ -602,6 +602,13 @@ impl BackendRenderer for SDL2Renderer {
Ok(TextureId::new(sdl_texture.texture.as_ref().map(|t| t.raw()).unwrap_or(null_mut()) as usize))
}
fn prepare_imgui(&mut self, ui: &Ui) -> GameResult {
let refs = self.refs.borrow_mut();
self.imgui_event.borrow_mut().prepare_render(ui, refs.canvas.window());
Ok(())
}
fn render_imgui(&mut self, draw_data: &DrawData) -> GameResult {
let mut refs = self.refs.borrow_mut();
@ -1100,6 +1107,10 @@ impl ImguiSdl2 {
imgui.io_mut().key_super = super_;
}
if self.ignore_event(event) {
return;
}
match *event {
Event::MouseWheel { y, .. } => {
imgui.io_mut().mouse_wheel = y as f32;

View file

@ -128,6 +128,14 @@ pub fn imgui_texture_id(ctx: &Context, texture: &Box<dyn BackendTexture>) -> Gam
Err(GameError::RenderError("Rendering backend hasn't been initialized yet.".to_string()))
}
pub fn prepare_imgui(ctx: &mut Context, ui: &imgui::Ui) -> GameResult {
if let Some(renderer) = ctx.renderer.as_mut() {
return renderer.prepare_imgui(ui);
}
Err(GameError::RenderError("Rendering backend hasn't been initialized yet.".to_string()))
}
pub fn render_imgui(ctx: &mut Context, draw_data: &imgui::DrawData) -> GameResult {
if let Some(renderer) = ctx.renderer.as_mut() {
return renderer.render_imgui(draw_data);

View file

@ -1,3 +1,5 @@
#![allow(unused)]
pub mod backend;
pub mod backend_null;
#[cfg(feature = "backend-glutin")]

View file

@ -6,7 +6,7 @@ use std::mem::MaybeUninit;
use std::ptr::null;
use std::sync::Arc;
use imgui::{DrawCmd, DrawCmdParams, DrawData, DrawIdx, DrawVert, TextureId};
use imgui::{DrawCmd, DrawCmdParams, DrawData, DrawIdx, DrawVert, TextureId, Ui};
use crate::common::{Color, Rect};
use crate::framework::backend::{BackendRenderer, BackendShader, BackendTexture, SpriteBatchCommand, VertexData};
@ -1053,6 +1053,10 @@ impl BackendRenderer for OpenGLRenderer {
Ok(TextureId::new(gl_texture.texture_id as usize))
}
fn prepare_imgui(&mut self, _ui: &Ui) -> GameResult {
Ok(())
}
fn render_imgui(&mut self, draw_data: &DrawData) -> GameResult {
// https://github.com/michaelfairley/rust-imgui-opengl-renderer
if let Some((_, gl)) = self.get_context() {

View file

@ -6,6 +6,7 @@ use imgui::sys::*;
use crate::framework::context::Context;
use crate::framework::error::GameResult;
use crate::framework::graphics::{imgui_context, render_imgui};
use crate::graphics::prepare_imgui;
use crate::live_debugger::LiveDebugger;
use crate::scene::Scene;
use crate::shared_game_state::SharedGameState;
@ -128,6 +129,7 @@ impl UI {
scene.imgui_draw(&mut self.components, state, ctx2, &mut ui)?;
prepare_imgui(ctx2, &ui);
let draw_data = ui.render();
render_imgui(ctx2, draw_data)?;