Skip to content

Commit 11a505b

Browse files
committed
Show other peers' pointers
1 parent 9df7d4f commit 11a505b

15 files changed

Lines changed: 345 additions & 14 deletions

File tree

‎editor/src/dispatcher.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ impl Dispatcher {
291291
preferences: &self.message_handlers.preferences_message_handler,
292292
current_tool: &self.message_handlers.tool_message_handler.tool_state.tool_data.active_tool_type,
293293
tool_edit_target: &self.message_handlers.tool_message_handler.edit_target,
294+
tools: &self.message_handlers.tool_message_handler,
294295
reset_node_definitions_on_open: self.message_handlers.portfolio_message_handler.reset_node_definitions_on_open,
295296
timing_information: self.message_handlers.animation_message_handler.timing_information(),
296297
animation: &self.message_handlers.animation_message_handler,

‎editor/src/messages/frontend/frontend_message.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::messages::input_mapper::utility_types::misc::ActionShortcut;
66
use crate::messages::layout::utility_types::math_expression::MathExpressionCompletions;
77
use crate::messages::layout::utility_types::widget_prelude::*;
88
use crate::messages::portfolio::document::node_graph::utility_types::{
9-
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic,
9+
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, FrontendRemoteCursor, NodeGraphErrorDiagnostic,
1010
};
1111
use crate::messages::portfolio::document::utility_types::nodes::{LayerPanelEntry, LayerStructureEntry};
1212
use crate::messages::portfolio::document::utility_types::wires::{WirePath, WirePathUpdate};
@@ -194,6 +194,12 @@ pub enum FrontendMessage {
194194
#[serde(rename = "box")]
195195
box_selection: Option<BoxSelection>,
196196
},
197+
UpdateDocumentCursors {
198+
cursors: Vec<FrontendRemoteCursor>,
199+
},
200+
UpdateNodeGraphCursors {
201+
cursors: Vec<FrontendRemoteCursor>,
202+
},
197203
UpdateContextMenuInformation {
198204
#[serde(rename = "contextMenuInformation")]
199205
context_menu_information: Option<ContextMenuInformation>,

‎editor/src/messages/portfolio/document/document_message_handler.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,6 +2385,11 @@ impl DocumentMessageHandler {
23852385
self.network_interface.document_metadata()
23862386
}
23872387

2388+
/// The network the node graph shows, from the document network down.
2389+
pub fn breadcrumb_network_path(&self) -> &[NodeId] {
2390+
&self.breadcrumb_network_path
2391+
}
2392+
23882393
/// The name the working copy's registry holds as [`DOCUMENT_NAME_ATTRIBUTE`].
23892394
fn stored_name(&self) -> Option<&str> {
23902395
let attribute = self.storage()?.registry().attributes.get(DOCUMENT_NAME_ATTRIBUTE).filter(|attribute| !attribute.deleted)?;

‎editor/src/messages/portfolio/document/node_graph/utility_types.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,17 @@ pub enum Direction {
233233
Left,
234234
Right,
235235
}
236+
237+
/// Another peer's pointer over the node graph, in viewport pixels, with how to label it.
238+
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
239+
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
240+
pub struct FrontendRemoteCursor {
241+
pub x: f64,
242+
pub y: f64,
243+
pub name: String,
244+
/// A stand-in name for someone who gave none, shown in italics.
245+
pub anonymous: bool,
246+
pub color: String,
247+
/// The icon name of the tool the peer holds, if known.
248+
pub tool: Option<String>,
249+
}

‎editor/src/messages/portfolio/portfolio_message_handler.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct PortfolioMessageContext<'a> {
4343
pub animation: &'a AnimationMessageHandler,
4444
pub current_tool: &'a ToolType,
4545
pub tool_edit_target: &'a EditTarget,
46+
/// Its active tool's icon is shown to peers beside this user's pointer.
47+
pub tools: &'a ToolMessageHandler,
4648
pub reset_node_definitions_on_open: bool,
4749
pub timing_information: TimingInformation,
4850
pub viewport: &'a ViewportMessageHandler,
@@ -82,6 +84,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
8284
animation,
8385
current_tool,
8486
tool_edit_target,
87+
tools,
8588
reset_node_definitions_on_open,
8689
timing_information,
8790
viewport,
@@ -142,6 +145,9 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
142145
active_document_id: self.active_document_id,
143146
resource_storage,
144147
preferences,
148+
ipp,
149+
viewport,
150+
tools,
145151
};
146152
self.sync.process_message(message, responses, context);
147153
}

‎editor/src/messages/portfolio/sync/identity.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,22 @@ const ANONYMOUS_ANIMALS: [&str; 64] = [
7979
"Tiger",
8080
"Turtle",
8181
];
82+
83+
/// A hue picked by the user id, at a fixed saturation and lightness, as `#rrggbb`.
84+
pub(crate) fn user_color(user: UserId) -> String {
85+
let hue = (scramble(user) >> 32) % 360;
86+
let (h, s, l): (f64, f64, f64) = (hue as f64 / 60., 0.65, 0.5);
87+
let c = (1. - (2. * l - 1.).abs()) * s;
88+
let x = c * (1. - (h % 2. - 1.).abs());
89+
let m = l - c / 2.;
90+
let (r, g, b) = match h as u32 {
91+
0 => (c, x, 0.),
92+
1 => (x, c, 0.),
93+
2 => (0., c, x),
94+
3 => (0., x, c),
95+
4 => (x, 0., c),
96+
_ => (c, 0., x),
97+
};
98+
let channel = |value: f64| ((value + m) * 255.).round() as u8;
99+
format!("#{:02x}{:02x}{:02x}", channel(r), channel(g), channel(b))
100+
}

0 commit comments

Comments
 (0)