@@ -50,32 +50,39 @@ pub fn init_application() -> MainThreadMarker { |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /// One NSWindow + CAShapeLayer pair drawing a rounded-rect border. |
| 53 | +/// |
| 54 | +/// `bounds_cg_*` fields are the TARGET window's CG bounds (origin |
| 55 | +/// top-left, Y-down) — same coordinate system the rest of ers uses. |
| 53 | 56 | pub struct OverlayWindow { |
| 54 | 57 | window: Retained<NSWindow>, |
| 55 | 58 | border_layer: Retained<CAShapeLayer>, |
| 56 | | - pub bounds_cg: CGRect, |
| 59 | + pub bounds_cg_x: f64, |
| 60 | + pub bounds_cg_y: f64, |
| 61 | + pub bounds_cg_w: f64, |
| 62 | + pub bounds_cg_h: f64, |
| 57 | 63 | pub border_width: f64, |
| 58 | 64 | pub radius: f64, |
| 59 | 65 | mtm: MainThreadMarker, |
| 60 | 66 | } |
| 61 | 67 | |
| 62 | 68 | impl OverlayWindow { |
| 63 | | - /// Create an NSWindow border overlay covering `target_bounds_cg + border_width`. |
| 69 | + /// Create an NSWindow border overlay around the given target bounds. |
| 70 | + /// Coords are in CG space (origin top-left, Y-down). |
| 64 | 71 | pub fn new( |
| 65 | | - target_bounds_cg: CGRect, |
| 72 | + bounds_cg_x: f64, |
| 73 | + bounds_cg_y: f64, |
| 74 | + bounds_cg_w: f64, |
| 75 | + bounds_cg_h: f64, |
| 66 | 76 | border_width: f64, |
| 67 | 77 | radius: f64, |
| 68 | 78 | color: (f64, f64, f64, f64), |
| 69 | 79 | mtm: MainThreadMarker, |
| 70 | 80 | ) -> Option<Self> { |
| 71 | 81 | let outer_cg = CGRect::new( |
| 72 | | - CGPoint::new( |
| 73 | | - target_bounds_cg.origin.x - border_width, |
| 74 | | - target_bounds_cg.origin.y - border_width, |
| 75 | | - ), |
| 82 | + CGPoint::new(bounds_cg_x - border_width, bounds_cg_y - border_width), |
| 76 | 83 | CGSize::new( |
| 77 | | - target_bounds_cg.size.width + 2.0 * border_width, |
| 78 | | - target_bounds_cg.size.height + 2.0 * border_width, |
| 84 | + bounds_cg_w + 2.0 * border_width, |
| 85 | + bounds_cg_h + 2.0 * border_width, |
| 79 | 86 | ), |
| 80 | 87 | ); |
| 81 | 88 | let cocoa_frame = cg_to_cocoa_frame(outer_cg, mtm); |
@@ -141,7 +148,10 @@ impl OverlayWindow { |
| 141 | 148 | Some(OverlayWindow { |
| 142 | 149 | window, |
| 143 | 150 | border_layer, |
| 144 | | - bounds_cg: target_bounds_cg, |
| 151 | + bounds_cg_x, |
| 152 | + bounds_cg_y, |
| 153 | + bounds_cg_w, |
| 154 | + bounds_cg_h, |
| 145 | 155 | border_width, |
| 146 | 156 | radius, |
| 147 | 157 | mtm, |
@@ -153,16 +163,10 @@ impl OverlayWindow { |
| 153 | 163 | self.window.windowNumber() as u32 |
| 154 | 164 | } |
| 155 | 165 | |
| 156 | | - pub fn set_bounds(&mut self, target_bounds_cg: CGRect) { |
| 166 | + pub fn set_bounds(&mut self, x: f64, y: f64, w: f64, h: f64) { |
| 157 | 167 | let outer_cg = CGRect::new( |
| 158 | | - CGPoint::new( |
| 159 | | - target_bounds_cg.origin.x - self.border_width, |
| 160 | | - target_bounds_cg.origin.y - self.border_width, |
| 161 | | - ), |
| 162 | | - CGSize::new( |
| 163 | | - target_bounds_cg.size.width + 2.0 * self.border_width, |
| 164 | | - target_bounds_cg.size.height + 2.0 * self.border_width, |
| 165 | | - ), |
| 168 | + CGPoint::new(x - self.border_width, y - self.border_width), |
| 169 | + CGSize::new(w + 2.0 * self.border_width, h + 2.0 * self.border_width), |
| 166 | 170 | ); |
| 167 | 171 | let cocoa_frame = cg_to_cocoa_frame(outer_cg, self.mtm); |
| 168 | 172 | self.window.setFrame_display(cocoa_frame, true); |
@@ -182,7 +186,10 @@ impl OverlayWindow { |
| 182 | 186 | CGSize::new(outer_cg.size.width, outer_cg.size.height), |
| 183 | 187 | )); |
| 184 | 188 | } |
| 185 | | - self.bounds_cg = target_bounds_cg; |
| 189 | + self.bounds_cg_x = x; |
| 190 | + self.bounds_cg_y = y; |
| 191 | + self.bounds_cg_w = w; |
| 192 | + self.bounds_cg_h = h; |
| 186 | 193 | } |
| 187 | 194 | |
| 188 | 195 | pub fn set_color(&self, color: (f64, f64, f64, f64)) { |