mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
recast Image Modal to accept gam::Bitmap directly
This commit is contained in:
parent
278f6e884d
commit
b769b26a57
2 changed files with 16 additions and 35 deletions
|
|
@ -10,6 +10,7 @@ use gam::*;
|
||||||
use num_traits::*;
|
use num_traits::*;
|
||||||
#[cfg(feature = "ditherpunk")]
|
#[cfg(feature = "ditherpunk")]
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
use std::cmp::min;
|
||||||
use xous::{send_message, Message, CID};
|
use xous::{send_message, Message, CID};
|
||||||
use xous_ipc::Buffer;
|
use xous_ipc::Buffer;
|
||||||
|
|
||||||
|
|
@ -194,48 +195,22 @@ impl Modals {
|
||||||
|
|
||||||
/// this blocks until the image has been dismissed.
|
/// this blocks until the image has been dismissed.
|
||||||
#[cfg(feature = "ditherpunk")]
|
#[cfg(feature = "ditherpunk")]
|
||||||
pub fn show_image(&self, img: &Img) -> Result<(), xous::Error> {
|
pub fn show_image(&self, mut bm: Bitmap) -> Result<(), xous::Error> {
|
||||||
self.lock();
|
self.lock();
|
||||||
// resize and/or rotate
|
|
||||||
const BORDER: u32 = 3;
|
|
||||||
|
|
||||||
let (modal_width, modal_height) = (
|
|
||||||
gam::IMG_MODAL_WIDTH - 2 * BORDER,
|
|
||||||
gam::IMG_MODAL_HEIGHT - 2 * BORDER,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (w, h) = (img.width(), img.height());
|
|
||||||
let (img_width, img_height) = (w as f32, h as f32);
|
|
||||||
|
|
||||||
let portrait_scale = (modal_width as f32 / img_width).min(modal_height as f32 / img_height);
|
|
||||||
let landscape_scale =
|
|
||||||
(modal_width as f32 / img_height).min(modal_height as f32 / img_width);
|
|
||||||
let mut bm = if portrait_scale >= 1.0 {
|
|
||||||
log::info!("show image as is");
|
|
||||||
Bitmap::from(img)
|
|
||||||
} else if landscape_scale >= 1.0 {
|
|
||||||
log::info!("rotate image");
|
|
||||||
Bitmap::from(img).rotate90()
|
|
||||||
} else if portrait_scale >= landscape_scale {
|
|
||||||
log::info!("scale image {}", portrait_scale);
|
|
||||||
Bitmap::new_resize(img, (portrait_scale * img_width) as usize)
|
|
||||||
} else {
|
|
||||||
log::info!("scale image {} and rotate", landscape_scale);
|
|
||||||
Bitmap::new_resize(img, (landscape_scale * img_width) as usize).rotate90()
|
|
||||||
};
|
|
||||||
let (bm_width, bm_height) = bm.size();
|
let (bm_width, bm_height) = bm.size();
|
||||||
let (bm_width, bm_height) = (bm_width as u32, bm_height as u32);
|
let (bm_width, bm_height) = (bm_width as u32, bm_height as u32);
|
||||||
|
|
||||||
// center image in modal
|
// center image in modal
|
||||||
let center = Point::new(
|
const BORDER: u32 = 3;
|
||||||
(BORDER + (gam::IMG_MODAL_WIDTH - 2 * BORDER - bm_width) / 2)
|
let margin = Point::new(
|
||||||
|
(BORDER + min(0,(gam::IMG_MODAL_WIDTH - 2 * BORDER - bm_width) / 2))
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(BORDER + (gam::IMG_MODAL_HEIGHT - 2 * BORDER - bm_height) / 2)
|
(BORDER + min(0, (gam::IMG_MODAL_HEIGHT - 2 * BORDER - bm_height) / 2))
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
bm.translate(center);
|
bm.translate(margin);
|
||||||
|
|
||||||
let mut tiles: [Option<Tile>; 6] = [None; 6];
|
let mut tiles: [Option<Tile>; 6] = [None; 6];
|
||||||
for (t, tile) in bm.iter().enumerate() {
|
for (t, tile) in bm.iter().enumerate() {
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,14 @@ pub fn spawn_test() {
|
||||||
*/
|
*/
|
||||||
#[cfg(feature = "ditherpunk")]
|
#[cfg(feature = "ditherpunk")]
|
||||||
{
|
{
|
||||||
let img = clifford();
|
const BORDER: u32 = 3;
|
||||||
|
let modal_size = gam::Point::new(
|
||||||
|
(gam::IMG_MODAL_WIDTH - 2 * BORDER).try_into().unwrap(),
|
||||||
|
(gam::IMG_MODAL_HEIGHT - 2 * BORDER).try_into().unwrap()
|
||||||
|
);
|
||||||
|
let bm = gam::Bitmap::from_img(&clifford(), Some(modal_size));
|
||||||
log::info!("showing image");
|
log::info!("showing image");
|
||||||
modals.show_image(&img).expect("show image modal failed");
|
modals.show_image(bm).expect("show image modal failed");
|
||||||
log::info!("image modal test done");
|
log::info!("image modal test done");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -188,7 +193,8 @@ fn clifford() -> Img {
|
||||||
let (mut x, mut y): (f32, f32) = (0.0, 0.0);
|
let (mut x, mut y): (f32, f32) = (0.0, 0.0);
|
||||||
|
|
||||||
log::info!("generating image");
|
log::info!("generating image");
|
||||||
for _ in 0..=ITERATIONS { // this takes a couple minutes to run
|
for _ in 0..=ITERATIONS {
|
||||||
|
// this takes a couple minutes to run
|
||||||
let x1 = f32::sin(a * y) + c * f32::cos(a * x);
|
let x1 = f32::sin(a * y) + c * f32::cos(a * x);
|
||||||
let y1 = f32::sin(b * x) + d * f32::cos(b * y);
|
let y1 = f32::sin(b * x) + d * f32::cos(b * y);
|
||||||
(x, y) = (x1, y1);
|
(x, y) = (x1, y1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue