forked from 1b-agent/opencadstudio-upstream
fix: NAVVCUBE and UCSICON commands now properly toggle visibility
NAVVCUBE: propagate show_viewcube flag through ViewportPane and the wgpu Primitive so the ViewCube pipeline skips upload/render when hidden. UCSICON: bare command (no subcommand) now toggles current state instead of printing usage info. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
1ec53a4730
commit
5f3182fa9a
4 files changed
+41
-16
No files matched your search
+17
-9
@@ -88,6 +88,7 @@ pub struct Primitive {
|
||||
pub(super) hover_region: Option<usize>,
|
||||
/// Background color used to clear the MSAA buffer at the start of each frame.
|
||||
pub(super) bg_color: [f32; 4],
|
||||
pub(super) show_viewcube: bool,
|
||||
}
|
||||
|
||||
// ── shader::Primitive impl ────────────────────────────────────────────────
|
||||
@@ -120,13 +121,15 @@ impl shader::Primitive for Primitive {
|
||||
pipeline.upload_images(device, queue, &self.images);
|
||||
pipeline.upload_meshes(device, &self.meshes);
|
||||
pipeline.upload_wires(device, &self.wires);
|
||||
pipeline.viewcube.upload(
|
||||
queue,
|
||||
self.cam_rotation,
|
||||
bounds.width as u32,
|
||||
bounds.height as u32,
|
||||
self.hover_region,
|
||||
);
|
||||
if self.show_viewcube {
|
||||
pipeline.viewcube.upload(
|
||||
queue,
|
||||
self.cam_rotation,
|
||||
bounds.width as u32,
|
||||
bounds.height as u32,
|
||||
self.hover_region,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn render(
|
||||
@@ -137,7 +140,9 @@ impl shader::Primitive for Primitive {
|
||||
clip: &Rectangle<u32>,
|
||||
) {
|
||||
pipeline.render(encoder, target, *clip, self.bg_color);
|
||||
pipeline.viewcube.render(encoder, target, *clip);
|
||||
if self.show_viewcube {
|
||||
pipeline.viewcube.render(encoder, target, *clip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +221,7 @@ impl Scene {
|
||||
&self,
|
||||
hover_region: Option<usize>,
|
||||
bounds: Rectangle,
|
||||
show_viewcube: bool,
|
||||
) -> Primitive {
|
||||
let cam = self.camera.borrow();
|
||||
self.selection.borrow_mut().vp_size = (bounds.width, bounds.height);
|
||||
@@ -242,6 +248,7 @@ impl Scene {
|
||||
cam_rotation: cam.view_rotation_mat(),
|
||||
hover_region,
|
||||
bg_color,
|
||||
show_viewcube,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +263,7 @@ impl Scene {
|
||||
) -> Primitive {
|
||||
let cam = match self.camera_for_viewport(vp_handle) {
|
||||
Some(c) => c,
|
||||
None => return self.build_primitive(hover_region, bounds),
|
||||
None => return self.build_primitive(hover_region, bounds, false),
|
||||
};
|
||||
|
||||
let mut all_wires = self.model_wires_for_viewport(vp_handle);
|
||||
@@ -275,6 +282,7 @@ impl Scene {
|
||||
cam_rotation: cam.view_rotation_mat(),
|
||||
hover_region,
|
||||
bg_color: self.bg_color,
|
||||
show_viewcube: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,18 +25,19 @@ pub enum ViewportPaneMode {
|
||||
pub struct ViewportPane<'a> {
|
||||
pub scene: &'a Scene,
|
||||
pub mode: ViewportPaneMode,
|
||||
pub show_viewcube: bool,
|
||||
}
|
||||
|
||||
impl<'a> ViewportPane<'a> {
|
||||
pub fn model(scene: &'a Scene) -> Self {
|
||||
Self { scene, mode: ViewportPaneMode::Model }
|
||||
pub fn model(scene: &'a Scene, show_viewcube: bool) -> Self {
|
||||
Self { scene, mode: ViewportPaneMode::Model, show_viewcube }
|
||||
}
|
||||
|
||||
/// One paper-space viewport: model content rendered through its own camera.
|
||||
/// See [`ViewportPaneMode::Paper`] for why this is currently unused.
|
||||
#[allow(dead_code)]
|
||||
pub fn paper(scene: &'a Scene, handle: Handle) -> Self {
|
||||
Self { scene, mode: ViewportPaneMode::Paper { handle } }
|
||||
Self { scene, mode: ViewportPaneMode::Paper { handle }, show_viewcube: false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ impl<'a, Msg: std::fmt::Debug + Clone> shader::Program<Msg> for ViewportPane<'a>
|
||||
) -> Self::Primitive {
|
||||
match &self.mode {
|
||||
ViewportPaneMode::Model => {
|
||||
self.scene.build_primitive(state.hover_region, bounds)
|
||||
self.scene.build_primitive(state.hover_region, bounds, self.show_viewcube)
|
||||
}
|
||||
ViewportPaneMode::Paper { handle } => {
|
||||
self.scene.build_viewport_primitive(*handle, state.hover_region, bounds)
|
||||
@@ -122,8 +123,10 @@ impl<'a, Msg: std::fmt::Debug + Clone> shader::Program<Msg> for ViewportPane<'a>
|
||||
cursor: mouse::Cursor,
|
||||
) -> Option<iced::widget::Action<Msg>> {
|
||||
// ViewCube hover only makes sense in the full model-space view.
|
||||
if matches!(self.mode, ViewportPaneMode::Model) {
|
||||
if matches!(self.mode, ViewportPaneMode::Model) && self.show_viewcube {
|
||||
self.scene.update_viewcube_state(state, bounds, cursor);
|
||||
} else {
|
||||
state.hover_region = None;
|
||||
}
|
||||
let _ = event;
|
||||
None
|
||||
@@ -135,7 +138,7 @@ impl<'a, Msg: std::fmt::Debug + Clone> shader::Program<Msg> for ViewportPane<'a>
|
||||
_b: Rectangle,
|
||||
_c: mouse::Cursor,
|
||||
) -> mouse::Interaction {
|
||||
if matches!(self.mode, ViewportPaneMode::Model) {
|
||||
if matches!(self.mode, ViewportPaneMode::Model) && self.show_viewcube {
|
||||
self.scene.viewcube_mouse_interaction(state)
|
||||
} else {
|
||||
mouse::Interaction::default()
|
||||
|
||||
Reference in new issue
Block a user