clean os/user codes for graph show
This commit is contained in:
parent
f2635c2dba
commit
2dfd195841
6 changed files with 7 additions and 224 deletions
|
@ -1,8 +1,5 @@
|
|||
use crate::drivers::bus::virtio::VirtioHal;
|
||||
use crate::{
|
||||
gui::{move_rect, reset},
|
||||
sync::UPIntrFreeCell,
|
||||
};
|
||||
use crate::sync::UPIntrFreeCell;
|
||||
use alloc::sync::Arc;
|
||||
use core::any::Any;
|
||||
use virtio_drivers::{VirtIOHeader, VirtIOInput};
|
||||
|
@ -49,21 +46,6 @@ impl InputDevice for VirtIOInputWrapper {
|
|||
virtio_input_decoder::DecodeType::Key(key, r#type) => {
|
||||
if r#type == KeyType::Press {
|
||||
match key {
|
||||
Key::C | Key::MouseLeft => {
|
||||
reset();
|
||||
}
|
||||
Key::W => {
|
||||
move_rect(0, -10);
|
||||
}
|
||||
Key::S => {
|
||||
move_rect(0, 10);
|
||||
}
|
||||
Key::A => {
|
||||
move_rect(-10, 0);
|
||||
}
|
||||
Key::D => {
|
||||
move_rect(10, 0);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
use alloc::sync::Arc;
|
||||
use embedded_graphics::{
|
||||
draw_target::DrawTarget,
|
||||
pixelcolor::Rgb888,
|
||||
prelude::{OriginDimensions, Point, RgbColor, Size},
|
||||
};
|
||||
|
||||
use crate::board::VIRTGPU_XRES;
|
||||
use crate::drivers::{GpuDevice, GPU_DEVICE};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Graphics {
|
||||
pub size: Size,
|
||||
pub point: Point,
|
||||
pub drv: Arc<dyn GpuDevice>,
|
||||
}
|
||||
|
||||
impl Graphics {
|
||||
pub fn new(size: Size, point: Point) -> Self {
|
||||
Self {
|
||||
size,
|
||||
point,
|
||||
drv: GPU_DEVICE.clone(),
|
||||
}
|
||||
}
|
||||
pub fn reset(&self) {
|
||||
let fb = self.drv.get_framebuffer();
|
||||
fb.fill(0u8);
|
||||
}
|
||||
|
||||
pub fn get_framebuffer(&self)-> &mut [u8] {
|
||||
self.drv.get_framebuffer()
|
||||
}
|
||||
}
|
||||
|
||||
impl OriginDimensions for Graphics {
|
||||
fn size(&self) -> Size {
|
||||
self.size
|
||||
}
|
||||
}
|
||||
|
||||
impl DrawTarget for Graphics {
|
||||
type Color = Rgb888;
|
||||
|
||||
type Error = core::convert::Infallible;
|
||||
|
||||
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
|
||||
where
|
||||
I: IntoIterator<Item = embedded_graphics::Pixel<Self::Color>>,
|
||||
{
|
||||
let fb = self.drv.get_framebuffer();
|
||||
|
||||
pixels.into_iter().for_each(|px| {
|
||||
let idx = ((self.point.y + px.0.y) * VIRTGPU_XRES as i32 + self.point.x + px.0.x)
|
||||
as usize
|
||||
* 4;
|
||||
if idx + 2 >= fb.len() {
|
||||
return;
|
||||
}
|
||||
fb[idx] = px.1.b();
|
||||
fb[idx + 1] = px.1.g();
|
||||
fb[idx + 2] = px.1.r();
|
||||
});
|
||||
self.drv.flush();
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
mod graphic;
|
||||
mod paint;
|
||||
|
||||
use graphic::Graphics;
|
||||
pub use paint::{init_paint, move_rect, reset};
|
|
@ -1,69 +0,0 @@
|
|||
use super::Graphics;
|
||||
use crate::sync::UPIntrFreeCell;
|
||||
use embedded_graphics::pixelcolor::Rgb888;
|
||||
use embedded_graphics::prelude::{Drawable, Point, RgbColor, Size};
|
||||
use embedded_graphics::primitives::Primitive;
|
||||
use embedded_graphics::primitives::{PrimitiveStyle, Rectangle};
|
||||
use lazy_static::*;
|
||||
|
||||
const INIT_X: i32 = 640;
|
||||
const INIT_Y: i32 = 400;
|
||||
const RECT_SIZE: u32 = 40;
|
||||
|
||||
pub struct DrawingBoard {
|
||||
graphics: Graphics,
|
||||
latest_pos: Point,
|
||||
}
|
||||
|
||||
impl DrawingBoard {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
graphics: Graphics::new(Size::new(1280, 800), Point::new(0, 0)),
|
||||
latest_pos: Point::new(INIT_X, INIT_Y),
|
||||
}
|
||||
}
|
||||
fn paint(&mut self) {
|
||||
Rectangle::with_center(self.latest_pos, Size::new(RECT_SIZE, RECT_SIZE))
|
||||
.into_styled(PrimitiveStyle::with_stroke(Rgb888::WHITE, 1))
|
||||
.draw(&mut self.graphics)
|
||||
.ok();
|
||||
}
|
||||
fn unpaint(&mut self) {
|
||||
Rectangle::with_center(self.latest_pos, Size::new(RECT_SIZE, RECT_SIZE))
|
||||
.into_styled(PrimitiveStyle::with_stroke(Rgb888::BLACK, 1))
|
||||
.draw(&mut self.graphics)
|
||||
.ok();
|
||||
}
|
||||
pub fn move_rect(&mut self, dx: i32, dy: i32) {
|
||||
self.unpaint();
|
||||
self.latest_pos.x += dx;
|
||||
self.latest_pos.y += dy;
|
||||
self.paint();
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.latest_pos = Point::new(INIT_X, INIT_Y);
|
||||
self.graphics.reset();
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DRAWING_BOARD: UPIntrFreeCell<DrawingBoard> = unsafe { UPIntrFreeCell::new(DrawingBoard::new()) };
|
||||
}
|
||||
|
||||
pub fn init_paint() {
|
||||
DRAWING_BOARD.exclusive_session(|ripple| {
|
||||
ripple.paint();
|
||||
});
|
||||
}
|
||||
|
||||
pub fn move_rect(dx: i32, dy: i32) {
|
||||
DRAWING_BOARD.exclusive_session(|ripple| {
|
||||
ripple.move_rect(dx, dy);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn reset() {
|
||||
DRAWING_BOARD.exclusive_session(|ripple| {
|
||||
ripple.reset();
|
||||
});
|
||||
}
|
|
@ -18,7 +18,6 @@ mod console;
|
|||
mod config;
|
||||
mod drivers;
|
||||
mod fs;
|
||||
mod gui;
|
||||
mod lang_items;
|
||||
mod mm;
|
||||
mod sbi;
|
||||
|
@ -70,7 +69,7 @@ pub fn rust_main() -> ! {
|
|||
timer::set_next_trigger();
|
||||
board::device_init();
|
||||
fs::list_apps();
|
||||
gui::init_paint();
|
||||
//gui::init_paint();
|
||||
task::add_initproc();
|
||||
*DEV_NON_BLOCKING_ACCESS.exclusive_access() = true;
|
||||
task::run_tasks();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue