@ -11,18 +11,14 @@ use super::animation_utils::*;
use super ::{ Renderer , RendererSettings } ;
use super ::{ Renderer , RendererSettings } ;
use crate ::editor ::WindowDrawCommand ;
use crate ::editor ::WindowDrawCommand ;
use crate ::redraw_scheduler ::REDRAW_SCHEDULER ;
use crate ::redraw_scheduler ::REDRAW_SCHEDULER ;
use crate ::utils ::Dimensions ;
fn build_window_surface (
fn build_window_surface ( parent_canvas : & mut Canvas , pixel_size : ( i32 , i32 ) ) -> Surface {
parent_canvas : & mut Canvas ,
pixel_width : u64 ,
pixel_height : u64 ,
) -> Surface {
let dimensions = ( pixel_width as i32 , pixel_height as i32 ) ;
let mut context = parent_canvas . recording_context ( ) . unwrap ( ) ;
let mut context = parent_canvas . recording_context ( ) . unwrap ( ) ;
let budgeted = Budgeted ::Yes ;
let budgeted = Budgeted ::Yes ;
let parent_image_info = parent_canvas . image_info ( ) ;
let parent_image_info = parent_canvas . image_info ( ) ;
let image_info = ImageInfo ::new (
let image_info = ImageInfo ::new (
dimensions ,
pixel_size ,
parent_image_info . color_type ( ) ,
parent_image_info . color_type ( ) ,
parent_image_info . alpha_type ( ) ,
parent_image_info . alpha_type ( ) ,
parent_image_info . color_space ( ) ,
parent_image_info . color_space ( ) ,
@ -45,12 +41,10 @@ fn build_window_surface(
fn build_window_surface_with_grid_size (
fn build_window_surface_with_grid_size (
parent_canvas : & mut Canvas ,
parent_canvas : & mut Canvas ,
renderer : & Renderer ,
renderer : & Renderer ,
grid_width : u64 ,
grid_size : Dimensions ,
grid_height : u64 ,
) -> Surface {
) -> Surface {
let pixel_width = ( ( grid_width * renderer . font_width ) as f32 ) as u64 ;
let mut surface =
let pixel_height = ( ( grid_height * renderer . font_height ) as f32 ) as u64 ;
build_window_surface ( parent_canvas , ( grid_size * renderer . font_dimensions ) . into ( ) ) ;
let mut surface = build_window_surface ( parent_canvas , pixel_width , pixel_height ) ;
let canvas = surface . canvas ( ) ;
let canvas = surface . canvas ( ) ;
canvas . clear ( renderer . get_default_background ( ) ) ;
canvas . clear ( renderer . get_default_background ( ) ) ;
@ -71,12 +65,10 @@ impl LocatedSurface {
fn new (
fn new (
parent_canvas : & mut Canvas ,
parent_canvas : & mut Canvas ,
renderer : & Renderer ,
renderer : & Renderer ,
grid_width : u64 ,
grid_size : Dimensions ,
grid_height : u64 ,
top_line : u64 ,
top_line : u64 ,
) -> LocatedSurface {
) -> LocatedSurface {
let surface =
let surface = build_window_surface_with_grid_size ( parent_canvas , renderer , grid_size ) ;
build_window_surface_with_grid_size ( parent_canvas , renderer , grid_width , grid_height ) ;
LocatedSurface { surface , top_line }
LocatedSurface { surface , top_line }
}
}
@ -98,8 +90,7 @@ pub struct RenderedWindow {
pub hidden : bool ,
pub hidden : bool ,
pub floating_order : Option < u64 > ,
pub floating_order : Option < u64 > ,
pub grid_width : u64 ,
pub grid_size : Dimensions ,
pub grid_height : u64 ,
grid_start_position : Point ,
grid_start_position : Point ,
pub grid_current_position : Point ,
pub grid_current_position : Point ,
@ -125,11 +116,9 @@ impl RenderedWindow {
renderer : & Renderer ,
renderer : & Renderer ,
id : u64 ,
id : u64 ,
grid_position : Point ,
grid_position : Point ,
grid_width : u64 ,
grid_size : Dimensions ,
grid_height : u64 ,
) -> RenderedWindow {
) -> RenderedWindow {
let current_surface =
let current_surface = LocatedSurface ::new ( parent_canvas , renderer , grid_size , 0 ) ;
LocatedSurface ::new ( parent_canvas , renderer , grid_width , grid_height , 0 ) ;
RenderedWindow {
RenderedWindow {
snapshots : VecDeque ::new ( ) ,
snapshots : VecDeque ::new ( ) ,
@ -138,8 +127,7 @@ impl RenderedWindow {
hidden : false ,
hidden : false ,
floating_order : None ,
floating_order : None ,
grid_width ,
grid_size ,
grid_height ,
grid_start_position : grid_position ,
grid_start_position : grid_position ,
grid_current_position : grid_position ,
grid_current_position : grid_position ,
@ -153,16 +141,15 @@ impl RenderedWindow {
}
}
}
}
pub fn pixel_region ( & self , font_ width: u64 , font_height : u64 ) -> Rect {
pub fn pixel_region ( & self , font_ dimensions: Dimensions ) -> Rect {
let current_pixel_position = Point ::new (
let current_pixel_position = Point ::new (
self . grid_current_position . x * font_ width as f32 ,
self . grid_current_position . x * font_ dimensions. width as f32 ,
self . grid_current_position . y * font_ height as f32 ,
self . grid_current_position . y * font_ dimensions. height as f32 ,
) ;
) ;
let image_width = ( self . grid_width * font_width ) as i32 ;
let image_size : ( i32 , i32 ) = ( self . grid_size * font_dimensions ) . into ( ) ;
let image_height = ( self . grid_height * font_height ) as i32 ;
Rect ::from_point_and_size ( current_pixel_position , ( image_width , image_height ) )
Rect ::from_point_and_size ( current_pixel_position , image_size )
}
}
pub fn update ( & mut self , settings : & RendererSettings , dt : f32 ) -> bool {
pub fn update ( & mut self , settings : & RendererSettings , dt : f32 ) -> bool {
@ -212,15 +199,14 @@ impl RenderedWindow {
root_canvas : & mut Canvas ,
root_canvas : & mut Canvas ,
settings : & RendererSettings ,
settings : & RendererSettings ,
default_background : Color ,
default_background : Color ,
font_width : u64 ,
font_dimensions : Dimensions ,
font_height : u64 ,
dt : f32 ,
dt : f32 ,
) -> WindowDrawDetails {
) -> WindowDrawDetails {
if self . update ( settings , dt ) {
if self . update ( settings , dt ) {
REDRAW_SCHEDULER . queue_next_frame ( ) ;
REDRAW_SCHEDULER . queue_next_frame ( ) ;
}
}
let pixel_region = self . pixel_region ( font_ width, font_height ) ;
let pixel_region = self . pixel_region ( font_ dimensions ) ;
root_canvas . save ( ) ;
root_canvas . save ( ) ;
root_canvas . clip_rect ( & pixel_region , None , Some ( false ) ) ;
root_canvas . clip_rect ( & pixel_region , None , Some ( false ) ) ;
@ -252,6 +238,8 @@ impl RenderedWindow {
paint . set_color ( Color ::from_argb ( a , 255 , 255 , 255 ) ) ;
paint . set_color ( Color ::from_argb ( a , 255 , 255 , 255 ) ) ;
let font_height = font_dimensions . height ;
// Draw scrolling snapshots
// Draw scrolling snapshots
for snapshot in self . snapshots . iter_mut ( ) . rev ( ) {
for snapshot in self . snapshots . iter_mut ( ) . rev ( ) {
let scroll_offset = ( snapshot . top_line * font_height ) as f32
let scroll_offset = ( snapshot . top_line * font_height ) as f32
@ -298,10 +286,11 @@ impl RenderedWindow {
match draw_command {
match draw_command {
WindowDrawCommand ::Position {
WindowDrawCommand ::Position {
grid_position : ( grid_left , grid_top ) ,
grid_position : ( grid_left , grid_top ) ,
grid_size : ( grid_width , grid_height ) ,
grid_size ,
floating_order ,
floating_order ,
} = > {
} = > {
let new_destination : Point = ( grid_left as f32 , grid_top as f32 ) . into ( ) ;
let new_destination : Point = ( grid_left as f32 , grid_top as f32 ) . into ( ) ;
let new_grid_size : Dimensions = grid_size . into ( ) ;
if self . grid_destination ! = new_destination {
if self . grid_destination ! = new_destination {
if self . grid_start_position . x . abs ( ) > f32 ::EPSILON
if self . grid_start_position . x . abs ( ) > f32 ::EPSILON
@ -318,13 +307,12 @@ impl RenderedWindow {
self . grid_destination = new_destination ;
self . grid_destination = new_destination ;
}
}
if grid_width ! = self . grid_width | | grid_height ! = self . grid_height {
if self . grid_size ! = new_grid_size {
let mut old_surface = self . current_surface . surface ;
let mut old_surface = self . current_surface . surface ;
self . current_surface . surface = build_window_surface_with_grid_size (
self . current_surface . surface = build_window_surface_with_grid_size (
old_surface . canvas ( ) ,
old_surface . canvas ( ) ,
renderer ,
renderer ,
grid_width ,
new_grid_size ,
grid_height ,
) ;
) ;
old_surface . draw (
old_surface . draw (
self . current_surface . surface . canvas ( ) ,
self . current_surface . surface . canvas ( ) ,
@ -333,8 +321,7 @@ impl RenderedWindow {
None ,
None ,
) ;
) ;
self . grid_width = grid_width ;
self . grid_size = new_grid_size ;
self . grid_height = grid_height ;
}
}
self . floating_order = floating_order ;
self . floating_order = floating_order ;
@ -354,8 +341,8 @@ impl RenderedWindow {
style ,
style ,
} = > {
} = > {
let grid_position = ( window_left , window_top ) ;
let grid_position = ( window_left , window_top ) ;
let canvas = self . current_surface . surface . canvas ( ) ;
let canvas = self . current_surface . surface . canvas ( ) ;
canvas . save ( ) ;
canvas . save ( ) ;
renderer . draw_background ( canvas , grid_position , width , & style ) ;
renderer . draw_background ( canvas , grid_position , width , & style ) ;
renderer . draw_foreground ( canvas , & cells , grid_position , width , & style ) ;
renderer . draw_foreground ( canvas , & cells , grid_position , width , & style ) ;
@ -369,17 +356,22 @@ impl RenderedWindow {
rows ,
rows ,
cols ,
cols ,
} = > {
} = > {
let font_width = renderer . font_width as f32 ;
let Dimensions {
let font_height = renderer . font_height as f32 ;
width : font_width ,
height : font_height ,
} = renderer . font_dimensions ;
let scrolled_region = Rect ::new (
let scrolled_region = Rect ::new (
left as f32 * font_width ,
( left * font_width ) as f32 ,
top as f32 * font_height ,
( top * font_height ) as f32 ,
right as f32 * font_width ,
( right * font_width ) as f32 ,
bottom as f32 * font_height ,
( bottom * font_height ) as f32 ,
) ;
) ;
let mut translated_region = scrolled_region ;
let mut translated_region = scrolled_region ;
translated_region . offset ( ( - cols as f32 * font_width , - rows as f32 * font_height ) ) ;
translated_region . offset ( (
- cols as f32 * font_width as f32 ,
- rows as f32 * font_height as f32 ,
) ) ;
let snapshot = self . current_surface . surface . image_snapshot ( ) ;
let snapshot = self . current_surface . surface . image_snapshot ( ) ;
let canvas = self . current_surface . surface . canvas ( ) ;
let canvas = self . current_surface . surface . canvas ( ) ;
@ -400,8 +392,7 @@ impl RenderedWindow {
self . current_surface . surface = build_window_surface_with_grid_size (
self . current_surface . surface = build_window_surface_with_grid_size (
self . current_surface . surface . canvas ( ) ,
self . current_surface . surface . canvas ( ) ,
renderer ,
renderer ,
self . grid_width ,
self . grid_size ,
self . grid_height ,
) ;
) ;
self . snapshots . clear ( ) ;
self . snapshots . clear ( ) ;