diff --git a/AUTHORS b/AUTHORS index 730b6756..92da0319 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,2 +1,9 @@ +Source code: Fredrick Brennan (@ctrlcctrlv) @jazzfool + +Design, icons: +Eli Heuer (@eliheuer) + +Font: +Ubuntu (Canonical Ltd., Dalton Maag) diff --git a/Cargo.toml b/Cargo.toml index f06d9edc..b4b436d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,14 +6,23 @@ authors = ["Fredrick Brennan "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# For display reclutch = { git = "https://github.com/jazzfool/reclutch", features = ["skia"] } imgui-glium-renderer = "0.4.0" imgui-winit-support = "0.4.0" imgui = "0.4.0" gl = "0.14.0" glium = "0.27.0" + +# For icons in toolbox +nsvg = "0.5.1" + +# For glifparser xmltree = "0.10.1" + +# For global state lazy_static = "1.4.0" + +# For argument parsing clap = "2.33.3" git-version = "0.3.4" -thiserror = "1.0.20" diff --git a/resources/fonts/Ubuntu-Regular.ttf b/resources/fonts/Ubuntu-Regular.ttf new file mode 100644 index 00000000..dbb834a4 Binary files /dev/null and b/resources/fonts/Ubuntu-Regular.ttf differ diff --git a/src/main.rs b/src/main.rs index 52c96c00..942ce864 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,11 @@ #![feature(assoc_char_funcs, panic_info_message)] +//! Qglif - A cross-platform .glif renderer and editor. +//! Main author is Fredrick Brennan (@ctrlcctrlv); see AUTHORS. +//! (c) 2020. Apache 2.0 licensed. +// Cargo.toml comments say what crates are used for what. #[macro_use] extern crate lazy_static; -extern crate thiserror; #[macro_use] extern crate glium; extern crate clap; @@ -10,6 +13,7 @@ extern crate gl; extern crate xmltree; #[macro_use] extern crate git_version; // for util::parse_args +extern crate nsvg; extern crate reclutch; use glium::glutin; @@ -29,7 +33,7 @@ extern crate imgui_glium_renderer; extern crate imgui_winit_support; use imgui::Context as ImguiContext; use imgui_glium_renderer::Renderer as ImguiRenderer; -use imgui_winit_support::WinitPlatform; +use imgui_winit_support::{HiDpiMode, WinitPlatform}; #[macro_use] mod util; @@ -119,8 +123,22 @@ fn main() { let mut imgui = ImguiContext::create(); let mut platform = WinitPlatform::init(&mut imgui); + platform.attach_window( + imgui.io_mut(), + &gl_display.gl_window().window(), + HiDpiMode::Default, + ); + debug!("DPI is {}", gl_display.gl_window().window().scale_factor()); + imgui.set_ini_filename(None); - imgui.io_mut().display_size = [window_size.0 as f32, window_size.1 as f32]; + + state.with(|v| { + v.borrow_mut().dpi = gl_display.gl_window().window().scale_factor(); + }); + + opengl::imgui::set_imgui_fonts(&mut imgui); + opengl::imgui::set_imgui_dpi(&mut imgui, window_size); + let mut renderer = ImguiRenderer::init(&mut imgui, &gl_display).expect("Failed to initialize renderer"); @@ -150,8 +168,10 @@ fn main() { .unwrap(); gl_display.gl_window().resize(physical_size); - imgui.io_mut().display_size = - [physical_size.width as f32, physical_size.height as f32]; + opengl::imgui::set_imgui_dpi( + &mut imgui, + (physical_size.width, physical_size.height), + ); skia_context = Some(unsafe { skia_context.take().unwrap().make_current().unwrap() }); @@ -282,7 +302,6 @@ fn main() { ) .unwrap(); - let mut frame_target = gl_display.draw(); let target = &mut out_texture_fb; //target.clear_color_and_depth((1.0, 1.0, 1.0, 1.0), 1.0); @@ -309,6 +328,7 @@ fn main() { &mut last_frame, &mut renderer, ); + let mut frame_target = gl_display.draw(); frame_target .draw( &quad_vertex_buffer, diff --git a/src/opengl/imgui.rs b/src/opengl/imgui.rs index 8d333d2f..5e013e93 100644 --- a/src/opengl/imgui.rs +++ b/src/opengl/imgui.rs @@ -6,6 +6,8 @@ use std::time::Instant; use crate::state::state; +mod icons; + pub fn build_imgui_ui(ui: &mut imgui::Ui) { imgui::Window::new(im_str!("Hello world")) .bg_alpha(1.) // See comment on fn redraw_skia @@ -22,6 +24,35 @@ pub fn build_imgui_ui(ui: &mut imgui::Ui) { }); } +pub fn set_imgui_fonts(imgui: &mut imgui::Context) { + let dpi = state.with(|v| v.borrow().dpi as f32); + let mut fontconfig = imgui::FontConfig::default(); + fontconfig.oversample_h = f32::ceil(dpi) as i32 + 1; + fontconfig.oversample_v = fontconfig.oversample_h; + imgui.fonts().add_font(&[imgui::FontSource::TtfData { + data: include_bytes!(concat!( + env!("PWD"), + "/", + "resources/fonts/Ubuntu-Regular.ttf" + )), + size_pixels: 14., + config: Some(fontconfig), + }]); +} + +pub fn set_imgui_dpi(imgui: &mut imgui::Context, window_size: (u32, u32)) { + state.with(|v| { + let dpi = v.borrow().dpi as f32; + imgui.style_mut().scale_all_sizes(dpi); + imgui.io_mut().display_size = [ + window_size.0 as f32 * (1. / dpi), + window_size.1 as f32 * (1. / dpi), + ]; + imgui.io_mut().font_global_scale = 1.; + imgui.style_mut().use_light_colors(); + }); +} + pub fn render_imgui_frame( target: &mut glium::framebuffer::SimpleFrameBuffer, imgui: &mut imgui::Context, diff --git a/src/state.rs b/src/state.rs index 37f4d363..578c557b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -14,6 +14,7 @@ pub enum Mode { Move, Select, } + // Thread local state. pub struct State { pub mode: Mode, @@ -28,6 +29,7 @@ pub struct State { pub winsize: PhysicalSize, // for Skia pub factor: f32, pub offset: (f32, f32), + pub dpi: f64, // from glutin scale_factor() } impl State { @@ -48,6 +50,7 @@ impl State { }, factor: 1., offset: (0., 0.), + dpi: 1., } } }