104 lines
3.1 KiB
Rust
104 lines
3.1 KiB
Rust
use std::rc::Rc;
|
|
|
|
use evdev::KeyCode;
|
|
use linfb::shape::Color;
|
|
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType, Rgb565Pixel};
|
|
use slint::platform::{Platform, WindowEvent};
|
|
use slint::{LogicalPosition, PhysicalSize, Rgb8Pixel, WindowSize};
|
|
|
|
use self::input::InputState;
|
|
use self::screen::Screen;
|
|
|
|
mod input;
|
|
mod screen;
|
|
|
|
pub struct Context {
|
|
pub screen: Screen,
|
|
pub input: InputState,
|
|
}
|
|
|
|
pub struct Trekstor {
|
|
window: Rc<MinimalSoftwareWindow>,
|
|
}
|
|
|
|
impl Trekstor {
|
|
pub fn new() -> Self {
|
|
let window = MinimalSoftwareWindow::new(RepaintBufferType::NewBuffer);
|
|
|
|
Self { window }
|
|
}
|
|
}
|
|
|
|
impl Platform for Trekstor {
|
|
fn create_window_adapter(
|
|
&self,
|
|
) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> {
|
|
Ok(self.window.clone())
|
|
}
|
|
|
|
fn run_event_loop(&self) -> Result<(), slint::PlatformError> {
|
|
let screen = Screen::new();
|
|
let input = InputState::new(&screen);
|
|
let mut ctx = Context { screen, input };
|
|
|
|
let mut buffer1 = [Rgb565Pixel(0); 614400];
|
|
|
|
let window_width = ctx.screen.width();
|
|
let window_height = ctx.screen.height();
|
|
|
|
self.window.set_size(WindowSize::Physical(PhysicalSize::new(
|
|
window_width,
|
|
window_height,
|
|
)));
|
|
|
|
loop {
|
|
ctx.input.handle_event();
|
|
|
|
slint::platform::update_timers_and_animations();
|
|
|
|
if ctx.input.is_just_pressed(KeyCode::BTN_TOUCH) {
|
|
self.window
|
|
.try_dispatch_event(WindowEvent::PointerPressed {
|
|
position: LogicalPosition::new(ctx.input.x as f32, ctx.input.y as f32),
|
|
button: slint::platform::PointerEventButton::Left,
|
|
})
|
|
.unwrap();
|
|
}
|
|
|
|
if ctx.input.is_just_released(KeyCode::BTN_TOUCH) {
|
|
self.window
|
|
.try_dispatch_event(WindowEvent::PointerReleased {
|
|
position: LogicalPosition::new(ctx.input.x as f32, ctx.input.y as f32),
|
|
button: slint::platform::PointerEventButton::Left,
|
|
})
|
|
.unwrap();
|
|
}
|
|
|
|
if ctx.input.is_down(KeyCode::BTN_TOUCH) {
|
|
self.window
|
|
.try_dispatch_event(WindowEvent::PointerMoved {
|
|
position: LogicalPosition::new(ctx.input.x as f32, ctx.input.y as f32),
|
|
})
|
|
.unwrap();
|
|
}
|
|
|
|
self.window.draw_if_needed(|renderer| {
|
|
renderer.render(&mut buffer1, window_width as usize);
|
|
|
|
for (i, px) in buffer1.into_iter().enumerate() {
|
|
let x = (i % window_width as usize) as u32;
|
|
let y = (i / window_width as usize) as u32;
|
|
|
|
let pixel = Rgb8Pixel::from(px);
|
|
let c = Color::from((pixel.r, pixel.g, pixel.b, 255));
|
|
|
|
ctx.screen.framebuffer.set_pixel(x, y, c);
|
|
}
|
|
ctx.screen.flush();
|
|
});
|
|
|
|
ctx.input.finish();
|
|
}
|
|
}
|
|
}
|