mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 15:38:11 +08:00
Implement outline view mode (#401)
* Created wasm binding to action's of the radio buttons which control the view mode
Added entry to DocumentMessage Enum
* draw in wireframe mode by changing parameters on each shape
added functions/changed behavior to do as above
not working yet
- newly added shapes should be drawn in wireframe
- setting fill to "none" on a path does not only draw an outline
- maybe the stroke width is 0?
* Wire frame view mostly functional for ellipses
- Need to implement for all shapes
- BUG: shapes don't immediatley update upon changing view-mode
* Fixed: active document now updates after view mode swap
* The Pros:
- wire frame mode effects all shapes correctly
The Cons:
- wire frame mode effects everything, including things that maybe shouldn't be, like select boxes and pen lines
* wire frame view no longer effects overlay layers
* Fixed: While in wireframe view the pen tool will draw regular thickness lines.
* some commenting
* Fixed potential bug:
In layer/file system with a Folder layer with a sub-layer that is also
a Folder cache_dirty must be set in order for all shapes to update properly
* refactored code to use ViewMode enum names throughout
* Changed: All wireframe lines are blank
cargo fmt
* Wireframe thickness doesn't change as a result of zooming
- Added DocumentMessage::ReRenderDocument, which marks layers as dirty and renders with the updated render-string
- All "zoom" messages in the movement_handler send a re-render message
- while in wireframe view, the "render-transform" of all shapes includes the root layer transform
Added getter/setter methods for graphene::Document::view_mode
* cargo fmt
* wireframe now has proper thickness after "Zoom Canvas to Fit all" action
* Refactored
- Changed FrontendMessage::UpdateCanvas to RenderDocument message to allow for lazy evaluation
- Created DocumentOperation::SetViewMode to be more consistent with existing code
- removed log statement
- Added constants for empty fill and thin-black stroke
* cargo fmt
* Removed ReRenderDocument message
* cargo fmt
* Fixes as suggested by TrueDoctor
* clean up merge
cargo fmt
* Refactor:
moved view_mode to DocumentMessageHandler
* Polishing
* changed those two comments
* Remove unknown todo comment
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
e13e9337f4
commit
20f154bc25
@@ -1,15 +1,29 @@
|
||||
use crate::color::Color;
|
||||
use crate::consts::{LAYER_OUTLINE_STROKE_COLOR, LAYER_OUTLINE_STROKE_WIDTH};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const OPACITY_PRECISION: usize = 3;
|
||||
|
||||
fn format_opacity(name: &str, opacity: f32) -> String {
|
||||
if (opacity - 1.).abs() > 10f32.powi(-(OPACITY_PRECISION as i32)) {
|
||||
if (opacity - 1.).abs() > 10_f32.powi(-(OPACITY_PRECISION as i32)) {
|
||||
format!(r#" {}-opacity="{:.precision$}""#, name, opacity, precision = OPACITY_PRECISION)
|
||||
} else {
|
||||
String::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
|
||||
pub enum ViewMode {
|
||||
Normal,
|
||||
Outline,
|
||||
Pixels,
|
||||
}
|
||||
impl Default for ViewMode {
|
||||
fn default() -> Self {
|
||||
ViewMode::Normal
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct Fill {
|
||||
@@ -22,7 +36,7 @@ impl Fill {
|
||||
pub fn color(&self) -> Option<Color> {
|
||||
self.color
|
||||
}
|
||||
pub fn none() -> Self {
|
||||
pub const fn none() -> Self {
|
||||
Self { color: None }
|
||||
}
|
||||
pub fn render(&self) -> String {
|
||||
@@ -41,7 +55,7 @@ pub struct Stroke {
|
||||
}
|
||||
|
||||
impl Stroke {
|
||||
pub fn new(color: Color, width: f32) -> Self {
|
||||
pub const fn new(color: Color, width: f32) -> Self {
|
||||
Self { color, width }
|
||||
}
|
||||
pub fn color(&self) -> Color {
|
||||
@@ -83,17 +97,18 @@ impl PathStyle {
|
||||
pub fn clear_stroke(&mut self) {
|
||||
self.stroke = None;
|
||||
}
|
||||
pub fn render(&self) -> String {
|
||||
format!(
|
||||
"{}{}",
|
||||
match self.fill {
|
||||
Some(fill) => fill.render(),
|
||||
None => String::new(),
|
||||
},
|
||||
match self.stroke {
|
||||
Some(stroke) => stroke.render(),
|
||||
None => String::new(),
|
||||
},
|
||||
)
|
||||
|
||||
pub fn render(&self, view_mode: ViewMode) -> String {
|
||||
let fill_attribute = match (view_mode, self.fill) {
|
||||
(ViewMode::Outline, _) => Fill::none().render(),
|
||||
(_, Some(fill)) => fill.render(),
|
||||
(_, None) => String::new(),
|
||||
};
|
||||
let stroke_attribute = match (view_mode, self.stroke) {
|
||||
(ViewMode::Outline, _) => Stroke::new(LAYER_OUTLINE_STROKE_COLOR, LAYER_OUTLINE_STROKE_WIDTH).render(),
|
||||
(_, Some(stroke)) => stroke.render(),
|
||||
(_, None) => String::new(),
|
||||
};
|
||||
format!("{}{}", fill_attribute, stroke_attribute)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user