Fix device pixel ratio being tied to the document by moving it from overlays to portfolio
This commit is contained in:
parent
fff0a53799
commit
4e418bbfe1
|
|
@ -42,6 +42,7 @@ pub struct DocumentMessageData<'a> {
|
||||||
pub executor: &'a mut NodeGraphExecutor,
|
pub executor: &'a mut NodeGraphExecutor,
|
||||||
pub current_tool: &'a ToolType,
|
pub current_tool: &'a ToolType,
|
||||||
pub preferences: &'a PreferencesMessageHandler,
|
pub preferences: &'a PreferencesMessageHandler,
|
||||||
|
pub device_pixel_ratio: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
|
|
@ -173,6 +174,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||||
executor,
|
executor,
|
||||||
current_tool,
|
current_tool,
|
||||||
preferences,
|
preferences,
|
||||||
|
device_pixel_ratio,
|
||||||
} = data;
|
} = data;
|
||||||
|
|
||||||
let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
|
let selected_nodes_bounding_box_viewport = self.network_interface.selected_nodes_bounding_box_viewport(&self.breadcrumb_network_path);
|
||||||
|
|
@ -197,7 +199,15 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||||
}
|
}
|
||||||
DocumentMessage::Overlays(message) => {
|
DocumentMessage::Overlays(message) => {
|
||||||
let overlays_visible = self.overlays_visible;
|
let overlays_visible = self.overlays_visible;
|
||||||
self.overlays_message_handler.process_message(message, responses, OverlaysMessageData { overlays_visible, ipp });
|
self.overlays_message_handler.process_message(
|
||||||
|
message,
|
||||||
|
responses,
|
||||||
|
OverlaysMessageData {
|
||||||
|
overlays_visible,
|
||||||
|
ipp,
|
||||||
|
device_pixel_ratio,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
DocumentMessage::PropertiesPanel(message) => {
|
DocumentMessage::PropertiesPanel(message) => {
|
||||||
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
|
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ use crate::messages::prelude::*;
|
||||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||||
pub enum OverlaysMessage {
|
pub enum OverlaysMessage {
|
||||||
Draw,
|
Draw,
|
||||||
SetDevicePixelRatio { ratio: f64 },
|
|
||||||
// Serde functionality isn't used but is required by the message system macros
|
// Serde functionality isn't used but is required by the message system macros
|
||||||
AddProvider(#[serde(skip, default = "empty_provider")] OverlayProvider),
|
AddProvider(#[serde(skip, default = "empty_provider")] OverlayProvider),
|
||||||
RemoveProvider(#[serde(skip, default = "empty_provider")] OverlayProvider),
|
RemoveProvider(#[serde(skip, default = "empty_provider")] OverlayProvider),
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::messages::prelude::*;
|
||||||
pub struct OverlaysMessageData<'a> {
|
pub struct OverlaysMessageData<'a> {
|
||||||
pub overlays_visible: bool,
|
pub overlays_visible: bool,
|
||||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||||
|
pub device_pixel_ratio: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
|
@ -11,12 +12,15 @@ pub struct OverlaysMessageHandler {
|
||||||
pub overlay_providers: HashSet<OverlayProvider>,
|
pub overlay_providers: HashSet<OverlayProvider>,
|
||||||
canvas: Option<web_sys::HtmlCanvasElement>,
|
canvas: Option<web_sys::HtmlCanvasElement>,
|
||||||
context: Option<web_sys::CanvasRenderingContext2d>,
|
context: Option<web_sys::CanvasRenderingContext2d>,
|
||||||
device_pixel_ratio: Option<f64>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
|
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
|
||||||
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, data: OverlaysMessageData) {
|
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, data: OverlaysMessageData) {
|
||||||
let OverlaysMessageData { overlays_visible, ipp } = data;
|
let OverlaysMessageData {
|
||||||
|
overlays_visible,
|
||||||
|
ipp,
|
||||||
|
device_pixel_ratio,
|
||||||
|
} = data;
|
||||||
|
|
||||||
match message {
|
match message {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
|
@ -41,8 +45,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
|
||||||
|
|
||||||
let size = ipp.viewport_bounds.size().as_uvec2();
|
let size = ipp.viewport_bounds.size().as_uvec2();
|
||||||
|
|
||||||
let device_pixel_ratio = self.device_pixel_ratio.unwrap_or(1.);
|
|
||||||
|
|
||||||
let [a, b, c, d, e, f] = DAffine2::from_scale(DVec2::splat(device_pixel_ratio)).to_cols_array();
|
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);
|
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);
|
context.clear_rect(0., 0., ipp.viewport_bounds.size().x, ipp.viewport_bounds.size().y);
|
||||||
|
|
@ -70,10 +72,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
|
||||||
self.canvas, self.context
|
self.canvas, self.context
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
OverlaysMessage::SetDevicePixelRatio { ratio } => {
|
|
||||||
self.device_pixel_ratio = Some(ratio);
|
|
||||||
responses.add(OverlaysMessage::Draw);
|
|
||||||
}
|
|
||||||
OverlaysMessage::AddProvider(message) => {
|
OverlaysMessage::AddProvider(message) => {
|
||||||
self.overlay_providers.insert(message);
|
self.overlay_providers.insert(message);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,9 @@ pub enum PortfolioMessage {
|
||||||
SetActivePanel {
|
SetActivePanel {
|
||||||
panel: PanelType,
|
panel: PanelType,
|
||||||
},
|
},
|
||||||
|
SetDevicePixelRatio {
|
||||||
|
ratio: f64,
|
||||||
|
},
|
||||||
SelectDocument {
|
SelectDocument {
|
||||||
document_id: DocumentId,
|
document_id: DocumentId,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ pub struct PortfolioMessageHandler {
|
||||||
pub selection_mode: SelectionMode,
|
pub selection_mode: SelectionMode,
|
||||||
/// The spreadsheet UI allows for instance data to be previewed.
|
/// The spreadsheet UI allows for instance data to be previewed.
|
||||||
pub spreadsheet: SpreadsheetMessageHandler,
|
pub spreadsheet: SpreadsheetMessageHandler,
|
||||||
|
device_pixel_ratio: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
|
impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
|
||||||
|
|
@ -103,6 +104,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
||||||
executor: &mut self.executor,
|
executor: &mut self.executor,
|
||||||
current_tool,
|
current_tool,
|
||||||
preferences,
|
preferences,
|
||||||
|
device_pixel_ratio: self.device_pixel_ratio.unwrap_or(1.),
|
||||||
};
|
};
|
||||||
document.process_message(message, responses, document_inputs)
|
document.process_message(message, responses, document_inputs)
|
||||||
}
|
}
|
||||||
|
|
@ -119,6 +121,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
||||||
executor: &mut self.executor,
|
executor: &mut self.executor,
|
||||||
current_tool,
|
current_tool,
|
||||||
preferences,
|
preferences,
|
||||||
|
device_pixel_ratio: self.device_pixel_ratio.unwrap_or(1.),
|
||||||
};
|
};
|
||||||
document.process_message(message, responses, document_inputs)
|
document.process_message(message, responses, document_inputs)
|
||||||
}
|
}
|
||||||
|
|
@ -1008,6 +1011,10 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
||||||
self.active_panel = panel;
|
self.active_panel = panel;
|
||||||
responses.add(DocumentMessage::SetActivePanel { active_panel: self.active_panel });
|
responses.add(DocumentMessage::SetActivePanel { active_panel: self.active_panel });
|
||||||
}
|
}
|
||||||
|
PortfolioMessage::SetDevicePixelRatio { ratio } => {
|
||||||
|
self.device_pixel_ratio = Some(ratio);
|
||||||
|
responses.add(OverlaysMessage::Draw);
|
||||||
|
}
|
||||||
PortfolioMessage::SelectDocument { document_id } => {
|
PortfolioMessage::SelectDocument { document_id } => {
|
||||||
// Auto-save the document we are leaving
|
// Auto-save the document we are leaving
|
||||||
let mut node_graph_open = false;
|
let mut node_graph_open = false;
|
||||||
|
|
|
||||||
|
|
@ -352,7 +352,7 @@ impl EditorHandle {
|
||||||
/// Inform the overlays system of the current device pixel ratio
|
/// Inform the overlays system of the current device pixel ratio
|
||||||
#[wasm_bindgen(js_name = setDevicePixelRatio)]
|
#[wasm_bindgen(js_name = setDevicePixelRatio)]
|
||||||
pub fn set_device_pixel_ratio(&self, ratio: f64) {
|
pub fn set_device_pixel_ratio(&self, ratio: f64) {
|
||||||
let message = OverlaysMessage::SetDevicePixelRatio { ratio };
|
let message = PortfolioMessage::SetDevicePixelRatio { ratio };
|
||||||
self.dispatch(message);
|
self.dispatch(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue