From 9be9ed9c17333a6b8b03375189249e6342ebd36d Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Wed, 30 Sep 2009 21:37:16 +0000 Subject: [PATCH] [layers] Sped up the switching from one active layer to another, when the new layer was already displayed (thanks to the depth buffer, again) git-svn-id: svn://pulkomandy.tk/GrafX2/branches/layers@1049 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- buttons.c | 12 ++++++++++-- pages.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ pages.h | 4 ++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/buttons.c b/buttons.c index 41c757ec..74edc017 100644 --- a/buttons.c +++ b/buttons.c @@ -2879,6 +2879,7 @@ void Load_picture(byte image) } Compute_optimal_menu_colors(Main_palette); + Redraw_layered_image(); Display_all_screen(); if (image) @@ -2980,7 +2981,7 @@ void Button_Reload(void) Compute_limits(); Compute_paintbrush_coordinates(); } - + Redraw_layered_image(); Display_all_screen(); Main_image_is_modified=0; @@ -4260,6 +4261,10 @@ void Transparency_set(byte amount) void Layer_activate(short layer, short side) { + byte old_layers; + + // Keep a copy of which layers were visible + old_layers = Main_layers_visible; if (side == RIGHT_SIDE) { // Right-click on current layer @@ -4290,7 +4295,10 @@ void Layer_activate(short layer, short side) } Hide_cursor(); - Redraw_layered_image(); + if (Main_layers_visible != old_layers) + Redraw_layered_image(); + else + Update_depth_buffer(); // Only need the depth buffer //Download_infos_page_main(Main_backups->Pages); //Download_infos_backup(Main_backups); Display_all_screen(); diff --git a/pages.c b/pages.c index 4a0e0b76..9a113213 100644 --- a/pages.c +++ b/pages.c @@ -191,6 +191,51 @@ void Redraw_layered_image(void) Download_infos_backup(Main_backups); } +void Update_depth_buffer(void) +{ + // Re-construct the depth buffer with the visible layers. + // This function doesn't touch the visible buffer, it assumes + // that it was already up-to-date. (Ex. user only changed active layer) + + int layer; + // First layer + for (layer=0; layerPages->Nb_layers; layer++) + { + if ((1<Pages->Nb_layers; layer++) + { + // skip the current layer, whenever we reach it + if (layer == Main_current_layer) + continue; + + if ((1<Pages->Image[layer]+i); + if (color != 0) /* transp color */ + { + *(Visible_image_depth_buffer.Image+i) = layer; + } + } + } + } + Download_infos_backup(Main_backups); +} + void Redraw_current_layer(void) { int i; diff --git a/pages.h b/pages.h index 461c124e..ad22e7c6 100644 --- a/pages.h +++ b/pages.h @@ -82,4 +82,8 @@ void Free_current_page(void); // 'Kill' button void Exchange_main_and_spare(void); void End_of_modification(void); +void Update_depth_buffer(void); +void Redraw_layered_image(void); +void Redraw_current_layer(void); + #endif