forked from 1b-agent/opencadstudio-upstream
Background dialog: adjust an image's offset and scale; visual style names
- The Image tab gains an Adjust card: X/Y offset in pixels (-2000..2000) and X/Y scale (-10..10, tenth steps, a negative scale mirrors, zero keeps the image's scale) with spinners and Reset, inactive while the image is stretched; Keep aspect ratio is a switch and makes both scales follow. - The preview shows the image at its offset and scale, tiled when tiled, and a stretched image kept to its aspect ratio covers the view. - Automation: step=<field>,+1|-1 and reset; offset/scale take any numbers. - Shaded with edges, Shades of Gray and Sketchy have catalog entries in every language. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
064da8829e
commit
0ee95fa4ba
27 files changed
+439
-91
No files matched your search
+24
-12
@@ -1798,7 +1798,8 @@ impl OpenCADStudio {
|
||||
"ribbon_dropdown" => Message::ToggleRibbonDropdown(string(req, "value")?.into()),
|
||||
// The -VIEW Background dialog, one field per call: "type=gradient",
|
||||
// "color|top|middle|bottom=r,g,b", "three=1", "rotation=30",
|
||||
// "image=<path>", "position=center|stretch|tile", "aspect=1", "offset=x,y" (pixels), "scale=x,y" (non-zero),
|
||||
// "image=<path>", "position=center|stretch|tile", "aspect=1", "offset=x,y" (pixels), "scale=x,y",
|
||||
// "step=offset_x|offset_y|scale_x|scale_y,+1|-1", "reset",
|
||||
// "apply" or "cancel".
|
||||
"view_background" => {
|
||||
use crate::ui::window::pdf_dialogs::{BgKind, BgPosition, PdfDialogMsg as P};
|
||||
@@ -1841,20 +1842,31 @@ impl OpenCADStudio {
|
||||
})),
|
||||
"aspect" => Message::PdfDialog(P::BgAspect(value == "1")),
|
||||
"offset" | "scale" => {
|
||||
let pair: Vec<f64> = value
|
||||
.split(',')
|
||||
.map(|part| part.trim().parse::<f64>())
|
||||
.collect::<Result<_, _>>()
|
||||
.map_err(|_| bad())?;
|
||||
let pair = <[f64; 2]>::try_from(pair).map_err(|_| bad())?;
|
||||
if key == "offset" {
|
||||
Message::PdfDialog(P::BgOffset(pair))
|
||||
} else if pair.iter().all(|v| v.is_finite() && *v != 0.0) {
|
||||
Message::PdfDialog(P::BgScale(pair))
|
||||
} else {
|
||||
let pair: Vec<String> = value.split(',').map(|part| part.trim().to_string()).collect();
|
||||
let pair = <[String; 2]>::try_from(pair).map_err(|_| bad())?;
|
||||
if pair.iter().any(|v| v.parse::<f64>().map_or(true, |v| !v.is_finite())) {
|
||||
return Err(bad());
|
||||
}
|
||||
if key == "offset" {
|
||||
Message::PdfDialog(P::BgOffset(pair))
|
||||
} else {
|
||||
Message::PdfDialog(P::BgScale(pair))
|
||||
}
|
||||
}
|
||||
"step" => {
|
||||
// step=offset_x|offset_y|scale_x|scale_y,+1|-1
|
||||
let (field, dir) = value.split_once(',').ok_or_else(bad)?;
|
||||
let field = match field {
|
||||
"offset_x" => 0,
|
||||
"offset_y" => 1,
|
||||
"scale_x" => 2,
|
||||
"scale_y" => 3,
|
||||
_ => return Err(bad()),
|
||||
};
|
||||
let dir: i8 = dir.trim().parse().map_err(|_| bad())?;
|
||||
Message::PdfDialog(P::BgStep(field, dir))
|
||||
}
|
||||
"reset" => Message::PdfDialog(P::BgReset),
|
||||
_ => return Err(bad()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user