-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add an Autoscale option to the Brush tool #4485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
timon-schelling
wants to merge
1
commit into
master
Choose a base branch
from
brush-tool-autoscale
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ use crate::messages::portfolio::document::node_graph::document_node_definitions: | |||||
| use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier; | ||||||
| use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, OutputConnector}; | ||||||
| use crate::messages::tool::common_functionality::color_selector::{ToolColorOptions, selection_changed_since_last_sync, solid}; | ||||||
| use crate::messages::tool::common_functionality::resize::viewport_zoom; | ||||||
| use graph_craft::document::value::TaggedValue; | ||||||
| use graph_craft::document::{NodeId, NodeInput}; | ||||||
| use graphene_std::Color; | ||||||
|
|
@@ -29,6 +30,7 @@ pub struct BrushOptions { | |||||
| hardness: f64, | ||||||
| flow: f64, | ||||||
| color: ToolColorOptions, | ||||||
| autoscale: bool, | ||||||
| last_synced_selection: Vec<LayerNodeIdentifier>, | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -39,6 +41,7 @@ impl Default for BrushOptions { | |||||
| hardness: BRUSH_HARDNESS_DEFAULT, | ||||||
| flow: BRUSH_FLOW_DEFAULT, | ||||||
| color: ToolColorOptions::default(), | ||||||
| autoscale: false, | ||||||
| last_synced_selection: Vec::new(), | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -48,6 +51,10 @@ impl BrushOptions { | |||||
| fn active_color(&self) -> Color { | ||||||
| self.color.active_color().unwrap_or_default() | ||||||
| } | ||||||
|
|
||||||
| fn stroke_diameter(&self, document: &DocumentMessageHandler) -> f64 { | ||||||
| if self.autoscale { self.diameter / viewport_zoom(document) } else { self.diameter } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[impl_message(Message, ToolMessage, Brush)] | ||||||
|
|
@@ -74,6 +81,7 @@ pub enum BrushToolMessageOptionsUpdate { | |||||
| Diameter(f64), | ||||||
| Hardness(f64), | ||||||
| Flow(f64), | ||||||
| Autoscale(bool), | ||||||
| WorkingColorsChanged, | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -98,6 +106,8 @@ impl ToolMetadata for BrushTool { | |||||
|
|
||||||
| impl LayoutHolder for BrushTool { | ||||||
| fn layout(&self) -> Layout { | ||||||
| let autoscale_id = CheckboxId::new(); | ||||||
| let autoscale_description = "Automatically scale the brush with viewport zoom."; | ||||||
| let widgets = vec![ | ||||||
| ColorInput::new(FillChoice::<SRGBA8>::from(self.options.color.fill_choice.as_ref().unwrap_or(&FillChoice::None))) | ||||||
| .mixed(self.options.color.fill_choice.is_none()) | ||||||
|
|
@@ -149,6 +159,24 @@ impl LayoutHolder for BrushTool { | |||||
| .into() | ||||||
| }) | ||||||
| .widget_instance(), | ||||||
| Separator::new(SeparatorStyle::Unrelated).widget_instance(), | ||||||
| CheckboxInput::new(self.options.autoscale) | ||||||
| .tooltip_label("Autoscale") | ||||||
| .tooltip_description(autoscale_description) | ||||||
| .for_label(autoscale_id) | ||||||
| .on_update(|checkbox_input: &CheckboxInput| { | ||||||
| BrushToolMessage::UpdateOptions { | ||||||
| options: BrushToolMessageOptionsUpdate::Autoscale(checkbox_input.checked), | ||||||
| } | ||||||
| .into() | ||||||
| }) | ||||||
| .widget_instance(), | ||||||
| Separator::new(SeparatorStyle::Related).widget_instance(), | ||||||
| TextLabel::new("Autoscale") | ||||||
| .tooltip_label("Autoscale") | ||||||
| .tooltip_description(autoscale_description) | ||||||
| .for_checkbox(autoscale_id) | ||||||
| .widget_instance(), | ||||||
| ]; | ||||||
|
|
||||||
| Layout(vec![LayoutGroup::row(widgets)]) | ||||||
|
|
@@ -190,6 +218,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Brus | |||||
| responses.add(ToolMessage::SelectWorkingColor { color, primary: true }); | ||||||
| } | ||||||
| } | ||||||
| BrushToolMessageOptionsUpdate::Autoscale(autoscale) => self.options.autoscale = autoscale, | ||||||
| BrushToolMessageOptionsUpdate::WorkingColorsChanged => { | ||||||
| self.options.color.fill_choice = Some(solid(context.global_tool_data.primary_color)); | ||||||
| } | ||||||
|
|
@@ -234,7 +263,7 @@ impl BrushTool { | |||||
| }; | ||||||
| let value = |index: usize| node.inputs.get(index).and_then(|input| input.as_value()); | ||||||
| if let Some(TaggedValue::F64(diameter)) = value(STROKES_DIAMETER_INPUT) { | ||||||
| self.options.diameter = *diameter; | ||||||
| self.options.diameter = if self.options.autoscale { *diameter * viewport_zoom(document) } else { *diameter }; | ||||||
| } | ||||||
| if let Some(TaggedValue::F64(hardness)) = value(STROKES_HARDNESS_INPUT) { | ||||||
| self.options.hardness = *hardness; | ||||||
|
|
@@ -355,7 +384,7 @@ impl BrushToolData { | |||||
| }; | ||||||
| let value = |index: usize| node.inputs.get(index).and_then(|input| input.as_value()); | ||||||
| matches!(value(STROKES_COLOR_INPUT), Some(TaggedValue::Color(color)) if *color == options.active_color()) | ||||||
| && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.diameter) | ||||||
| && matches!(value(STROKES_DIAMETER_INPUT), Some(TaggedValue::F64(diameter)) if *diameter == options.stroke_diameter(document)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: When autoscale selection sync round-trips a diameter through a non-representable zoom, exact equality rejects the matching stroke and creates a new brush group. Compare the diameters with a scale-aware floating-point tolerance. Prompt for AI agents
Suggested change
|
||||||
| && matches!(value(STROKES_HARDNESS_INPUT), Some(TaggedValue::F64(hardness)) if *hardness == options.hardness) | ||||||
| && matches!(value(STROKES_FLOW_INPUT), Some(TaggedValue::F64(flow)) if *flow == options.flow) | ||||||
| } | ||||||
|
|
@@ -447,7 +476,7 @@ impl Fsm for BrushToolFsmState { | |||||
| parent, | ||||||
| insert_index, | ||||||
| color: tool_options.active_color(), | ||||||
| diameter: tool_options.diameter, | ||||||
| diameter: tool_options.stroke_diameter(document), | ||||||
| hardness: tool_options.hardness, | ||||||
| flow: tool_options.flow, | ||||||
| }); | ||||||
|
|
@@ -461,7 +490,7 @@ impl Fsm for BrushToolFsmState { | |||||
| layer, | ||||||
| strokes_node_id, | ||||||
| color: tool_options.active_color(), | ||||||
| diameter: tool_options.diameter, | ||||||
| diameter: tool_options.stroke_diameter(document), | ||||||
| hardness: tool_options.hardness, | ||||||
| flow: tool_options.flow, | ||||||
| }); | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: When the user toggles Autoscale with a brush layer selected, this branch reinterprets the unchanged diameter in the wrong unit. Convert
options.diameterby the current viewport zoom when changing modes so the existing document-space diameter remains unchanged.Prompt for AI agents