From 5952f80763cb9bb62b06ebfa313c3a1245930d03 Mon Sep 17 00:00:00 2001 From: nworbnhoj Date: Sun, 22 May 2022 22:06:55 +1000 Subject: [PATCH] add missing modal image.rs --- services/gam/src/modal/image.rs | 62 +++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 services/gam/src/modal/image.rs diff --git a/services/gam/src/modal/image.rs b/services/gam/src/modal/image.rs new file mode 100644 index 000000000..467aee885 --- /dev/null +++ b/services/gam/src/modal/image.rs @@ -0,0 +1,62 @@ +use crate::*; + +#[derive(Debug)] +pub struct Image { + pub action_conn: xous::CID, + pub action_opcode: u32, + pub bitmap: Option, +} + +impl Image { + pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self { + Image { + action_conn, + action_opcode, + bitmap: None, + } + } + pub fn set_bitmap(&mut self, setting: Option) { + self.bitmap = setting; + } +} + +impl ActionApi for Image { + fn set_action_opcode(&mut self, op: u32) { + self.action_opcode = op + } + fn height(&self, _glyph_height: i16, margin: i16) -> i16 { + let bm_height = match &self.bitmap { + Some(bm) => bm.bound.br.y - bm.bound.tl.y, + None => 0, + }; + + log::info!("bitmap height {:?} : margin {}", bm_height, margin); + margin * 2 + bm_height + } + fn redraw(&self, _at_height: i16, modal: &Modal) { + if self.bitmap.is_some() { + //bm.translate(Point::new(0, at_height)); + modal + .gam + .draw_bitmap(modal.canvas, self.bitmap.as_ref().unwrap()) + .expect("couldn't draw bitmap"); + } + } + fn key_action(&mut self, k: char) -> (Option, bool) { + log::trace!("key_action: {}", k); + match k { + '\u{0}' => { + // ignore null messages + } + _ => { + send_message( + self.action_conn, + xous::Message::new_scalar(self.action_opcode as usize, 0, 0, 0, 0), + ) + .expect("couldn't pass on dismissal"); + return (None, true); + } + } + (None, false) + } +}