|
|
@ -1,19 +1,21 @@
|
|
|
|
mod cursor;
|
|
|
|
mod cursor;
|
|
|
|
|
|
|
|
mod draw_command_batcher;
|
|
|
|
mod grid;
|
|
|
|
mod grid;
|
|
|
|
mod style;
|
|
|
|
mod style;
|
|
|
|
mod window;
|
|
|
|
mod window;
|
|
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
use std::sync::mpsc::{Receiver, Sender};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::mpsc::{Sender, Receiver};
|
|
|
|
|
|
|
|
use std::thread;
|
|
|
|
use std::thread;
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use log::{error, warn, trace};
|
|
|
|
use log::{error, trace, warn};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::bridge::{EditorMode, GuiOption, RedrawEvent, WindowAnchor};
|
|
|
|
use crate::bridge::{EditorMode, GuiOption, RedrawEvent, WindowAnchor};
|
|
|
|
use crate::redraw_scheduler::REDRAW_SCHEDULER;
|
|
|
|
use crate::redraw_scheduler::REDRAW_SCHEDULER;
|
|
|
|
pub use cursor::{Cursor, CursorMode, CursorShape};
|
|
|
|
pub use cursor::{Cursor, CursorMode, CursorShape};
|
|
|
|
|
|
|
|
pub use draw_command_batcher::DrawCommandBatcher;
|
|
|
|
pub use grid::CharacterGrid;
|
|
|
|
pub use grid::CharacterGrid;
|
|
|
|
pub use style::{Colors, Style};
|
|
|
|
pub use style::{Colors, Style};
|
|
|
|
pub use window::*;
|
|
|
|
pub use window::*;
|
|
|
@ -26,24 +28,18 @@ pub struct AnchorInfo {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl WindowAnchor {
|
|
|
|
impl WindowAnchor {
|
|
|
|
fn modified_top_left(&self, grid_left: f64, grid_top: f64, width: u64, height: u64) -> (f64, f64) {
|
|
|
|
fn modified_top_left(
|
|
|
|
|
|
|
|
&self,
|
|
|
|
|
|
|
|
grid_left: f64,
|
|
|
|
|
|
|
|
grid_top: f64,
|
|
|
|
|
|
|
|
width: u64,
|
|
|
|
|
|
|
|
height: u64,
|
|
|
|
|
|
|
|
) -> (f64, f64) {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
WindowAnchor::NorthWest => (
|
|
|
|
WindowAnchor::NorthWest => (grid_left, grid_top),
|
|
|
|
grid_left,
|
|
|
|
WindowAnchor::NorthEast => (grid_left - width as f64, grid_top),
|
|
|
|
grid_top,
|
|
|
|
WindowAnchor::SouthWest => (grid_left, grid_top - height as f64),
|
|
|
|
),
|
|
|
|
WindowAnchor::SouthEast => (grid_left - width as f64, grid_top - height as f64),
|
|
|
|
WindowAnchor::NorthEast => (
|
|
|
|
|
|
|
|
grid_left - width as f64,
|
|
|
|
|
|
|
|
grid_top,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
WindowAnchor::SouthWest => (
|
|
|
|
|
|
|
|
grid_left,
|
|
|
|
|
|
|
|
grid_top - height as f64,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
WindowAnchor::SouthEast => (
|
|
|
|
|
|
|
|
grid_left - width as f64,
|
|
|
|
|
|
|
|
grid_top - height as f64,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -52,7 +48,7 @@ pub enum DrawCommand {
|
|
|
|
CloseWindow(u64),
|
|
|
|
CloseWindow(u64),
|
|
|
|
Window {
|
|
|
|
Window {
|
|
|
|
grid_id: u64,
|
|
|
|
grid_id: u64,
|
|
|
|
command: WindowDrawCommand
|
|
|
|
command: WindowDrawCommand,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
UpdateCursor(Cursor),
|
|
|
|
UpdateCursor(Cursor),
|
|
|
|
FontChanged(String),
|
|
|
|
FontChanged(String),
|
|
|
@ -68,7 +64,9 @@ impl fmt::Debug for DrawCommand {
|
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
DrawCommand::CloseWindow(_) => write!(formatter, "CloseWindow"),
|
|
|
|
DrawCommand::CloseWindow(_) => write!(formatter, "CloseWindow"),
|
|
|
|
DrawCommand::Window { grid_id, command } => write!(formatter, "Window {} {:?}", grid_id, command),
|
|
|
|
DrawCommand::Window { grid_id, command } => {
|
|
|
|
|
|
|
|
write!(formatter, "Window {} {:?}", grid_id, command)
|
|
|
|
|
|
|
|
}
|
|
|
|
DrawCommand::UpdateCursor(_) => write!(formatter, "UpdateCursor"),
|
|
|
|
DrawCommand::UpdateCursor(_) => write!(formatter, "UpdateCursor"),
|
|
|
|
DrawCommand::FontChanged(_) => write!(formatter, "FontChanged"),
|
|
|
|
DrawCommand::FontChanged(_) => write!(formatter, "FontChanged"),
|
|
|
|
DrawCommand::DefaultStyleChanged(_) => write!(formatter, "DefaultStyleChanged"),
|
|
|
|
DrawCommand::DefaultStyleChanged(_) => write!(formatter, "DefaultStyleChanged"),
|
|
|
@ -82,28 +80,33 @@ pub struct Editor {
|
|
|
|
pub defined_styles: HashMap<u64, Arc<Style>>,
|
|
|
|
pub defined_styles: HashMap<u64, Arc<Style>>,
|
|
|
|
pub mode_list: Vec<CursorMode>,
|
|
|
|
pub mode_list: Vec<CursorMode>,
|
|
|
|
pub current_mode: EditorMode,
|
|
|
|
pub current_mode: EditorMode,
|
|
|
|
pub draw_command_sender: Sender<DrawCommand>,
|
|
|
|
pub draw_command_batcher: Arc<DrawCommandBatcher>,
|
|
|
|
pub window_command_sender: Sender<WindowCommand>,
|
|
|
|
pub window_command_sender: Sender<WindowCommand>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Editor {
|
|
|
|
impl Editor {
|
|
|
|
pub fn new(draw_command_sender: Sender<DrawCommand>, window_command_sender: Sender<WindowCommand>) -> Editor {
|
|
|
|
pub fn new(
|
|
|
|
|
|
|
|
batched_draw_command_sender: Sender<Vec<DrawCommand>>,
|
|
|
|
|
|
|
|
window_command_sender: Sender<WindowCommand>,
|
|
|
|
|
|
|
|
) -> Editor {
|
|
|
|
Editor {
|
|
|
|
Editor {
|
|
|
|
windows: HashMap::new(),
|
|
|
|
windows: HashMap::new(),
|
|
|
|
cursor: Cursor::new(),
|
|
|
|
cursor: Cursor::new(),
|
|
|
|
defined_styles: HashMap::new(),
|
|
|
|
defined_styles: HashMap::new(),
|
|
|
|
mode_list: Vec::new(),
|
|
|
|
mode_list: Vec::new(),
|
|
|
|
current_mode: EditorMode::Unknown(String::from("")),
|
|
|
|
current_mode: EditorMode::Unknown(String::from("")),
|
|
|
|
draw_command_sender,
|
|
|
|
draw_command_batcher: Arc::new(DrawCommandBatcher::new(batched_draw_command_sender)),
|
|
|
|
window_command_sender
|
|
|
|
window_command_sender,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn handle_redraw_event(&mut self, event: RedrawEvent) {
|
|
|
|
pub fn handle_redraw_event(&mut self, event: RedrawEvent) {
|
|
|
|
match event {
|
|
|
|
match event {
|
|
|
|
RedrawEvent::SetTitle { title } => {
|
|
|
|
RedrawEvent::SetTitle { title } => {
|
|
|
|
self.window_command_sender.send(WindowCommand::TitleChanged(title)).ok();
|
|
|
|
self.window_command_sender
|
|
|
|
},
|
|
|
|
.send(WindowCommand::TitleChanged(title))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
|
|
|
|
}
|
|
|
|
RedrawEvent::ModeInfoSet { cursor_modes } => self.mode_list = cursor_modes,
|
|
|
|
RedrawEvent::ModeInfoSet { cursor_modes } => self.mode_list = cursor_modes,
|
|
|
|
RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option),
|
|
|
|
RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option),
|
|
|
|
RedrawEvent::ModeChange { mode, mode_index } => {
|
|
|
|
RedrawEvent::ModeChange { mode, mode_index } => {
|
|
|
@ -113,10 +116,14 @@ impl Editor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::MouseOn => {
|
|
|
|
RedrawEvent::MouseOn => {
|
|
|
|
self.window_command_sender.send(WindowCommand::SetMouseEnabled(true)).ok();
|
|
|
|
self.window_command_sender
|
|
|
|
|
|
|
|
.send(WindowCommand::SetMouseEnabled(true))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::MouseOff => {
|
|
|
|
RedrawEvent::MouseOff => {
|
|
|
|
self.window_command_sender.send(WindowCommand::SetMouseEnabled(false)).ok();
|
|
|
|
self.window_command_sender
|
|
|
|
|
|
|
|
.send(WindowCommand::SetMouseEnabled(false))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::BusyStart => {
|
|
|
|
RedrawEvent::BusyStart => {
|
|
|
|
trace!("Cursor off");
|
|
|
|
trace!("Cursor off");
|
|
|
@ -129,17 +136,22 @@ impl Editor {
|
|
|
|
RedrawEvent::Flush => {
|
|
|
|
RedrawEvent::Flush => {
|
|
|
|
trace!("Image flushed");
|
|
|
|
trace!("Image flushed");
|
|
|
|
self.send_cursor_info();
|
|
|
|
self.send_cursor_info();
|
|
|
|
|
|
|
|
self.draw_command_batcher.send_batch().ok();
|
|
|
|
REDRAW_SCHEDULER.queue_next_frame();
|
|
|
|
REDRAW_SCHEDULER.queue_next_frame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::DefaultColorsSet { colors } => {
|
|
|
|
RedrawEvent::DefaultColorsSet { colors } => {
|
|
|
|
self.draw_command_sender.send(DrawCommand::DefaultStyleChanged(Style::new(colors))).ok();
|
|
|
|
self.draw_command_batcher
|
|
|
|
|
|
|
|
.queue(DrawCommand::DefaultStyleChanged(Style::new(colors)))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::HighlightAttributesDefine { id, style } => {
|
|
|
|
RedrawEvent::HighlightAttributesDefine { id, style } => {
|
|
|
|
self.defined_styles.insert(id, Arc::new(style));
|
|
|
|
self.defined_styles.insert(id, Arc::new(style));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::CursorGoto { grid, column: left, row: top } => {
|
|
|
|
RedrawEvent::CursorGoto {
|
|
|
|
self.set_cursor_position(grid, left, top)
|
|
|
|
grid,
|
|
|
|
}
|
|
|
|
column: left,
|
|
|
|
|
|
|
|
row: top,
|
|
|
|
|
|
|
|
} => self.set_cursor_position(grid, left, top),
|
|
|
|
RedrawEvent::Resize {
|
|
|
|
RedrawEvent::Resize {
|
|
|
|
grid,
|
|
|
|
grid,
|
|
|
|
width,
|
|
|
|
width,
|
|
|
@ -154,19 +166,12 @@ impl Editor {
|
|
|
|
cells,
|
|
|
|
cells,
|
|
|
|
} => {
|
|
|
|
} => {
|
|
|
|
let defined_styles = &self.defined_styles;
|
|
|
|
let defined_styles = &self.defined_styles;
|
|
|
|
self.windows.get_mut(&grid).map(|window| {
|
|
|
|
|
|
|
|
window.draw_grid_line(
|
|
|
|
|
|
|
|
row,
|
|
|
|
|
|
|
|
column_start,
|
|
|
|
|
|
|
|
cells,
|
|
|
|
|
|
|
|
defined_styles
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RedrawEvent::Clear { grid } => {
|
|
|
|
|
|
|
|
self.windows
|
|
|
|
self.windows
|
|
|
|
.get_mut(&grid)
|
|
|
|
.get_mut(&grid)
|
|
|
|
.map(|window| window.clear());
|
|
|
|
.map(|window| window.draw_grid_line(row, column_start, cells, defined_styles));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RedrawEvent::Clear { grid } => {
|
|
|
|
|
|
|
|
self.windows.get_mut(&grid).map(|window| window.clear());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::Destroy { grid } => self.close_window(grid),
|
|
|
|
RedrawEvent::Destroy { grid } => self.close_window(grid),
|
|
|
|
RedrawEvent::Scroll {
|
|
|
|
RedrawEvent::Scroll {
|
|
|
@ -196,13 +201,9 @@ impl Editor {
|
|
|
|
anchor_column: anchor_left,
|
|
|
|
anchor_column: anchor_left,
|
|
|
|
anchor_row: anchor_top,
|
|
|
|
anchor_row: anchor_top,
|
|
|
|
..
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
} => self.set_window_float_position(grid, anchor_grid, anchor, anchor_left, anchor_top),
|
|
|
|
self.set_window_float_position(grid, anchor_grid, anchor, anchor_left, anchor_top)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RedrawEvent::WindowHide { grid } => {
|
|
|
|
RedrawEvent::WindowHide { grid } => {
|
|
|
|
self.windows
|
|
|
|
self.windows.get(&grid).map(|window| window.hide());
|
|
|
|
.get(&grid)
|
|
|
|
|
|
|
|
.map(|window| window.hide());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RedrawEvent::WindowClose { grid } => self.close_window(grid),
|
|
|
|
RedrawEvent::WindowClose { grid } => self.close_window(grid),
|
|
|
|
RedrawEvent::MessageSetPosition { grid, row, .. } => {
|
|
|
|
RedrawEvent::MessageSetPosition { grid, row, .. } => {
|
|
|
@ -215,7 +216,9 @@ impl Editor {
|
|
|
|
fn close_window(&mut self, grid: u64) {
|
|
|
|
fn close_window(&mut self, grid: u64) {
|
|
|
|
if let Some(window) = self.windows.remove(&grid) {
|
|
|
|
if let Some(window) = self.windows.remove(&grid) {
|
|
|
|
window.close();
|
|
|
|
window.close();
|
|
|
|
self.draw_command_sender.send(DrawCommand::CloseWindow(grid)).ok();
|
|
|
|
self.draw_command_batcher
|
|
|
|
|
|
|
|
.queue(DrawCommand::CloseWindow(grid))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -225,13 +228,14 @@ impl Editor {
|
|
|
|
window.resize(width, height);
|
|
|
|
window.resize(width, height);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let window = Window::new(
|
|
|
|
let window = Window::new(
|
|
|
|
grid,
|
|
|
|
grid,
|
|
|
|
width,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
height,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
self.draw_command_sender.clone());
|
|
|
|
self.draw_command_batcher.clone(),
|
|
|
|
|
|
|
|
);
|
|
|
|
self.windows.insert(grid, window);
|
|
|
|
self.windows.insert(grid, window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -246,12 +250,7 @@ impl Editor {
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
warn!("position {}", grid);
|
|
|
|
warn!("position {}", grid);
|
|
|
|
if let Some(window) = self.windows.get_mut(&grid) {
|
|
|
|
if let Some(window) = self.windows.get_mut(&grid) {
|
|
|
|
window.position(
|
|
|
|
window.position(width, height, None, start_left as f64, start_top as f64);
|
|
|
|
width,
|
|
|
|
|
|
|
|
height,
|
|
|
|
|
|
|
|
None,
|
|
|
|
|
|
|
|
start_left as f64,
|
|
|
|
|
|
|
|
start_top as f64);
|
|
|
|
|
|
|
|
window.show();
|
|
|
|
window.show();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let new_window = Window::new(
|
|
|
|
let new_window = Window::new(
|
|
|
@ -261,7 +260,7 @@ impl Editor {
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
start_left as f64,
|
|
|
|
start_left as f64,
|
|
|
|
start_top as f64,
|
|
|
|
start_top as f64,
|
|
|
|
self.draw_command_sender.clone()
|
|
|
|
self.draw_command_batcher.clone(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
self.windows.insert(grid, new_window);
|
|
|
|
self.windows.insert(grid, new_window);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -280,9 +279,8 @@ impl Editor {
|
|
|
|
if let Some(window) = self.windows.get_mut(&grid) {
|
|
|
|
if let Some(window) = self.windows.get_mut(&grid) {
|
|
|
|
let width = window.get_width();
|
|
|
|
let width = window.get_width();
|
|
|
|
let height = window.get_height();
|
|
|
|
let height = window.get_height();
|
|
|
|
let (mut modified_left, mut modified_top) = anchor_type.modified_top_left(
|
|
|
|
let (mut modified_left, mut modified_top) =
|
|
|
|
anchor_left, anchor_top,
|
|
|
|
anchor_type.modified_top_left(anchor_left, anchor_top, width, height);
|
|
|
|
width, height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some((parent_left, parent_top)) = parent_position {
|
|
|
|
if let Some((parent_left, parent_top)) = parent_position {
|
|
|
|
modified_left = parent_left + modified_left;
|
|
|
|
modified_left = parent_left + modified_left;
|
|
|
@ -290,12 +288,17 @@ impl Editor {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
window.position(
|
|
|
|
window.position(
|
|
|
|
width, height,
|
|
|
|
width,
|
|
|
|
|
|
|
|
height,
|
|
|
|
Some(AnchorInfo {
|
|
|
|
Some(AnchorInfo {
|
|
|
|
anchor_grid_id: anchor_grid,
|
|
|
|
anchor_grid_id: anchor_grid,
|
|
|
|
anchor_type, anchor_left, anchor_top
|
|
|
|
anchor_type,
|
|
|
|
|
|
|
|
anchor_left,
|
|
|
|
|
|
|
|
anchor_top,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
modified_left, modified_top);
|
|
|
|
modified_left,
|
|
|
|
|
|
|
|
modified_top,
|
|
|
|
|
|
|
|
);
|
|
|
|
window.show();
|
|
|
|
window.show();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
error!("Attempted to float window that does not exist.");
|
|
|
|
error!("Attempted to float window that does not exist.");
|
|
|
@ -304,14 +307,20 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
|
|
fn set_message_position(&mut self, grid: u64, grid_top: u64) {
|
|
|
|
fn set_message_position(&mut self, grid: u64, grid_top: u64) {
|
|
|
|
warn!("message position {}", grid);
|
|
|
|
warn!("message position {}", grid);
|
|
|
|
let parent_width = self.windows.get(&1).map(|parent| parent.get_width()).unwrap_or(1);
|
|
|
|
let parent_width = self
|
|
|
|
|
|
|
|
.windows
|
|
|
|
|
|
|
|
.get(&1)
|
|
|
|
|
|
|
|
.map(|parent| parent.get_width())
|
|
|
|
|
|
|
|
.unwrap_or(1);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(window) = self.windows.get_mut(&grid) {
|
|
|
|
if let Some(window) = self.windows.get_mut(&grid) {
|
|
|
|
window.position(
|
|
|
|
window.position(
|
|
|
|
parent_width, window.get_height(),
|
|
|
|
parent_width,
|
|
|
|
|
|
|
|
window.get_height(),
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
grid_top as f64);
|
|
|
|
grid_top as f64,
|
|
|
|
|
|
|
|
);
|
|
|
|
window.show();
|
|
|
|
window.show();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let new_window = Window::new(
|
|
|
|
let new_window = Window::new(
|
|
|
@ -321,7 +330,7 @@ impl Editor {
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
0.0,
|
|
|
|
0.0,
|
|
|
|
grid_top as f64,
|
|
|
|
grid_top as f64,
|
|
|
|
self.draw_command_sender.clone()
|
|
|
|
self.draw_command_batcher.clone(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
self.windows.insert(grid, new_window);
|
|
|
|
self.windows.insert(grid, new_window);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -336,11 +345,18 @@ impl Editor {
|
|
|
|
let (parent_anchor_left, parent_anchor_top) =
|
|
|
|
let (parent_anchor_left, parent_anchor_top) =
|
|
|
|
self.get_window_top_left(anchor_info.anchor_grid_id)?;
|
|
|
|
self.get_window_top_left(anchor_info.anchor_grid_id)?;
|
|
|
|
|
|
|
|
|
|
|
|
let (anchor_modified_left, anchor_modified_top) = anchor_info.anchor_type.modified_top_left(
|
|
|
|
let (anchor_modified_left, anchor_modified_top) =
|
|
|
|
anchor_info.anchor_left, anchor_info.anchor_top,
|
|
|
|
anchor_info.anchor_type.modified_top_left(
|
|
|
|
window.get_width(), window.get_height());
|
|
|
|
anchor_info.anchor_left,
|
|
|
|
|
|
|
|
anchor_info.anchor_top,
|
|
|
|
|
|
|
|
window.get_width(),
|
|
|
|
|
|
|
|
window.get_height(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Some((parent_anchor_left + anchor_modified_left, parent_anchor_top + anchor_modified_top))
|
|
|
|
Some((
|
|
|
|
|
|
|
|
parent_anchor_left + anchor_modified_left,
|
|
|
|
|
|
|
|
parent_anchor_top + anchor_modified_top,
|
|
|
|
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => Some(window.get_grid_position()),
|
|
|
|
None => Some(window.get_grid_position()),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -355,10 +371,12 @@ impl Editor {
|
|
|
|
let (grid_left, grid_top) = self.cursor.grid_position;
|
|
|
|
let (grid_left, grid_top) = self.cursor.grid_position;
|
|
|
|
match self.get_window_top_left(self.cursor.parent_window_id) {
|
|
|
|
match self.get_window_top_left(self.cursor.parent_window_id) {
|
|
|
|
Some((window_left, window_top)) => {
|
|
|
|
Some((window_left, window_top)) => {
|
|
|
|
self.cursor.position = (window_left + grid_left as f64, window_top + grid_top as f64);
|
|
|
|
self.cursor.position =
|
|
|
|
|
|
|
|
(window_left + grid_left as f64, window_top + grid_top as f64);
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(window) = self.windows.get(&self.cursor.parent_window_id) {
|
|
|
|
if let Some(window) = self.windows.get(&self.cursor.parent_window_id) {
|
|
|
|
let (character, double_width) = window.get_cursor_character(grid_left, grid_top);
|
|
|
|
let (character, double_width) =
|
|
|
|
|
|
|
|
window.get_cursor_character(grid_left, grid_top);
|
|
|
|
self.cursor.character = character;
|
|
|
|
self.cursor.character = character;
|
|
|
|
self.cursor.double_width = double_width;
|
|
|
|
self.cursor.double_width = double_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -369,20 +387,28 @@ impl Editor {
|
|
|
|
self.cursor.character = " ".to_string();
|
|
|
|
self.cursor.character = " ".to_string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.draw_command_sender.send(DrawCommand::UpdateCursor(self.cursor.clone())).ok();
|
|
|
|
self.draw_command_batcher
|
|
|
|
|
|
|
|
.queue(DrawCommand::UpdateCursor(self.cursor.clone()))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn set_option(&mut self, gui_option: GuiOption) {
|
|
|
|
fn set_option(&mut self, gui_option: GuiOption) {
|
|
|
|
trace!("Option set {:?}", &gui_option);
|
|
|
|
trace!("Option set {:?}", &gui_option);
|
|
|
|
if let GuiOption::GuiFont(guifont) = gui_option {
|
|
|
|
if let GuiOption::GuiFont(guifont) = gui_option {
|
|
|
|
self.draw_command_sender.send(DrawCommand::FontChanged(guifont)).ok();
|
|
|
|
self.draw_command_batcher
|
|
|
|
|
|
|
|
.queue(DrawCommand::FontChanged(guifont))
|
|
|
|
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn start_editor(redraw_event_receiver: Receiver<RedrawEvent>, draw_command_sender: Sender<DrawCommand>, window_command_sender: Sender<WindowCommand>) {
|
|
|
|
pub fn start_editor(
|
|
|
|
|
|
|
|
redraw_event_receiver: Receiver<RedrawEvent>,
|
|
|
|
|
|
|
|
batched_draw_command_sender: Sender<Vec<DrawCommand>>,
|
|
|
|
|
|
|
|
window_command_sender: Sender<WindowCommand>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
thread::spawn(move || {
|
|
|
|
thread::spawn(move || {
|
|
|
|
let mut editor = Editor::new(draw_command_sender, window_command_sender);
|
|
|
|
let mut editor = Editor::new(batched_draw_command_sender, window_command_sender);
|
|
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
if let Ok(redraw_event) = redraw_event_receiver.recv() {
|
|
|
|
if let Ok(redraw_event) = redraw_event_receiver.recv() {
|
|
|
|