diff options
author | Matt Keeler <mjkeeler7@gmail.com> | 2018-07-31 07:31:39 -0400 |
---|---|---|
committer | Matt Keeler <mjkeeler7@gmail.com> | 2018-08-07 07:39:44 -0400 |
commit | 7537f68db1a998d2260dd20b9d142f9f2d6b9874 (patch) | |
tree | f0dd4ce7d740bd4aca48a194746a6cccce742cef | |
parent | 27b8ab5dbcfd9ebd02befd5459013d89341a5371 (diff) | |
download | alacritty-7537f68db1a998d2260dd20b9d142f9f2d6b9874.tar.gz alacritty-7537f68db1a998d2260dd20b9d142f9f2d6b9874.zip |
Scale padding with DPR
-rw-r--r-- | src/display.rs | 16 | ||||
-rw-r--r-- | src/renderer/mod.rs | 37 |
2 files changed, 28 insertions, 25 deletions
diff --git a/src/display.rs b/src/display.rs index bb52c55a..371cc4e5 100644 --- a/src/display.rs +++ b/src/display.rs @@ -148,7 +148,7 @@ impl Display { .expect("glutin returns window size").to_physical(dpr); // Create renderer - let mut renderer = QuadRenderer::new(config, viewport_size)?; + let mut renderer = QuadRenderer::new(config, viewport_size, dpr)?; let (glyph_cache, cell_width, cell_height) = Self::new_glyph_cache(dpr, &mut renderer, config)?; @@ -163,11 +163,11 @@ impl Display { let height = cell_height as u32 * dimensions.lines_u32(); let new_viewport_size = PhysicalSize::new( - (width + 2 * u32::from(config.padding().x)) as f64, - (height + 2 * u32::from(config.padding().y)) as f64); + (width + 2 * u32::from(config.padding().x) * dpr.floor() as u32) as f64, + (height + 2 * u32::from(config.padding().y) * dpr.floor() as u32) as f64); window.set_inner_size(new_viewport_size.to_logical(dpr)); - renderer.resize(new_viewport_size); + renderer.resize(new_viewport_size, dpr); viewport_size = new_viewport_size; } @@ -179,8 +179,8 @@ impl Display { height: viewport_size.height as f32, cell_width: cell_width as f32, cell_height: cell_height as f32, - padding_x: f32::from(config.padding().x), - padding_y: f32::from(config.padding().y), + padding_x: f32::from(config.padding().x) * dpr as f32, + padding_y: f32::from(config.padding().y) * dpr as f32, }; // Channel for resize events @@ -298,6 +298,8 @@ impl Display { if terminal.font_size != self.font_size || dpr != self.size_info.dpr { self.font_size = terminal.font_size; self.size_info.dpr = dpr; + self.size_info.padding_x = f32::from(config.padding().x) * dpr as f32; + self.size_info.padding_y = f32::from(config.padding().y) * dpr as f32; self.update_glyph_cache(config); if new_size == None { @@ -322,7 +324,7 @@ impl Display { } self.window.resize(psize); - self.renderer.resize(psize); + self.renderer.resize(psize, dpr); } } diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index b0f03645..c260f64d 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -479,8 +479,8 @@ const ATLAS_SIZE: i32 = 1024; impl QuadRenderer { // TODO should probably hand this a transform instead of width/height - pub fn new(config: &Config, size: PhysicalSize) -> Result<QuadRenderer, Error> { - let program = ShaderProgram::new(config, size)?; + pub fn new(config: &Config, size: PhysicalSize, dpr: f64) -> Result<QuadRenderer, Error> { + let program = ShaderProgram::new(config, size, dpr)?; let mut vao: GLuint = 0; let mut vbo: GLuint = 0; @@ -639,7 +639,7 @@ impl QuadRenderer { while let Ok(msg) = self.rx.try_recv() { match msg { Msg::ShaderReload => { - self.reload_shaders(config, PhysicalSize::new(props.width as f64, props.height as f64)); + self.reload_shaders(config, PhysicalSize::new(props.width as f64, props.height as f64), props.dpr); } } } @@ -690,9 +690,9 @@ impl QuadRenderer { }) } - pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize) { + pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize, dpr: f64) { warn!("Reloading shaders ..."); - let program = match ShaderProgram::new(config, size) { + let program = match ShaderProgram::new(config, size, dpr) { Ok(program) => { warn!(" ... OK"); program @@ -718,11 +718,11 @@ impl QuadRenderer { self.program = program; } - pub fn resize(&mut self, size: PhysicalSize) { + pub fn resize(&mut self, size: PhysicalSize, dpr: f64) { let (width, height) : (u32, u32) = size.into(); - let padding_x = i32::from(self.program.padding_x); - let padding_y = i32::from(self.program.padding_y); + let padding_x = (self.program.padding_x as f64 * dpr).floor() as i32; + let padding_y = (self.program.padding_y as f64 * dpr).floor() as i32; // viewport unsafe { @@ -731,7 +731,7 @@ impl QuadRenderer { // update projection self.program.activate(); - self.program.update_projection(width as f32, height as f32); + self.program.update_projection(width as f32, height as f32, dpr as f32); self.program.deactivate(); } } @@ -955,7 +955,8 @@ impl ShaderProgram { pub fn new( config: &Config, - size: PhysicalSize + size: PhysicalSize, + dpr: f64 ) -> Result<ShaderProgram, ShaderCreationError> { let vertex_source = if cfg!(feature = "live-shader-reload") { None @@ -1019,21 +1020,21 @@ impl ShaderProgram { u_cell_dim: cell_dim, u_visual_bell: visual_bell, u_background: background, - padding_x: config.padding().x, - padding_y: config.padding().y, + padding_x: u8::from(config.padding().x), + padding_y: u8::from(config.padding().y), }; - shader.update_projection(size.width as f32, size.height as f32); + shader.update_projection(size.width as f32, size.height as f32, dpr as f32); shader.deactivate(); Ok(shader) } - fn update_projection(&self, width: f32, height: f32) { + fn update_projection(&self, width: f32, height: f32, dpr: f32) { // Bounds check - if (width as u32) < (2 * u32::from(self.padding_x)) || - (height as u32) < (2 * u32::from(self.padding_y)) + if (width as u32) < (2 * (self.padding_x as f32 * dpr).floor() as u32) || + (height as u32) < (2 * (self.padding_y as f32 * dpr).floor() as u32) { return; } @@ -1045,8 +1046,8 @@ impl ShaderProgram { // correctly. let ortho = cgmath::ortho( 0., - width - 2. * f32::from(self.padding_x), - 2. * f32::from(self.padding_y), + width - (2. * f32::from(self.padding_x) * dpr), + 2. * f32::from(self.padding_y) * dpr, height, -1., 1., |