-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to layer architecture (osbook_day09a)
- Loading branch information
Showing
13 changed files
with
708 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,67 @@ | ||
use crate::{ | ||
framebuffer, | ||
graphics::{Color, Draw, Point, Rectangle, Size}, | ||
Result, | ||
layer::{self, Layer, LayerEvent}, | ||
prelude::*, | ||
window::Window, | ||
}; | ||
|
||
pub(crate) const BG_COLOR: Color = Color::new(45, 118, 237); | ||
pub(crate) const FG_COLOR: Color = Color::WHITE; | ||
|
||
pub(crate) fn draw() -> Result<()> { | ||
let screen = *framebuffer::info()?; | ||
let mut drawer = framebuffer::lock_drawer()?; | ||
fn draw(drawer: &mut dyn Draw, size: Size<i32>) { | ||
drawer.fill_rect( | ||
Rectangle::new( | ||
Point::new(0, 0), | ||
Size::new(screen.width, screen.height - 50), | ||
), | ||
Rectangle::new(Point::new(0, 0), Size::new(size.x, size.y - 50)), | ||
BG_COLOR, | ||
); | ||
drawer.fill_rect( | ||
Rectangle::new( | ||
Point::new(0, screen.height - 50), | ||
Size::new(screen.width, 50), | ||
), | ||
Rectangle::new(Point::new(0, size.y - 50), Size::new(size.x, 50)), | ||
Color::new(1, 8, 17), | ||
); | ||
drawer.fill_rect( | ||
Rectangle::new( | ||
Point::new(0, screen.height - 50), | ||
Size::new(screen.width / 5, 50), | ||
), | ||
Rectangle::new(Point::new(0, size.y - 50), Size::new(size.x / 5, 50)), | ||
Color::new(80, 80, 80), | ||
); | ||
drawer.draw_rect( | ||
Rectangle::new(Point::new(10, screen.height - 40), Size::new(30, 30)), | ||
Rectangle::new(Point::new(10, size.y - 40), Size::new(30, 30)), | ||
Color::new(160, 160, 160), | ||
); | ||
Ok(()) | ||
} | ||
|
||
pub(crate) async fn handler_task() { | ||
let res = async { | ||
let screen_info = *framebuffer::info()?; | ||
let window = Window::new(screen_info.size()); | ||
|
||
{ | ||
let drawer = window | ||
.try_lock() | ||
.ok_or(ErrorKind::Deadlock("window"))? | ||
.drawer(); | ||
let mut drawer = drawer | ||
.try_lock() | ||
.ok_or(ErrorKind::Deadlock("window drawer"))?; | ||
draw(&mut *drawer, screen_info.size()); | ||
} | ||
|
||
let mut layer = Layer::new(); | ||
let layer_id = layer.id(); | ||
layer.set_window(Some(window)); | ||
layer.move_to(Point::new(0, 0)); | ||
|
||
let tx = layer::event_tx()?; | ||
tx.send(LayerEvent::Register { layer })?; | ||
tx.send(LayerEvent::SetHeight { | ||
layer_id, | ||
height: layer::DESKTOP_HEIGHT, | ||
})?; | ||
tx.send(LayerEvent::Draw {})?; | ||
|
||
Ok::<(), Error>(()) | ||
} | ||
.await; | ||
|
||
if let Err(err) = res { | ||
panic!("error occurred during handling desktop drawing: {}", err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.