use std::rc::Rc; use evdev::KeyCode; use slint::LogicalPosition; use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType}; use slint::platform::{Platform, WindowEvent}; use crate::rgba::Rgba; 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, } impl Trekstor { pub fn new() -> Self { let window = MinimalSoftwareWindow::new(RepaintBufferType::ReusedBuffer); Self { window } } } impl Platform for Trekstor { fn create_window_adapter( &self, ) -> Result, 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 = [Rgba::from((0, 0, 0, 0)); 614400]; 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(); } self.window.draw_if_needed(|renderer| { dbg!("Rendering"); renderer.render(&mut buffer1, ctx.screen.width() as usize); // ctx // .screen // .fill_contiguous(&ctx.screen.rect(), buffer1) // .ok(); }); ctx.screen.flush(); ctx.input.finish(); } } }