Draw FPS and resolution label overlay. 绘制 FPS 和分辨率标签叠加。
(buf: &mut [u32], stride: usize, fps: f64, label: &str)
| 152 | /// Draw FPS and resolution label overlay. |
| 153 | /// 绘制 FPS 和分辨率标签叠加。 |
| 154 | fn draw_fps_overlay(buf: &mut [u32], stride: usize, fps: f64, label: &str) { |
| 155 | let text = format!("{} FPS:{:.1}", label, fps); |
| 156 | let scale = 2; |
| 157 | let x0 = 8; |
| 158 | let y0 = 8; |
| 159 | |
| 160 | // Black background. |
| 161 | // 黑色背景。 |
| 162 | let text_w = text.len() * 6 * scale; |
| 163 | let text_h = 7 * scale; |
| 164 | for dy in 0..text_h + 4 { |
| 165 | for dx in 0..text_w + 8 { |
| 166 | let px = x0 + dx - 2; |
| 167 | let py = y0 + dy - 2; |
| 168 | if py < buf.len() / stride && px < stride { |
| 169 | buf[py * stride + px] = 0x00000000; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | for (ci, ch) in text.chars().enumerate() { |
| 175 | let glyph = char_glyph(ch); |
| 176 | for (row, &glyph_row) in glyph.iter().enumerate() { |
| 177 | for col in 0..5 { |
| 178 | if glyph_row & (1 << (4 - col)) != 0 { |
| 179 | for sy in 0..scale { |
| 180 | for sx in 0..scale { |
| 181 | let px = x0 + ci * 6 * scale + col * scale + sx; |
| 182 | let py = y0 + row * scale + sy; |
| 183 | if py < buf.len() / stride && px < stride { |
| 184 | buf[py * stride + px] = 0x0000FF00; // green |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | fn char_glyph(ch: char) -> [u8; 7] { |
| 195 | match ch { |
no test coverage detected