mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
1253 lines
46 KiB
Rust
1253 lines
46 KiB
Rust
use super::TelemetryState;
|
|
use super::StackStr;
|
|
use crate::controller::ControlSource;
|
|
use crate::g29_bridge::G29State;
|
|
use std::fmt::Write as FmtWrite;
|
|
|
|
/// Pages du Menu Minimaliste VR intégré à l'OSD OpenXR.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
|
pub enum VrMenuPage {
|
|
#[default]
|
|
Main,
|
|
Advanced,
|
|
}
|
|
|
|
impl VrMenuPage {
|
|
pub const fn item_count(self) -> usize {
|
|
match self {
|
|
Self::Main => VR_MENU_MAIN_COUNT,
|
|
Self::Advanced => VR_MENU_ADV_COUNT,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Nombre d'entrées dans le menu principal minimaliste VR (actions essentielles).
|
|
pub const VR_MENU_MAIN_COUNT: usize = 9;
|
|
/// Nombre d'entrées dans le sous-menu Avancé VR.
|
|
pub const VR_MENU_ADV_COUNT: usize = 10;
|
|
|
|
/// Données d'affichage zéro-allocation (`Copy`) pour le Menu Minimaliste VR dans le casque.
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct VrMenuRenderData {
|
|
pub page: VrMenuPage,
|
|
pub selected_idx: usize,
|
|
pub profile_name: StackStr<32>,
|
|
pub control_source: ControlSource,
|
|
pub head_tracking_on: bool,
|
|
pub telemetry_osd_on: bool,
|
|
pub projection_label: &'static str,
|
|
pub vr_lock_label: &'static str,
|
|
pub vr_hud_smoothing_pct: u8,
|
|
pub screen_distance_m: f32,
|
|
pub lens_k1: f32,
|
|
pub camera_fov_deg: f32,
|
|
pub dvr_recording: bool,
|
|
pub gear_3_max: u16,
|
|
pub vibration_pct: u8,
|
|
pub audio_alerts_on: bool,
|
|
pub audio_volume_pct: u8,
|
|
pub wifi_channel: u16,
|
|
pub quit_confirm_pending: bool,
|
|
pub feedback_msg: Option<(StackStr<48>, bool)>,
|
|
}
|
|
|
|
/// Options d'affichage avancées pour le moteur OSD (cellules LiPo, stats vidéo, GPS/Mode).
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct OsdExtraOptions {
|
|
pub battery_cells: u8,
|
|
pub battery_warn_cell_v: f32,
|
|
pub battery_crit_cell_v: f32,
|
|
pub show_video_stats: bool,
|
|
pub show_gps: bool,
|
|
pub video_fps: f32,
|
|
pub video_jitter_ms: f32,
|
|
pub video_dropped: u64,
|
|
}
|
|
|
|
impl Default for OsdExtraOptions {
|
|
fn default() -> Self {
|
|
Self {
|
|
battery_cells: 0,
|
|
battery_warn_cell_v: 3.5,
|
|
battery_crit_cell_v: 3.3,
|
|
show_video_stats: true,
|
|
show_gps: true,
|
|
video_fps: 0.0,
|
|
video_jitter_ms: 0.0,
|
|
video_dropped: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Moteur d'incrustation graphique OSD (HUD vectoriel + police bitmap 5x7 avec contour)
|
|
pub struct OsdOverlay;
|
|
|
|
impl OsdOverlay {
|
|
fn draw_heading_ribbon(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
heading_deg: f32,
|
|
y: i32,
|
|
scale: u32,
|
|
) {
|
|
let cx = width as i32 / 2;
|
|
let norm_hdg = if heading_deg.is_finite() {
|
|
heading_deg.rem_euclid(360.0)
|
|
} else {
|
|
0.0
|
|
};
|
|
let card_label = match norm_hdg.round() as i32 {
|
|
338..=360 | 0..=22 => "N",
|
|
23..=67 => "NE",
|
|
68..=112 => "E",
|
|
113..=157 => "SE",
|
|
158..=202 => "S",
|
|
203..=247 => "SW",
|
|
248..=292 => "W",
|
|
293..=337 => "NW",
|
|
_ => "N",
|
|
};
|
|
let mut hdg_buf = StackStr::<32>::new();
|
|
let _ = write!(hdg_buf, "{:03}° {}", norm_hdg.round() as i32, card_label);
|
|
let char_count = hdg_buf.as_str().chars().count() as i32;
|
|
let hx = cx - ((char_count * 6 * scale as i32) / 2);
|
|
Self::draw_text(rgba, width, height, hx, y, hdg_buf.as_str(), scale, [210, 230, 255, 240]);
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub fn render(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
telem: &TelemetryState,
|
|
g29: &G29State,
|
|
head_pan_deg: f32,
|
|
head_tilt_deg: f32,
|
|
head_roll_deg: f32,
|
|
max_pan_deg: f32,
|
|
max_tilt_deg: f32,
|
|
projection_label: &str,
|
|
dvr_recording: bool,
|
|
dvr_elapsed_secs: u64,
|
|
extra: &OsdExtraOptions,
|
|
) {
|
|
let scale = (height / 360).max(2);
|
|
|
|
// Indicateur d'enregistrement DVR en direct
|
|
if dvr_recording {
|
|
let mins = dvr_elapsed_secs / 60;
|
|
let secs = dvr_elapsed_secs % 60;
|
|
let mut rec_buf = StackStr::<32>::new();
|
|
let _ = write!(rec_buf, "* REC {:02}:{:02}", mins, secs);
|
|
Self::draw_text(rgba, width, height, 32, 12, rec_buf.as_str(), scale, [255, 45, 45, 255]);
|
|
}
|
|
|
|
// État de la connexion télémétrie (Attente / Perte) OU Ruban de Cap en haut-centre (sans superposition)
|
|
let top_center_y = 10;
|
|
let top_center_bottom = top_center_y + (7 * scale as i32);
|
|
if telem.packets_received == 0 {
|
|
let wait_text = "WAIT TELEM";
|
|
let wx = (width as i32 / 2) - ((wait_text.chars().count() as i32 * 6 * scale as i32) / 2);
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
wx,
|
|
top_center_y,
|
|
wait_text,
|
|
scale,
|
|
[255, 210, 50, 255],
|
|
);
|
|
} else if !telem.is_live() {
|
|
let lost_text = "! TELEM LOST !";
|
|
let lx = (width as i32 / 2) - ((lost_text.chars().count() as i32 * 6 * scale as i32) / 2);
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
lx,
|
|
top_center_y,
|
|
lost_text,
|
|
scale,
|
|
[255, 60, 60, 255],
|
|
);
|
|
// Mode « Véhicule Perdu » : afficher immédiatement la dernière position GPS valide connue
|
|
if extra.show_gps {
|
|
if let Some((lat, lon, _, sats)) = telem.last_valid_gps {
|
|
let mut last_gps_buf = StackStr::<64>::new();
|
|
let _ = write!(last_gps_buf, "LAST GPS {:.5},{:.5} ({}S)", lat, lon, sats);
|
|
let gx = (width as i32 / 2)
|
|
- ((last_gps_buf.as_str().chars().count() as i32 * 6 * scale as i32) / 2);
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
gx,
|
|
top_center_bottom + 2,
|
|
last_gps_buf.as_str(),
|
|
scale,
|
|
[255, 200, 50, 255],
|
|
);
|
|
}
|
|
}
|
|
} else {
|
|
Self::draw_heading_ribbon(
|
|
rgba,
|
|
width,
|
|
height,
|
|
telem.drone_heading_deg,
|
|
top_center_y,
|
|
scale,
|
|
);
|
|
}
|
|
|
|
let cell_v_opt = telem.cell_voltage_v(extra.battery_cells);
|
|
let eff_cells = telem.effective_cells(extra.battery_cells);
|
|
let bat_color = if let Some(cv) = cell_v_opt {
|
|
if cv < extra.battery_crit_cell_v {
|
|
[255, 65, 65, 255]
|
|
} else if cv < extra.battery_warn_cell_v {
|
|
[255, 200, 45, 255]
|
|
} else {
|
|
[90, 255, 130, 255]
|
|
}
|
|
} else {
|
|
[170, 190, 210, 255]
|
|
};
|
|
|
|
let mut bat_buf = StackStr::<64>::new();
|
|
if let Some(cv) = cell_v_opt {
|
|
if telem.battery_remaining_pct >= 0 {
|
|
let _ = write!(
|
|
bat_buf,
|
|
"BAT {:4.1}V ({}S {:3.2}V/C) {:4.1}A {:3}%",
|
|
telem.battery_voltage_v,
|
|
eff_cells,
|
|
cv,
|
|
telem.battery_current_a,
|
|
telem.battery_remaining_pct
|
|
);
|
|
} else {
|
|
let _ = write!(
|
|
bat_buf,
|
|
"BAT {:4.1}V ({}S {:3.2}V/C) {:4.1}A",
|
|
telem.battery_voltage_v, eff_cells, cv, telem.battery_current_a
|
|
);
|
|
}
|
|
} else if telem.battery_remaining_pct >= 0 {
|
|
let _ = write!(
|
|
bat_buf,
|
|
"BAT {:4.1}V {:4.1}A {:3}%",
|
|
telem.battery_voltage_v, telem.battery_current_a, telem.battery_remaining_pct
|
|
);
|
|
} else {
|
|
let _ = write!(
|
|
bat_buf,
|
|
"BAT {:4.1}V {:4.1}A",
|
|
telem.battery_voltage_v, telem.battery_current_a
|
|
);
|
|
}
|
|
Self::draw_text(rgba, width, height, 32, 28, bat_buf.as_str(), scale, bat_color);
|
|
|
|
// Ligne GPS / Mode de vol CRSF + Flèche Home & distance (si activée et disponible)
|
|
if extra.show_gps && (!telem.flight_mode.is_empty() || telem.gps_sats > 0) {
|
|
let mut gps_buf = StackStr::<64>::new();
|
|
if !telem.flight_mode.is_empty() && telem.gps_sats > 0 {
|
|
let _ = write!(gps_buf, "MODE {} SAT {}", telem.flight_mode, telem.gps_sats);
|
|
} else if !telem.flight_mode.is_empty() {
|
|
let _ = write!(gps_buf, "MODE {}", telem.flight_mode);
|
|
} else {
|
|
let _ = write!(gps_buf, "GPS SAT {}", telem.gps_sats);
|
|
}
|
|
let gps_y = 28 + (9 * scale as i32);
|
|
Self::draw_text(rgba, width, height, 32, gps_y, gps_buf.as_str(), scale, [190, 225, 255, 245]);
|
|
|
|
if let Some((dist_m, rel_deg)) = telem.home_vector() {
|
|
let home_y = gps_y + (9 * scale as i32);
|
|
let arrow_cx = 32 + 6 * scale as i32;
|
|
let arrow_cy = home_y + 4 * scale as i32;
|
|
Self::draw_home_arrow(rgba, width, height, arrow_cx, arrow_cy, rel_deg, scale);
|
|
let mut home_buf = StackStr::<32>::new();
|
|
if dist_m >= 1000.0 {
|
|
let _ = write!(home_buf, "HOME {:4.2}KM", dist_m / 1000.0);
|
|
} else {
|
|
let _ = write!(home_buf, "HOME {:4.0}M", dist_m);
|
|
}
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
arrow_cx + 10 * scale as i32,
|
|
home_y,
|
|
home_buf.as_str(),
|
|
scale,
|
|
[120, 255, 190, 250],
|
|
);
|
|
}
|
|
}
|
|
|
|
let lq_color = if !telem.is_live() || telem.link_quality_pct < 50 {
|
|
[255, 65, 65, 255]
|
|
} else if telem.link_quality_pct < 70 {
|
|
[255, 180, 40, 255]
|
|
} else {
|
|
[100, 225, 255, 255]
|
|
};
|
|
let mut link_buf = StackStr::<48>::new();
|
|
let _ = write!(link_buf, "LQ {:3}% RSSI {:3}DBM", telem.link_quality_pct, telem.rssi_dbm);
|
|
let right_x = width.saturating_sub((link_buf.as_str().chars().count() as u32) * 6 * scale + 32) as i32;
|
|
Self::draw_text(rgba, width, height, right_x, 28, link_buf.as_str(), scale, lq_color);
|
|
|
|
// Ligne compacte de métriques lien vidéo (FPS / Jitter / Drops)
|
|
if extra.show_video_stats && extra.video_fps > 0.5 {
|
|
let mut vid_buf = StackStr::<48>::new();
|
|
let _ = write!(
|
|
vid_buf,
|
|
"VID {:2.0}FPS JIT {:3.1}MS DRP {}",
|
|
extra.video_fps, extra.video_jitter_ms, extra.video_dropped
|
|
);
|
|
let vx = width.saturating_sub((vid_buf.as_str().chars().count() as u32) * 6 * scale + 32) as i32;
|
|
let vy = 28 + (9 * scale as i32);
|
|
let vid_col = if extra.video_jitter_ms > 8.0 {
|
|
[255, 190, 60, 245]
|
|
} else {
|
|
[150, 220, 200, 240]
|
|
};
|
|
Self::draw_text(rgba, width, height, vx, vy, vid_buf.as_str(), scale, vid_col);
|
|
}
|
|
|
|
if extra.show_video_stats && g29.vrx.is_live() {
|
|
let mut vrx_buf = StackStr::<48>::new();
|
|
if g29.vrx.temp_c >= 0.0 {
|
|
let _ = write!(
|
|
vrx_buf,
|
|
"VRX {:2.0}C {}/{}DBM FEC:{}",
|
|
g29.vrx.temp_c, g29.vrx.rssi_a_dbm, g29.vrx.rssi_b_dbm, g29.vrx.fec_lost
|
|
);
|
|
} else {
|
|
let _ = write!(
|
|
vrx_buf,
|
|
"VRX {}/{}DBM FEC:{}",
|
|
g29.vrx.rssi_a_dbm, g29.vrx.rssi_b_dbm, g29.vrx.fec_lost
|
|
);
|
|
}
|
|
let rx = width
|
|
.saturating_sub((vrx_buf.as_str().chars().count() as u32) * 6 * scale + 32)
|
|
as i32;
|
|
let ry = 28 + (18 * scale as i32);
|
|
let vrx_col = if g29.vrx.is_overheating() || g29.vrx.fec_lost > 0 {
|
|
[255, 70, 70, 255]
|
|
} else if g29.vrx.temp_c >= 65.0 {
|
|
[255, 190, 60, 245]
|
|
} else {
|
|
[130, 225, 255, 240]
|
|
};
|
|
Self::draw_text(rgba, width, height, rx, ry, vrx_buf.as_str(), scale, vrx_col);
|
|
}
|
|
|
|
let radar_top = top_center_bottom + 6;
|
|
let radar_bottom = Self::draw_gimbal_radar(
|
|
rgba,
|
|
width,
|
|
height,
|
|
head_pan_deg,
|
|
head_tilt_deg,
|
|
max_pan_deg,
|
|
max_tilt_deg,
|
|
radar_top,
|
|
scale,
|
|
);
|
|
let mut ht_buf = StackStr::<64>::new();
|
|
let _ = write!(
|
|
ht_buf,
|
|
"HT PAN {:+4.0} TILT {:+4.0} ROLL {:+4.0}",
|
|
head_pan_deg, head_tilt_deg, head_roll_deg
|
|
);
|
|
let ht_x = (width as i32 / 2) - ((ht_buf.as_str().chars().count() as i32 * 6 * scale as i32) / 2);
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
ht_x,
|
|
radar_bottom + 6,
|
|
ht_buf.as_str(),
|
|
scale,
|
|
[230, 240, 255, 255],
|
|
);
|
|
|
|
Self::draw_artificial_horizon(
|
|
rgba,
|
|
width,
|
|
height,
|
|
telem.drone_roll_rad,
|
|
telem.drone_pitch_rad,
|
|
);
|
|
|
|
// Inclinomètre numérique (Pitch / Roll en degrés) avec alerte dévers crawler/aile (>= 25° orange, >= 35° rouge)
|
|
if telem.is_live() {
|
|
let pitch_deg = telem.drone_pitch_rad.to_degrees();
|
|
let roll_deg = telem.drone_roll_rad.to_degrees();
|
|
let max_tilt = pitch_deg.abs().max(roll_deg.abs());
|
|
let inc_color = if max_tilt >= 35.0 {
|
|
[255, 60, 60, 255]
|
|
} else if max_tilt >= 25.0 {
|
|
[255, 185, 45, 255]
|
|
} else {
|
|
[180, 230, 255, 220]
|
|
};
|
|
let mut inc_buf = StackStr::<32>::new();
|
|
let _ = write!(inc_buf, "P:{:+3.0}° R:{:+3.0}°", pitch_deg, roll_deg);
|
|
let ix = (width as i32 / 2)
|
|
- ((inc_buf.as_str().chars().count() as i32 * 6 * scale as i32) / 2);
|
|
let iy = (height as i32 / 2) + 52;
|
|
Self::draw_text(rgba, width, height, ix, iy, inc_buf.as_str(), scale, inc_color);
|
|
}
|
|
|
|
let bottom_y = height.saturating_sub(28 + 8 * scale) as i32;
|
|
let spd_kmh = telem.groundspeed_ms * 3.6;
|
|
let mut left_bottom_buf = StackStr::<48>::new();
|
|
let _ = write!(left_bottom_buf, "SPD {:4.1}KM/H THR {:3}%", spd_kmh, telem.throttle_pct);
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
32,
|
|
bottom_y,
|
|
left_bottom_buf.as_str(),
|
|
scale,
|
|
[240, 240, 240, 255],
|
|
);
|
|
|
|
let mut right_bottom_buf = StackStr::<64>::new();
|
|
let _ = write!(
|
|
right_bottom_buf,
|
|
"ALT {:5.1}M VSI {:+4.1}M/S [{}]",
|
|
telem.altitude_m, telem.climb_ms, projection_label
|
|
);
|
|
let rb_x = width.saturating_sub((right_bottom_buf.as_str().len() as u32) * 6 * scale + 32) as i32;
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
rb_x,
|
|
bottom_y,
|
|
right_bottom_buf.as_str(),
|
|
scale,
|
|
[240, 240, 240, 255],
|
|
);
|
|
|
|
Self::draw_g29_hud(rgba, width, height, g29, scale, bottom_y);
|
|
}
|
|
|
|
/// Mini-barre discrète affichée dans le casque au démarrage ou en l'absence de signal VRX.
|
|
pub fn render_vr_standby_bar(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
has_video_stream: bool,
|
|
control_source: ControlSource,
|
|
dvr_recording: bool,
|
|
) {
|
|
let scale = (height / 360).max(1);
|
|
let s = scale as i32;
|
|
let char_w = 6 * s;
|
|
|
|
let mut bar_buf = StackStr::<64>::new();
|
|
let vrx_lbl = if has_video_stream { "VRX OK" } else { "VRX ATTENTE" };
|
|
let src_lbl = match control_source {
|
|
ControlSource::G29 => "G29",
|
|
ControlSource::SteamController => "STEAM",
|
|
};
|
|
let dvr_lbl = if dvr_recording { " | REC" } else { "" };
|
|
let _ = write!(
|
|
bar_buf,
|
|
"{} | CTRL: {}{} | MENU: OPT/VIEW/MENU",
|
|
vrx_lbl, src_lbl, dvr_lbl
|
|
);
|
|
|
|
let text = bar_buf.as_str();
|
|
let text_w = text.chars().count() as i32 * char_w;
|
|
let pad_x = 10 * s;
|
|
let bar_w = (text_w + pad_x * 2).min(width as i32 - 16);
|
|
let bar_h = 15 * s;
|
|
let bx = (width as i32 - bar_w) / 2;
|
|
let by = (height as i32) - bar_h - 14 * s;
|
|
|
|
Self::darken_rect(rgba, width, height, bx, by, bar_w, bar_h, [8, 14, 24]);
|
|
Self::draw_rect_outline(
|
|
rgba,
|
|
width,
|
|
height,
|
|
bx,
|
|
by,
|
|
bar_w,
|
|
bar_h,
|
|
if has_video_stream {
|
|
[0, 220, 255, 255]
|
|
} else {
|
|
[255, 180, 40, 255]
|
|
},
|
|
);
|
|
let tx = bx + (bar_w - text_w) / 2;
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
tx.max(bx + 4),
|
|
by + 4 * s,
|
|
text,
|
|
scale,
|
|
[225, 240, 255, 255],
|
|
);
|
|
}
|
|
|
|
/// Dessine le Menu Minimaliste VR superposé (navigable au Volant G29, Steam Controller et Contrôleurs OpenXR).
|
|
pub fn render_vr_menu(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
menu: &VrMenuRenderData,
|
|
) {
|
|
let scale = (height / 360).max(1);
|
|
let s = scale as i32;
|
|
let char_w = 6 * s;
|
|
let row_h = 12 * s;
|
|
let item_count = menu.page.item_count();
|
|
|
|
let panel_w = (304 * s).min(width as i32 - 16).max(180);
|
|
let header_h = 18 * s;
|
|
let footer_h = 20 * s;
|
|
let panel_h = (header_h + (item_count as i32 * row_h) + footer_h)
|
|
.min(height as i32 - 12);
|
|
|
|
let px0 = (width as i32 - panel_w) / 2;
|
|
let py0 = (height as i32 - panel_h) / 2;
|
|
|
|
// 1. Fond assombri translucide haute lisibilité (assombrissement 75% + teinte cockpit bleu nuit)
|
|
Self::darken_rect(rgba, width, height, px0, py0, panel_w, panel_h, [6, 10, 18]);
|
|
|
|
// Bandeau titre supérieur
|
|
Self::fill_rect(
|
|
rgba,
|
|
width,
|
|
height,
|
|
px0 + 1,
|
|
py0 + 1,
|
|
panel_w - 2,
|
|
header_h - 2,
|
|
[12, 28, 46, 255],
|
|
);
|
|
|
|
// Double bordure cyan lumineuse
|
|
Self::draw_rect_outline(
|
|
rgba,
|
|
width,
|
|
height,
|
|
px0,
|
|
py0,
|
|
panel_w,
|
|
panel_h,
|
|
[0, 229, 255, 255],
|
|
);
|
|
Self::draw_rect_outline(
|
|
rgba,
|
|
width,
|
|
height,
|
|
px0 + 2,
|
|
py0 + 2,
|
|
panel_w - 4,
|
|
panel_h - 4,
|
|
[25, 75, 110, 255],
|
|
);
|
|
|
|
let title = match menu.page {
|
|
VrMenuPage::Main => "[ STEAMFRAME VR MENU ]",
|
|
VrMenuPage::Advanced => "[ MENU VR : AVANCE ]",
|
|
};
|
|
let title_x = px0 + (panel_w - (title.len() as i32 * char_w)) / 2;
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
title_x.max(px0 + 6),
|
|
py0 + 5 * s,
|
|
title,
|
|
scale,
|
|
[0, 235, 255, 255],
|
|
);
|
|
|
|
let selected = menu.selected_idx % item_count;
|
|
|
|
for idx in 0..item_count {
|
|
let ry = py0 + header_h + (idx as i32 * row_h);
|
|
if ry + row_h > py0 + panel_h - footer_h + 2 {
|
|
break;
|
|
}
|
|
let is_sel = idx == selected;
|
|
if is_sel {
|
|
let is_quit_row = menu.page == VrMenuPage::Main && idx == VR_MENU_MAIN_COUNT - 1;
|
|
let row_bg = if is_quit_row && menu.quit_confirm_pending {
|
|
[120, 24, 24, 255]
|
|
} else {
|
|
[20, 58, 86, 255]
|
|
};
|
|
Self::fill_rect(
|
|
rgba,
|
|
width,
|
|
height,
|
|
px0 + 4,
|
|
ry,
|
|
panel_w - 8,
|
|
row_h - 1,
|
|
row_bg,
|
|
);
|
|
}
|
|
|
|
let mut label_buf = StackStr::<32>::new();
|
|
let mut val_buf = StackStr::<32>::new();
|
|
let prefix = if is_sel { "> " } else { " " };
|
|
|
|
let val_color = match (menu.page, idx) {
|
|
// --- PAGE PRINCIPALE MINIMALISTE (9 entrées) ---
|
|
(VrMenuPage::Main, 0) => {
|
|
let _ = write!(label_buf, "{}PROFIL VEHICULE", prefix);
|
|
let raw = menu.profile_name.as_str();
|
|
if raw.is_empty() {
|
|
let _ = write!(val_buf, "< DEFAUT >");
|
|
} else {
|
|
let _ = write!(val_buf, "< ");
|
|
for c in raw.chars().take(16) {
|
|
let _ = write!(val_buf, "{}", c.to_ascii_uppercase());
|
|
}
|
|
let _ = write!(val_buf, " >");
|
|
}
|
|
[110, 255, 175, 255]
|
|
}
|
|
(VrMenuPage::Main, 1) => {
|
|
let _ = write!(label_buf, "{}SOURCE PILOTAGE", prefix);
|
|
let src_lbl = match menu.control_source {
|
|
ControlSource::G29 => "< G29 VOLANT >",
|
|
ControlSource::SteamController => "< STEAM CTRL >",
|
|
};
|
|
let _ = write!(val_buf, "{}", src_lbl);
|
|
[255, 190, 60, 255]
|
|
}
|
|
(VrMenuPage::Main, 2) => {
|
|
let _ = write!(label_buf, "{}CENTRER VUE HT", prefix);
|
|
let _ = write!(val_buf, "[ TARE ]");
|
|
[0, 235, 255, 255]
|
|
}
|
|
(VrMenuPage::Main, 3) => {
|
|
let _ = write!(label_buf, "{}PROJECTION VR", prefix);
|
|
let _ = write!(val_buf, "< {} >", menu.projection_label);
|
|
[100, 225, 255, 255]
|
|
}
|
|
(VrMenuPage::Main, 4) => {
|
|
let _ = write!(label_buf, "{}DISTANCE ECRAN", prefix);
|
|
let _ = write!(val_buf, "< {:.1} M >", menu.screen_distance_m);
|
|
[235, 240, 250, 255]
|
|
}
|
|
(VrMenuPage::Main, 5) => {
|
|
let _ = write!(label_buf, "{}OSD TELEMETRIE", prefix);
|
|
let _ = write!(
|
|
val_buf,
|
|
"{}",
|
|
if menu.telemetry_osd_on { "< ON >" } else { "< OFF >" }
|
|
);
|
|
if menu.telemetry_osd_on {
|
|
[90, 255, 130, 255]
|
|
} else {
|
|
[160, 175, 195, 255]
|
|
}
|
|
}
|
|
(VrMenuPage::Main, 6) => {
|
|
let _ = write!(label_buf, "{}ENREGISTREUR DVR", prefix);
|
|
let _ = write!(
|
|
val_buf,
|
|
"{}",
|
|
if menu.dvr_recording { "< REC >" } else { "< STOP >" }
|
|
);
|
|
if menu.dvr_recording {
|
|
[255, 70, 70, 255]
|
|
} else {
|
|
[180, 190, 205, 255]
|
|
}
|
|
}
|
|
(VrMenuPage::Main, 7) => {
|
|
let _ = write!(label_buf, "{}REGLAGES AVANCES", prefix);
|
|
let _ = write!(val_buf, "[ OUVRIR > ]");
|
|
[160, 215, 255, 255]
|
|
}
|
|
(VrMenuPage::Main, _) => {
|
|
let _ = write!(label_buf, "{}QUITTER L'APP", prefix);
|
|
if menu.quit_confirm_pending {
|
|
let _ = write!(val_buf, "[ CONFIRMER ! ]");
|
|
[255, 80, 80, 255]
|
|
} else {
|
|
let _ = write!(val_buf, "[ FERMER ]");
|
|
[255, 130, 120, 255]
|
|
}
|
|
}
|
|
// --- SOUS-MENU AVANCÉ (9 entrées) ---
|
|
(VrMenuPage::Advanced, 0) => {
|
|
let _ = write!(label_buf, "{}< RETOUR MENU", prefix);
|
|
let _ = write!(val_buf, "[ B / RETOUR ]");
|
|
[0, 235, 255, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 1) => {
|
|
let _ = write!(label_buf, "{}ANCRAGE VR", prefix);
|
|
let _ = write!(val_buf, "< {} >", menu.vr_lock_label);
|
|
[100, 225, 255, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 2) => {
|
|
let _ = write!(label_buf, "{}AMORTI SMOOTH", prefix);
|
|
let _ = write!(val_buf, "< {}% >", menu.vr_hud_smoothing_pct);
|
|
[235, 240, 250, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 3) => {
|
|
let _ = write!(label_buf, "{}SUIVI TETE (HT)", prefix);
|
|
let _ = write!(
|
|
val_buf,
|
|
"{}",
|
|
if menu.head_tracking_on { "< ON >" } else { "< OFF >" }
|
|
);
|
|
if menu.head_tracking_on {
|
|
[90, 255, 130, 255]
|
|
} else {
|
|
[160, 175, 195, 255]
|
|
}
|
|
}
|
|
(VrMenuPage::Advanced, 4) => {
|
|
let _ = write!(label_buf, "{}CORRECTION K1", prefix);
|
|
let _ = write!(val_buf, "< {:+.2} >", menu.lens_k1);
|
|
[235, 240, 250, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 5) => {
|
|
let _ = write!(label_buf, "{}FOV CAMERA", prefix);
|
|
let _ = write!(val_buf, "< {:.0}° >", menu.camera_fov_deg);
|
|
[235, 240, 250, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 6) => {
|
|
let _ = write!(label_buf, "{}PLAFOND 3E VIT.", prefix);
|
|
let _ = write!(val_buf, "< {} >", menu.gear_3_max);
|
|
[255, 190, 60, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 7) => {
|
|
let _ = write!(label_buf, "{}VIBRATIONS SC", prefix);
|
|
let _ = write!(val_buf, "< {}% >", menu.vibration_pct);
|
|
[100, 225, 255, 255]
|
|
}
|
|
(VrMenuPage::Advanced, 8) => {
|
|
let _ = write!(label_buf, "{}ALERTES AUDIO", prefix);
|
|
if menu.audio_alerts_on && menu.audio_volume_pct > 0 {
|
|
let _ = write!(val_buf, "< {}% >", menu.audio_volume_pct);
|
|
[90, 255, 130, 255]
|
|
} else {
|
|
let _ = write!(val_buf, "< OFF >");
|
|
[160, 175, 195, 255]
|
|
}
|
|
}
|
|
(VrMenuPage::Advanced, _) => {
|
|
let _ = write!(label_buf, "{}CANAL RADXA 5.8G", prefix);
|
|
let _ = write!(val_buf, "< CH {} >", menu.wifi_channel);
|
|
[255, 190, 60, 255]
|
|
}
|
|
};
|
|
|
|
let lbl_color = if is_sel {
|
|
[255, 255, 255, 255]
|
|
} else {
|
|
[195, 210, 228, 255]
|
|
};
|
|
let text_y = ry + 3 * s;
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
px0 + 8 * s,
|
|
text_y,
|
|
label_buf.as_str(),
|
|
scale,
|
|
lbl_color,
|
|
);
|
|
|
|
let vx = (px0 + panel_w - 8 * s) - (val_buf.as_str().chars().count() as i32 * char_w);
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
vx.max(px0 + panel_w / 2),
|
|
text_y,
|
|
val_buf.as_str(),
|
|
scale,
|
|
val_color,
|
|
);
|
|
}
|
|
|
|
// Pied du menu : message de retour (erreur d'armement / confirmation) ou aide touches
|
|
let footer_y = py0 + panel_h - footer_h + 6 * s;
|
|
if let Some((msg_buf, is_err)) = menu.feedback_msg {
|
|
let msg = msg_buf.as_str();
|
|
let color = if is_err {
|
|
[255, 75, 75, 255]
|
|
} else {
|
|
[90, 255, 130, 255]
|
|
};
|
|
let fx = px0 + (panel_w - (msg.chars().count() as i32 * char_w)) / 2;
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
fx.max(px0 + 6),
|
|
footer_y,
|
|
msg,
|
|
scale,
|
|
color,
|
|
);
|
|
} else {
|
|
let help = match menu.page {
|
|
VrMenuPage::Main => "STICK/DPAD:CHOIX A/G/D:REGLER B:FERMER",
|
|
VrMenuPage::Advanced => "G/D:CHANGER A:APPLIQUER B:RETOUR MENU",
|
|
};
|
|
let hx = px0 + (panel_w - (help.len() as i32 * char_w)) / 2;
|
|
Self::draw_text(
|
|
rgba,
|
|
width,
|
|
height,
|
|
hx.max(px0 + 6),
|
|
footer_y,
|
|
help,
|
|
scale,
|
|
[150, 180, 210, 255],
|
|
);
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn darken_rect(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
x: i32,
|
|
y: i32,
|
|
w: i32,
|
|
h: i32,
|
|
tint: [u8; 3],
|
|
) {
|
|
let x0 = x.clamp(0, width as i32) as u32;
|
|
let y0 = y.clamp(0, height as i32) as u32;
|
|
let x1 = (x + w).clamp(0, width as i32) as u32;
|
|
let y1 = (y + h).clamp(0, height as i32) as u32;
|
|
for row in y0..y1 {
|
|
let row_start = (row * width + x0) as usize * 4;
|
|
let row_end = (row * width + x1) as usize * 4;
|
|
if row_end <= rgba.len() {
|
|
for px in rgba[row_start..row_end].as_chunks_mut::<4>().0 {
|
|
if px[3] == 0 {
|
|
// Sur couche OpenXR transparente dédiée : fond verre fumé semi-transparent
|
|
px[0] = tint[0];
|
|
px[1] = tint[1];
|
|
px[2] = tint[2];
|
|
px[3] = 215;
|
|
} else {
|
|
px[0] = (px[0] >> 2).saturating_add(tint[0]);
|
|
px[1] = (px[1] >> 2).saturating_add(tint[1]);
|
|
px[2] = (px[2] >> 2).saturating_add(tint[2]);
|
|
px[3] = 255;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn fill_rect(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
x: i32,
|
|
y: i32,
|
|
w: i32,
|
|
h: i32,
|
|
color: [u8; 4],
|
|
) {
|
|
let x0 = x.clamp(0, width as i32) as u32;
|
|
let y0 = y.clamp(0, height as i32) as u32;
|
|
let x1 = (x + w).clamp(0, width as i32) as u32;
|
|
let y1 = (y + h).clamp(0, height as i32) as u32;
|
|
for row in y0..y1 {
|
|
let row_start = (row * width + x0) as usize * 4;
|
|
let row_end = (row * width + x1) as usize * 4;
|
|
if row_end <= rgba.len() {
|
|
for px in rgba[row_start..row_end].as_chunks_mut::<4>().0 {
|
|
px.copy_from_slice(&color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn draw_g29_hud(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
g29: &G29State,
|
|
scale: u32,
|
|
bottom_y: i32,
|
|
) {
|
|
if let Some(toast) = g29.active_toast() {
|
|
let mut toast_buf = StackStr::<32>::new();
|
|
let _ = write!(toast_buf, "[ {} ]", toast);
|
|
let tx = (width as i32 / 2) - ((toast_buf.as_str().len() as i32 * 6 * scale as i32) / 2);
|
|
let ty = 48 + 46 * scale as i32 / 2;
|
|
Self::draw_text(rgba, width, height, tx, ty, toast_buf.as_str(), scale, [255, 230, 80, 255]);
|
|
}
|
|
|
|
if g29.packets_received == 0 && !g29.connected {
|
|
return;
|
|
}
|
|
|
|
let gear_y = bottom_y - (12 * scale as i32);
|
|
let gear_color = match g29.gear {
|
|
-1 => [255, 70, 70, 255], // R : Rouge
|
|
0 => [255, 165, 40, 255], // N : Orange
|
|
1 => [80, 240, 255, 255], // 1 : Cyan
|
|
2 => [90, 255, 120, 255], // 2 : Vert
|
|
3 => [200, 110, 255, 255], // 3 : Violet
|
|
_ => [220, 220, 220, 255],
|
|
};
|
|
|
|
let mut gear_buf = StackStr::<12>::new();
|
|
let _ = write!(gear_buf, "[{}]", g29.gear_label());
|
|
Self::draw_text(rgba, width, height, 32, gear_y, gear_buf.as_str(), scale, gear_color);
|
|
|
|
let is_steam = g29.remote_source == ControlSource::SteamController;
|
|
let (arm_lbl, arm_color) = if !g29.is_live() || g29.failsafe {
|
|
(
|
|
if is_steam { "SC FAIL" } else { "G29 FAIL" },
|
|
[255, 65, 65, 255],
|
|
)
|
|
} else if g29.armed {
|
|
(
|
|
if is_steam { "SC ARMED" } else { "ARMED" },
|
|
[90, 255, 120, 255],
|
|
)
|
|
} else {
|
|
(
|
|
if is_steam { "SC SAFE" } else { "SAFE" },
|
|
[255, 180, 50, 255],
|
|
)
|
|
};
|
|
let arm_x = 32 + (4 * 6 * scale as i32);
|
|
Self::draw_text(rgba, width, height, arm_x, gear_y, arm_lbl, scale, arm_color);
|
|
|
|
let mut pedal_buf = StackStr::<32>::new();
|
|
let _ = write!(pedal_buf, "GAZ {:3}% FRN {:3}%", g29.throttle_pct, g29.brake_pct);
|
|
let pedal_x = arm_x + ((arm_lbl.len() as i32 + 2) * 6 * scale as i32);
|
|
Self::draw_text(rgba, width, height, pedal_x, gear_y, pedal_buf.as_str(), scale, [230, 235, 245, 255]);
|
|
}
|
|
|
|
/// Dessine une flèche vectorielle directionnelle vers le point Home (0° = haut, +90° = droite).
|
|
fn draw_home_arrow(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
cx: i32,
|
|
cy: i32,
|
|
rel_deg: f32,
|
|
scale: u32,
|
|
) {
|
|
let r = (5 * scale as i32) as f32;
|
|
let rad = rel_deg.to_radians();
|
|
let sin_a = rad.sin();
|
|
let cos_a = rad.cos();
|
|
// Pointe de flèche (0° = vers le haut -> dx=sin, dy=-cos)
|
|
let tip_x = cx + (sin_a * r).round() as i32;
|
|
let tip_y = cy - (cos_a * r).round() as i32;
|
|
let tail_x = cx - (sin_a * r * 0.8).round() as i32;
|
|
let tail_y = cy + (cos_a * r * 0.8).round() as i32;
|
|
// Deux ailettes à ±140°
|
|
let wing_l = (rel_deg - 140.0).to_radians();
|
|
let wing_r = (rel_deg + 140.0).to_radians();
|
|
let lx = cx + (wing_l.sin() * r * 0.75).round() as i32;
|
|
let ly = cy - (wing_l.cos() * r * 0.75).round() as i32;
|
|
let rx = cx + (wing_r.sin() * r * 0.75).round() as i32;
|
|
let ry = cy - (wing_r.cos() * r * 0.75).round() as i32;
|
|
|
|
let col = [100, 255, 180, 255];
|
|
Self::draw_line(rgba, width, height, tail_x, tail_y, tip_x, tip_y, col);
|
|
Self::draw_line(rgba, width, height, tip_x, tip_y, lx, ly, col);
|
|
Self::draw_line(rgba, width, height, tip_x, tip_y, rx, ry, col);
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn draw_gimbal_radar(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
pan_deg: f32,
|
|
tilt_deg: f32,
|
|
max_pan: f32,
|
|
max_tilt: f32,
|
|
top_y: i32,
|
|
scale: u32,
|
|
) -> i32 {
|
|
let box_w = (44 * scale) as i32;
|
|
let box_h = (24 * scale) as i32;
|
|
let cx = width as i32 / 2;
|
|
let cy = top_y + box_h / 2;
|
|
|
|
Self::draw_rect_outline(
|
|
rgba,
|
|
width,
|
|
height,
|
|
cx - box_w / 2,
|
|
cy - box_h / 2,
|
|
box_w,
|
|
box_h,
|
|
[160, 190, 220, 220],
|
|
);
|
|
|
|
Self::draw_line(
|
|
rgba,
|
|
width,
|
|
height,
|
|
cx - 4,
|
|
cy,
|
|
cx + 4,
|
|
cy,
|
|
[100, 120, 140, 200],
|
|
);
|
|
Self::draw_line(
|
|
rgba,
|
|
width,
|
|
height,
|
|
cx,
|
|
cy - 4,
|
|
cx,
|
|
cy + 4,
|
|
[100, 120, 140, 200],
|
|
);
|
|
|
|
let norm_x = (pan_deg / max_pan.max(1.0)).clamp(-1.0, 1.0);
|
|
let norm_y = (-tilt_deg / max_tilt.max(1.0)).clamp(-1.0, 1.0);
|
|
let dot_x = cx + (norm_x * (box_w as f32 * 0.44)) as i32;
|
|
let dot_y = cy + (norm_y * (box_h as f32 * 0.42)) as i32;
|
|
|
|
let r = (2 * scale as i32).max(3);
|
|
for dy in -r..=r {
|
|
for dx in -r..=r {
|
|
if dx * dx + dy * dy <= r * r {
|
|
Self::put_pixel(rgba, width, height, dot_x + dx, dot_y + dy, [0, 255, 180, 255]);
|
|
}
|
|
}
|
|
}
|
|
top_y + box_h
|
|
}
|
|
|
|
fn draw_artificial_horizon(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
roll_rad: f32,
|
|
pitch_rad: f32,
|
|
) {
|
|
if !roll_rad.is_finite() || !pitch_rad.is_finite() {
|
|
return;
|
|
}
|
|
let cx = width as i32 / 2;
|
|
let cy = height as i32 / 2;
|
|
let max_offset = height as i32;
|
|
let pitch_offset = ((pitch_rad.to_degrees() * (height as f32 / 70.0)) as i32)
|
|
.clamp(-max_offset, max_offset);
|
|
|
|
let cos_r = (-roll_rad).cos();
|
|
let sin_r = (-roll_rad).sin();
|
|
let half_span = (width as f32 * 0.14) as i32;
|
|
let gap = (width as f32 * 0.03) as i32;
|
|
|
|
for &(r0, r1) in &[(-half_span, -gap), (gap, half_span)] {
|
|
let x0 = cx + (r0 as f32 * cos_r) as i32;
|
|
let y0 = cy + pitch_offset + (r0 as f32 * sin_r) as i32;
|
|
let x1 = cx + (r1 as f32 * cos_r) as i32;
|
|
let y1 = cy + pitch_offset + (r1 as f32 * sin_r) as i32;
|
|
Self::draw_line(rgba, width, height, x0, y0, x1, y1, [0, 255, 160, 220]);
|
|
Self::draw_line(rgba, width, height, x0, y0 + 1, x1, y1 + 1, [0, 80, 50, 200]);
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn draw_rect_outline(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
x: i32,
|
|
y: i32,
|
|
w: i32,
|
|
h: i32,
|
|
color: [u8; 4],
|
|
) {
|
|
Self::draw_line(rgba, width, height, x, y, x + w, y, color);
|
|
Self::draw_line(rgba, width, height, x, y + h, x + w, y + h, color);
|
|
Self::draw_line(rgba, width, height, x, y, x, y + h, color);
|
|
Self::draw_line(rgba, width, height, x + w, y, x + w, y + h, color);
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
fn draw_line(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
mut x0: i32,
|
|
mut y0: i32,
|
|
x1: i32,
|
|
y1: i32,
|
|
color: [u8; 4],
|
|
) {
|
|
let w = width as i32;
|
|
let h = height as i32;
|
|
// Rejet rapide hors-cadre (évite toute boucle longue sur coordonnées extrêmes)
|
|
if (x0 < 0 && x1 < 0) || (x0 >= w && x1 >= w) || (y0 < 0 && y1 < 0) || (y0 >= h && y1 >= h)
|
|
{
|
|
return;
|
|
}
|
|
let dx = x1.saturating_sub(x0).saturating_abs();
|
|
let sx = if x0 < x1 { 1 } else { -1 };
|
|
let dy = -y1.saturating_sub(y0).saturating_abs();
|
|
let sy = if y0 < y1 { 1 } else { -1 };
|
|
let mut err = dx.saturating_add(dy);
|
|
let max_steps = (w + h).saturating_mul(2).max(16) as u32;
|
|
|
|
for _ in 0..max_steps {
|
|
Self::put_pixel(rgba, width, height, x0, y0, color);
|
|
if x0 == x1 && y0 == y1 {
|
|
break;
|
|
}
|
|
let e2 = err.saturating_mul(2);
|
|
if e2 >= dy {
|
|
err = err.saturating_add(dy);
|
|
x0 = x0.saturating_add(sx);
|
|
}
|
|
if e2 <= dx {
|
|
err = err.saturating_add(dx);
|
|
y0 = y0.saturating_add(sy);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
fn put_pixel(rgba: &mut [u8], width: u32, height: u32, x: i32, y: i32, color: [u8; 4]) {
|
|
if x >= 0 && y >= 0 && (x as u32) < width && (y as u32) < height {
|
|
let idx = ((y as u32 * width + x as u32) * 4) as usize;
|
|
if idx + 3 < rgba.len() {
|
|
rgba[idx] = color[0];
|
|
rgba[idx + 1] = color[1];
|
|
rgba[idx + 2] = color[2];
|
|
rgba[idx + 3] = color[3];
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub fn draw_text(
|
|
rgba: &mut [u8],
|
|
width: u32,
|
|
height: u32,
|
|
x: i32,
|
|
y: i32,
|
|
text: &str,
|
|
scale: u32,
|
|
color: [u8; 4],
|
|
) {
|
|
let s = scale.max(1) as i32;
|
|
for (i, ch) in text.chars().enumerate() {
|
|
let glyph = Self::glyph_5x7(ch);
|
|
let gx = x + (i as i32) * 6 * s;
|
|
for (row_idx, &row_bits) in glyph.iter().enumerate() {
|
|
for col_idx in 0..5 {
|
|
if (row_bits & (1 << (4 - col_idx))) != 0 {
|
|
let px = gx + col_idx * s;
|
|
let py = y + (row_idx as i32) * s;
|
|
for sy in 0..s {
|
|
for sx in 0..s {
|
|
Self::put_pixel(
|
|
rgba,
|
|
width,
|
|
height,
|
|
px + sx + 2,
|
|
py + sy + 2,
|
|
[0, 0, 0, 220],
|
|
);
|
|
Self::put_pixel(rgba, width, height, px + sx, py + sy, color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn glyph_5x7(c: char) -> [u8; 7] {
|
|
match c.to_ascii_uppercase() {
|
|
'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110],
|
|
'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
|
'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111],
|
|
'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110],
|
|
'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010],
|
|
'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110],
|
|
'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110],
|
|
'7' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b01000, 0b01000],
|
|
'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110],
|
|
'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100],
|
|
'A' => [0b01110, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
|
'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110],
|
|
'C' => [0b01110, 0b10001, 0b10000, 0b10000, 0b10000, 0b10001, 0b01110],
|
|
'D' => [0b11100, 0b10010, 0b10001, 0b10001, 0b10001, 0b10010, 0b11100],
|
|
'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111],
|
|
'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000],
|
|
'G' => [0b01110, 0b10001, 0b10000, 0b10111, 0b10001, 0b10001, 0b01110],
|
|
'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
|
'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
|
'J' => [0b00001, 0b00001, 0b00001, 0b00001, 0b10001, 0b10001, 0b01110],
|
|
'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
|
|
'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
|
|
'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
|
|
'N' => [0b10001, 0b11001, 0b10101, 0b10011, 0b10001, 0b10001, 0b10001],
|
|
'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
|
'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000],
|
|
'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101],
|
|
'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001],
|
|
'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110],
|
|
'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100],
|
|
'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
|
'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
|
|
'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
|
|
'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001],
|
|
'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
|
|
'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111],
|
|
'.' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01100, 0b01100],
|
|
':' => [0b00000, 0b01100, 0b01100, 0b00000, 0b01100, 0b01100, 0b00000],
|
|
'-' => [0b00000, 0b00000, 0b00000, 0b11111, 0b00000, 0b00000, 0b00000],
|
|
'+' => [0b00000, 0b00100, 0b00100, 0b11111, 0b00100, 0b00100, 0b00000],
|
|
'%' => [0b11001, 0b11010, 0b00010, 0b00100, 0b01000, 0b01011, 0b10011],
|
|
'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
|
|
'[' => [0b01110, 0b01000, 0b01000, 0b01000, 0b01000, 0b01000, 0b01110],
|
|
']' => [0b01110, 0b00010, 0b00010, 0b00010, 0b00010, 0b00010, 0b01110],
|
|
'(' => [0b00010, 0b00100, 0b01000, 0b01000, 0b01000, 0b00100, 0b00010],
|
|
')' => [0b01000, 0b00100, 0b00010, 0b00010, 0b00010, 0b00100, 0b01000],
|
|
'!' => [0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00000, 0b00100],
|
|
',' => [0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00100, 0b01000],
|
|
'*' => [0b00000, 0b10101, 0b01110, 0b11111, 0b01110, 0b10101, 0b00000],
|
|
'°' => [0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000],
|
|
'<' => [0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010],
|
|
'>' => [0b01000, 0b00100, 0b00010, 0b00001, 0b00010, 0b00100, 0b01000],
|
|
'=' => [0b00000, 0b00000, 0b11111, 0b00000, 0b11111, 0b00000, 0b00000],
|
|
'\'' => [0b00100, 0b00100, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000],
|
|
'|' => [0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100],
|
|
|
|
_ => [0b00000; 7],
|
|
}
|
|
}
|
|
}
|
|
|