tirbofish/dropbear
main / crates / eucalyptus-editor / src / debug / window.rs · 4205 bytes
crates/eucalyptus-editor/src/debug/window.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! Creates a dummy debug window, testing multi window management capabilities
//!
//! Can also be technically used as a template for other windowed scenes (as its essentially the basics)
use egui::{CentralPanel, Ui};
use gilrs::{Button, GamepadId};
use winit::dpi::PhysicalPosition;
use winit::event::MouseButton;
use winit::event_loop::ActiveEventLoop;
use winit::keyboard::KeyCode;
use winit::window::WindowId;
use dropbear_engine::input::{Controller, Keyboard, Mouse};
use dropbear_engine::scene::{Scene, SceneCommand};
use eucalyptus_core::input::InputState;
pub struct DebugWindow {
scene_command: SceneCommand,
input_state: InputState,
window: Option<WindowId>,
}
impl DebugWindow {
pub fn new() -> Self {
Self {
scene_command: SceneCommand::None,
input_state: Default::default(),
window: None,
}
}
}
impl Scene for DebugWindow {
fn load(&mut self, graphics: std::sync::Arc<dropbear_engine::graphics::SharedGraphicsContext>, _ui: &mut Ui,) {
self.window = Some(graphics.window.id());
}
fn physics_update(
&mut self,
_dt: f32,
_graphics: std::sync::Arc<dropbear_engine::graphics::SharedGraphicsContext>,
_ui: &mut Ui,
) {
}
fn update(
&mut self,
_dt: f32,
graphics: std::sync::Arc<dropbear_engine::graphics::SharedGraphicsContext>,
ui: &mut Ui,
) {
CentralPanel::default().show_inside(ui, |ui| {
ui.label("Hello Debug Window!");
});
self.window = Some(graphics.window.id());
}
fn render<'a>(
&mut self,
_graphics: std::sync::Arc<dropbear_engine::graphics::SharedGraphicsContext>,
_ui: &mut Ui,
) {
}
fn exit(&mut self, _event_loop: &ActiveEventLoop) {}
fn run_command(&mut self) -> SceneCommand {
std::mem::replace(&mut self.scene_command, SceneCommand::None)
}
}
impl Keyboard for DebugWindow {
fn key_down(&mut self, key: KeyCode, _event_loop: &ActiveEventLoop) {
match key {
KeyCode::Escape => {
if let Some(id) = self.window {
self.scene_command = SceneCommand::CloseWindow(id);
}
}
_ => {
self.input_state.pressed_keys.insert(key);
}
}
self.input_state.pressed_keys.insert(key);
}
fn key_up(&mut self, key: KeyCode, _event_loop: &ActiveEventLoop) {
self.input_state.pressed_keys.remove(&key);
}
}
impl Mouse for DebugWindow {
fn mouse_move(&mut self, position: PhysicalPosition<f64>, delta: Option<(f64, f64)>) {
self.input_state.last_mouse_pos = Some(<(f64, f64)>::from(position));
self.input_state.mouse_delta = delta;
self.input_state.mouse_pos = (position.x, position.y);
}
fn mouse_down(&mut self, button: MouseButton) {
self.input_state.mouse_button.insert(button);
}
fn mouse_up(&mut self, button: MouseButton) {
self.input_state.mouse_button.remove(&button);
}
}
impl Controller for DebugWindow {
fn button_down(&mut self, button: Button, id: GamepadId) {
self.input_state
.pressed_buttons
.entry(id)
.or_default()
.insert(button);
}
fn button_up(&mut self, button: Button, id: GamepadId) {
if let Some(buttons) = self.input_state.pressed_buttons.get_mut(&id) {
buttons.remove(&button);
}
}
fn left_stick_changed(&mut self, x: f32, y: f32, id: GamepadId) {
self.input_state.left_stick_position.insert(id, (x, y));
}
fn right_stick_changed(&mut self, x: f32, y: f32, id: GamepadId) {
self.input_state.right_stick_position.insert(id, (x, y));
}
fn on_connect(&mut self, id: GamepadId) {
self.input_state.connected_gamepads.insert(id);
}
fn on_disconnect(&mut self, id: GamepadId) {
self.input_state.connected_gamepads.remove(&id);
self.input_state.pressed_buttons.remove(&id);
self.input_state.left_stick_position.remove(&id);
self.input_state.right_stick_position.remove(&id);
}
}