Add Character fill and stroke eyedroppers
This commit is contained in:
@@ -194,6 +194,7 @@ pub(crate) fn toggle_pick(app: &mut EffectcraftApp, kind: &str, layer: &Layer, p
|
||||
app.ui.fx_pick = None;
|
||||
} else {
|
||||
app.ui.fx_pick = Some(pick);
|
||||
app.ui.text_color_pick = None;
|
||||
app.ui.status = if kind == "point" {
|
||||
format!("Click in the Composition panel to set {}", prop.name)
|
||||
} else {
|
||||
@@ -1386,7 +1387,50 @@ pub fn viewer_hook(
|
||||
app.ui.status.clear();
|
||||
}
|
||||
}
|
||||
let picking = app.ui.fx_pick.is_some();
|
||||
if let Some(pick) = app.ui.text_color_pick.clone() {
|
||||
if ectx.comp.layer(effectcraft_engine::project::LayerId(pick.layer)).is_none() {
|
||||
app.ui.text_color_pick = None;
|
||||
app.ui.status.clear();
|
||||
} else {
|
||||
app.viewer_pixels();
|
||||
let resp = ui.interact(map.area, egui::Id::new("viewer-text-color-pick"), Sense::click());
|
||||
app.auto.add("viewer.textColorPick", map.area, &pick.field);
|
||||
let chip = Rect::from_min_size(map.area.min + vec2(10.0, 10.0), vec2(220.0, 22.0));
|
||||
painter.rect_filled(chip, 11.0, Color32::from_black_alpha(180));
|
||||
painter.text(chip.center(), Align2::CENTER_CENTER, format!("Click to sample text {}", pick.field), Tokens::ui(11.5), t.text);
|
||||
if let Some(pos) = resp.hover_pos() {
|
||||
ctx.set_cursor_icon(egui::CursorIcon::Crosshair);
|
||||
let c = map.to_comp(pos);
|
||||
app.pointer_comp = Some([c[0] as f32, c[1] as f32]);
|
||||
if let Some(img) = &app.viewer_image
|
||||
&& let Some(s) = fw::sample_frame(img, super::viewer_tools::shown_region(&ctx, map.comp), c)
|
||||
{
|
||||
let sw = Rect::from_min_size(pos + vec2(14.0, 14.0), vec2(26.0, 18.0));
|
||||
painter.rect_filled(sw, 2.0, Color32::from_rgb((s[0] * 255.0) as u8, (s[1] * 255.0) as u8, (s[2] * 255.0) as u8));
|
||||
painter.rect_stroke(sw, 2.0, Stroke::new(1.0, Color32::WHITE), egui::StrokeKind::Outside);
|
||||
}
|
||||
}
|
||||
if resp.clicked()
|
||||
&& let Some(pos) = resp.interact_pointer_pos()
|
||||
&& let Some(img) = &app.viewer_image
|
||||
&& let Some(s) = fw::sample_frame(img, super::viewer_tools::shown_region(&ctx, map.comp), map.to_comp(pos))
|
||||
{
|
||||
let mut params = json!({"layer": pick.layer});
|
||||
params[&pick.field] = json!([s[0], s[1], s[2]]);
|
||||
if let Some(range) = pick.range {
|
||||
params["range"] = json!(range);
|
||||
}
|
||||
actions.push(("layer.setText".into(), params));
|
||||
app.ui.text_color_pick = None;
|
||||
app.ui.status.clear();
|
||||
}
|
||||
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
app.ui.text_color_pick = None;
|
||||
app.ui.status.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
let picking = app.ui.fx_pick.is_some() || app.ui.text_color_pick.is_some();
|
||||
let point_pick = app.ui.fx_pick.clone().filter(|p| p.kind == "point");
|
||||
if app.ui.viewer.show_layer_controls || point_pick.is_some() {
|
||||
// ⊕ controls for the point parameters of the selected effects.
|
||||
|
||||
@@ -8,6 +8,7 @@ use effectcraft_engine::render::EvalCtx;
|
||||
use egui::{Align2, Rect, Sense, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::state::TextColorPick;
|
||||
use crate::theme::Tokens;
|
||||
use crate::{EffectcraftApp, widgets};
|
||||
|
||||
@@ -201,7 +202,21 @@ pub fn character(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if crate::widgets::color_popup(ui, pop, fs.left_bottom(), &mut rgb) {
|
||||
actions.push(json!({key: [rgb[0], rgb[1], rgb[2]], "merge": format!("char-{key}")}));
|
||||
}
|
||||
p.text(pos2(fs.max.x + 6.0, y + 10.0), Align2::LEFT_CENTER, label, Tokens::ui(11.5), t.text_dim);
|
||||
let er = Rect::from_min_size(pos2(fs.max.x + 4.0, y + 1.0), vec2(18.0, 18.0));
|
||||
let active = app.ui.text_color_pick.as_ref().is_some_and(|pick| pick.layer == target.as_ref().map_or(0, |tt| tt.layer) && pick.field == key);
|
||||
let eye = super::fx_widgets::eyedropper_button(ui, er, active, egui::Id::new(("char-eye", key)), &t);
|
||||
app.auto.add(&format!("character.{key}.eyedropper"), er, &format!("{label} eyedropper"));
|
||||
if eye.clicked() {
|
||||
if active {
|
||||
app.ui.text_color_pick = None;
|
||||
app.ui.status.clear();
|
||||
} else if let Some(tt) = &target {
|
||||
app.ui.fx_pick = None;
|
||||
app.ui.text_color_pick = Some(TextColorPick { layer: tt.layer, field: key.into(), range: tt.range });
|
||||
app.ui.status = format!("Click in the Composition panel to sample text {label}");
|
||||
}
|
||||
}
|
||||
p.text(pos2(er.max.x + 6.0, y + 10.0), Align2::LEFT_CENTER, label, Tokens::ui(11.5), t.text_dim);
|
||||
}
|
||||
y += 32.0;
|
||||
// Style toggles: Faux Bold, Faux Italic, All Caps, Small Caps, Superscript, Subscript.
|
||||
|
||||
@@ -488,6 +488,15 @@ pub struct FxPick {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// A Character panel Fill or Stroke eyedropper waiting for a Composition viewer click.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TextColorPick {
|
||||
pub layer: u64,
|
||||
pub field: String,
|
||||
/// Preserve the edited character range when focus moves from the panel to the viewer.
|
||||
pub range: Option<[usize; 2]>,
|
||||
}
|
||||
|
||||
/// Effects & Presets contents-menu options.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct EffectsView {
|
||||
@@ -615,6 +624,9 @@ pub struct UiState {
|
||||
/// Effect Controls: a point crosshair or colour eyedropper waiting for a viewer click.
|
||||
#[serde(default)]
|
||||
pub fx_pick: Option<FxPick>,
|
||||
/// Character panel colour eyedropper waiting for a viewer click.
|
||||
#[serde(default)]
|
||||
pub text_color_pick: Option<TextColorPick>,
|
||||
/// Curves editor: shown channel (index into RGB/Red/Green/Blue/Alpha) per effect uid.
|
||||
#[serde(default)]
|
||||
pub fx_curve_channel: BTreeMap<u64, usize>,
|
||||
@@ -702,6 +714,7 @@ impl Default for UiState {
|
||||
fx_closed: BTreeSet::new(),
|
||||
fx_slider_open: BTreeSet::new(),
|
||||
fx_pick: None,
|
||||
text_color_pick: None,
|
||||
fx_curve_channel: BTreeMap::new(),
|
||||
fx_curve_pencil: BTreeSet::new(),
|
||||
fx_levels_channel: BTreeMap::new(),
|
||||
|
||||
Reference in New Issue
Block a user