add increase count when dragging

This commit is contained in:
0SlowPoke0
2025-08-27 21:52:12 +05:30
parent 2698409315
commit 9ac766b824
4 changed files with 49 additions and 2 deletions

View File

@@ -178,6 +178,10 @@ pub fn input_mappings() -> Mapping {
entry!(KeyDown(MouseRight); action_dispatch=OperationToolMessage::Confirm),
entry!(KeyDown(Escape); action_dispatch=OperationToolMessage::Abort),
entry!(KeyDown(Enter); action_dispatch=OperationToolMessage::Confirm),
entry!(KeyDown(ArrowUp);action_dispatch=OperationToolMessage::IncreaseCount),
entry!(KeyDown(ArrowDown);action_dispatch=OperationToolMessage::DecreaseCount),
entry!(KeyDown(BracketRight);action_dispatch=OperationToolMessage::IncreaseCount),
entry!(KeyDown(BracketLeft);action_dispatch=OperationToolMessage::DecreaseCount),
//
// ShapeToolMessage
entry!(KeyDown(MouseLeft); action_dispatch=ShapeToolMessage::DragStart),

View File

@@ -76,6 +76,11 @@ impl CircularRepeatOperation {
for (layer, initial_radius) in &tool_data.circular_operation_data.layers_dragging {
// If the layers sign differs from the clicked layer, invert delta to preserve consistent in/out dragging behavior
let Some((angle, _, count)) = extract_circular_repeat_parameters(Some(*layer), document) else {
return;
};
let new_radius = if initial_radius.signum() == clicked_radius.signum() {
*initial_radius + delta
} else {
@@ -84,9 +89,9 @@ impl CircularRepeatOperation {
responses.add(GraphOperationMessage::CircularRepeatSet {
layer: *layer,
angle: 0.,
angle,
radius: new_radius,
count: 6,
count,
});
}
@@ -136,6 +141,24 @@ impl CircularRepeatOperation {
}
}
pub fn increase_decrease_count(tool_data: &mut OperationToolData, increase: bool, document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) {
for (layer, _) in &tool_data.circular_operation_data.layers_dragging {
let Some((angle, radius, mut count)) = extract_circular_repeat_parameters(Some(*layer), document) else {
return;
};
if increase {
count += 1
} else {
count = (count - 1).max(1)
}
responses.add(GraphOperationMessage::CircularRepeatSet { layer: *layer, angle, radius, count });
}
responses.add(NodeGraphMessage::RunDocumentGraph);
}
pub fn cleanup(tool_data: &mut OperationToolData) {
// Clear stored drag state at the end of the operation
tool_data.circular_operation_data.layers_dragging.clear();

View File

@@ -230,6 +230,8 @@ pub fn extract_star_parameters(layer: Option<LayerNodeIdentifier>, document: &Do
Some((sides, radius_1, radius_2))
}
/// Extract the node input values of Circular Repeat Node.
/// Returns an option of (angle_offset, radius, count).
pub fn extract_circular_repeat_parameters(layer: Option<LayerNodeIdentifier>, document: &DocumentMessageHandler) -> Option<(f64, f64, u32)> {
let node_inputs = NodeGraphLayer::new(layer?, &document.network_interface).find_node_inputs("Circular Repeat")?;

View File

@@ -37,6 +37,8 @@ pub enum OperationToolMessage {
WorkingColorChanged,
// Tool-specific messages
IncreaseCount,
DecreaseCount,
Confirm,
DragStart,
DragStop,
@@ -127,6 +129,8 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Oper
PointerMove,
Confirm,
Abort,
IncreaseCount,
DecreaseCount,
),
}
}
@@ -212,6 +216,20 @@ impl Fsm for OperationToolFsmState {
OperationToolFsmState::Drawing
}
(OperationToolFsmState::Drawing, OperationToolMessage::IncreaseCount) => {
match tool_options.operation_type {
OperationType::CircularRepeat => CircularRepeatOperation::increase_decrease_count(tool_data, true, document, responses),
_ => {}
}
self
}
(OperationToolFsmState::Drawing, OperationToolMessage::DecreaseCount) => {
match tool_options.operation_type {
OperationType::CircularRepeat => CircularRepeatOperation::increase_decrease_count(tool_data, false, document, responses),
_ => {}
}
self
}
(_, OperationToolMessage::PointerMove) => {
responses.add(OverlaysMessage::Draw);
self