|
|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
extern crate sdl2; |
|
|
|
|
|
|
|
|
|
use clipboard::{ClipboardProvider, ClipboardContext}; |
|
|
|
|
use editor_render::GlyphAtlas; |
|
|
|
|
use render::GlyphAtlas; |
|
|
|
|
use num_format::{Locale, ToFormattedString}; |
|
|
|
|
use sdl2::{ |
|
|
|
|
event::{Event, WindowEvent}, |
|
|
|
|
@ -12,7 +12,7 @@ use sdl2::{ |
|
|
|
|
video::Window, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
mod editor_render; |
|
|
|
|
mod render; |
|
|
|
|
|
|
|
|
|
static SCREEN_WIDTH: u32 = 1280; |
|
|
|
|
static SCREEN_HEIGHT: u32 = 720; |
|
|
|
|
@ -32,29 +32,22 @@ struct ModifierKeys { |
|
|
|
|
|
|
|
|
|
// struct EditorGraphics {
|
|
|
|
|
// canvas: Canvas<Window>,
|
|
|
|
|
// window_size: (u32, u32),
|
|
|
|
|
// glyph_atlas: GlyphAtlas,
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/// Draw all contents to the window
|
|
|
|
|
fn draw(canvas: &mut Canvas<Window>, |
|
|
|
|
window_size: (u32, u32), |
|
|
|
|
glyph_atlas: &GlyphAtlas, |
|
|
|
|
buffer: &str, |
|
|
|
|
cursor_position: usize) -> Result<(), String> { |
|
|
|
|
fn draw(canvas: &mut Canvas<Window>, glyph_atlas: &GlyphAtlas, buffer: &str, cursor_position: usize) -> Result<(), String> { |
|
|
|
|
// Quick initialization
|
|
|
|
|
let window_size = canvas.output_size()?; |
|
|
|
|
let text_offset = Point::new(10, 10); |
|
|
|
|
|
|
|
|
|
// Draw background
|
|
|
|
|
canvas.set_draw_color(Color::RGB(32, 32, 32)); |
|
|
|
|
canvas.clear(); |
|
|
|
|
|
|
|
|
|
// Draw text
|
|
|
|
|
canvas.set_draw_color(Color::RGB(240, 240, 240)); |
|
|
|
|
let fb_text = editor_render::draw_text( |
|
|
|
|
&glyph_atlas.glyphs, |
|
|
|
|
&glyph_atlas.metrics, |
|
|
|
|
buffer, |
|
|
|
|
text_offset |
|
|
|
|
); |
|
|
|
|
let fb_text = render::draw_text(&glyph_atlas, buffer, text_offset); |
|
|
|
|
canvas.draw_points(&fb_text[..])?; |
|
|
|
|
|
|
|
|
|
// Draw info
|
|
|
|
|
@ -72,22 +65,12 @@ fn draw(canvas: &mut Canvas<Window>, |
|
|
|
|
))?; |
|
|
|
|
|
|
|
|
|
canvas.set_draw_color(Color::RGB(127, 240, 240)); |
|
|
|
|
let status_bar = editor_render::draw_text( |
|
|
|
|
&glyph_atlas.glyphs, |
|
|
|
|
&glyph_atlas.metrics, |
|
|
|
|
&status, |
|
|
|
|
status_position |
|
|
|
|
); |
|
|
|
|
let status_bar = render::draw_text(&glyph_atlas, &status, status_position); |
|
|
|
|
canvas.draw_points(&status_bar[..])?; |
|
|
|
|
|
|
|
|
|
// Draw cursor
|
|
|
|
|
canvas.set_draw_color(Color::RGB(64, 240, 240)); |
|
|
|
|
let fb_cursor = editor_render::draw_cursor( |
|
|
|
|
&glyph_atlas.metrics, |
|
|
|
|
cursor_position, |
|
|
|
|
buffer, |
|
|
|
|
text_offset |
|
|
|
|
); |
|
|
|
|
let fb_cursor = render::draw_cursor(&glyph_atlas, cursor_position, buffer, text_offset); |
|
|
|
|
canvas.draw_line(fb_cursor.0, fb_cursor.1)?; |
|
|
|
|
|
|
|
|
|
canvas.present(); |
|
|
|
|
@ -113,8 +96,6 @@ pub fn main() -> Result<(), String> { |
|
|
|
|
|
|
|
|
|
let mut canvas = window.into_canvas().build().map_err(|e| e.to_string())?; |
|
|
|
|
|
|
|
|
|
let mut window_size = canvas.output_size()?; |
|
|
|
|
|
|
|
|
|
// Initalize buffer
|
|
|
|
|
let mut buffer = String::new(); |
|
|
|
|
|
|
|
|
|
@ -129,12 +110,12 @@ pub fn main() -> Result<(), String> { |
|
|
|
|
let mut selection_anchor: Option<usize> = None; |
|
|
|
|
|
|
|
|
|
// Initialize graphics data and values
|
|
|
|
|
let glyph_atlas = editor_render::generate_glyph_data(); |
|
|
|
|
let glyph_atlas = render::generate_glyph_data(); |
|
|
|
|
|
|
|
|
|
// Easier way to please the borrow checker
|
|
|
|
|
macro_rules! draw { |
|
|
|
|
() => { |
|
|
|
|
draw(&mut canvas, window_size, &glyph_atlas, &buffer, cursor_position)? |
|
|
|
|
draw(&mut canvas, &glyph_atlas, &buffer, cursor_position)? |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -145,9 +126,7 @@ pub fn main() -> Result<(), String> { |
|
|
|
|
for event in sdl_context.event_pump()?.poll_iter() { |
|
|
|
|
match event { |
|
|
|
|
Event::Window { win_event, .. } => { |
|
|
|
|
if let WindowEvent::Resized(w, h) = win_event { |
|
|
|
|
window_size = (w as u32, h as u32); |
|
|
|
|
|
|
|
|
|
if let WindowEvent::Resized(_w, _h) = win_event { |
|
|
|
|
draw!(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -398,7 +377,7 @@ pub fn main() -> Result<(), String> { |
|
|
|
|
undo_position += 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
::std::thread::sleep(std::time::Duration::new(0, 1_000_000_000 / REFRESH_RATE)); |
|
|
|
|
std::thread::sleep(std::time::Duration::new(0, 1_000_000_000 / REFRESH_RATE)); |
|
|
|
|
} |
|
|
|
|
println!("{buffer}"); |
|
|
|
|
Ok(()) |
|
|
|
|
|