wip: edit mode overlay
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use glam::{Affine2, Affine3A, Vec2};
|
||||
use std::sync::Arc;
|
||||
use std::{any::Any, sync::Arc};
|
||||
use vulkano::{format::Format, image::view::ImageView};
|
||||
|
||||
use crate::{
|
||||
@@ -25,7 +25,7 @@ pub enum ShouldRender {
|
||||
Unable,
|
||||
}
|
||||
|
||||
pub trait OverlayBackend {
|
||||
pub trait OverlayBackend: Any {
|
||||
/// Called once, before the first frame is rendered
|
||||
fn init(&mut self, app: &mut AppState) -> anyhow::Result<()>;
|
||||
fn pause(&mut self, app: &mut AppState) -> anyhow::Result<()>;
|
||||
@@ -46,7 +46,7 @@ pub trait OverlayBackend {
|
||||
/// Called to retrieve the effective extent of the image
|
||||
/// Used for creating swapchains.
|
||||
///
|
||||
/// Must be true if should_render was also true on the same frame.
|
||||
/// Must be Some if should_render was Should or Can on the same frame.
|
||||
fn frame_meta(&mut self) -> Option<FrameMeta>;
|
||||
|
||||
fn on_hover(&mut self, app: &mut AppState, hit: &PointerHit) -> HoverResult;
|
||||
@@ -69,3 +69,42 @@ pub fn ui_transform(extent: [u32; 2]) -> Affine2 {
|
||||
let center = Vec2 { x: 0.5, y: 0.5 };
|
||||
Affine2::from_scale_angle_translation(scale, 0.0, center)
|
||||
}
|
||||
|
||||
pub struct DummyBackend {}
|
||||
|
||||
impl OverlayBackend for DummyBackend {
|
||||
fn init(&mut self, _: &mut AppState) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn pause(&mut self, _: &mut AppState) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn resume(&mut self, _: &mut AppState) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn should_render(&mut self, _: &mut AppState) -> anyhow::Result<ShouldRender> {
|
||||
Ok(ShouldRender::Unable)
|
||||
}
|
||||
fn render(
|
||||
&mut self,
|
||||
_: &mut AppState,
|
||||
_: Arc<ImageView>,
|
||||
_: &mut CommandBuffers,
|
||||
_: f32,
|
||||
) -> anyhow::Result<bool> {
|
||||
Ok(false)
|
||||
}
|
||||
fn frame_meta(&mut self) -> Option<FrameMeta> {
|
||||
None
|
||||
}
|
||||
|
||||
fn on_hover(&mut self, _: &mut AppState, _: &PointerHit) -> HoverResult {
|
||||
HoverResult::default()
|
||||
}
|
||||
fn on_left(&mut self, _: &mut AppState, _: usize) {}
|
||||
fn on_pointer(&mut self, _: &mut AppState, _: &PointerHit, _: bool) {}
|
||||
fn on_scroll(&mut self, _: &mut AppState, _: &PointerHit, _: f32, _: f32) {}
|
||||
fn get_interaction_transform(&mut self) -> Option<glam::Affine2> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ use slotmap::{HopSlotMap, Key, SecondaryMap};
|
||||
|
||||
use crate::{
|
||||
overlays::{
|
||||
anchor::create_anchor, keyboard::builder::create_keyboard, screen::create_screens,
|
||||
watch::create_watch,
|
||||
adjust::EditModeManager, anchor::create_anchor, keyboard::builder::create_keyboard,
|
||||
screen::create_screens, watch::create_watch,
|
||||
},
|
||||
state::AppState,
|
||||
windowing::{
|
||||
@@ -18,6 +18,7 @@ use crate::{
|
||||
};
|
||||
|
||||
pub struct OverlayWindowManager<T> {
|
||||
wrappers: EditModeManager,
|
||||
overlays: HopSlotMap<OverlayID, OverlayWindowData<T>>,
|
||||
sets: Vec<OverlayWindowSet>,
|
||||
/// The set that is currently visible.
|
||||
@@ -37,6 +38,7 @@ where
|
||||
let mut maybe_keymap = None;
|
||||
|
||||
let mut me = Self {
|
||||
wrappers: EditModeManager::default(),
|
||||
overlays: HopSlotMap::with_key(),
|
||||
current_set: Some(0),
|
||||
restore_set: 0,
|
||||
@@ -168,6 +170,20 @@ impl<T> OverlayWindowManager<T> {
|
||||
self.restore_set = (app.session.config.last_set as usize).min(self.sets.len() - 1);
|
||||
}
|
||||
|
||||
pub fn edit_overlay(&mut self, id: OverlayID, enabled: bool, app: &mut AppState) {
|
||||
let Some(overlay) = self.overlays.get_mut(id) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if enabled {
|
||||
self.wrappers
|
||||
.wrap_edit_mode(&mut overlay.config, app)
|
||||
.unwrap(); // FIXME: unwrap
|
||||
} else {
|
||||
self.wrappers.unwrap_edit_mode(&mut overlay.config);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mut_by_selector(
|
||||
&mut self,
|
||||
selector: &OverlaySelector,
|
||||
|
||||
@@ -99,6 +99,8 @@ pub struct OverlayWindowConfig {
|
||||
pub global: bool,
|
||||
/// True if transform, curvature, alpha has changed. Only used by OpenVR.
|
||||
pub dirty: bool,
|
||||
/// True if the window is showing the edit overlay
|
||||
pub editing: bool,
|
||||
pub saved_transform: Option<Affine3A>,
|
||||
}
|
||||
|
||||
@@ -118,6 +120,7 @@ impl OverlayWindowConfig {
|
||||
show_on_spawn: false,
|
||||
global: false,
|
||||
dirty: true,
|
||||
editing: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user