diff options
author | Joe Wilm <joe@jwilm.com> | 2016-06-29 10:21:02 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-06-29 10:21:02 -0700 |
commit | 22789f35c7ab90a5ada70fdca25ca1c626eb1ca5 (patch) | |
tree | 4588f58a30b542a09fedc143f8ed710115440923 /src/renderer | |
parent | 69ed81d2495c6eb548c44e73c0e9ed359d3820f0 (diff) | |
download | alacritty-22789f35c7ab90a5ada70fdca25ca1c626eb1ca5.tar.gz alacritty-22789f35c7ab90a5ada70fdca25ca1c626eb1ca5.zip |
Implement terminal resizing
The resize event is received from glutin on the update thread, but the
renderer needs to be informed as well for updating the viewport and
projection matrix. This is achieved with an mpsc::channel.
To support resizing, the grid now offers methods for growing and
shrinking, and there are several implementations available for
clear_region based on different Range* types.
Core resize logic is all in Term::resize. It attempts to keep as much
context as possible when shinking the window. When growing, it's
basically just adding rows.
Diffstat (limited to 'src/renderer')
-rw-r--r-- | src/renderer/mod.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 9df4052d..8e548dd3 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -478,6 +478,18 @@ impl QuadRenderer { self.active_tex = 0; self.program = program; } + + pub fn resize(&mut self, width: i32, height: i32) { + // viewport + unsafe { + gl::Viewport(0, 0, width, height); + } + + // update projection + self.program.activate(); + self.program.update_projection(width as f32, height as f32); + self.program.deactivate(); + } } impl<'a> RenderApi<'a> { @@ -665,20 +677,25 @@ impl ShaderProgram { u_background: background, }; + shader.update_projection(width as f32, height as f32); + + shader.deactivate(); + + Ok(shader) + } + + fn update_projection(&self, width: f32, height: f32) { // set projection uniform - let ortho = cgmath::ortho(0., width as f32, 0., height as f32, -1., 1.); + let ortho = cgmath::ortho(0., width, 0., height, -1., 1.); let projection: [[f32; 4]; 4] = ortho.into(); println!("width: {}, height: {}", width, height); unsafe { - gl::UniformMatrix4fv(shader.u_projection, + gl::UniformMatrix4fv(self.u_projection, 1, gl::FALSE, projection.as_ptr() as *const _); } - shader.deactivate(); - - Ok(shader) } fn set_term_uniforms(&self, props: &term::SizeInfo) { |