Add resized/moved events, minor cleanup

This commit is contained in:
Phillip Stephens 2022-02-06 14:53:42 -08:00
parent c53ee12578
commit 710b9ae6b3
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
5 changed files with 43 additions and 24 deletions

View File

@ -3,6 +3,7 @@
#include <array>
#include <type_traits>
#include <vector>
#include <cinttypes>
namespace aurora {
struct WindowSize;
@ -20,6 +21,8 @@ struct AppDelegate {
virtual bool onAppIdle(float dt) noexcept = 0;
virtual void onAppDraw() noexcept = 0;
virtual void onAppPostDraw() noexcept = 0;
virtual void onAppWindowResized(const WindowSize& size) noexcept = 0;
virtual void onAppWindowMoved(std::int32_t x, std::int32_t y) noexcept = 0;
virtual void onAppExiting() noexcept = 0;
// virtual void resized([[maybe_unused]] const WindowSize& rect, [[maybe_unused]] bool sync) noexcept {}

View File

@ -1,9 +1,12 @@
#include "aurora.hpp"
#include <cinttypes>
namespace aurora {
void App_onAppLaunched(AppDelegate& cb) noexcept;
bool App_onAppIdle(AppDelegate& cb, float dt) noexcept;
void App_onAppDraw(AppDelegate& cb) noexcept;
void App_onAppPostDraw(AppDelegate& cb) noexcept;
void App_onAppWindowResized(AppDelegate& cb, const WindowSize& size) noexcept;
void App_onAppWindowMoved(AppDelegate& cb, std::int32_t x, std::int32_t y) noexcept;
void App_onAppExiting(AppDelegate& cb) noexcept;
} // namespace aurora

View File

@ -5,5 +5,11 @@ void App_onAppLaunched(AppDelegate& cb) noexcept { return cb.onAppLaunched(); }
bool App_onAppIdle(AppDelegate& cb, float dt) noexcept { return cb.onAppIdle(dt); }
void App_onAppDraw(AppDelegate& cb) noexcept { cb.onAppDraw(); }
void App_onAppPostDraw(AppDelegate& cb) noexcept { cb.onAppPostDraw(); }
void App_onAppWindowResized(AppDelegate& cb, const WindowSize& size) noexcept {
cb.onAppWindowResized(size);
}
void App_onAppWindowMoved(AppDelegate& cb, std::int32_t x, std::int32_t y) noexcept {
cb.onAppWindowMoved(x, y);
}
void App_onAppExiting(AppDelegate& cb) noexcept { cb.onAppExiting(); }
} // namespace aurora

View File

@ -7,14 +7,16 @@ use std::{num::NonZeroU8, time::Instant};
use wgpu::Backend;
use winit::{
event::{Event, WindowEvent},
event::{Event, WindowEvent, KeyboardInput},
event_loop::ControlFlow,
};
use crate::{
gpu::{create_depth_texture, create_render_texture, initialize_gpu, DeviceHolder},
imgui::{initialize_imgui, ImGuiState},
shaders::render_into_pass,
ffi::{WindowSize},
};
mod gpu;
@ -37,16 +39,20 @@ mod ffi {
pub(crate) fn App_onAppIdle(cb: Pin<&mut AppDelegate>, dt: f32) -> bool;
pub(crate) fn App_onAppDraw(cb: Pin<&mut AppDelegate>);
pub(crate) fn App_onAppPostDraw(cb: Pin<&mut AppDelegate>);
pub(crate) fn App_onAppWindowResized(cb: Pin<&mut AppDelegate>, size: &WindowSize);
pub(crate) fn App_onAppWindowMoved(cb: Pin<&mut AppDelegate>, x: i32, y: i32);
pub(crate) fn App_onAppExiting(cb: Pin<&mut AppDelegate>);
}
pub struct Window {
pub(crate) inner: Box<WindowContext>,
}
pub struct WindowSize {
pub width: u32,
pub height: u32,
}
#[derive(Debug)]
pub enum Backend {
Invalid,
@ -62,12 +68,14 @@ mod ffi {
Pressed,
Released,
}
pub enum MouseButton {
Left,
Right,
Middle,
Other,
}
pub enum SpecialKey {
None = 0,
F1 = 1,
@ -97,6 +105,7 @@ mod ffi {
Down = 25,
Tab = 26,
}
pub struct KeyboardInput {
pub scancode: u32,
pub state: ElementState,
@ -177,9 +186,21 @@ fn app_run(mut delegate: cxx::UniquePtr<ffi::AppDelegate>) {
&app.gpu.surface_config,
&app.gpu.config,
);
// TODO resize callback
unsafe {
let window_size = WindowSize{width: app.gpu.surface_config.width, height: app.gpu.surface_config.height};
ffi::App_onAppWindowResized(delegate.as_mut().unwrap(), &window_size);
}
}
Event::WindowEvent { event: WindowEvent::Moved(loc), ..} => {
unsafe {
ffi::App_onAppWindowMoved(delegate.as_mut().unwrap(), loc.x, loc.y);
}
}
Event::WindowEvent { event: WindowEvent::KeyboardInput {
input: KeyboardInput, .. }, .. } => {
}
Event::WindowEvent { event: WindowEvent::KeyboardInput { .. }, .. } => {}
Event::WindowEvent { .. } => {}
Event::DeviceEvent { .. } => {}
Event::UserEvent(_) => {}

View File

@ -365,20 +365,6 @@ public:
}
OPTICK_FRAME("MainThread");
// CGraphics::SetCommitResourcesAsLazy(m_cvarCommons.m_lazyCommitResources->toBoolean());
// TODO
// boo::SWindowRect rect = m_windowCallback.m_lastRect;
// rect.location = {0, 0};
// boo::IGraphicsCommandQueue* gfxQ = m_window->getCommandQueue();
// if (m_windowCallback.m_rectDirty) {
// gfxQ->resizeRenderTexture(m_renderTex, rect.size[0], rect.size[1]);
// CGraphics::SetViewportResolution({rect.size[0], rect.size[1]});
// m_windowCallback.m_rectDirty = false;
// } else if (m_firstFrame) {
auto rect = aurora::get_window_size();
CGraphics::SetViewportResolution({static_cast<int32_t>(rect.width), static_cast<int32_t>(rect.height)});
// }
// Check if fullscreen has been toggled, if so set the fullscreen cvar accordingly
if (m_windowCallback.m_fullscreenToggleRequested) {
@ -394,9 +380,6 @@ public:
// Let CVarManager inform all CVar listeners of the CVar's state and clear all mdoified flags if necessary
m_cvarManager.proc();
// TODO
// boo::IGraphicsDataFactory* gfxF = m_window->getMainContextDataFactory();
// float scale = std::floor(m_window->getVirtualPixelFactor() * 4.f) / 4.f;
if (!g_mainMP1 && m_projectInitialized) {
g_mainMP1.emplace(nullptr, nullptr);
g_mainMP1->Init(m_fileMgr, &m_cvarManager, m_voiceEngine.get(), *m_amuseAllocWrapper);
@ -404,10 +387,6 @@ public:
g_mainMP1->WarmupShaders();
}
}
// if (!m_imGuiInitialized) {
// ImGuiEngine::Initialize(gfxF, m_window.get(), scale, m_fileMgr.getStoreRoot());
// m_imGuiInitialized = true;
// }
float dt = 1 / 60.f;
if (m_cvarCommons.m_variableDt->toBoolean()) {
@ -453,6 +432,13 @@ public:
++logvisor::FrameIndex;
}
void onAppWindowResized(const aurora::WindowSize& size) noexcept override {
CGraphics::SetViewportResolution({static_cast<s32>(size.width), static_cast<s32>(size.height)});
}
void onAppWindowMoved(std::int32_t x, std::int32_t y) noexcept override {
// TODO: implement this
}
void onAppExiting() noexcept override {
m_imGuiConsole.Shutdown();
if (g_mainMP1) {