use bevy::{
ecs::{query::With, system::Query},
math::Vec2,
prelude::{
Component, Reflect, ReflectComponent, ReflectDefault, ReflectDeserialize, ReflectSerialize,
},
window::{PrimaryWindow, Window},
};
use serde::{Deserialize, Serialize};
use crate::{RectrayFrame, Transform2D};
#[derive(Debug, Clone, Copy, Default, Reflect, Serialize, Deserialize, Component)]
#[reflect(Default, Serialize, Deserialize, Component)]
pub struct RectrayWindow;
#[derive(Debug, Clone, Copy, Default, Reflect, Serialize, Deserialize, Component)]
#[reflect(Default, Serialize, Deserialize, Component)]
pub struct RectrayCursor;
pub fn window_frame_system(
windows: Query<&Window, With<PrimaryWindow>>,
mut frames: Query<&mut RectrayFrame, With<RectrayWindow>>,
mut cursors: Query<&mut Transform2D, With<RectrayCursor>>,
) {
let Ok(window) = windows.single() else {
return;
};
let size = window.size();
for mut frame in &mut frames {
frame.dimension = size;
}
if let Some(pos) = window.cursor_position() {
for mut transform in &mut cursors {
transform.offset = (pos - size / 2.) * Vec2::new(1., -1.);
}
}
}