2025-10-23 11:25:02 -06:00
|
|
|
mod cursors;
|
|
|
|
|
|
|
|
|
|
pub use cursors::{Cursor, set_cursor};
|
|
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
2025-10-30 14:44:41 -06:00
|
|
|
parser::{self, TEST_XML},
|
2025-10-23 11:25:02 -06:00
|
|
|
render::Renderer,
|
|
|
|
|
views::{View, default_view},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
|
pub struct App {
|
|
|
|
|
// pub(crate) activities: Vec<Box<dyn Activity>>,
|
|
|
|
|
pub(crate) root_view: Option<Box<dyn View>>,
|
|
|
|
|
pub(crate) renderer: Renderer,
|
|
|
|
|
// pub(crate) current_activity: Option<usize>,
|
|
|
|
|
pub(crate) state: AppState,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct AppState {
|
|
|
|
|
pub(crate) mouse_x: f32,
|
|
|
|
|
pub(crate) mouse_y: f32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AppState {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
AppState {
|
|
|
|
|
mouse_x: 0.0,
|
|
|
|
|
mouse_y: 0.0,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl App {
|
|
|
|
|
pub fn new(renderer: Renderer) -> Self {
|
2025-10-29 21:10:51 -06:00
|
|
|
let (width, height) = (renderer.actual_width, renderer.actual_height);
|
|
|
|
|
|
2025-10-30 14:44:41 -06:00
|
|
|
let root_view = parser::parse(TEST_XML);
|
|
|
|
|
|
2025-10-29 21:10:51 -06:00
|
|
|
let mut this = App {
|
2025-10-30 14:44:41 -06:00
|
|
|
root_view: Some(root_view),
|
2025-10-23 11:25:02 -06:00
|
|
|
renderer,
|
|
|
|
|
// current_activity: Some(0),
|
|
|
|
|
state: AppState::new(),
|
2025-10-29 21:10:51 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.resize(width, height);
|
|
|
|
|
|
|
|
|
|
this
|
2025-10-23 11:25:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn draw(&mut self) {
|
2025-10-30 14:44:41 -06:00
|
|
|
// self.renderer.img.randomize(&mut self.renderer.rand);
|
2025-10-27 10:43:40 -06:00
|
|
|
if let Some(view) = &mut self.root_view {
|
2025-10-23 11:25:02 -06:00
|
|
|
let (width, height) = (
|
|
|
|
|
self.renderer.actual_width.clone() as f32,
|
|
|
|
|
self.renderer.actual_height.clone() as f32,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
view.draw(&mut self.renderer, 0., 0., width, height);
|
|
|
|
|
self.renderer.update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// App events
|
|
|
|
|
impl App {
|
2025-10-29 14:18:23 -06:00
|
|
|
pub fn resize(&mut self, width: usize, height: usize) {
|
2025-10-23 11:25:02 -06:00
|
|
|
self.renderer.resize(width, height);
|
2025-10-29 21:10:51 -06:00
|
|
|
if let Some(view) = &mut self.root_view {
|
|
|
|
|
view.resize(0., 0., width as f32, height as f32);
|
|
|
|
|
}
|
2025-10-23 11:25:02 -06:00
|
|
|
self.draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn mouse_move(&mut self, x: f32, y: f32) {
|
|
|
|
|
self.state.mouse_x = x;
|
|
|
|
|
self.state.mouse_y = y;
|
|
|
|
|
|
|
|
|
|
// if let Some(current_activity) = self.current_activity {
|
|
|
|
|
// self.activities[current_activity].mouse_move(&mut self.renderer, &self.state);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn l_click(&mut self, x: f32, y: f32) {
|
|
|
|
|
self.state.mouse_x = x;
|
|
|
|
|
self.state.mouse_y = y;
|
|
|
|
|
|
|
|
|
|
// if let Some(current_activity) = self.current_activity {
|
|
|
|
|
// self.activities[current_activity].l_click(&mut self.renderer, &self.state);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
}
|