|
|
|
@ -8,10 +8,9 @@ use skulpin::winit::dpi::LogicalSize;
|
|
|
|
|
use skulpin::winit::event::{ElementState, Event, MouseScrollDelta, StartCause, WindowEvent};
|
|
|
|
|
use skulpin::winit::event_loop::{ControlFlow, EventLoop};
|
|
|
|
|
use skulpin::winit::window::{Icon, WindowBuilder};
|
|
|
|
|
use tokio::sync::mpsc::UnboundedSender;
|
|
|
|
|
|
|
|
|
|
use crate::editor::Editor;
|
|
|
|
|
use crate::bridge::construct_keybinding_string;
|
|
|
|
|
use crate::bridge::{construct_keybinding_string, Bridge};
|
|
|
|
|
use crate::renderer::Renderer;
|
|
|
|
|
use crate::bridge::UiCommand;
|
|
|
|
|
|
|
|
|
@ -21,16 +20,16 @@ struct Asset;
|
|
|
|
|
|
|
|
|
|
const EXTRA_LIVE_FRAMES: usize = 10;
|
|
|
|
|
|
|
|
|
|
fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer, command_channel: &mut UnboundedSender<UiCommand>) {
|
|
|
|
|
fn handle_new_grid_size(new_size: LogicalSize, renderer: &Renderer, bridge: &mut Bridge) {
|
|
|
|
|
if new_size.width > 0.0 && new_size.height > 0.0 {
|
|
|
|
|
let new_width = ((new_size.width + 1.0) as f32 / renderer.font_width) as u64;
|
|
|
|
|
let new_height = ((new_size.height + 1.0) as f32 / renderer.font_height) as u64;
|
|
|
|
|
// Add 1 here to make sure resizing doesn't change the grid size on startup
|
|
|
|
|
command_channel.send(UiCommand::Resize { width: new_width as i64, height: new_height as i64 });
|
|
|
|
|
bridge.queue_command(UiCommand::Resize { width: new_width as i64, height: new_height as i64 });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<UiCommand>, initial_size: (u64, u64)) {
|
|
|
|
|
pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut bridge: Bridge, initial_size: (u64, u64)) {
|
|
|
|
|
let mut renderer = Renderer::new(editor.clone());
|
|
|
|
|
let event_loop = EventLoop::<()>::with_user_event();
|
|
|
|
|
|
|
|
|
@ -94,7 +93,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
event: WindowEvent::Resized(new_size),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
handle_new_grid_size(new_size, &renderer, &mut command_channel)
|
|
|
|
|
handle_new_grid_size(new_size, &renderer, &mut bridge)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Event::WindowEvent {
|
|
|
|
@ -106,7 +105,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
} => {
|
|
|
|
|
construct_keybinding_string(input)
|
|
|
|
|
.map(UiCommand::Keyboard)
|
|
|
|
|
.map(|keybinding_string| command_channel.send(keybinding_string));
|
|
|
|
|
.map(|keybinding_string| bridge.queue_command(keybinding_string));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Event::WindowEvent {
|
|
|
|
@ -120,7 +119,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
let grid_x = (position.y as f32 / renderer.font_height) as i64;
|
|
|
|
|
mouse_pos = (grid_x, grid_y);
|
|
|
|
|
if mouse_down {
|
|
|
|
|
command_channel.send(UiCommand::Drag(grid_x, grid_y));
|
|
|
|
|
bridge.queue_command(UiCommand::Drag(grid_x, grid_y));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -142,7 +141,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let (grid_x, grid_y) = mouse_pos;
|
|
|
|
|
command_channel.send(UiCommand::MouseButton { action: input_type.to_string(), position: (grid_x, grid_y) });
|
|
|
|
|
bridge.queue_command(UiCommand::MouseButton { action: input_type.to_string(), position: (grid_x, grid_y) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Event::WindowEvent {
|
|
|
|
@ -161,7 +160,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Some(input_type) = vertical_input_type {
|
|
|
|
|
command_channel.send(UiCommand::Scroll { direction: input_type.to_string(), position: mouse_pos });
|
|
|
|
|
bridge.queue_command(UiCommand::Scroll { direction: input_type.to_string(), position: mouse_pos });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let horizontal_input_type = if horizontal > 0.0 {
|
|
|
|
@ -173,7 +172,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Some(input_type) = horizontal_input_type {
|
|
|
|
|
command_channel.send(UiCommand::Scroll { direction: input_type.to_string(), position: mouse_pos });
|
|
|
|
|
bridge.queue_command(UiCommand::Scroll { direction: input_type.to_string(), position: mouse_pos });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -190,7 +189,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, mut command_channel: UnboundedSender<
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if draw_result.font_changed {
|
|
|
|
|
handle_new_grid_size(window.inner_size(), &renderer, &mut command_channel)
|
|
|
|
|
handle_new_grid_size(window.inner_size(), &renderer, &mut bridge)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if live_frames > 0 {
|
|
|
|
|