mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-21 12:08:11 +08:00
Rename the message system's 'data' argument to 'context' (#2872)
This commit is contained in:
+106
-122
@@ -1,6 +1,6 @@
|
||||
use crate::messages::debug::utility_types::MessageLoggingVerbosity;
|
||||
use crate::messages::dialog::DialogMessageData;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions;
|
||||
use crate::messages::dialog::DialogMessageContext;
|
||||
use crate::messages::layout::layout_message_handler::LayoutMessageContext;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@@ -91,7 +91,7 @@ impl Dispatcher {
|
||||
pub fn handle_message<T: Into<Message>>(&mut self, message: T, process_after_all_current: bool) {
|
||||
let message = message.into();
|
||||
// Add all additional messages to the buffer if it exists (except from the end buffer message)
|
||||
if !matches!(message, Message::EndBuffer(_)) {
|
||||
if !matches!(message, Message::EndBuffer { .. }) {
|
||||
if let Some(buffered_queue) = &mut self.buffered_queue {
|
||||
Self::schedule_execution(buffered_queue, true, [message]);
|
||||
|
||||
@@ -126,10 +126,112 @@ impl Dispatcher {
|
||||
|
||||
// Process the action by forwarding it to the relevant message handler, or saving the FrontendMessage to be sent to the frontend
|
||||
match message {
|
||||
Message::Animation(message) => {
|
||||
self.message_handlers.animation_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::Broadcast(message) => self.message_handlers.broadcast_message_handler.process_message(message, &mut queue, ()),
|
||||
Message::Debug(message) => {
|
||||
self.message_handlers.debug_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::Dialog(message) => {
|
||||
let context = DialogMessageContext {
|
||||
portfolio: &self.message_handlers.portfolio_message_handler,
|
||||
preferences: &self.message_handlers.preferences_message_handler,
|
||||
};
|
||||
self.message_handlers.dialog_message_handler.process_message(message, &mut queue, context);
|
||||
}
|
||||
Message::Frontend(message) => {
|
||||
// Handle these messages immediately by returning early
|
||||
if let FrontendMessage::TriggerFontLoad { .. } = message {
|
||||
self.responses.push(message);
|
||||
self.cleanup_queues(false);
|
||||
|
||||
// Return early to avoid running the code after the match block
|
||||
return;
|
||||
} else {
|
||||
// `FrontendMessage`s are saved and will be sent to the frontend after the message queue is done being processed
|
||||
self.responses.push(message);
|
||||
}
|
||||
}
|
||||
Message::Globals(message) => {
|
||||
self.message_handlers.globals_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::InputPreprocessor(message) => {
|
||||
let keyboard_platform = GLOBAL_PLATFORM.get().copied().unwrap_or_default().as_keyboard_platform_layout();
|
||||
|
||||
self.message_handlers
|
||||
.input_preprocessor_message_handler
|
||||
.process_message(message, &mut queue, InputPreprocessorMessageContext { keyboard_platform });
|
||||
}
|
||||
Message::KeyMapping(message) => {
|
||||
let input = &self.message_handlers.input_preprocessor_message_handler;
|
||||
let actions = self.collect_actions();
|
||||
|
||||
self.message_handlers
|
||||
.key_mapping_message_handler
|
||||
.process_message(message, &mut queue, KeyMappingMessageContext { input, actions });
|
||||
}
|
||||
Message::Layout(message) => {
|
||||
let action_input_mapping = &|action_to_find: &MessageDiscriminant| self.message_handlers.key_mapping_message_handler.action_input_mapping(action_to_find);
|
||||
let context = LayoutMessageContext { action_input_mapping };
|
||||
|
||||
self.message_handlers.layout_message_handler.process_message(message, &mut queue, context);
|
||||
}
|
||||
Message::Portfolio(message) => {
|
||||
let ipp = &self.message_handlers.input_preprocessor_message_handler;
|
||||
let preferences = &self.message_handlers.preferences_message_handler;
|
||||
let current_tool = &self.message_handlers.tool_message_handler.tool_state.tool_data.active_tool_type;
|
||||
let message_logging_verbosity = self.message_handlers.debug_message_handler.message_logging_verbosity;
|
||||
let reset_node_definitions_on_open = self.message_handlers.portfolio_message_handler.reset_node_definitions_on_open;
|
||||
let timing_information = self.message_handlers.animation_message_handler.timing_information();
|
||||
let animation = &self.message_handlers.animation_message_handler;
|
||||
|
||||
self.message_handlers.portfolio_message_handler.process_message(
|
||||
message,
|
||||
&mut queue,
|
||||
PortfolioMessageContext {
|
||||
ipp,
|
||||
preferences,
|
||||
current_tool,
|
||||
message_logging_verbosity,
|
||||
reset_node_definitions_on_open,
|
||||
timing_information,
|
||||
animation,
|
||||
},
|
||||
);
|
||||
}
|
||||
Message::Preferences(message) => {
|
||||
self.message_handlers.preferences_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::Tool(message) => {
|
||||
let document_id = self.message_handlers.portfolio_message_handler.active_document_id().unwrap();
|
||||
let Some(document) = self.message_handlers.portfolio_message_handler.documents.get_mut(&document_id) else {
|
||||
warn!("Called ToolMessage without an active document.\nGot {message:?}");
|
||||
return;
|
||||
};
|
||||
|
||||
let context = ToolMessageContext {
|
||||
document_id,
|
||||
document,
|
||||
input: &self.message_handlers.input_preprocessor_message_handler,
|
||||
persistent_data: &self.message_handlers.portfolio_message_handler.persistent_data,
|
||||
node_graph: &self.message_handlers.portfolio_message_handler.executor,
|
||||
preferences: &self.message_handlers.preferences_message_handler,
|
||||
};
|
||||
|
||||
self.message_handlers.tool_message_handler.process_message(message, &mut queue, context);
|
||||
}
|
||||
Message::Workspace(message) => {
|
||||
self.message_handlers.workspace_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::NoOp => {}
|
||||
Message::Batched { messages } => {
|
||||
messages.iter().for_each(|message| self.handle_message(message.to_owned(), false));
|
||||
}
|
||||
Message::StartBuffer => {
|
||||
self.buffered_queue = Some(std::mem::take(&mut self.message_queues));
|
||||
}
|
||||
Message::EndBuffer(render_metadata) => {
|
||||
Message::EndBuffer { render_metadata } => {
|
||||
// Assign the message queue to the currently buffered queue
|
||||
if let Some(buffered_queue) = self.buffered_queue.take() {
|
||||
self.cleanup_queues(false);
|
||||
@@ -157,124 +259,6 @@ impl Dispatcher {
|
||||
];
|
||||
Self::schedule_execution(&mut self.message_queues, false, messages.map(Message::from));
|
||||
}
|
||||
Message::NoOp => {}
|
||||
Message::Init => {
|
||||
// Load persistent data from the browser database
|
||||
queue.add(FrontendMessage::TriggerLoadFirstAutoSaveDocument);
|
||||
queue.add(FrontendMessage::TriggerLoadPreferences);
|
||||
|
||||
// Display the menu bar at the top of the window
|
||||
queue.add(MenuBarMessage::SendLayout);
|
||||
|
||||
// Send the information for tooltips and categories for each node/input.
|
||||
queue.add(FrontendMessage::SendUIMetadata {
|
||||
node_descriptions: document_node_definitions::collect_node_descriptions(),
|
||||
node_types: document_node_definitions::collect_node_types(),
|
||||
});
|
||||
|
||||
// Finish loading persistent data from the browser database
|
||||
queue.add(FrontendMessage::TriggerLoadRestAutoSaveDocuments);
|
||||
}
|
||||
Message::Animation(message) => {
|
||||
self.message_handlers.animation_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::Batched(messages) => {
|
||||
messages.iter().for_each(|message| self.handle_message(message.to_owned(), false));
|
||||
}
|
||||
Message::Broadcast(message) => self.message_handlers.broadcast_message_handler.process_message(message, &mut queue, ()),
|
||||
Message::Debug(message) => {
|
||||
self.message_handlers.debug_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::Dialog(message) => {
|
||||
let data = DialogMessageData {
|
||||
portfolio: &self.message_handlers.portfolio_message_handler,
|
||||
preferences: &self.message_handlers.preferences_message_handler,
|
||||
};
|
||||
self.message_handlers.dialog_message_handler.process_message(message, &mut queue, data);
|
||||
}
|
||||
Message::Frontend(message) => {
|
||||
// Handle these messages immediately by returning early
|
||||
if let FrontendMessage::TriggerFontLoad { .. } = message {
|
||||
self.responses.push(message);
|
||||
self.cleanup_queues(false);
|
||||
|
||||
// Return early to avoid running the code after the match block
|
||||
return;
|
||||
} else {
|
||||
// `FrontendMessage`s are saved and will be sent to the frontend after the message queue is done being processed
|
||||
self.responses.push(message);
|
||||
}
|
||||
}
|
||||
Message::Globals(message) => {
|
||||
self.message_handlers.globals_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::InputPreprocessor(message) => {
|
||||
let keyboard_platform = GLOBAL_PLATFORM.get().copied().unwrap_or_default().as_keyboard_platform_layout();
|
||||
|
||||
self.message_handlers
|
||||
.input_preprocessor_message_handler
|
||||
.process_message(message, &mut queue, InputPreprocessorMessageData { keyboard_platform });
|
||||
}
|
||||
Message::KeyMapping(message) => {
|
||||
let input = &self.message_handlers.input_preprocessor_message_handler;
|
||||
let actions = self.collect_actions();
|
||||
|
||||
self.message_handlers
|
||||
.key_mapping_message_handler
|
||||
.process_message(message, &mut queue, KeyMappingMessageData { input, actions });
|
||||
}
|
||||
Message::Layout(message) => {
|
||||
let action_input_mapping = &|action_to_find: &MessageDiscriminant| self.message_handlers.key_mapping_message_handler.action_input_mapping(action_to_find);
|
||||
|
||||
self.message_handlers.layout_message_handler.process_message(message, &mut queue, action_input_mapping);
|
||||
}
|
||||
Message::Portfolio(message) => {
|
||||
let ipp = &self.message_handlers.input_preprocessor_message_handler;
|
||||
let preferences = &self.message_handlers.preferences_message_handler;
|
||||
let current_tool = &self.message_handlers.tool_message_handler.tool_state.tool_data.active_tool_type;
|
||||
let message_logging_verbosity = self.message_handlers.debug_message_handler.message_logging_verbosity;
|
||||
let reset_node_definitions_on_open = self.message_handlers.portfolio_message_handler.reset_node_definitions_on_open;
|
||||
let timing_information = self.message_handlers.animation_message_handler.timing_information();
|
||||
let animation = &self.message_handlers.animation_message_handler;
|
||||
|
||||
self.message_handlers.portfolio_message_handler.process_message(
|
||||
message,
|
||||
&mut queue,
|
||||
PortfolioMessageData {
|
||||
ipp,
|
||||
preferences,
|
||||
current_tool,
|
||||
message_logging_verbosity,
|
||||
reset_node_definitions_on_open,
|
||||
timing_information,
|
||||
animation,
|
||||
},
|
||||
);
|
||||
}
|
||||
Message::Preferences(message) => {
|
||||
self.message_handlers.preferences_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
Message::Tool(message) => {
|
||||
let document_id = self.message_handlers.portfolio_message_handler.active_document_id().unwrap();
|
||||
let Some(document) = self.message_handlers.portfolio_message_handler.documents.get_mut(&document_id) else {
|
||||
warn!("Called ToolMessage without an active document.\nGot {message:?}");
|
||||
return;
|
||||
};
|
||||
|
||||
let data = ToolMessageData {
|
||||
document_id,
|
||||
document,
|
||||
input: &self.message_handlers.input_preprocessor_message_handler,
|
||||
persistent_data: &self.message_handlers.portfolio_message_handler.persistent_data,
|
||||
node_graph: &self.message_handlers.portfolio_message_handler.executor,
|
||||
preferences: &self.message_handlers.preferences_message_handler,
|
||||
};
|
||||
|
||||
self.message_handlers.tool_message_handler.process_message(message, &mut queue, data);
|
||||
}
|
||||
Message::Workspace(message) => {
|
||||
self.message_handlers.workspace_message_handler.process_message(message, &mut queue, ());
|
||||
}
|
||||
}
|
||||
|
||||
// If there are child messages, append the queue to the list of queues
|
||||
|
||||
@@ -9,9 +9,9 @@ pub enum AnimationMessage {
|
||||
EnableLivePreview,
|
||||
DisableLivePreview,
|
||||
RestartAnimation,
|
||||
SetFrameIndex(f64),
|
||||
SetTime(f64),
|
||||
SetFrameIndex { frame: f64 },
|
||||
SetTime { time: f64 },
|
||||
UpdateTime,
|
||||
IncrementFrameCounter,
|
||||
SetAnimationTimeMode(AnimationTimeMode),
|
||||
SetAnimationTimeMode { animation_time_mode: AnimationTimeMode },
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ impl AnimationMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<AnimationMessage, ()> for AnimationMessageHandler {
|
||||
fn process_message(&mut self, message: AnimationMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: AnimationMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
AnimationMessage::ToggleLivePreview => match self.animation_state {
|
||||
AnimationState::Stopped => responses.add(AnimationMessage::EnableLivePreview),
|
||||
@@ -82,13 +82,13 @@ impl MessageHandler<AnimationMessage, ()> for AnimationMessageHandler {
|
||||
// Update the restart and pause/play buttons
|
||||
responses.add(PortfolioMessage::UpdateDocumentWidgets);
|
||||
}
|
||||
AnimationMessage::SetFrameIndex(frame) => {
|
||||
AnimationMessage::SetFrameIndex { frame } => {
|
||||
self.frame_index = frame;
|
||||
responses.add(PortfolioMessage::SubmitActiveGraphRender);
|
||||
// Update the restart and pause/play buttons
|
||||
responses.add(PortfolioMessage::UpdateDocumentWidgets);
|
||||
}
|
||||
AnimationMessage::SetTime(time) => {
|
||||
AnimationMessage::SetTime { time } => {
|
||||
self.timestamp = time;
|
||||
responses.add(AnimationMessage::UpdateTime);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ impl MessageHandler<AnimationMessage, ()> for AnimationMessageHandler {
|
||||
// Update the restart and pause/play buttons
|
||||
responses.add(PortfolioMessage::UpdateDocumentWidgets);
|
||||
}
|
||||
AnimationMessage::SetAnimationTimeMode(animation_time_mode) => {
|
||||
AnimationMessage::SetAnimationTimeMode { animation_time_mode } => {
|
||||
self.animation_time_mode = animation_time_mode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct BroadcastMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<BroadcastMessage, ()> for BroadcastMessageHandler {
|
||||
fn process_message(&mut self, message: BroadcastMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: BroadcastMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
// Sub-messages
|
||||
BroadcastMessage::TriggerEvent(event) => {
|
||||
|
||||
@@ -8,7 +8,7 @@ pub struct DebugMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<DebugMessage, ()> for DebugMessageHandler {
|
||||
fn process_message(&mut self, message: DebugMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: DebugMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
DebugMessage::ToggleTraceLogs => {
|
||||
if log::max_level() == log::LevelFilter::Debug {
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct DialogMessageData<'a> {
|
||||
pub struct DialogMessageContext<'a> {
|
||||
pub portfolio: &'a PortfolioMessageHandler,
|
||||
pub preferences: &'a PreferencesMessageHandler,
|
||||
}
|
||||
@@ -17,14 +17,14 @@ pub struct DialogMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<DialogMessage, DialogMessageData<'_>> for DialogMessageHandler {
|
||||
fn process_message(&mut self, message: DialogMessage, responses: &mut VecDeque<Message>, data: DialogMessageData) {
|
||||
let DialogMessageData { portfolio, preferences } = data;
|
||||
impl MessageHandler<DialogMessage, DialogMessageContext<'_>> for DialogMessageHandler {
|
||||
fn process_message(&mut self, message: DialogMessage, responses: &mut VecDeque<Message>, context: DialogMessageContext) {
|
||||
let DialogMessageContext { portfolio, preferences } = context;
|
||||
|
||||
match message {
|
||||
DialogMessage::ExportDialog(message) => self.export_dialog.process_message(message, responses, ExportDialogMessageData { portfolio }),
|
||||
DialogMessage::ExportDialog(message) => self.export_dialog.process_message(message, responses, ExportDialogMessageContext { portfolio }),
|
||||
DialogMessage::NewDocumentDialog(message) => self.new_document_dialog.process_message(message, responses, ()),
|
||||
DialogMessage::PreferencesDialog(message) => self.preferences_dialog.process_message(message, responses, PreferencesDialogMessageData { preferences }),
|
||||
DialogMessage::PreferencesDialog(message) => self.preferences_dialog.process_message(message, responses, PreferencesDialogMessageContext { preferences }),
|
||||
|
||||
DialogMessage::CloseAllDocumentsWithConfirmation => {
|
||||
let dialog = simple_dialogs::CloseAllDocumentsDialog {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::messages::portfolio::document::utility_types::document_metadata::Laye
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct ExportDialogMessageData<'a> {
|
||||
pub struct ExportDialogMessageContext<'a> {
|
||||
pub portfolio: &'a PortfolioMessageHandler,
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ impl Default for ExportDialogMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<ExportDialogMessage, ExportDialogMessageData<'_>> for ExportDialogMessageHandler {
|
||||
fn process_message(&mut self, message: ExportDialogMessage, responses: &mut VecDeque<Message>, data: ExportDialogMessageData) {
|
||||
let ExportDialogMessageData { portfolio } = data;
|
||||
impl MessageHandler<ExportDialogMessage, ExportDialogMessageContext<'_>> for ExportDialogMessageHandler {
|
||||
fn process_message(&mut self, message: ExportDialogMessage, responses: &mut VecDeque<Message>, context: ExportDialogMessageContext) {
|
||||
let ExportDialogMessageContext { portfolio } = context;
|
||||
|
||||
match message {
|
||||
ExportDialogMessage::FileType(export_type) => self.file_type = export_type,
|
||||
|
||||
@@ -4,4 +4,4 @@ mod export_dialog_message_handler;
|
||||
#[doc(inline)]
|
||||
pub use export_dialog_message::{ExportDialogMessage, ExportDialogMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use export_dialog_message_handler::{ExportDialogMessageData, ExportDialogMessageHandler};
|
||||
pub use export_dialog_message_handler::{ExportDialogMessageContext, ExportDialogMessageHandler};
|
||||
|
||||
@@ -16,4 +16,4 @@ pub mod simple_dialogs;
|
||||
#[doc(inline)]
|
||||
pub use dialog_message::{DialogMessage, DialogMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use dialog_message_handler::{DialogMessageData, DialogMessageHandler};
|
||||
pub use dialog_message_handler::{DialogMessageContext, DialogMessageHandler};
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ pub struct NewDocumentDialogMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<NewDocumentDialogMessage, ()> for NewDocumentDialogMessageHandler {
|
||||
fn process_message(&mut self, message: NewDocumentDialogMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: NewDocumentDialogMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
NewDocumentDialogMessage::Name(name) => self.name = name,
|
||||
NewDocumentDialogMessage::Infinite(infinite) => self.infinite = infinite,
|
||||
|
||||
@@ -4,4 +4,4 @@ mod preferences_dialog_message_handler;
|
||||
#[doc(inline)]
|
||||
pub use preferences_dialog_message::{PreferencesDialogMessage, PreferencesDialogMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use preferences_dialog_message_handler::{PreferencesDialogMessageData, PreferencesDialogMessageHandler};
|
||||
pub use preferences_dialog_message_handler::{PreferencesDialogMessageContext, PreferencesDialogMessageHandler};
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::messages::preferences::SelectionMode;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct PreferencesDialogMessageData<'a> {
|
||||
pub struct PreferencesDialogMessageContext<'a> {
|
||||
pub preferences: &'a PreferencesMessageHandler,
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ pub struct PreferencesDialogMessageData<'a> {
|
||||
pub struct PreferencesDialogMessageHandler {}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<PreferencesDialogMessage, PreferencesDialogMessageData<'_>> for PreferencesDialogMessageHandler {
|
||||
fn process_message(&mut self, message: PreferencesDialogMessage, responses: &mut VecDeque<Message>, data: PreferencesDialogMessageData) {
|
||||
let PreferencesDialogMessageData { preferences } = data;
|
||||
impl MessageHandler<PreferencesDialogMessage, PreferencesDialogMessageContext<'_>> for PreferencesDialogMessageHandler {
|
||||
fn process_message(&mut self, message: PreferencesDialogMessage, responses: &mut VecDeque<Message>, context: PreferencesDialogMessageContext) {
|
||||
let PreferencesDialogMessageContext { preferences } = context;
|
||||
|
||||
match message {
|
||||
PreferencesDialogMessage::Confirm => {}
|
||||
|
||||
@@ -5,7 +5,7 @@ pub struct GlobalsMessageHandler {}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<GlobalsMessage, ()> for GlobalsMessageHandler {
|
||||
fn process_message(&mut self, message: GlobalsMessage, _responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: GlobalsMessage, _responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
GlobalsMessage::SetPlatform { platform } => {
|
||||
if GLOBAL_PLATFORM.get() != Some(&platform) {
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::messages::prelude::*;
|
||||
use std::fmt::Write;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct InputMapperMessageData<'a> {
|
||||
pub struct InputMapperMessageContext<'a> {
|
||||
pub input: &'a InputPreprocessorMessageHandler,
|
||||
pub actions: ActionList,
|
||||
}
|
||||
@@ -18,9 +18,9 @@ pub struct InputMapperMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<InputMapperMessage, InputMapperMessageData<'_>> for InputMapperMessageHandler {
|
||||
fn process_message(&mut self, message: InputMapperMessage, responses: &mut VecDeque<Message>, data: InputMapperMessageData) {
|
||||
let InputMapperMessageData { input, actions } = data;
|
||||
impl MessageHandler<InputMapperMessage, InputMapperMessageContext<'_>> for InputMapperMessageHandler {
|
||||
fn process_message(&mut self, message: InputMapperMessage, responses: &mut VecDeque<Message>, context: InputMapperMessageContext) {
|
||||
let InputMapperMessageContext { input, actions } = context;
|
||||
|
||||
if let Some(message) = self.mapping.match_input_message(message, &input.keyboard, actions) {
|
||||
responses.add(message);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::messages::input_mapper::input_mapper_message_handler::InputMapperMessageData;
|
||||
use crate::messages::input_mapper::input_mapper_message_handler::InputMapperMessageContext;
|
||||
use crate::messages::input_mapper::utility_types::input_keyboard::KeysGroup;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct KeyMappingMessageData<'a> {
|
||||
pub struct KeyMappingMessageContext<'a> {
|
||||
pub input: &'a InputPreprocessorMessageHandler,
|
||||
pub actions: ActionList,
|
||||
}
|
||||
@@ -14,12 +14,12 @@ pub struct KeyMappingMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<KeyMappingMessage, KeyMappingMessageData<'_>> for KeyMappingMessageHandler {
|
||||
fn process_message(&mut self, message: KeyMappingMessage, responses: &mut VecDeque<Message>, data: KeyMappingMessageData) {
|
||||
let KeyMappingMessageData { input, actions } = data;
|
||||
impl MessageHandler<KeyMappingMessage, KeyMappingMessageContext<'_>> for KeyMappingMessageHandler {
|
||||
fn process_message(&mut self, message: KeyMappingMessage, responses: &mut VecDeque<Message>, context: KeyMappingMessageContext) {
|
||||
let KeyMappingMessageContext { input, actions } = context;
|
||||
|
||||
match message {
|
||||
KeyMappingMessage::Lookup(input_message) => self.mapping_handler.process_message(input_message, responses, InputMapperMessageData { input, actions }),
|
||||
KeyMappingMessage::Lookup(input_message) => self.mapping_handler.process_message(input_message, responses, InputMapperMessageContext { input, actions }),
|
||||
KeyMappingMessage::ModifyMapping(new_layout) => self.mapping_handler.set_mapping(new_layout.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,4 +4,4 @@ mod key_mapping_message_handler;
|
||||
#[doc(inline)]
|
||||
pub use key_mapping_message::{KeyMappingMessage, KeyMappingMessageDiscriminant, MappingVariant, MappingVariantDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use key_mapping_message_handler::{KeyMappingMessageData, KeyMappingMessageHandler};
|
||||
pub use key_mapping_message_handler::{KeyMappingMessageContext, KeyMappingMessageHandler};
|
||||
|
||||
@@ -8,4 +8,4 @@ pub mod utility_types;
|
||||
#[doc(inline)]
|
||||
pub use input_mapper_message::{InputMapperMessage, InputMapperMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use input_mapper_message_handler::{InputMapperMessageData, InputMapperMessageHandler};
|
||||
pub use input_mapper_message_handler::{InputMapperMessageContext, InputMapperMessageHandler};
|
||||
|
||||
@@ -7,7 +7,7 @@ use glam::DVec2;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct InputPreprocessorMessageData {
|
||||
pub struct InputPreprocessorMessageContext {
|
||||
pub keyboard_platform: KeyboardPlatformLayout,
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ pub struct InputPreprocessorMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageData> for InputPreprocessorMessageHandler {
|
||||
fn process_message(&mut self, message: InputPreprocessorMessage, responses: &mut VecDeque<Message>, data: InputPreprocessorMessageData) {
|
||||
let InputPreprocessorMessageData { keyboard_platform } = data;
|
||||
impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageContext> for InputPreprocessorMessageHandler {
|
||||
fn process_message(&mut self, message: InputPreprocessorMessage, responses: &mut VecDeque<Message>, context: InputPreprocessorMessageContext) {
|
||||
let InputPreprocessorMessageContext { keyboard_platform } = context;
|
||||
|
||||
match message {
|
||||
InputPreprocessorMessage::BoundsOfViewports { bounds_of_viewports } => {
|
||||
@@ -98,7 +98,7 @@ impl MessageHandler<InputPreprocessorMessage, InputPreprocessorMessageData> for
|
||||
self.translate_mouse_event(mouse_state, false, responses);
|
||||
}
|
||||
InputPreprocessorMessage::CurrentTime { timestamp } => {
|
||||
responses.add(AnimationMessage::SetTime(timestamp as f64));
|
||||
responses.add(AnimationMessage::SetTime { time: timestamp as f64 });
|
||||
self.time = timestamp;
|
||||
self.frame_time.advance_timestamp(Duration::from_millis(timestamp));
|
||||
}
|
||||
@@ -214,10 +214,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
let data = InputPreprocessorMessageData {
|
||||
let context = InputPreprocessorMessageContext {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
input_preprocessor.process_message(message, &mut responses, context);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Alt as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyDown(Key::Alt).into()));
|
||||
@@ -233,10 +233,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
let data = InputPreprocessorMessageData {
|
||||
let context = InputPreprocessorMessageContext {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
input_preprocessor.process_message(message, &mut responses, context);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Control as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyDown(Key::Control).into()));
|
||||
@@ -252,10 +252,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
let data = InputPreprocessorMessageData {
|
||||
let context = InputPreprocessorMessageContext {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
input_preprocessor.process_message(message, &mut responses, context);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Shift as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyDown(Key::Shift).into()));
|
||||
@@ -273,10 +273,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
let data = InputPreprocessorMessageData {
|
||||
let context = InputPreprocessorMessageContext {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
input_preprocessor.process_message(message, &mut responses, context);
|
||||
|
||||
assert!(!input_preprocessor.keyboard.get(Key::Control as usize));
|
||||
assert_eq!(responses.pop_front(), Some(InputMapperMessage::KeyUp(Key::Control).into()));
|
||||
@@ -293,10 +293,10 @@ mod test {
|
||||
|
||||
let mut responses = VecDeque::new();
|
||||
|
||||
let data = InputPreprocessorMessageData {
|
||||
let context = InputPreprocessorMessageContext {
|
||||
keyboard_platform: KeyboardPlatformLayout::Standard,
|
||||
};
|
||||
input_preprocessor.process_message(message, &mut responses, data);
|
||||
input_preprocessor.process_message(message, &mut responses, context);
|
||||
|
||||
assert!(input_preprocessor.keyboard.get(Key::Control as usize));
|
||||
assert!(input_preprocessor.keyboard.get(Key::Shift as usize));
|
||||
|
||||
@@ -4,4 +4,4 @@ mod input_preprocessor_message_handler;
|
||||
#[doc(inline)]
|
||||
pub use input_preprocessor_message::{InputPreprocessorMessage, InputPreprocessorMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use input_preprocessor_message_handler::{InputPreprocessorMessageData, InputPreprocessorMessageHandler};
|
||||
pub use input_preprocessor_message_handler::{InputPreprocessorMessageContext, InputPreprocessorMessageHandler};
|
||||
|
||||
@@ -6,14 +6,53 @@ use graphene_std::text::Font;
|
||||
use graphene_std::vector::style::{FillChoice, GradientStops};
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct LayoutMessageContext<'a> {
|
||||
pub action_input_mapping: &'a dyn Fn(&MessageDiscriminant) -> Option<KeysGroup>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ExtractField)]
|
||||
pub struct LayoutMessageHandler {
|
||||
layouts: [Layout; LayoutTarget::LayoutTargetLength as usize],
|
||||
}
|
||||
|
||||
enum WidgetValueAction {
|
||||
Commit,
|
||||
Update,
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<LayoutMessage, LayoutMessageContext<'_>> for LayoutMessageHandler {
|
||||
fn process_message(&mut self, message: LayoutMessage, responses: &mut std::collections::VecDeque<Message>, context: LayoutMessageContext) {
|
||||
let action_input_mapping = &context.action_input_mapping;
|
||||
|
||||
match message {
|
||||
LayoutMessage::ResendActiveWidget { layout_target, widget_id } => {
|
||||
// Find the updated diff based on the specified layout target
|
||||
let Some(diff) = (match &self.layouts[layout_target as usize] {
|
||||
Layout::MenuLayout(_) => return,
|
||||
Layout::WidgetLayout(layout) => Self::get_widget_path(layout, widget_id).map(|(widget, widget_path)| {
|
||||
// Create a widget update diff for the relevant id
|
||||
let new_value = DiffUpdate::Widget(widget.clone());
|
||||
WidgetDiff { widget_path, new_value }
|
||||
}),
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
// Resend that diff
|
||||
self.send_diff(vec![diff], layout_target, responses, action_input_mapping);
|
||||
}
|
||||
LayoutMessage::SendLayout { layout, layout_target } => {
|
||||
self.diff_and_send_layout_to_frontend(layout_target, layout, responses, action_input_mapping);
|
||||
}
|
||||
LayoutMessage::WidgetValueCommit { layout_target, widget_id, value } => {
|
||||
self.handle_widget_callback(layout_target, widget_id, value, WidgetValueAction::Commit, responses);
|
||||
}
|
||||
LayoutMessage::WidgetValueUpdate { layout_target, widget_id, value } => {
|
||||
self.handle_widget_callback(layout_target, widget_id, value, WidgetValueAction::Update, responses);
|
||||
responses.add(LayoutMessage::ResendActiveWidget { layout_target, widget_id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
actions!(LayoutMessageDiscriminant;)
|
||||
}
|
||||
}
|
||||
|
||||
impl LayoutMessageHandler {
|
||||
@@ -340,54 +379,7 @@ impl LayoutMessageHandler {
|
||||
Widget::WorkingColorsInput(_) => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn custom_data() -> MessageData {
|
||||
// TODO: When <https://github.com/dtolnay/proc-macro2/issues/503> is resolved and released,
|
||||
// TODO: use <https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.line> to get
|
||||
// TODO: the line number instead of hardcoding it to the magic number on the following line.
|
||||
// TODO: Also, utilize the line number in the actual output, since it is currently unused.
|
||||
MessageData::new(String::from("Function"), vec![(String::from("Fn(&MessageDiscriminant) -> Option<KeysGroup>"), 350)], file!())
|
||||
}
|
||||
|
||||
#[message_handler_data(CustomData)]
|
||||
impl<F: Fn(&MessageDiscriminant) -> Option<KeysGroup>> MessageHandler<LayoutMessage, F> for LayoutMessageHandler {
|
||||
fn process_message(&mut self, message: LayoutMessage, responses: &mut std::collections::VecDeque<Message>, action_input_mapping: F) {
|
||||
match message {
|
||||
LayoutMessage::ResendActiveWidget { layout_target, widget_id } => {
|
||||
// Find the updated diff based on the specified layout target
|
||||
let Some(diff) = (match &self.layouts[layout_target as usize] {
|
||||
Layout::MenuLayout(_) => return,
|
||||
Layout::WidgetLayout(layout) => Self::get_widget_path(layout, widget_id).map(|(widget, widget_path)| {
|
||||
// Create a widget update diff for the relevant id
|
||||
let new_value = DiffUpdate::Widget(widget.clone());
|
||||
WidgetDiff { widget_path, new_value }
|
||||
}),
|
||||
}) else {
|
||||
return;
|
||||
};
|
||||
// Resend that diff
|
||||
self.send_diff(vec![diff], layout_target, responses, &action_input_mapping);
|
||||
}
|
||||
LayoutMessage::SendLayout { layout, layout_target } => {
|
||||
self.diff_and_send_layout_to_frontend(layout_target, layout, responses, &action_input_mapping);
|
||||
}
|
||||
LayoutMessage::WidgetValueCommit { layout_target, widget_id, value } => {
|
||||
self.handle_widget_callback(layout_target, widget_id, value, WidgetValueAction::Commit, responses);
|
||||
}
|
||||
LayoutMessage::WidgetValueUpdate { layout_target, widget_id, value } => {
|
||||
self.handle_widget_callback(layout_target, widget_id, value, WidgetValueAction::Update, responses);
|
||||
responses.add(LayoutMessage::ResendActiveWidget { layout_target, widget_id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
actions!(LayoutMessageDiscriminant;)
|
||||
}
|
||||
}
|
||||
|
||||
impl LayoutMessageHandler {
|
||||
/// Diff the update and send to the frontend where necessary
|
||||
fn diff_and_send_layout_to_frontend(
|
||||
&mut self,
|
||||
@@ -453,3 +445,8 @@ impl LayoutMessageHandler {
|
||||
responses.add(message);
|
||||
}
|
||||
}
|
||||
|
||||
enum WidgetValueAction {
|
||||
Commit,
|
||||
Update,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod layout_message;
|
||||
mod layout_message_handler;
|
||||
pub mod layout_message_handler;
|
||||
|
||||
pub mod utility_types;
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
use crate::messages::prelude::*;
|
||||
use graphene_std::renderer::RenderMetadata;
|
||||
use graphite_proc_macros::*;
|
||||
|
||||
#[impl_message]
|
||||
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Message {
|
||||
NoOp,
|
||||
Init,
|
||||
Batched(Box<[Message]>),
|
||||
StartBuffer,
|
||||
EndBuffer(graphene_std::renderer::RenderMetadata),
|
||||
|
||||
// Sub-messages
|
||||
#[child]
|
||||
Animation(AnimationMessage),
|
||||
#[child]
|
||||
@@ -36,6 +32,16 @@ pub enum Message {
|
||||
Tool(ToolMessage),
|
||||
#[child]
|
||||
Workspace(WorkspaceMessage),
|
||||
|
||||
// Messages
|
||||
NoOp,
|
||||
Batched {
|
||||
messages: Box<[Message]>,
|
||||
},
|
||||
StartBuffer,
|
||||
EndBuffer {
|
||||
render_metadata: RenderMetadata,
|
||||
},
|
||||
}
|
||||
|
||||
/// Provides an impl of `specta::Type` for `MessageDiscriminant`, the struct created by `impl_message`.
|
||||
|
||||
@@ -10,10 +10,10 @@ use crate::consts::{ASYMPTOTIC_EFFECT, COLOR_OVERLAY_GRAY, DEFAULT_DOCUMENT_NAME
|
||||
use crate::messages::input_mapper::utility_types::macros::action_keys;
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||
use crate::messages::portfolio::document::node_graph::NodeGraphHandlerData;
|
||||
use crate::messages::portfolio::document::node_graph::NodeGraphMessageContext;
|
||||
use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay, overlay_options};
|
||||
use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType, OverlaysVisibilitySettings};
|
||||
use crate::messages::portfolio::document::properties_panel::utility_types::PropertiesPanelMessageHandlerData;
|
||||
use crate::messages::portfolio::document::properties_panel::properties_panel_message_handler::PropertiesPanelMessageContext;
|
||||
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
|
||||
use crate::messages::portfolio::document::utility_types::misc::{AlignAggregate, AlignAxis, DocumentMode, FlipAxis, PTZ};
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{FlowType, InputConnector, NodeTemplate};
|
||||
@@ -39,7 +39,7 @@ use graphene_std::vector::style::ViewMode;
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct DocumentMessageData<'a> {
|
||||
pub struct DocumentMessageContext<'a> {
|
||||
pub document_id: DocumentId,
|
||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||
pub persistent_data: &'a PersistentData,
|
||||
@@ -170,9 +170,9 @@ impl Default for DocumentMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessageHandler {
|
||||
fn process_message(&mut self, message: DocumentMessage, responses: &mut VecDeque<Message>, data: DocumentMessageData) {
|
||||
let DocumentMessageData {
|
||||
impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMessageHandler {
|
||||
fn process_message(&mut self, message: DocumentMessage, responses: &mut VecDeque<Message>, context: DocumentMessageContext) {
|
||||
let DocumentMessageContext {
|
||||
document_id,
|
||||
ipp,
|
||||
persistent_data,
|
||||
@@ -180,14 +180,14 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
current_tool,
|
||||
preferences,
|
||||
device_pixel_ratio,
|
||||
} = data;
|
||||
} = context;
|
||||
|
||||
let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
|
||||
let selected_visible_layers_bounding_box_viewport = self.selected_visible_layers_bounding_box_viewport();
|
||||
match message {
|
||||
// Sub-messages
|
||||
DocumentMessage::Navigation(message) => {
|
||||
let data = NavigationMessageData {
|
||||
let context = NavigationMessageContext {
|
||||
network_interface: &mut self.network_interface,
|
||||
breadcrumb_network_path: &self.breadcrumb_network_path,
|
||||
ipp,
|
||||
@@ -201,7 +201,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
preferences,
|
||||
};
|
||||
|
||||
self.navigation_handler.process_message(message, responses, data);
|
||||
self.navigation_handler.process_message(message, responses, context);
|
||||
}
|
||||
DocumentMessage::Overlays(message) => {
|
||||
let visibility_settings = self.overlays_visibility_settings;
|
||||
@@ -210,7 +210,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
self.overlays_message_handler.process_message(
|
||||
message,
|
||||
responses,
|
||||
OverlaysMessageData {
|
||||
OverlaysMessageContext {
|
||||
visibility_settings,
|
||||
ipp,
|
||||
device_pixel_ratio,
|
||||
@@ -218,20 +218,20 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
);
|
||||
}
|
||||
DocumentMessage::PropertiesPanel(message) => {
|
||||
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
|
||||
let context = PropertiesPanelMessageContext {
|
||||
network_interface: &mut self.network_interface,
|
||||
selection_network_path: &self.selection_network_path,
|
||||
document_name: self.name.as_str(),
|
||||
executor,
|
||||
persistent_data,
|
||||
};
|
||||
self.properties_panel_message_handler
|
||||
.process_message(message, responses, (persistent_data, properties_panel_message_handler_data));
|
||||
self.properties_panel_message_handler.process_message(message, responses, context);
|
||||
}
|
||||
DocumentMessage::NodeGraph(message) => {
|
||||
self.node_graph_handler.process_message(
|
||||
message,
|
||||
responses,
|
||||
NodeGraphHandlerData {
|
||||
NodeGraphMessageContext {
|
||||
network_interface: &mut self.network_interface,
|
||||
selection_network_path: &self.selection_network_path,
|
||||
breadcrumb_network_path: &self.breadcrumb_network_path,
|
||||
@@ -246,13 +246,13 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
);
|
||||
}
|
||||
DocumentMessage::GraphOperation(message) => {
|
||||
let data = GraphOperationMessageData {
|
||||
let context = GraphOperationMessageContext {
|
||||
network_interface: &mut self.network_interface,
|
||||
collapsed: &mut self.collapsed,
|
||||
node_graph: &mut self.node_graph_handler,
|
||||
};
|
||||
let mut graph_operation_message_handler = GraphOperationMessageHandler {};
|
||||
graph_operation_message_handler.process_message(message, responses, data);
|
||||
graph_operation_message_handler.process_message(message, responses, context);
|
||||
}
|
||||
DocumentMessage::AlignSelectedLayers { axis, aggregate } => {
|
||||
let axis = match axis {
|
||||
|
||||
+11
-11
@@ -14,15 +14,8 @@ use graphene_std::renderer::convert_usvg_path::convert_usvg_path;
|
||||
use graphene_std::text::{Font, TypesettingConfig};
|
||||
use graphene_std::vector::style::{Fill, Gradient, GradientStops, GradientType, PaintOrder, Stroke, StrokeAlign, StrokeCap, StrokeJoin};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct ArtboardInfo {
|
||||
input_node: NodeInput,
|
||||
output_nodes: Vec<InputConnector>,
|
||||
merge_node: NodeId,
|
||||
}
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct GraphOperationMessageData<'a> {
|
||||
pub struct GraphOperationMessageContext<'a> {
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub collapsed: &'a mut CollapsedLayers,
|
||||
pub node_graph: &'a mut NodeGraphMessageHandler,
|
||||
@@ -34,9 +27,9 @@ pub struct GraphOperationMessageHandler {}
|
||||
// GraphOperationMessageHandler always modified the document network. This is so changes to the layers panel will only affect the document network.
|
||||
// For changes to the selected network, use NodeGraphMessageHandler. No NodeGraphMessage's should be added here, since they will affect the selected nested network.
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for GraphOperationMessageHandler {
|
||||
fn process_message(&mut self, message: GraphOperationMessage, responses: &mut VecDeque<Message>, data: GraphOperationMessageData) {
|
||||
let network_interface = data.network_interface;
|
||||
impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for GraphOperationMessageHandler {
|
||||
fn process_message(&mut self, message: GraphOperationMessage, responses: &mut VecDeque<Message>, context: GraphOperationMessageContext) {
|
||||
let network_interface = context.network_interface;
|
||||
|
||||
match message {
|
||||
GraphOperationMessage::FillSet { layer, fill } => {
|
||||
@@ -323,6 +316,13 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct ArtboardInfo {
|
||||
input_node: NodeInput,
|
||||
output_nodes: Vec<InputConnector>,
|
||||
merge_node: NodeId,
|
||||
}
|
||||
|
||||
fn usvg_color(c: usvg::Color, a: f32) -> Color {
|
||||
Color::from_rgbaf32_unchecked(c.red as f32 / 255., c.green as f32 / 255., c.blue as f32 / 255., a)
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ pub mod utility_types;
|
||||
#[doc(inline)]
|
||||
pub use document_message::{DocumentMessage, DocumentMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use document_message_handler::{DocumentMessageData, DocumentMessageHandler};
|
||||
pub use document_message_handler::{DocumentMessageContext, DocumentMessageHandler};
|
||||
|
||||
@@ -5,4 +5,4 @@ pub mod utility_types;
|
||||
#[doc(inline)]
|
||||
pub use navigation_message::{NavigationMessage, NavigationMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use navigation_message_handler::{NavigationMessageData, NavigationMessageHandler};
|
||||
pub use navigation_message_handler::{NavigationMessageContext, NavigationMessageHandler};
|
||||
|
||||
@@ -14,7 +14,7 @@ use glam::{DAffine2, DVec2};
|
||||
use graph_craft::document::NodeId;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct NavigationMessageData<'a> {
|
||||
pub struct NavigationMessageContext<'a> {
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub breadcrumb_network_path: &'a [NodeId],
|
||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||
@@ -33,9 +33,9 @@ pub struct NavigationMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for NavigationMessageHandler {
|
||||
fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, data: NavigationMessageData) {
|
||||
let NavigationMessageData {
|
||||
impl MessageHandler<NavigationMessage, NavigationMessageContext<'_>> for NavigationMessageHandler {
|
||||
fn process_message(&mut self, message: NavigationMessage, responses: &mut VecDeque<Message>, context: NavigationMessageContext) {
|
||||
let NavigationMessageContext {
|
||||
network_interface,
|
||||
breadcrumb_network_path,
|
||||
ipp,
|
||||
@@ -43,7 +43,7 @@ impl MessageHandler<NavigationMessage, NavigationMessageData<'_>> for Navigation
|
||||
document_ptz,
|
||||
graph_view_overlay_open,
|
||||
preferences,
|
||||
} = data;
|
||||
} = context;
|
||||
|
||||
fn get_ptz<'a>(document_ptz: &'a PTZ, network_interface: &'a NodeNetworkInterface, graph_view_overlay_open: bool, breadcrumb_network_path: &[NodeId]) -> Option<&'a PTZ> {
|
||||
if !graph_view_overlay_open {
|
||||
|
||||
@@ -28,7 +28,7 @@ use renderer::Quad;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[derive(Debug, ExtractField)]
|
||||
pub struct NodeGraphHandlerData<'a> {
|
||||
pub struct NodeGraphMessageContext<'a> {
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub selection_network_path: &'a [NodeId],
|
||||
pub breadcrumb_network_path: &'a [NodeId],
|
||||
@@ -93,9 +93,9 @@ pub struct NodeGraphMessageHandler {
|
||||
|
||||
/// NodeGraphMessageHandler always modifies the network which the selected nodes are in. No GraphOperationMessages should be added here, since those messages will always affect the document network.
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGraphMessageHandler {
|
||||
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, data: NodeGraphHandlerData<'a>) {
|
||||
let NodeGraphHandlerData {
|
||||
impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeGraphMessageHandler {
|
||||
fn process_message(&mut self, message: NodeGraphMessage, responses: &mut VecDeque<Message>, context: NodeGraphMessageContext<'a>) {
|
||||
let NodeGraphMessageContext {
|
||||
network_interface,
|
||||
selection_network_path,
|
||||
breadcrumb_network_path,
|
||||
@@ -106,7 +106,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
graph_fade_artwork_percentage,
|
||||
navigation_handler,
|
||||
preferences,
|
||||
} = data;
|
||||
} = context;
|
||||
|
||||
match message {
|
||||
// TODO: automatically remove broadcast messages.
|
||||
@@ -1833,16 +1833,18 @@ impl NodeGraphMessageHandler {
|
||||
.on_update(move |node_type| {
|
||||
let node_id = NodeId::new();
|
||||
|
||||
Message::Batched(Box::new([
|
||||
NodeGraphMessage::CreateNodeFromContextMenu {
|
||||
node_id: Some(node_id),
|
||||
node_type: node_type.clone(),
|
||||
xy: None,
|
||||
add_transaction: true,
|
||||
}
|
||||
.into(),
|
||||
NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(),
|
||||
]))
|
||||
Message::Batched {
|
||||
messages: Box::new([
|
||||
NodeGraphMessage::CreateNodeFromContextMenu {
|
||||
node_id: Some(node_id),
|
||||
node_type: node_type.clone(),
|
||||
xy: None,
|
||||
add_transaction: true,
|
||||
}
|
||||
.into(),
|
||||
NodeGraphMessage::SelectedNodesSet { nodes: vec![node_id] }.into(),
|
||||
]),
|
||||
}
|
||||
})
|
||||
.widget_holder();
|
||||
vec![LayoutGroup::Row { widgets: vec![node_chooser] }]
|
||||
|
||||
@@ -59,13 +59,13 @@ pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphData
|
||||
} else {
|
||||
"Expose this parameter as a node input in the graph"
|
||||
})
|
||||
.on_update(move |_parameter| {
|
||||
Message::Batched(Box::new([NodeGraphMessage::ExposeInput {
|
||||
.on_update(move |_parameter| Message::Batched {
|
||||
messages: Box::new([NodeGraphMessage::ExposeInput {
|
||||
input_connector: InputConnector::node(node_id, index),
|
||||
set_to_exposed: !exposed,
|
||||
start_transaction: true,
|
||||
}
|
||||
.into()]))
|
||||
.into()]),
|
||||
})
|
||||
.widget_holder()
|
||||
}
|
||||
@@ -1307,8 +1307,8 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
|
||||
// Uniform/individual radio input widget
|
||||
let uniform = RadioEntryData::new("Uniform")
|
||||
.label("Uniform")
|
||||
.on_update(move |_| {
|
||||
Message::Batched(Box::new([
|
||||
.on_update(move |_| Message::Batched {
|
||||
messages: Box::new([
|
||||
NodeGraphMessage::SetInputValue {
|
||||
node_id,
|
||||
input_index: IndividualCornerRadiiInput::INDEX,
|
||||
@@ -1321,13 +1321,13 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
|
||||
value: TaggedValue::F64(uniform_val),
|
||||
}
|
||||
.into(),
|
||||
]))
|
||||
]),
|
||||
})
|
||||
.on_commit(commit_value);
|
||||
let individual = RadioEntryData::new("Individual")
|
||||
.label("Individual")
|
||||
.on_update(move |_| {
|
||||
Message::Batched(Box::new([
|
||||
.on_update(move |_| Message::Batched {
|
||||
messages: Box::new([
|
||||
NodeGraphMessage::SetInputValue {
|
||||
node_id,
|
||||
input_index: IndividualCornerRadiiInput::INDEX,
|
||||
@@ -1340,7 +1340,7 @@ pub(crate) fn rectangle_properties(node_id: NodeId, context: &mut NodeProperties
|
||||
value: TaggedValue::F64Array4(individual_val),
|
||||
}
|
||||
.into(),
|
||||
]))
|
||||
]),
|
||||
})
|
||||
.on_commit(commit_value);
|
||||
let radio_input = RadioInput::new(vec![uniform, individual]).selected_index(Some(is_individual as u32)).widget_holder();
|
||||
@@ -1539,8 +1539,8 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
|
||||
widgets_first_row.push(
|
||||
ColorInput::default()
|
||||
.value(fill.clone().into())
|
||||
.on_update(move |x: &ColorInput| {
|
||||
Message::Batched(Box::new([
|
||||
.on_update(move |x: &ColorInput| Message::Batched {
|
||||
messages: Box::new([
|
||||
match &fill2 {
|
||||
Fill::None => NodeGraphMessage::SetInputValue {
|
||||
node_id,
|
||||
@@ -1567,7 +1567,7 @@ pub(crate) fn fill_properties(node_id: NodeId, context: &mut NodePropertiesConte
|
||||
value: TaggedValue::Fill(x.value.to_fill(fill2.as_gradient())),
|
||||
}
|
||||
.into(),
|
||||
]))
|
||||
]),
|
||||
})
|
||||
.on_commit(commit_value)
|
||||
.widget_holder(),
|
||||
|
||||
@@ -7,4 +7,4 @@ pub mod utility_types;
|
||||
#[doc(inline)]
|
||||
pub use overlays_message::{OverlaysMessage, OverlaysMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use overlays_message_handler::{OverlaysMessageData, OverlaysMessageHandler};
|
||||
pub use overlays_message_handler::{OverlaysMessageContext, OverlaysMessageHandler};
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::utility_types::{OverlayProvider, OverlaysVisibilitySettings};
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct OverlaysMessageData<'a> {
|
||||
pub struct OverlaysMessageContext<'a> {
|
||||
pub visibility_settings: OverlaysVisibilitySettings,
|
||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||
pub device_pixel_ratio: f64,
|
||||
@@ -18,9 +18,11 @@ pub struct OverlaysMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
|
||||
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, data: OverlaysMessageData) {
|
||||
let OverlaysMessageData { visibility_settings, ipp, .. } = data;
|
||||
impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMessageHandler {
|
||||
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, context: OverlaysMessageContext) {
|
||||
let OverlaysMessageContext { visibility_settings, ipp, .. } = context;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let device_pixel_ratio = context.device_pixel_ratio;
|
||||
|
||||
match message {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
@@ -30,8 +32,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
|
||||
use glam::{DAffine2, DVec2};
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
let device_pixel_ratio = data.device_pixel_ratio;
|
||||
|
||||
let canvas = match &self.canvas {
|
||||
Some(canvas) => canvas,
|
||||
None => {
|
||||
@@ -40,28 +40,28 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
|
||||
}
|
||||
};
|
||||
|
||||
let context = self.context.get_or_insert_with(|| {
|
||||
let context = canvas.get_context("2d").ok().flatten().expect("Failed to get canvas context");
|
||||
context.dyn_into().expect("Context should be a canvas 2d context")
|
||||
let canvas_context = self.context.get_or_insert_with(|| {
|
||||
let canvas_context = canvas.get_context("2d").ok().flatten().expect("Failed to get canvas context");
|
||||
canvas_context.dyn_into().expect("Context should be a canvas 2d context")
|
||||
});
|
||||
|
||||
let size = ipp.viewport_bounds.size().as_uvec2();
|
||||
|
||||
let [a, b, c, d, e, f] = DAffine2::from_scale(DVec2::splat(device_pixel_ratio)).to_cols_array();
|
||||
let _ = context.set_transform(a, b, c, d, e, f);
|
||||
context.clear_rect(0., 0., ipp.viewport_bounds.size().x, ipp.viewport_bounds.size().y);
|
||||
let _ = context.reset_transform();
|
||||
let _ = canvas_context.set_transform(a, b, c, d, e, f);
|
||||
canvas_context.clear_rect(0., 0., ipp.viewport_bounds.size().x, ipp.viewport_bounds.size().y);
|
||||
let _ = canvas_context.reset_transform();
|
||||
|
||||
if visibility_settings.all() {
|
||||
responses.add(DocumentMessage::GridOverlays(OverlayContext {
|
||||
render_context: context.clone(),
|
||||
render_context: canvas_context.clone(),
|
||||
size: size.as_dvec2(),
|
||||
device_pixel_ratio,
|
||||
visibility_settings: visibility_settings.clone(),
|
||||
}));
|
||||
for provider in &self.overlay_providers {
|
||||
responses.add(provider(OverlayContext {
|
||||
render_context: context.clone(),
|
||||
render_context: canvas_context.clone(),
|
||||
size: size.as_dvec2(),
|
||||
device_pixel_ratio,
|
||||
visibility_settings: visibility_settings.clone(),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
mod properties_panel_message;
|
||||
mod properties_panel_message_handler;
|
||||
|
||||
pub mod utility_types;
|
||||
pub mod properties_panel_message_handler;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use properties_panel_message::{PropertiesPanelMessage, PropertiesPanelMessageDiscriminant};
|
||||
|
||||
+21
-8
@@ -1,21 +1,34 @@
|
||||
use super::utility_types::PropertiesPanelMessageHandlerData;
|
||||
use graphene_std::uuid::NodeId;
|
||||
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions::NodePropertiesContext;
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
|
||||
use crate::messages::portfolio::utility_types::PersistentData;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::node_graph_executor::NodeGraphExecutor;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct PropertiesPanelMessageContext<'a> {
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub selection_network_path: &'a [NodeId],
|
||||
pub document_name: &'a str,
|
||||
pub executor: &'a mut NodeGraphExecutor,
|
||||
pub persistent_data: &'a PersistentData,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ExtractField)]
|
||||
pub struct PropertiesPanelMessageHandler {}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMessageHandlerData<'_>)> for PropertiesPanelMessageHandler {
|
||||
fn process_message(&mut self, message: PropertiesPanelMessage, responses: &mut VecDeque<Message>, (persistent_data, data): (&PersistentData, PropertiesPanelMessageHandlerData)) {
|
||||
let PropertiesPanelMessageHandlerData {
|
||||
impl MessageHandler<PropertiesPanelMessage, PropertiesPanelMessageContext<'_>> for PropertiesPanelMessageHandler {
|
||||
fn process_message(&mut self, message: PropertiesPanelMessage, responses: &mut VecDeque<Message>, context: PropertiesPanelMessageContext) {
|
||||
let PropertiesPanelMessageContext {
|
||||
network_interface,
|
||||
selection_network_path,
|
||||
document_name,
|
||||
executor,
|
||||
} = data;
|
||||
persistent_data,
|
||||
} = context;
|
||||
|
||||
match message {
|
||||
PropertiesPanelMessage::Clear => {
|
||||
@@ -25,7 +38,7 @@ impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMes
|
||||
});
|
||||
}
|
||||
PropertiesPanelMessage::Refresh => {
|
||||
let mut context = NodePropertiesContext {
|
||||
let mut node_properties_context = NodePropertiesContext {
|
||||
persistent_data,
|
||||
responses,
|
||||
network_interface,
|
||||
@@ -33,9 +46,9 @@ impl MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPanelMes
|
||||
document_name,
|
||||
executor,
|
||||
};
|
||||
let properties_sections = NodeGraphMessageHandler::collate_properties(&mut context);
|
||||
let properties_sections = NodeGraphMessageHandler::collate_properties(&mut node_properties_context);
|
||||
|
||||
context.responses.add(LayoutMessage::SendLayout {
|
||||
node_properties_context.responses.add(LayoutMessage::SendLayout {
|
||||
layout: Layout::WidgetLayout(WidgetLayout::new(properties_sections)),
|
||||
layout_target: LayoutTarget::PropertiesSections,
|
||||
});
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::NodeNetworkInterface;
|
||||
use crate::node_graph_executor::NodeGraphExecutor;
|
||||
use graph_craft::document::NodeId;
|
||||
|
||||
pub struct PropertiesPanelMessageHandlerData<'a> {
|
||||
pub network_interface: &'a mut NodeNetworkInterface,
|
||||
pub selection_network_path: &'a [NodeId],
|
||||
pub document_name: &'a str,
|
||||
pub executor: &'a mut NodeGraphExecutor,
|
||||
}
|
||||
@@ -23,7 +23,7 @@ pub struct MenuBarMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<MenuBarMessage, ()> for MenuBarMessageHandler {
|
||||
fn process_message(&mut self, message: MenuBarMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: MenuBarMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
MenuBarMessage::SendLayout => self.send_layout(responses, LayoutTarget::MenuBar),
|
||||
}
|
||||
|
||||
@@ -10,4 +10,4 @@ pub mod utility_types;
|
||||
#[doc(inline)]
|
||||
pub use portfolio_message::{PortfolioMessage, PortfolioMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use portfolio_message_handler::{PortfolioMessageData, PortfolioMessageHandler};
|
||||
pub use portfolio_message_handler::{PortfolioMessageContext, PortfolioMessageHandler};
|
||||
|
||||
@@ -19,6 +19,7 @@ pub enum PortfolioMessage {
|
||||
Spreadsheet(SpreadsheetMessage),
|
||||
|
||||
// Messages
|
||||
Init,
|
||||
DocumentPassMessage {
|
||||
document_id: DocumentId,
|
||||
message: DocumentMessage,
|
||||
|
||||
@@ -9,8 +9,9 @@ use crate::messages::debug::utility_types::MessageLoggingVerbosity;
|
||||
use crate::messages::dialog::simple_dialogs;
|
||||
use crate::messages::frontend::utility_types::FrontendDocumentDetails;
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::DocumentMessageData;
|
||||
use crate::messages::portfolio::document::DocumentMessageContext;
|
||||
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
|
||||
use crate::messages::portfolio::document::node_graph::document_node_definitions;
|
||||
use crate::messages::portfolio::document::utility_types::clipboards::{Clipboard, CopyBufferEntry, INTERNAL_CLIPBOARD_COUNT};
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::OutputConnector;
|
||||
use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
|
||||
@@ -26,7 +27,7 @@ use graphene_std::text::Font;
|
||||
use std::vec;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct PortfolioMessageData<'a> {
|
||||
pub struct PortfolioMessageContext<'a> {
|
||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||
pub preferences: &'a PreferencesMessageHandler,
|
||||
pub current_tool: &'a ToolType,
|
||||
@@ -54,9 +55,9 @@ pub struct PortfolioMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
|
||||
fn process_message(&mut self, message: PortfolioMessage, responses: &mut VecDeque<Message>, data: PortfolioMessageData) {
|
||||
let PortfolioMessageData {
|
||||
impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for PortfolioMessageHandler {
|
||||
fn process_message(&mut self, message: PortfolioMessage, responses: &mut VecDeque<Message>, context: PortfolioMessageContext) {
|
||||
let PortfolioMessageContext {
|
||||
ipp,
|
||||
preferences,
|
||||
current_tool,
|
||||
@@ -64,7 +65,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
||||
reset_node_definitions_on_open,
|
||||
timing_information,
|
||||
animation,
|
||||
} = data;
|
||||
} = context;
|
||||
|
||||
match message {
|
||||
// Sub-messages
|
||||
@@ -104,7 +105,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
||||
PortfolioMessage::Document(message) => {
|
||||
if let Some(document_id) = self.active_document_id {
|
||||
if let Some(document) = self.documents.get_mut(&document_id) {
|
||||
let document_inputs = DocumentMessageData {
|
||||
let document_inputs = DocumentMessageContext {
|
||||
document_id,
|
||||
ipp,
|
||||
persistent_data: &self.persistent_data,
|
||||
@@ -119,9 +120,26 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
||||
}
|
||||
|
||||
// Messages
|
||||
PortfolioMessage::Init => {
|
||||
// Load persistent data from the browser database
|
||||
responses.add(FrontendMessage::TriggerLoadFirstAutoSaveDocument);
|
||||
responses.add(FrontendMessage::TriggerLoadPreferences);
|
||||
|
||||
// Display the menu bar at the top of the window
|
||||
responses.add(MenuBarMessage::SendLayout);
|
||||
|
||||
// Send the information for tooltips and categories for each node/input.
|
||||
responses.add(FrontendMessage::SendUIMetadata {
|
||||
node_descriptions: document_node_definitions::collect_node_descriptions(),
|
||||
node_types: document_node_definitions::collect_node_types(),
|
||||
});
|
||||
|
||||
// Finish loading persistent data from the browser database
|
||||
responses.add(FrontendMessage::TriggerLoadRestAutoSaveDocuments);
|
||||
}
|
||||
PortfolioMessage::DocumentPassMessage { document_id, message } => {
|
||||
if let Some(document) = self.documents.get_mut(&document_id) {
|
||||
let document_inputs = DocumentMessageData {
|
||||
let document_inputs = DocumentMessageContext {
|
||||
document_id,
|
||||
ipp,
|
||||
persistent_data: &self.persistent_data,
|
||||
@@ -972,7 +990,9 @@ impl PortfolioMessageHandler {
|
||||
/text>"#
|
||||
// It's a mystery why the `/text>` tag above needs to be missing its `<`, but when it exists it prints the `<` character in the text. However this works with it removed.
|
||||
.to_string();
|
||||
responses.add(Message::EndBuffer(graphene_std::renderer::RenderMetadata::default()));
|
||||
responses.add(Message::EndBuffer {
|
||||
render_metadata: graphene_std::renderer::RenderMetadata::default(),
|
||||
});
|
||||
responses.add(FrontendMessage::UpdateDocumentArtwork { svg: error });
|
||||
}
|
||||
result
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct SpreadsheetMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<SpreadsheetMessage, ()> for SpreadsheetMessageHandler {
|
||||
fn process_message(&mut self, message: SpreadsheetMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: SpreadsheetMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
SpreadsheetMessage::ToggleOpen => {
|
||||
self.spreadsheet_view_open = !self.spreadsheet_view_open;
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Default for PreferencesMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<PreferencesMessage, ()> for PreferencesMessageHandler {
|
||||
fn process_message(&mut self, message: PreferencesMessage, responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: PreferencesMessage, responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
// Management messages
|
||||
PreferencesMessage::Load { preferences } => {
|
||||
|
||||
@@ -5,28 +5,28 @@ pub use crate::utility_types::{DebugMessageTree, MessageData};
|
||||
pub use crate::messages::animation::{AnimationMessage, AnimationMessageDiscriminant, AnimationMessageHandler};
|
||||
pub use crate::messages::broadcast::{BroadcastMessage, BroadcastMessageDiscriminant, BroadcastMessageHandler};
|
||||
pub use crate::messages::debug::{DebugMessage, DebugMessageDiscriminant, DebugMessageHandler};
|
||||
pub use crate::messages::dialog::export_dialog::{ExportDialogMessage, ExportDialogMessageData, ExportDialogMessageDiscriminant, ExportDialogMessageHandler};
|
||||
pub use crate::messages::dialog::export_dialog::{ExportDialogMessage, ExportDialogMessageContext, ExportDialogMessageDiscriminant, ExportDialogMessageHandler};
|
||||
pub use crate::messages::dialog::new_document_dialog::{NewDocumentDialogMessage, NewDocumentDialogMessageDiscriminant, NewDocumentDialogMessageHandler};
|
||||
pub use crate::messages::dialog::preferences_dialog::{PreferencesDialogMessage, PreferencesDialogMessageData, PreferencesDialogMessageDiscriminant, PreferencesDialogMessageHandler};
|
||||
pub use crate::messages::dialog::{DialogMessage, DialogMessageData, DialogMessageDiscriminant, DialogMessageHandler};
|
||||
pub use crate::messages::dialog::preferences_dialog::{PreferencesDialogMessage, PreferencesDialogMessageContext, PreferencesDialogMessageDiscriminant, PreferencesDialogMessageHandler};
|
||||
pub use crate::messages::dialog::{DialogMessage, DialogMessageContext, DialogMessageDiscriminant, DialogMessageHandler};
|
||||
pub use crate::messages::frontend::{FrontendMessage, FrontendMessageDiscriminant};
|
||||
pub use crate::messages::globals::{GlobalsMessage, GlobalsMessageDiscriminant, GlobalsMessageHandler};
|
||||
pub use crate::messages::input_mapper::key_mapping::{KeyMappingMessage, KeyMappingMessageData, KeyMappingMessageDiscriminant, KeyMappingMessageHandler};
|
||||
pub use crate::messages::input_mapper::{InputMapperMessage, InputMapperMessageData, InputMapperMessageDiscriminant, InputMapperMessageHandler};
|
||||
pub use crate::messages::input_preprocessor::{InputPreprocessorMessage, InputPreprocessorMessageData, InputPreprocessorMessageDiscriminant, InputPreprocessorMessageHandler};
|
||||
pub use crate::messages::input_mapper::key_mapping::{KeyMappingMessage, KeyMappingMessageContext, KeyMappingMessageDiscriminant, KeyMappingMessageHandler};
|
||||
pub use crate::messages::input_mapper::{InputMapperMessage, InputMapperMessageContext, InputMapperMessageDiscriminant, InputMapperMessageHandler};
|
||||
pub use crate::messages::input_preprocessor::{InputPreprocessorMessage, InputPreprocessorMessageContext, InputPreprocessorMessageDiscriminant, InputPreprocessorMessageHandler};
|
||||
pub use crate::messages::layout::{LayoutMessage, LayoutMessageDiscriminant, LayoutMessageHandler};
|
||||
pub use crate::messages::portfolio::document::graph_operation::{GraphOperationMessage, GraphOperationMessageData, GraphOperationMessageDiscriminant, GraphOperationMessageHandler};
|
||||
pub use crate::messages::portfolio::document::navigation::{NavigationMessage, NavigationMessageData, NavigationMessageDiscriminant, NavigationMessageHandler};
|
||||
pub use crate::messages::portfolio::document::graph_operation::{GraphOperationMessage, GraphOperationMessageContext, GraphOperationMessageDiscriminant, GraphOperationMessageHandler};
|
||||
pub use crate::messages::portfolio::document::navigation::{NavigationMessage, NavigationMessageContext, NavigationMessageDiscriminant, NavigationMessageHandler};
|
||||
pub use crate::messages::portfolio::document::node_graph::{NodeGraphMessage, NodeGraphMessageDiscriminant, NodeGraphMessageHandler};
|
||||
pub use crate::messages::portfolio::document::overlays::{OverlaysMessage, OverlaysMessageData, OverlaysMessageDiscriminant, OverlaysMessageHandler};
|
||||
pub use crate::messages::portfolio::document::overlays::{OverlaysMessage, OverlaysMessageContext, OverlaysMessageDiscriminant, OverlaysMessageHandler};
|
||||
pub use crate::messages::portfolio::document::properties_panel::{PropertiesPanelMessage, PropertiesPanelMessageDiscriminant, PropertiesPanelMessageHandler};
|
||||
pub use crate::messages::portfolio::document::{DocumentMessage, DocumentMessageData, DocumentMessageDiscriminant, DocumentMessageHandler};
|
||||
pub use crate::messages::portfolio::document::{DocumentMessage, DocumentMessageContext, DocumentMessageDiscriminant, DocumentMessageHandler};
|
||||
pub use crate::messages::portfolio::menu_bar::{MenuBarMessage, MenuBarMessageDiscriminant, MenuBarMessageHandler};
|
||||
pub use crate::messages::portfolio::spreadsheet::{SpreadsheetMessage, SpreadsheetMessageDiscriminant};
|
||||
pub use crate::messages::portfolio::{PortfolioMessage, PortfolioMessageData, PortfolioMessageDiscriminant, PortfolioMessageHandler};
|
||||
pub use crate::messages::portfolio::{PortfolioMessage, PortfolioMessageContext, PortfolioMessageDiscriminant, PortfolioMessageHandler};
|
||||
pub use crate::messages::preferences::{PreferencesMessage, PreferencesMessageDiscriminant, PreferencesMessageHandler};
|
||||
pub use crate::messages::tool::transform_layer::{TransformLayerMessage, TransformLayerMessageDiscriminant, TransformLayerMessageHandler};
|
||||
pub use crate::messages::tool::{ToolMessage, ToolMessageData, ToolMessageDiscriminant, ToolMessageHandler};
|
||||
pub use crate::messages::tool::{ToolMessage, ToolMessageContext, ToolMessageDiscriminant, ToolMessageHandler};
|
||||
pub use crate::messages::workspace::{WorkspaceMessage, WorkspaceMessageDiscriminant, WorkspaceMessageHandler};
|
||||
|
||||
// Message, MessageDiscriminant
|
||||
|
||||
@@ -9,6 +9,6 @@ pub mod utility_types;
|
||||
#[doc(inline)]
|
||||
pub use tool_message::{ToolMessage, ToolMessageDiscriminant};
|
||||
#[doc(inline)]
|
||||
pub use tool_message_handler::{ToolMessageData, ToolMessageHandler};
|
||||
pub use tool_message_handler::{ToolMessageContext, ToolMessageHandler};
|
||||
#[doc(inline)]
|
||||
pub use transform_layer::{TransformLayerMessage, TransformLayerMessageDiscriminant};
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
use super::common_functionality::shape_editor::ShapeState;
|
||||
use super::common_functionality::shapes::shape_utility::ShapeType::{self, Ellipse, Line, Rectangle};
|
||||
use super::utility_types::{ToolActionHandlerData, ToolFsmState, tool_message_to_tool_type};
|
||||
use super::utility_types::{ToolActionMessageContext, ToolFsmState, tool_message_to_tool_type};
|
||||
use crate::application::generate_uuid;
|
||||
use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayProvider;
|
||||
use crate::messages::portfolio::utility_types::PersistentData;
|
||||
use crate::messages::prelude::*;
|
||||
use crate::messages::tool::transform_layer::transform_layer_message_handler::TransformLayerMessageContext;
|
||||
use crate::messages::tool::utility_types::ToolType;
|
||||
use crate::node_graph_executor::NodeGraphExecutor;
|
||||
use graphene_std::raster::color::Color;
|
||||
|
||||
const ARTBOARD_OVERLAY_PROVIDER: OverlayProvider = |context| DocumentMessage::DrawArtboardOverlays(context).into();
|
||||
const ARTBOARD_OVERLAY_PROVIDER: OverlayProvider = |overlay_context| DocumentMessage::DrawArtboardOverlays(overlay_context).into();
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct ToolMessageData<'a> {
|
||||
pub struct ToolMessageContext<'a> {
|
||||
pub document_id: DocumentId,
|
||||
pub document: &'a mut DocumentMessageHandler,
|
||||
pub input: &'a InputPreprocessorMessageHandler,
|
||||
@@ -31,23 +32,30 @@ pub struct ToolMessageHandler {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, data: ToolMessageData) {
|
||||
let ToolMessageData {
|
||||
impl MessageHandler<ToolMessage, ToolMessageContext<'_>> for ToolMessageHandler {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: ToolMessageContext) {
|
||||
let ToolMessageContext {
|
||||
document_id,
|
||||
document,
|
||||
input,
|
||||
persistent_data,
|
||||
node_graph,
|
||||
preferences,
|
||||
} = data;
|
||||
} = context;
|
||||
let font_cache = &persistent_data.font_cache;
|
||||
|
||||
match message {
|
||||
// Messages
|
||||
ToolMessage::TransformLayer(message) => self
|
||||
.transform_layer_handler
|
||||
.process_message(message, responses, (document, input, &self.tool_state.tool_data, &mut self.shape_editor)),
|
||||
ToolMessage::TransformLayer(message) => self.transform_layer_handler.process_message(
|
||||
message,
|
||||
responses,
|
||||
TransformLayerMessageContext {
|
||||
document,
|
||||
input,
|
||||
tool_data: &self.tool_state.tool_data,
|
||||
shape_editor: &mut self.shape_editor,
|
||||
},
|
||||
),
|
||||
|
||||
ToolMessage::ActivateToolSelect => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Select }),
|
||||
ToolMessage::ActivateToolArtboard => responses.add_front(ToolMessage::ActivateTool { tool_type: ToolType::Artboard }),
|
||||
@@ -106,7 +114,7 @@ impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
|
||||
// Send the old and new tools a transition to their FSM Abort states
|
||||
let mut send_abort_to_tool = |old_tool: ToolType, new_tool: ToolType, update_hints_and_cursor: bool| {
|
||||
if let Some(tool) = tool_data.tools.get_mut(&new_tool) {
|
||||
let mut data = ToolActionHandlerData {
|
||||
let mut data = ToolActionMessageContext {
|
||||
document,
|
||||
document_id,
|
||||
global_tool_data: &self.tool_state.document_tool_data,
|
||||
@@ -206,7 +214,7 @@ impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
|
||||
// Notify the frontend about the initial working colors
|
||||
document_data.update_working_colors(responses);
|
||||
|
||||
let mut data = ToolActionHandlerData {
|
||||
let mut data = ToolActionMessageContext {
|
||||
document,
|
||||
document_id,
|
||||
global_tool_data: &self.tool_state.document_tool_data,
|
||||
@@ -302,7 +310,7 @@ impl MessageHandler<ToolMessage, ToolMessageData<'_>> for ToolMessageHandler {
|
||||
let graph_view_overlay_open = document.graph_view_overlay_open();
|
||||
|
||||
if tool_type == tool_data.active_tool_type {
|
||||
let mut data = ToolActionHandlerData {
|
||||
let mut data = ToolActionMessageContext {
|
||||
document,
|
||||
document_id,
|
||||
global_tool_data: &self.tool_state.document_tool_data,
|
||||
|
||||
@@ -49,9 +49,9 @@ impl ToolMetadata for ArtboardTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for ArtboardTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
self.fsm_state.process_event(message, &mut self.data, tool_data, &(), responses, false);
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for ArtboardTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
self.fsm_state.process_event(message, &mut self.data, context, &(), responses, false);
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
@@ -218,8 +218,8 @@ impl Fsm for ArtboardToolFsmState {
|
||||
type ToolData = ArtboardToolData;
|
||||
type ToolOptions = ();
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, _tool_options: &(), responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData { document, input, .. } = tool_action_data;
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionMessageContext, _tool_options: &(), responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionMessageContext { document, input, .. } = tool_action_data;
|
||||
|
||||
let hovered = ArtboardToolData::hovered_artboard(document, input).is_some();
|
||||
|
||||
|
||||
@@ -186,10 +186,10 @@ impl LayoutHolder for BrushTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for BrushTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for BrushTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Brush(BrushToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.data, context, &self.options, responses, true);
|
||||
return;
|
||||
};
|
||||
match action {
|
||||
@@ -306,8 +306,15 @@ impl Fsm for BrushToolFsmState {
|
||||
type ToolData = BrushToolData;
|
||||
type ToolOptions = BrushOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
tool_action_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document, global_tool_data, input, ..
|
||||
} = tool_action_data;
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@ impl LayoutHolder for EyedropperTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for EyedropperTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
self.fsm_state.process_event(message, &mut self.data, tool_data, &(), responses, true);
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for EyedropperTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
self.fsm_state.process_event(message, &mut self.data, context, &(), responses, true);
|
||||
}
|
||||
|
||||
advertise_actions!(EyedropperToolMessageDiscriminant;
|
||||
@@ -80,8 +80,8 @@ impl Fsm for EyedropperToolFsmState {
|
||||
type ToolData = EyedropperToolData;
|
||||
type ToolOptions = ();
|
||||
|
||||
fn transition(self, event: ToolMessage, _tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, _tool_options: &(), responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData { global_tool_data, input, .. } = tool_action_data;
|
||||
fn transition(self, event: ToolMessage, _tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionMessageContext, _tool_options: &(), responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionMessageContext { global_tool_data, input, .. } = tool_action_data;
|
||||
|
||||
let ToolMessage::Eyedropper(event) = event else { return self };
|
||||
match (self, event) {
|
||||
|
||||
@@ -42,9 +42,9 @@ impl LayoutHolder for FillTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for FillTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
self.fsm_state.process_event(message, &mut (), tool_data, &(), responses, true);
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for FillTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
self.fsm_state.process_event(message, &mut (), context, &(), responses, true);
|
||||
}
|
||||
fn actions(&self) -> ActionList {
|
||||
match self.fsm_state {
|
||||
@@ -85,8 +85,15 @@ impl Fsm for FillToolFsmState {
|
||||
type ToolData = ();
|
||||
type ToolOptions = ();
|
||||
|
||||
fn transition(self, event: ToolMessage, _tool_data: &mut Self::ToolData, handler_data: &mut ToolActionHandlerData, _tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
_tool_data: &mut Self::ToolData,
|
||||
handler_data: &mut ToolActionMessageContext,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document, global_tool_data, input, ..
|
||||
} = handler_data;
|
||||
|
||||
|
||||
@@ -117,10 +117,10 @@ impl LayoutHolder for FreehandTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for FreehandTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for FreehandTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Freehand(FreehandToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.data, context, &self.options, responses, true);
|
||||
return;
|
||||
};
|
||||
match action {
|
||||
@@ -184,8 +184,15 @@ impl Fsm for FreehandToolFsmState {
|
||||
type ToolData = FreehandToolData;
|
||||
type ToolOptions = FreehandOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
tool_action_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document,
|
||||
global_tool_data,
|
||||
input,
|
||||
|
||||
@@ -54,10 +54,10 @@ impl ToolMetadata for GradientTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for GradientTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for GradientTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Gradient(GradientToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.data, tool_data, &self.options, responses, false);
|
||||
self.fsm_state.process_event(message, &mut self.data, context, &self.options, responses, false);
|
||||
return;
|
||||
};
|
||||
match action {
|
||||
@@ -67,7 +67,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for Gradien
|
||||
if let Some(selected_gradient) = &mut self.data.selected_gradient {
|
||||
// Check if the current layer is a raster layer
|
||||
if let Some(layer) = selected_gradient.layer {
|
||||
if NodeGraphLayer::is_raster_layer(layer, &mut tool_data.document.network_interface) {
|
||||
if NodeGraphLayer::is_raster_layer(layer, &mut context.document.network_interface) {
|
||||
return; // Don't proceed if it's a raster layer
|
||||
}
|
||||
selected_gradient.gradient.gradient_type = gradient_type;
|
||||
@@ -243,8 +243,15 @@ impl Fsm for GradientToolFsmState {
|
||||
type ToolData = GradientToolData;
|
||||
type ToolOptions = GradientOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
tool_action_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document, global_tool_data, input, ..
|
||||
} = tool_action_data;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pub mod tool_prelude {
|
||||
pub use crate::messages::input_mapper::utility_types::input_keyboard::{Key, MouseMotion};
|
||||
pub use crate::messages::layout::utility_types::widget_prelude::*;
|
||||
pub use crate::messages::prelude::*;
|
||||
pub use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, ToolActionHandlerData, ToolMetadata, ToolTransition, ToolType};
|
||||
pub use crate::messages::tool::utility_types::{EventToMessageMap, Fsm, ToolActionMessageContext, ToolMetadata, ToolTransition, ToolType};
|
||||
pub use crate::messages::tool::utility_types::{HintData, HintGroup, HintInfo};
|
||||
pub use glam::{DAffine2, DVec2};
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ impl LayoutHolder for NavigateTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for NavigateTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &(), responses, true);
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for NavigateTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &(), responses, true);
|
||||
}
|
||||
|
||||
fn actions(&self) -> ActionList {
|
||||
@@ -92,7 +92,7 @@ impl Fsm for NavigateToolFsmState {
|
||||
self,
|
||||
message: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
ToolActionHandlerData { input, .. }: &mut ToolActionHandlerData,
|
||||
ToolActionMessageContext { input, .. }: &mut ToolActionMessageContext,
|
||||
_tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
|
||||
@@ -306,8 +306,8 @@ impl LayoutHolder for PathTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for PathTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let updating_point = message == ToolMessage::Path(PathToolMessage::SelectedPointUpdated);
|
||||
|
||||
match message {
|
||||
@@ -350,20 +350,20 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PathToo
|
||||
},
|
||||
ToolMessage::Path(PathToolMessage::ClosePath) => {
|
||||
responses.add(DocumentMessage::AddTransaction);
|
||||
tool_data.shape_editor.close_selected_path(tool_data.document, responses);
|
||||
context.shape_editor.close_selected_path(context.document, responses);
|
||||
responses.add(DocumentMessage::EndTransaction);
|
||||
responses.add(OverlaysMessage::Draw);
|
||||
}
|
||||
ToolMessage::Path(PathToolMessage::SwapSelectedHandles) => {
|
||||
if tool_data.shape_editor.handle_with_pair_selected(&tool_data.document.network_interface) {
|
||||
tool_data.shape_editor.alternate_selected_handles(&tool_data.document.network_interface);
|
||||
if context.shape_editor.handle_with_pair_selected(&context.document.network_interface) {
|
||||
context.shape_editor.alternate_selected_handles(&context.document.network_interface);
|
||||
responses.add(PathToolMessage::SelectedPointUpdated);
|
||||
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::None });
|
||||
responses.add(OverlaysMessage::Draw);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &self.options, responses, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1387,8 +1387,15 @@ impl Fsm for PathToolFsmState {
|
||||
type ToolData = PathToolData;
|
||||
type ToolOptions = PathToolOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData { document, input, shape_editor, .. } = tool_action_data;
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
tool_action_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext { document, input, shape_editor, .. } = tool_action_data;
|
||||
|
||||
update_dynamic_hints(self, responses, shape_editor, document, tool_data, tool_options);
|
||||
|
||||
|
||||
@@ -187,10 +187,10 @@ impl LayoutHolder for PenTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for PenTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for PenTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Pen(PenToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &self.options, responses, true);
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -1403,8 +1403,15 @@ impl Fsm for PenToolFsmState {
|
||||
type ToolData = PenToolData;
|
||||
type ToolOptions = PenOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
tool_action_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document,
|
||||
global_tool_data,
|
||||
input,
|
||||
|
||||
@@ -273,8 +273,8 @@ impl LayoutHolder for SelectTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SelectTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for SelectTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let mut redraw_reference_pivot = false;
|
||||
|
||||
if let ToolMessage::Select(SelectToolMessage::SelectOptions(ref option_update)) = message {
|
||||
@@ -309,7 +309,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SelectT
|
||||
}
|
||||
}
|
||||
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &(), responses, false);
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &(), responses, false);
|
||||
|
||||
if self.tool_data.pivot_gizmo.pivot.should_refresh_pivot_position() || self.tool_data.selected_layers_changed || redraw_reference_pivot {
|
||||
// Send the layout containing the updated pivot position (a bit ugly to do it here not in the fsm but that doesn't have SelectTool)
|
||||
@@ -584,8 +584,8 @@ impl Fsm for SelectToolFsmState {
|
||||
type ToolData = SelectToolData;
|
||||
type ToolOptions = ();
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, _tool_options: &(), responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData { document, input, font_cache, .. } = tool_action_data;
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionMessageContext, _tool_options: &(), responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionMessageContext { document, input, font_cache, .. } = tool_action_data;
|
||||
|
||||
let ToolMessage::Select(event) = event else { return self };
|
||||
match (self, event) {
|
||||
|
||||
@@ -163,10 +163,10 @@ impl LayoutHolder for ShapeTool {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for ShapeTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for ShapeTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Shape(ShapeToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &self.options, responses, true);
|
||||
return;
|
||||
};
|
||||
match action {
|
||||
@@ -337,14 +337,14 @@ impl Fsm for ShapeToolFsmState {
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
ToolActionHandlerData {
|
||||
ToolActionMessageContext {
|
||||
document,
|
||||
global_tool_data,
|
||||
input,
|
||||
preferences,
|
||||
shape_editor,
|
||||
..
|
||||
}: &mut ToolActionHandlerData,
|
||||
}: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
|
||||
@@ -124,10 +124,10 @@ impl LayoutHolder for SplineTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for SplineTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for SplineTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Spline(SplineToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &self.options, responses, true);
|
||||
return;
|
||||
};
|
||||
match action {
|
||||
@@ -242,8 +242,15 @@ impl Fsm for SplineToolFsmState {
|
||||
type ToolData = SplineToolData;
|
||||
type ToolOptions = SplineOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, tool_action_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
tool_action_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document,
|
||||
global_tool_data,
|
||||
input,
|
||||
|
||||
@@ -171,10 +171,10 @@ impl LayoutHolder for TextTool {
|
||||
}
|
||||
|
||||
#[message_handler_data]
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionHandlerData<'a>> for TextTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, tool_data: &mut ToolActionHandlerData<'a>) {
|
||||
impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for TextTool {
|
||||
fn process_message(&mut self, message: ToolMessage, responses: &mut VecDeque<Message>, context: &mut ToolActionMessageContext<'a>) {
|
||||
let ToolMessage::Text(TextToolMessage::UpdateOptions(action)) = message else {
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, tool_data, &self.options, responses, true);
|
||||
self.fsm_state.process_event(message, &mut self.tool_data, context, &self.options, responses, true);
|
||||
return;
|
||||
};
|
||||
match action {
|
||||
@@ -449,8 +449,15 @@ impl Fsm for TextToolFsmState {
|
||||
type ToolData = TextToolData;
|
||||
type ToolOptions = TextOptions;
|
||||
|
||||
fn transition(self, event: ToolMessage, tool_data: &mut Self::ToolData, transition_data: &mut ToolActionHandlerData, tool_options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self {
|
||||
let ToolActionHandlerData {
|
||||
fn transition(
|
||||
self,
|
||||
event: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
transition_data: &mut ToolActionMessageContext,
|
||||
tool_options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
) -> Self {
|
||||
let ToolActionMessageContext {
|
||||
document,
|
||||
global_tool_data,
|
||||
input,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Handles Blender inspired layer transformation with the <kbd>G</kbd> <kbd>R</kbd> and <kbd>S</kbd> keys for grabbing, rotating and scaling.
|
||||
//! Handles Blender inspired layer transformation with the <kbd>G</kbd>, <kbd>R</kbd>, and <kbd>S</kbd> keys for grabbing, rotating, and scaling.
|
||||
//!
|
||||
//! Other features include
|
||||
//! - Typing a number for a precise transformation
|
||||
@@ -7,7 +7,7 @@
|
||||
//! - Escape or right click to cancel
|
||||
|
||||
mod transform_layer_message;
|
||||
mod transform_layer_message_handler;
|
||||
pub mod transform_layer_message_handler;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use transform_layer_message::{TransformLayerMessage, TransformLayerMessageDiscriminant};
|
||||
|
||||
@@ -21,6 +21,14 @@ const TRANSFORM_GRS_OVERLAY_PROVIDER: OverlayProvider = |context| TransformLayer
|
||||
const SLOW_KEY: Key = Key::Shift;
|
||||
const INCREMENTS_KEY: Key = Key::Control;
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct TransformLayerMessageContext<'a> {
|
||||
pub document: &'a DocumentMessageHandler,
|
||||
pub input: &'a InputPreprocessorMessageHandler,
|
||||
pub tool_data: &'a ToolData,
|
||||
pub shape_editor: &'a mut ShapeState,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, ExtractField)]
|
||||
pub struct TransformLayerMessageHandler {
|
||||
pub transform_operation: TransformOperation,
|
||||
@@ -55,148 +63,15 @@ pub struct TransformLayerMessageHandler {
|
||||
grs_pen_handle: bool,
|
||||
}
|
||||
|
||||
impl TransformLayerMessageHandler {
|
||||
pub fn is_transforming(&self) -> bool {
|
||||
self.transform_operation != TransformOperation::None
|
||||
}
|
||||
impl MessageHandler<TransformLayerMessage, TransformLayerMessageContext<'_>> for TransformLayerMessageHandler {
|
||||
fn process_message(&mut self, message: TransformLayerMessage, responses: &mut VecDeque<Message>, context: TransformLayerMessageContext) {
|
||||
let TransformLayerMessageContext {
|
||||
document,
|
||||
input,
|
||||
tool_data,
|
||||
shape_editor,
|
||||
} = context;
|
||||
|
||||
pub fn hints(&self, responses: &mut VecDeque<Message>) {
|
||||
self.transform_operation.hints(responses, self.local);
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_pivot(
|
||||
document: &DocumentMessageHandler,
|
||||
selected_points: &Vec<&ManipulatorPointId>,
|
||||
vector_data: &VectorData,
|
||||
viewspace: DAffine2,
|
||||
get_location: impl Fn(&ManipulatorPointId) -> Option<DVec2>,
|
||||
gizmo: &mut PivotGizmo,
|
||||
) -> (Option<(DVec2, DVec2)>, Option<[DVec2; 2]>) {
|
||||
let average_position = || {
|
||||
let mut point_count = 0_usize;
|
||||
selected_points.iter().filter_map(|p| get_location(p)).inspect(|_| point_count += 1).sum::<DVec2>() / point_count as f64
|
||||
};
|
||||
let bounds = selected_points.iter().filter_map(|p| get_location(p)).fold(None, |acc: Option<[DVec2; 2]>, point| {
|
||||
if let Some([mut min, mut max]) = acc {
|
||||
min.x = min.x.min(point.x);
|
||||
min.y = min.y.min(point.y);
|
||||
max.x = max.x.max(point.x);
|
||||
max.y = max.y.max(point.y);
|
||||
Some([min, max])
|
||||
} else {
|
||||
Some([point, point])
|
||||
}
|
||||
});
|
||||
gizmo.pivot.recalculate_pivot_for_layer(document, bounds);
|
||||
let position = || {
|
||||
(if !gizmo.state.disabled {
|
||||
match gizmo.state.gizmo_type {
|
||||
PivotGizmoType::Average => None,
|
||||
PivotGizmoType::Active => gizmo.point.and_then(|p| get_location(&p)),
|
||||
PivotGizmoType::Pivot => gizmo.pivot.pivot,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.unwrap_or_else(average_position)
|
||||
};
|
||||
let [point] = selected_points.as_slice() else {
|
||||
// Handle the case where there are multiple points
|
||||
let position = position();
|
||||
return (Some((position, position)), bounds);
|
||||
};
|
||||
|
||||
match point {
|
||||
ManipulatorPointId::PrimaryHandle(_) | ManipulatorPointId::EndHandle(_) => {
|
||||
// Get the anchor position and transform it to the pivot
|
||||
let (Some(pivot_position), Some(position)) = (
|
||||
point.get_anchor_position(vector_data).map(|anchor_position| viewspace.transform_point2(anchor_position)),
|
||||
point.get_position(vector_data),
|
||||
) else {
|
||||
return (None, None);
|
||||
};
|
||||
let target = viewspace.transform_point2(position);
|
||||
(Some((pivot_position, target)), None)
|
||||
}
|
||||
_ => {
|
||||
// Calculate the average position of all selected points
|
||||
let position = position();
|
||||
(Some((position, position)), bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn project_edge_to_quad(edge: DVec2, quad: &Quad, local: bool, axis_constraint: Axis) -> DVec2 {
|
||||
match axis_constraint {
|
||||
Axis::X => {
|
||||
if local {
|
||||
edge.project_onto(quad.top_right() - quad.top_left())
|
||||
} else {
|
||||
edge.with_y(0.)
|
||||
}
|
||||
}
|
||||
Axis::Y => {
|
||||
if local {
|
||||
edge.project_onto(quad.bottom_left() - quad.top_left())
|
||||
} else {
|
||||
edge.with_x(0.)
|
||||
}
|
||||
}
|
||||
_ => edge,
|
||||
}
|
||||
}
|
||||
|
||||
fn update_colinear_handles(selected_layers: &[LayerNodeIdentifier], document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) {
|
||||
for &layer in selected_layers {
|
||||
let Some(vector_data) = document.network_interface.compute_modified_vector(layer) else { continue };
|
||||
|
||||
for [handle1, handle2] in &vector_data.colinear_manipulators {
|
||||
let manipulator1 = handle1.to_manipulator_point();
|
||||
let manipulator2 = handle2.to_manipulator_point();
|
||||
|
||||
let Some(anchor) = manipulator1.get_anchor_position(&vector_data) else { continue };
|
||||
let Some(pos1) = manipulator1.get_position(&vector_data).map(|pos| pos - anchor) else { continue };
|
||||
let Some(pos2) = manipulator2.get_position(&vector_data).map(|pos| pos - anchor) else { continue };
|
||||
|
||||
let angle = pos1.angle_to(pos2);
|
||||
|
||||
// Check if handles are not colinear (not approximately equal to +/- PI)
|
||||
if (angle - PI).abs() > 1e-6 && (angle + PI).abs() > 1e-6 {
|
||||
let modification_type = VectorModificationType::SetG1Continuous {
|
||||
handles: [*handle1, *handle2],
|
||||
enabled: false,
|
||||
};
|
||||
|
||||
responses.add(GraphOperationMessage::Vector { layer, modification_type });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type TransformData<'a> = (&'a DocumentMessageHandler, &'a InputPreprocessorMessageHandler, &'a ToolData, &'a mut ShapeState);
|
||||
|
||||
pub fn custom_data() -> MessageData {
|
||||
MessageData::new(
|
||||
String::from("TransformData<'a>"),
|
||||
// TODO: When <https://github.com/dtolnay/proc-macro2/issues/503> is resolved and released,
|
||||
// TODO: use <https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.line> to get
|
||||
// TODO: the line number instead of hardcoding it to the magic number on the following lines
|
||||
// TODO: which points to the line of the `type TransformData<'a> = ...` definition above.
|
||||
// TODO: Also, utilize the line number in the actual output, since it is currently unused.
|
||||
vec![
|
||||
(String::from("&'a DocumentMessageHandler"), 177),
|
||||
(String::from("&'a InputPreprocessorMessageHandler"), 177),
|
||||
(String::from("&'a ToolData"), 177),
|
||||
(String::from("&'a mut ShapeState"), 177),
|
||||
],
|
||||
file!(),
|
||||
)
|
||||
}
|
||||
|
||||
#[message_handler_data(CustomData)]
|
||||
impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayerMessageHandler {
|
||||
fn process_message(&mut self, message: TransformLayerMessage, responses: &mut VecDeque<Message>, (document, input, tool_data, shape_editor): TransformData) {
|
||||
let using_path_tool = tool_data.active_tool_type == ToolType::Path;
|
||||
let using_select_tool = tool_data.active_tool_type == ToolType::Select;
|
||||
let using_pen_tool = tool_data.active_tool_type == ToolType::Pen;
|
||||
@@ -774,6 +649,125 @@ impl MessageHandler<TransformLayerMessage, TransformData<'_>> for TransformLayer
|
||||
}
|
||||
}
|
||||
|
||||
impl TransformLayerMessageHandler {
|
||||
pub fn is_transforming(&self) -> bool {
|
||||
self.transform_operation != TransformOperation::None
|
||||
}
|
||||
|
||||
pub fn hints(&self, responses: &mut VecDeque<Message>) {
|
||||
self.transform_operation.hints(responses, self.local);
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_pivot(
|
||||
document: &DocumentMessageHandler,
|
||||
selected_points: &Vec<&ManipulatorPointId>,
|
||||
vector_data: &VectorData,
|
||||
viewspace: DAffine2,
|
||||
get_location: impl Fn(&ManipulatorPointId) -> Option<DVec2>,
|
||||
gizmo: &mut PivotGizmo,
|
||||
) -> (Option<(DVec2, DVec2)>, Option<[DVec2; 2]>) {
|
||||
let average_position = || {
|
||||
let mut point_count = 0_usize;
|
||||
selected_points.iter().filter_map(|p| get_location(p)).inspect(|_| point_count += 1).sum::<DVec2>() / point_count as f64
|
||||
};
|
||||
let bounds = selected_points.iter().filter_map(|p| get_location(p)).fold(None, |acc: Option<[DVec2; 2]>, point| {
|
||||
if let Some([mut min, mut max]) = acc {
|
||||
min.x = min.x.min(point.x);
|
||||
min.y = min.y.min(point.y);
|
||||
max.x = max.x.max(point.x);
|
||||
max.y = max.y.max(point.y);
|
||||
Some([min, max])
|
||||
} else {
|
||||
Some([point, point])
|
||||
}
|
||||
});
|
||||
gizmo.pivot.recalculate_pivot_for_layer(document, bounds);
|
||||
let position = || {
|
||||
(if !gizmo.state.disabled {
|
||||
match gizmo.state.gizmo_type {
|
||||
PivotGizmoType::Average => None,
|
||||
PivotGizmoType::Active => gizmo.point.and_then(|p| get_location(&p)),
|
||||
PivotGizmoType::Pivot => gizmo.pivot.pivot,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
})
|
||||
.unwrap_or_else(average_position)
|
||||
};
|
||||
let [point] = selected_points.as_slice() else {
|
||||
// Handle the case where there are multiple points
|
||||
let position = position();
|
||||
return (Some((position, position)), bounds);
|
||||
};
|
||||
|
||||
match point {
|
||||
ManipulatorPointId::PrimaryHandle(_) | ManipulatorPointId::EndHandle(_) => {
|
||||
// Get the anchor position and transform it to the pivot
|
||||
let (Some(pivot_position), Some(position)) = (
|
||||
point.get_anchor_position(vector_data).map(|anchor_position| viewspace.transform_point2(anchor_position)),
|
||||
point.get_position(vector_data),
|
||||
) else {
|
||||
return (None, None);
|
||||
};
|
||||
let target = viewspace.transform_point2(position);
|
||||
(Some((pivot_position, target)), None)
|
||||
}
|
||||
_ => {
|
||||
// Calculate the average position of all selected points
|
||||
let position = position();
|
||||
(Some((position, position)), bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn project_edge_to_quad(edge: DVec2, quad: &Quad, local: bool, axis_constraint: Axis) -> DVec2 {
|
||||
match axis_constraint {
|
||||
Axis::X => {
|
||||
if local {
|
||||
edge.project_onto(quad.top_right() - quad.top_left())
|
||||
} else {
|
||||
edge.with_y(0.)
|
||||
}
|
||||
}
|
||||
Axis::Y => {
|
||||
if local {
|
||||
edge.project_onto(quad.bottom_left() - quad.top_left())
|
||||
} else {
|
||||
edge.with_x(0.)
|
||||
}
|
||||
}
|
||||
_ => edge,
|
||||
}
|
||||
}
|
||||
|
||||
fn update_colinear_handles(selected_layers: &[LayerNodeIdentifier], document: &DocumentMessageHandler, responses: &mut VecDeque<Message>) {
|
||||
for &layer in selected_layers {
|
||||
let Some(vector_data) = document.network_interface.compute_modified_vector(layer) else { continue };
|
||||
|
||||
for [handle1, handle2] in &vector_data.colinear_manipulators {
|
||||
let manipulator1 = handle1.to_manipulator_point();
|
||||
let manipulator2 = handle2.to_manipulator_point();
|
||||
|
||||
let Some(anchor) = manipulator1.get_anchor_position(&vector_data) else { continue };
|
||||
let Some(pos1) = manipulator1.get_position(&vector_data).map(|pos| pos - anchor) else { continue };
|
||||
let Some(pos2) = manipulator2.get_position(&vector_data).map(|pos| pos - anchor) else { continue };
|
||||
|
||||
let angle = pos1.angle_to(pos2);
|
||||
|
||||
// Check if handles are not colinear (not approximately equal to +/- PI)
|
||||
if (angle - PI).abs() > 1e-6 && (angle + PI).abs() > 1e-6 {
|
||||
let modification_type = VectorModificationType::SetG1Continuous {
|
||||
handles: [*handle1, *handle2],
|
||||
enabled: false,
|
||||
};
|
||||
|
||||
responses.add(GraphOperationMessage::Vector { layer, modification_type });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_transform_layer {
|
||||
use crate::messages::portfolio::document::graph_operation::transform_utils;
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::borrow::Cow;
|
||||
use std::fmt::{self, Debug};
|
||||
|
||||
#[derive(ExtractField)]
|
||||
pub struct ToolActionHandlerData<'a> {
|
||||
pub struct ToolActionMessageContext<'a> {
|
||||
pub document: &'a mut DocumentMessageHandler,
|
||||
pub document_id: DocumentId,
|
||||
pub global_tool_data: &'a DocumentToolData,
|
||||
@@ -30,8 +30,8 @@ pub struct ToolActionHandlerData<'a> {
|
||||
pub preferences: &'a PreferencesMessageHandler,
|
||||
}
|
||||
|
||||
pub trait ToolCommon: for<'a, 'b> MessageHandler<ToolMessage, &'b mut ToolActionHandlerData<'a>> + LayoutHolder + ToolTransition + ToolMetadata {}
|
||||
impl<T> ToolCommon for T where T: for<'a, 'b> MessageHandler<ToolMessage, &'b mut ToolActionHandlerData<'a>> + LayoutHolder + ToolTransition + ToolMetadata {}
|
||||
pub trait ToolCommon: for<'a, 'b> MessageHandler<ToolMessage, &'b mut ToolActionMessageContext<'a>> + LayoutHolder + ToolTransition + ToolMetadata {}
|
||||
impl<T> ToolCommon for T where T: for<'a, 'b> MessageHandler<ToolMessage, &'b mut ToolActionMessageContext<'a>> + LayoutHolder + ToolTransition + ToolMetadata {}
|
||||
|
||||
type Tool = dyn ToolCommon + Send + Sync;
|
||||
|
||||
@@ -53,7 +53,7 @@ pub trait Fsm {
|
||||
/// For example, if the tool's FSM is in a `Ready` state and receives a `DragStart` message as its event, it may decide to send some messages,
|
||||
/// update some internal tool variables, and end by transitioning to a `Drawing` state.
|
||||
#[must_use]
|
||||
fn transition(self, message: ToolMessage, tool_data: &mut Self::ToolData, transition_data: &mut ToolActionHandlerData, options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self;
|
||||
fn transition(self, message: ToolMessage, tool_data: &mut Self::ToolData, transition_data: &mut ToolActionMessageContext, options: &Self::ToolOptions, responses: &mut VecDeque<Message>) -> Self;
|
||||
|
||||
/// Implementing this trait function lets a specific tool provide a list of hints (user input actions presently available) to draw in the footer bar.
|
||||
fn update_hints(&self, responses: &mut VecDeque<Message>);
|
||||
@@ -82,7 +82,7 @@ pub trait Fsm {
|
||||
&mut self,
|
||||
message: ToolMessage,
|
||||
tool_data: &mut Self::ToolData,
|
||||
transition_data: &mut ToolActionHandlerData,
|
||||
transition_data: &mut ToolActionMessageContext,
|
||||
options: &Self::ToolOptions,
|
||||
responses: &mut VecDeque<Message>,
|
||||
update_cursor_on_transition: bool,
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct WorkspaceMessageHandler {
|
||||
|
||||
#[message_handler_data]
|
||||
impl MessageHandler<WorkspaceMessage, ()> for WorkspaceMessageHandler {
|
||||
fn process_message(&mut self, message: WorkspaceMessage, _responses: &mut VecDeque<Message>, _data: ()) {
|
||||
fn process_message(&mut self, message: WorkspaceMessage, _responses: &mut VecDeque<Message>, _: ()) {
|
||||
match message {
|
||||
// Messages
|
||||
WorkspaceMessage::NodeGraphToggleVisibility => {
|
||||
|
||||
@@ -53,7 +53,7 @@ pub enum NodeGraphUpdate {
|
||||
NodeGraphUpdateMessage(NodeGraphUpdateMessage),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct NodeGraphExecutor {
|
||||
runtime_io: NodeRuntimeIO,
|
||||
futures: HashMap<u64, ExecutionContext>,
|
||||
@@ -66,17 +66,6 @@ struct ExecutionContext {
|
||||
export_config: Option<ExportConfig>,
|
||||
}
|
||||
|
||||
impl Default for NodeGraphExecutor {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
futures: Default::default(),
|
||||
runtime_io: NodeRuntimeIO::new(),
|
||||
node_graph_hash: 0,
|
||||
old_inspect_node: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeGraphExecutor {
|
||||
/// A local runtime is useful on threads since having global state causes flakes
|
||||
#[cfg(test)]
|
||||
@@ -394,7 +383,9 @@ impl NodeGraphExecutor {
|
||||
return Err(format!("Invalid node graph output type: {node_graph_output:#?}"));
|
||||
}
|
||||
};
|
||||
responses.add(Message::EndBuffer(render_output_metadata));
|
||||
responses.add(Message::EndBuffer {
|
||||
render_metadata: render_output_metadata,
|
||||
});
|
||||
responses.add(DocumentMessage::RenderScrollbars);
|
||||
responses.add(DocumentMessage::RenderRulers);
|
||||
responses.add(OverlaysMessage::Draw);
|
||||
|
||||
@@ -31,7 +31,7 @@ impl EditorTestUtils {
|
||||
// It isn't sufficient to guard the message dispatch here with a check if the once_cell is empty, because that isn't atomic and the time between checking and handling the dispatch can let multiple through.
|
||||
let _ = GLOBAL_PLATFORM.set(Platform::Windows).is_ok();
|
||||
|
||||
editor.handle_message(Message::Init);
|
||||
editor.handle_message(PortfolioMessage::Init);
|
||||
|
||||
Self { editor, runtime }
|
||||
}
|
||||
|
||||
@@ -2,15 +2,14 @@ pub use crate::dispatcher::*;
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
/// Implements a message handler struct for a separate message struct.
|
||||
/// - The first generic argument (`M`) is that message struct type, representing a message enum variant to be matched and handled in `process_message()`.
|
||||
/// - The second generic argument (`D`) is the type of data that can be passed along by the caller to `process_message()`.
|
||||
pub trait MessageHandler<M: ToDiscriminant, D>
|
||||
/// - The first type argument (`M`) is that message struct type, representing a message enum variant to be matched and handled in `process_message()`.
|
||||
/// - The second type argument (`C`) is the type of the context struct that can be passed along by the caller to `process_message()`.
|
||||
pub trait MessageHandler<M: ToDiscriminant, C>
|
||||
where
|
||||
M::Discriminant: AsMessage,
|
||||
<M::Discriminant as TransitiveChild>::TopParent: TransitiveChild<Parent = <M::Discriminant as TransitiveChild>::TopParent, TopParent = <M::Discriminant as TransitiveChild>::TopParent> + AsMessage,
|
||||
{
|
||||
/// Return true if the Action is consumed.
|
||||
fn process_message(&mut self, message: M, responses: &mut VecDeque<Message>, data: D);
|
||||
fn process_message(&mut self, message: M, responses: &mut VecDeque<Message>, context: C);
|
||||
|
||||
fn actions(&self) -> ActionList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user