mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-07 15:55:00 +00:00
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
6 changed files with 28 additions and 11 deletions
|
@ -42,6 +42,7 @@ pub struct DocumentMessageData<'a> {
|
|||
pub executor: &'a mut NodeGraphExecutor,
|
||||
pub current_tool: &'a ToolType,
|
||||
pub preferences: &'a PreferencesMessageHandler,
|
||||
pub device_pixel_ratio: f64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -173,6 +174,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
|||
executor,
|
||||
current_tool,
|
||||
preferences,
|
||||
device_pixel_ratio,
|
||||
} = data;
|
||||
|
||||
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) => {
|
||||
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) => {
|
||||
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::messages::prelude::*;
|
|||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
|
||||
pub enum OverlaysMessage {
|
||||
Draw,
|
||||
SetDevicePixelRatio { ratio: f64 },
|
||||
// Serde functionality isn't used but is required by the message system macros
|
||||
AddProvider(#[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 overlays_visible: bool,
|
||||
pub ipp: &'a InputPreprocessorMessageHandler,
|
||||
pub device_pixel_ratio: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -11,12 +12,15 @@ pub struct OverlaysMessageHandler {
|
|||
pub overlay_providers: HashSet<OverlayProvider>,
|
||||
canvas: Option<web_sys::HtmlCanvasElement>,
|
||||
context: Option<web_sys::CanvasRenderingContext2d>,
|
||||
device_pixel_ratio: Option<f64>,
|
||||
}
|
||||
|
||||
impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessageHandler {
|
||||
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 {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
@ -41,8 +45,6 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageData<'_>> for OverlaysMessag
|
|||
|
||||
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 _ = context.set_transform(a, b, c, d, e, f);
|
||||
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
|
||||
);
|
||||
}
|
||||
OverlaysMessage::SetDevicePixelRatio { ratio } => {
|
||||
self.device_pixel_ratio = Some(ratio);
|
||||
responses.add(OverlaysMessage::Draw);
|
||||
}
|
||||
OverlaysMessage::AddProvider(message) => {
|
||||
self.overlay_providers.insert(message);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,9 @@ pub enum PortfolioMessage {
|
|||
SetActivePanel {
|
||||
panel: PanelType,
|
||||
},
|
||||
SetDevicePixelRatio {
|
||||
ratio: f64,
|
||||
},
|
||||
SelectDocument {
|
||||
document_id: DocumentId,
|
||||
},
|
||||
|
|
|
@ -50,6 +50,7 @@ pub struct PortfolioMessageHandler {
|
|||
pub selection_mode: SelectionMode,
|
||||
/// The spreadsheet UI allows for instance data to be previewed.
|
||||
pub spreadsheet: SpreadsheetMessageHandler,
|
||||
device_pixel_ratio: Option<f64>,
|
||||
}
|
||||
|
||||
impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMessageHandler {
|
||||
|
@ -103,6 +104,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
|||
executor: &mut self.executor,
|
||||
current_tool,
|
||||
preferences,
|
||||
device_pixel_ratio: self.device_pixel_ratio.unwrap_or(1.),
|
||||
};
|
||||
document.process_message(message, responses, document_inputs)
|
||||
}
|
||||
|
@ -119,6 +121,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
|||
executor: &mut self.executor,
|
||||
current_tool,
|
||||
preferences,
|
||||
device_pixel_ratio: self.device_pixel_ratio.unwrap_or(1.),
|
||||
};
|
||||
document.process_message(message, responses, document_inputs)
|
||||
}
|
||||
|
@ -1008,6 +1011,10 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
|
|||
self.active_panel = 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 } => {
|
||||
// Auto-save the document we are leaving
|
||||
let mut node_graph_open = false;
|
||||
|
|
|
@ -352,7 +352,7 @@ impl EditorHandle {
|
|||
/// Inform the overlays system of the current device pixel ratio
|
||||
#[wasm_bindgen(js_name = setDevicePixelRatio)]
|
||||
pub fn set_device_pixel_ratio(&self, ratio: f64) {
|
||||
let message = OverlaysMessage::SetDevicePixelRatio { ratio };
|
||||
let message = PortfolioMessage::SetDevicePixelRatio { ratio };
|
||||
self.dispatch(message);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue