1 use starry_client::base::{color::Color, renderer::Renderer}; 2 3 use super::{ 4 image::{Image, ImageRoi}, 5 rect::Rect, 6 }; 7 8 /// 一个显示窗口 9 pub struct Display { 10 /// 左上角x坐标 11 pub x: i32, 12 /// 左上角y坐标 13 pub y: i32, 14 /// 帧缓冲区 15 pub image: Image, 16 } 17 18 impl Display { 19 /// 创建新窗口 new(x: i32, y: i32, width: i32, height: i32) -> Self20 pub fn new(x: i32, y: i32, width: i32, height: i32) -> Self { 21 Display { 22 x, 23 y, 24 image: Image::new(width, height), 25 } 26 } 27 28 /// # 函数功能 29 /// 向一个矩形区域内填充单一颜色 30 /// 31 /// ## 参数值 32 /// - rect: 矩形区域(绝对位置) 33 /// - color: 填充的颜色 rect(&mut self, rect: &Rect, color: Color)34 pub fn rect(&mut self, rect: &Rect, color: Color) { 35 self.image.rect( 36 rect.left() - self.x, 37 rect.top() - self.y, 38 rect.width().try_into().unwrap_or(0), 39 rect.height().try_into().unwrap_or(0), 40 color, 41 ); 42 } 43 44 /// # 函数功能 45 /// 获得矩形区域相应的Roi 46 /// 47 /// ## 参数值 48 /// - rect: 矩形区域(绝对位置) 49 /// 50 /// ## 返回值 51 /// 矩形区域对应的Roi roi(&mut self, rect: &Rect) -> ImageRoi52 pub fn roi(&mut self, rect: &Rect) -> ImageRoi { 53 // 得到相对位置的矩形 54 self.image.roi(&Rect::new( 55 rect.left() - self.x, 56 rect.top() - self.y, 57 rect.width(), 58 rect.height(), 59 )) 60 } 61 62 /// 窗口调整大小 resize(&mut self, width: i32, height: i32)63 pub fn resize(&mut self, width: i32, height: i32) { 64 self.image = Image::new(width, height) 65 } 66 67 /// 获得展示窗口矩形 screen_rect(&self) -> Rect68 pub fn screen_rect(&self) -> Rect { 69 Rect::new(self.x, self.y, self.image.width(), self.image.height()) 70 } 71 } 72