-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
280 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
Cargo.lock | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,12 @@ authors = ["Fredrick Brennan <[email protected]>"] | |
# For display | ||
# We might need to vendorize these some day. See aclysma/skulpin#66: | ||
# https://github.com/aclysma/skulpin/issues/66#issuecomment-689244118 | ||
# Commented versions I occasionally use in development to stick extra debug!'s in Skulpin. | ||
#skulpin = { version = "0.10.0", default-features = false, features = ["skia_complete", "skulpin_winit"] } | ||
#skulpin = { path = "../skulpin", default-features = false, features = ["skia_complete", "skulpin_winit"] } | ||
#skulpin-plugin-imgui = { path = "../skulpin/skulpin-plugin-imgui" } | ||
skulpin = { version = "0.10.0", default-features = false, features = ["skia_complete", "skulpin_winit"] } | ||
skulpin-plugin-imgui = "0.5.0" | ||
skulpin-plugin-imgui = { version = "0.5.0" } | ||
imgui-winit-support = "0.4.0" | ||
|
||
# For choosing font for toolbox | ||
|
@@ -30,12 +34,22 @@ enum-iterator = "=0.6.0" | |
backtrace = "0.3.0" | ||
colored = "2.0.0" | ||
|
||
# Right now only for pasting into console | ||
clipboard = "0.5.0" | ||
|
||
# Logging | ||
log = "0.4.11" | ||
env_logger = "0.7.1" | ||
|
||
# Gives us derive(Display) | ||
derive_more = "0.99.10" | ||
|
||
## Our crates | ||
# parses .glif files and gives us a place to put arbitrary data | ||
glifparser = { git = "https://github.com/mfeq/glifparser" } | ||
#glifparser = { path = "../glifparser" } # for development | ||
mfeq-ipc = { git = "https://github.com/mfeq/ipc" } | ||
|
||
# See src/util/mod.rs::set_codepage_utf8 | ||
[target.'cfg(windows)'.dependencies] | ||
winapi = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Console | ||
use crate::CONSOLE; | ||
|
||
use clipboard::{ClipboardContext, ClipboardProvider}; | ||
|
||
use winit::event::{ModifiersState, VirtualKeyCode}; | ||
// Only called if ElementState::Pressed | ||
pub fn set_state(vk: VirtualKeyCode, m: ModifiersState) { | ||
CONSOLE.with(|c| match vk { | ||
VirtualKeyCode::Semicolon => { | ||
if !m.shift() { | ||
return; | ||
} | ||
c.borrow_mut().active(true); | ||
} | ||
VirtualKeyCode::Escape => { | ||
c.borrow_mut().active(false); | ||
} | ||
VirtualKeyCode::Return => { | ||
c.borrow_mut().active(false); | ||
run_command(&mut c.borrow_mut()); | ||
} | ||
_ => {} | ||
}); | ||
} | ||
|
||
const CHAR_BACKSPACE: char = '\x08'; | ||
|
||
use state::RendererConsole; | ||
impl RendererConsole { | ||
///! Handle chars which will not trigger events (so, not :, Escape or Return) | ||
pub fn handle_ch(&mut self, ch: char) { | ||
debug_event!("Got ch: {:x}", ch as u8); | ||
if ch != CHAR_BACKSPACE { | ||
self.stdin.push(ch); | ||
} else { | ||
if self.stdin.len() > 1 { | ||
// don't delete `:` | ||
self.stdin.pop(); | ||
} | ||
} | ||
} | ||
|
||
///! String from clipboard | ||
pub fn handle_clipboard(&mut self) { | ||
let mut ctx: ClipboardContext = | ||
ClipboardProvider::new().expect("Failed to set up clipboard provider"); | ||
if let Ok(s) = ctx.get_contents() { | ||
self.stdin.push_str(&s); | ||
} | ||
} | ||
} | ||
|
||
pub fn run_command(c: &mut RendererConsole) { | ||
debug!("Command requested to be run: {}", &c.stdin); | ||
c.stdin.clear() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
//! Our Console is not a normal Unix console. stdin is always one line long, and stdout can be any | ||
//! number of lines but disappears often and is not possible to be scrolled back. (It is always the | ||
//! output of a single Command.) That's because this is a *Renderer Console*, not supposed to | ||
//! represent the Console itself, but rather just what we show the user on the screen. We output to | ||
//! the normal stdout as well, that's the persistent stdout. | ||
pub struct Console { | ||
pub stdin: String, | ||
pub stdout: String, | ||
// Pressing `:` activates the console, like in Vim. | ||
pub active: bool, | ||
} | ||
|
||
impl Default for Console { | ||
fn default() -> Self { | ||
Console { | ||
stdin: String::new(), | ||
stdout: String::new(), | ||
active: false, | ||
} | ||
} | ||
} | ||
|
||
impl Console { | ||
pub fn active(&mut self, b: bool) { | ||
self.active = b; | ||
} | ||
} | ||
|
||
use imgui; | ||
use skulpin::skia_safe::{Data, Font, FontStyle, Typeface}; | ||
use std::fs; | ||
lazy_static! { | ||
static ref MONO_FONT_BYTES: Option<Vec<u8>> = { | ||
match imgui::SYSTEMMONO.path { | ||
Some(_) => Some(imgui::SYSTEMMONO.data.clone()), | ||
_ => None, | ||
} | ||
}; | ||
} | ||
|
||
use std::cell::RefCell; | ||
lazy_static! { | ||
static ref CONSOLE_TYPEFACE: Typeface = { | ||
match &*MONO_FONT_BYTES { | ||
Some(ref bytes) => { | ||
Typeface::from_data(unsafe { Data::new_bytes(bytes.as_slice()) }, None) | ||
.expect("Failed to load mono font from memory") | ||
} | ||
None => Typeface::from_name("monospace", FontStyle::bold()) | ||
.expect("Failed to load mono font"), | ||
} | ||
}; | ||
} | ||
|
||
use super::constants::*; | ||
use crate::STATE; | ||
use skulpin::skia_safe::{Canvas, Paint, PaintStyle, Path, Rect, TextBlob}; | ||
impl Console { | ||
pub fn draw(&mut self, canvas: &mut Canvas) { | ||
if !self.active { | ||
return; | ||
} | ||
STATE.with(|v| { | ||
let factor = v.borrow().factor; | ||
let offset = v.borrow().offset; | ||
let font = | ||
Font::from_typeface_with_params(&*CONSOLE_TYPEFACE, 14. * (1. / factor), 1., 0.0); | ||
let winsize = v.borrow().winsize; | ||
let mut topleft = (offset.0, (winsize.height as f32) * (1. / factor)); | ||
let mut size = ((winsize.width as f32) * (1. / factor), offset.1); | ||
|
||
let (_, trect) = font.measure_str("Q", None); | ||
topleft.1 -= (CONSOLE_PADDING_Y_TOP + CONSOLE_PADDING_Y_BOTTOM) * (1. / factor); | ||
topleft.1 -= trect.height(); // premultiplied by font | ||
size.1 += (CONSOLE_PADDING_Y_TOP + CONSOLE_PADDING_Y_BOTTOM) * (1. / factor); | ||
size.1 += trect.height(); // premultiplied by font | ||
|
||
// Draw background | ||
let console_rect = Rect::from_point_and_size(topleft, size); | ||
let mut paint = Paint::default(); | ||
let mut path = Path::new(); | ||
paint.set_style(PaintStyle::Fill); | ||
paint.set_color(CONSOLE_FILL); | ||
path.add_rect(console_rect, None); | ||
path.close(); | ||
|
||
canvas.draw_path(&path, &paint); | ||
|
||
// Draw text | ||
let blob = TextBlob::from_str(&self.stdin, &font) | ||
.expect(&format!("Failed to shape {}", &self.stdin)); | ||
|
||
paint.set_color(CONSOLE_TEXT_FILL); | ||
topleft.0 += CONSOLE_PADDING_X * (1. / factor); | ||
topleft.1 += CONSOLE_PADDING_Y_BOTTOM * (1. / factor); | ||
topleft.1 += trect.height(); // premultiplied by font | ||
|
||
canvas.draw_text_blob(&blob, topleft, &paint); | ||
}); | ||
} | ||
} | ||
|
||
enum Return { | ||
OK, | ||
Failure(String), | ||
} | ||
|
||
struct Command { | ||
name: String, | ||
args: Vec<String>, | ||
run: Fn() -> Return, | ||
} |
Oops, something went wrong.