[drag-and-drop] Add ability to translate layers and PaintCmd:s

This commit is contained in:
Emil Ernerfeldt 2020-11-02 17:41:52 +01:00
parent ed8a69ab2f
commit 9833ca57a6
3 changed files with 47 additions and 2 deletions

View file

@ -1,6 +1,6 @@
use ahash::AHashMap;
use crate::{math::Rect, paint::PaintCmd, Id};
use crate::{math::Rect, paint::PaintCmd, Id, *};
/// Different layer categories
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
@ -105,6 +105,14 @@ impl PaintList {
assert!(idx.0 < self.0.len());
self.0[idx.0] = (clip_rect, cmd);
}
/// Translate each paint-command and clip rectangle by this much, in-place
pub fn translate(&mut self, delta: Vec2) {
for (clip_rect, cmd) in &mut self.0 {
*clip_rect = clip_rect.translate(delta);
cmd.translate(delta);
}
}
}
#[derive(Clone, Default)]

View file

@ -3,6 +3,7 @@ use {
crate::{
align::{anchor_rect, Align},
math::{Pos2, Rect},
*,
},
};
@ -152,6 +153,35 @@ impl PaintCmd {
super::TextureId::Egui
}
}
/// Translate location by this much, in-place
pub fn translate(&mut self, delta: Vec2) {
match self {
PaintCmd::Noop => {}
PaintCmd::Circle { center, .. } => {
*center += delta;
}
PaintCmd::LineSegment { points, .. } => {
for p in points {
*p += delta;
}
}
PaintCmd::Path { points, .. } => {
for p in points {
*p += delta;
}
}
PaintCmd::Rect { rect, .. } => {
*rect = rect.translate(delta);
}
PaintCmd::Text { pos, .. } => {
*pos += delta;
}
PaintCmd::Triangles(triangles) => {
triangles.translate(delta);
}
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]

View file

@ -243,6 +243,13 @@ impl Triangles {
}
output
}
/// Translate location by this much, in-place
pub fn translate(&mut self, delta: Vec2) {
for v in &mut self.vertices {
v.pos += delta;
}
}
}
// ----------------------------------------------------------------------------
@ -697,7 +704,7 @@ fn tessellate_paint_command(
if triangles.is_valid() {
out.append(triangles);
} else {
debug_assert!(false, "Ivalid Triangles in PaintCmd::Traingles");
debug_assert!(false, "Invalid Triangles in PaintCmd::Triangles");
}
}
PaintCmd::LineSegment { points, stroke } => {