From 3ce35e8b001eecfd8ecd8fc284e15a6e627f6add Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 4 Sep 2008 11:45:23 +0000 Subject: [PATCH] Reduced flicker in card list git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1202 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/auto_replace_window.cpp | 2 +- src/gui/control/card_list.cpp | 2 +- src/gui/control/item_list.cpp | 26 +++++++++++++++++--------- src/gui/control/item_list.hpp | 2 +- src/gui/control/keyword_list.cpp | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/gui/auto_replace_window.cpp b/src/gui/auto_replace_window.cpp index 01d523d2..9b8af401 100644 --- a/src/gui/auto_replace_window.cpp +++ b/src/gui/auto_replace_window.cpp @@ -287,7 +287,7 @@ void AutoReplaceWindow::updateItem() { ar->replace = replace->GetValue(); ar->enabled = enabled->GetValue(); ar->whole_word = whole_word->GetValue(); - list->refreshList(); + list->refreshList(true); in_event = false; } diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index 041c9ccf..fe0ffe96 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -119,7 +119,7 @@ void CardListBase::onAction(const Action& action, bool undone) { return; } TYPE_CASE(action, ValueAction) { - if (action.card) refreshList(); + if (action.card) refreshList(true); } } diff --git a/src/gui/control/item_list.cpp b/src/gui/control/item_list.cpp index e9a2aa21..3c94198f 100644 --- a/src/gui/control/item_list.cpp +++ b/src/gui/control/item_list.cpp @@ -147,26 +147,34 @@ struct ItemList::ItemComparer { } }; -void ItemList::refreshList() { - Freeze(); +void ItemList::refreshList(bool refresh_current_only) { // Get all items - sorted_list.clear(); + vector old_sorted_list; + swap(sorted_list, old_sorted_list); getItems(sorted_list); - long item_count = (long)sorted_list.size(); - SetItemCount(item_count); // Sort the list if (sort_by_column >= 0) { sort(sorted_list.begin(), sorted_list.end(), ItemComparer(*this)); } + // Has the entire list changed? + if (refresh_current_only && sorted_list == old_sorted_list) { + if (selected_item_pos > 0) RefreshItem(selected_item_pos); + return; + } // refresh - if (item_count) - RefreshItems(0, item_count - 1); - if (item_count == 0) Refresh(); + // Note: Freeze/Thaw makes flicker worse + long item_count = (long)sorted_list.size(); + SetItemCount(item_count); // (re)select current item findSelectedItemPos(); focusNone(); focusSelectedItem(true); - Thaw(); + // refresh items + if (item_count == 0) { + Refresh(); + } else { + RefreshItems(0, item_count - 1); + } } void ItemList::sortBy(long column, bool ascending) { diff --git a/src/gui/control/item_list.hpp b/src/gui/control/item_list.hpp index c0afca71..a603b734 100644 --- a/src/gui/control/item_list.hpp +++ b/src/gui/control/item_list.hpp @@ -71,7 +71,7 @@ class ItemList : public wxListView { /// Sort by the given column virtual void sortBy(long column, bool ascending); /// Refresh the card list (resort, refresh and reselect current item) - void refreshList(); + void refreshList(bool refresh_current_only = false); /// Set the image of a column header (fixes wx bug) void SetColumnImage(int col, int image); diff --git a/src/gui/control/keyword_list.cpp b/src/gui/control/keyword_list.cpp index d5864adc..ac0bcbf2 100644 --- a/src/gui/control/keyword_list.cpp +++ b/src/gui/control/keyword_list.cpp @@ -76,7 +76,7 @@ void KeywordList::onAction(const Action& action, bool undone) { KeywordTextValue* value = dynamic_cast(action.valueP.get()); if (value) { // this is indeed an action on a keyword, refresh - refreshList(); + refreshList(true); } } }