stevenkhan commited on
Commit
86c91c8
·
verified ·
1 Parent(s): 46057b1

Upload spectral-core/src/damage.rs

Browse files
Files changed (1) hide show
  1. spectral-core/src/damage.rs +58 -0
spectral-core/src/damage.rs ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// Per-frame damage tracking for partial redraw.
2
+ #[derive(Clone, Debug, Default, PartialEq)]
3
+ pub enum Damage {
4
+ #[default]
5
+ None,
6
+ Full,
7
+ Lines(Vec<LineDamage>),
8
+ Rects(Vec<RectDamage>),
9
+ }
10
+
11
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12
+ pub struct LineDamage {
13
+ pub row: usize,
14
+ pub start_col: usize,
15
+ pub end_col: usize,
16
+ }
17
+
18
+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]
19
+ pub struct RectDamage {
20
+ pub x: u32,
21
+ pub y: u32,
22
+ pub w: u32,
23
+ pub h: u32,
24
+ }
25
+
26
+ impl Damage {
27
+ pub fn add_line(&mut self, row: usize, start_col: usize, end_col: usize) {
28
+ match self {
29
+ Damage::None => {
30
+ *self = Damage::Lines(vec![LineDamage { row, start_col, end_col }]);
31
+ }
32
+ Damage::Lines(lines) => {
33
+ lines.push(LineDamage { row, start_col, end_col });
34
+ }
35
+ _ => {}
36
+ }
37
+ }
38
+
39
+ pub fn add_rect(&mut self, x: u32, y: u32, w: u32, h: u32) {
40
+ match self {
41
+ Damage::None => {
42
+ *self = Damage::Rects(vec![RectDamage { x, y, w, h }]);
43
+ }
44
+ Damage::Rects(rects) => {
45
+ rects.push(RectDamage { x, y, w, h });
46
+ }
47
+ _ => {}
48
+ }
49
+ }
50
+
51
+ pub fn set_full(&mut self) {
52
+ *self = Damage::Full;
53
+ }
54
+
55
+ pub fn take(&mut self) -> Damage {
56
+ std::mem::take(self)
57
+ }
58
+ }