reduce flicker in the torrent list

This commit is contained in:
Charles Kerr 2007-08-03 20:46:02 +00:00
parent 03845215de
commit 8be21b668b
3 changed files with 36 additions and 14 deletions

View File

@ -171,6 +171,8 @@ BEGIN_EVENT_TABLE(TorrentListCtrl, wxListCtrl)
EVT_LIST_ITEM_DESELECTED( TORRENT_LIST_CTRL, TorrentListCtrl::OnItemDeselected ) EVT_LIST_ITEM_DESELECTED( TORRENT_LIST_CTRL, TorrentListCtrl::OnItemDeselected )
END_EVENT_TABLE() END_EVENT_TABLE()
TorrentListCtrl :: TorrentListCtrl( tr_handle_t * handle, TorrentListCtrl :: TorrentListCtrl( tr_handle_t * handle,
wxConfig * config, wxConfig * config,
wxWindow * parent, wxWindow * parent,
@ -194,6 +196,18 @@ TorrentListCtrl :: ~TorrentListCtrl()
{ {
} }
void
TorrentListCtrl :: SetCell( int item, int column, const wxString& xstr )
{
wxListItem i;
i.SetId( item );
i.SetColumn( column );
i.SetMask( wxLIST_MASK_TEXT );
GetItem( i );
if( i.GetText() != xstr )
SetItem( item, column, xstr );
}
void void
TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor, TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor,
int myTorrents_index, int myTorrents_index,
@ -247,7 +261,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor,
break; break;
case COL_PEERS: case COL_PEERS:
xstr = wxString::Format( _("%d of %d"), s->peersConnected, s->leechers ); xstr = wxString::Format( _("%d (%d)"), s->peersConnected, s->leechers );
break; break;
case COL_RATIO: case COL_RATIO:
@ -307,7 +321,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor,
} }
if( col ) if( col )
SetItem( row, col++, xstr ); SetCell( row, col++, xstr );
else { else {
// first column... find the right row to put the info in. // first column... find the right row to put the info in.
// if the torrent's in the list already, update that row. // if the torrent's in the list already, update that row.
@ -319,7 +333,7 @@ TorrentListCtrl :: RefreshTorrent( tr_torrent_t * tor,
} }
} }
if( row >= 0 ) { if( row >= 0 ) {
SetItem( row, col++, xstr ); SetCell( row, col++, xstr );
} }
else { else {
row = InsertItem( GetItemCount(), xstr ); row = InsertItem( GetItemCount(), xstr );
@ -602,7 +616,7 @@ TorrentListCtrl :: Rebuild()
InsertColumn( i++, h, format, width ); InsertColumn( i++, h, format, width );
} }
Repopulate (); Repopulate( );
} }
typedef std::set<tr_torrent_t*> torrent_set; typedef std::set<tr_torrent_t*> torrent_set;
@ -614,11 +628,14 @@ TorrentListCtrl :: Assign( const torrents_t& torrents )
torrents_v added; torrents_v added;
prev.insert( myTorrents.begin(), myTorrents.end() ); prev.insert( myTorrents.begin(), myTorrents.end() );
cur.insert( torrents.begin(), torrents.end() ); cur.insert( torrents.begin(), torrents.end() );
std::set_difference (prev.begin(), prev.end(), cur.begin(), cur.end(), inserter(removed, removed.begin())); std::set_difference (prev.begin(), prev.end(),
std::set_difference (cur.begin(), cur.end(), prev.begin(), prev.end(), inserter(added, added.begin())); cur.begin(), cur.end(), inserter(removed, removed.begin()));
std::set_difference (cur.begin(), cur.end(),
prev.begin(), prev.end(), inserter(added, added.begin()));
Remove( removed ); Remove( removed );
Add( added ); Add( added );
Refresh (); Refresh( );
Resort( );
} }
void void
@ -629,7 +646,6 @@ TorrentListCtrl :: Add( const torrents_v& add )
myTorrents.insert( myTorrents.end(), add.begin(), add.end() ); myTorrents.insert( myTorrents.end(), add.begin(), add.end() );
for( torrents_v::const_iterator it(add.begin()), end(add.end()); it!=end; ++it ) for( torrents_v::const_iterator it(add.begin()), end(add.end()); it!=end; ++it )
RefreshTorrent( *it, i++, cols ); RefreshTorrent( *it, i++, cols );
Resort( );
} }
void void

View File

@ -79,10 +79,10 @@ class TorrentListCtrl: public wxListCtrl
public: public:
typedef std::vector<tr_torrent_t*> torrents_v; typedef std::vector<tr_torrent_t*> torrents_v;
void Add( const torrents_v& torrents );
void Assign( const torrents_v& torrents ); void Assign( const torrents_v& torrents );
private: private:
void Add( const torrents_v& torrents );
void Sort( int column ); void Sort( int column );
void Resort( ); void Resort( );
void RefreshTorrent( tr_torrent_t*, int, const std::vector<int>& ); void RefreshTorrent( tr_torrent_t*, int, const std::vector<int>& );
@ -93,6 +93,9 @@ class TorrentListCtrl: public wxListCtrl
typedef std::map<std::string,int> str2int_t; typedef std::map<std::string,int> str2int_t;
str2int_t myHashToItem; str2int_t myHashToItem;
private:
void SetCell( int item, int col, const wxString& xstr );
private: private:
struct TorStat { struct TorStat {
time_t time; time_t time;
@ -108,6 +111,7 @@ class TorrentListCtrl: public wxListCtrl
void OnItemSelected( wxListEvent& ); void OnItemSelected( wxListEvent& );
void OnItemDeselected( wxListEvent& ); void OnItemDeselected( wxListEvent& );
private: private:
tr_handle_t * myHandle; tr_handle_t * myHandle;
wxConfig * myConfig; wxConfig * myConfig;

View File

@ -29,6 +29,7 @@
#include <wx/notebook.h> #include <wx/notebook.h>
#include <wx/snglinst.h> #include <wx/snglinst.h>
#include <wx/splitter.h> #include <wx/splitter.h>
#include <wx/statline.h>
#include <wx/taskbar.h> #include <wx/taskbar.h>
#include <wx/tglbtn.h> #include <wx/tglbtn.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>
@ -442,6 +443,7 @@ MyFrame :: OnPulse(wxTimerEvent& WXUNUSED(event) )
} }
RefreshFilterCounts( ); RefreshFilterCounts( );
ApplyCurrentFilter( );
mySpeedStats->Update( handle ); mySpeedStats->Update( handle );
@ -541,8 +543,8 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
wxIcon drop_icon( minus_xpm ); wxIcon drop_icon( minus_xpm );
wxBitmap bitmap; wxBitmap bitmap;
wxToolBar* toolbar = CreateToolBar( wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT | wxTB_TEXT ); wxToolBar* toolbar = CreateToolBar( wxTB_FLAT );
toolbar->SetToolBitmapSize( wxSize( 16, 16 ) ); toolbar->SetToolBitmapSize( wxSize( 24, 24 ) );
bitmap.CopyFromIcon( open_icon ); bitmap.CopyFromIcon( open_icon );
toolbar->AddTool( wxID_OPEN, _T("Open"), bitmap ); toolbar->AddTool( wxID_OPEN, _T("Open"), bitmap );
bitmap.CopyFromIcon( exec_icon ); bitmap.CopyFromIcon( exec_icon );
@ -557,7 +559,7 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
*** Row 1 *** Row 1
**/ **/
wxSplitterWindow * hsplit = new wxSplitterWindow( this ); wxSplitterWindow * hsplit = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3DSASH );
#if wxCHECK_VERSION(2,5,4) #if wxCHECK_VERSION(2,5,4)
hsplit->SetSashGravity( 0.8 ); hsplit->SetSashGravity( 0.8 );
#endif #endif
@ -582,6 +584,7 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
myTorrentList->AddListener( this ); myTorrentList->AddListener( this );
wxBoxSizer * panelSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer * panelSizer = new wxBoxSizer( wxVERTICAL );
panelSizer->Add( new wxStaticLine( panel_1 ), 0, wxEXPAND, 0 );
panelSizer->Add( buttonSizer, 0, 0, 0 ); panelSizer->Add( buttonSizer, 0, 0, 0 );
panelSizer->Add( myTorrentList, 1, wxEXPAND, 0 ); panelSizer->Add( myTorrentList, 1, wxEXPAND, 0 );
@ -630,7 +633,6 @@ MyFrame :: MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size
int count = 0; int count = 0;
tr_torrent_t ** torrents = tr_loadTorrents ( handle, mySavePath.c_str(), flags, &count ); tr_torrent_t ** torrents = tr_loadTorrents ( handle, mySavePath.c_str(), flags, &count );
myTorrents.insert( myTorrents.end(), torrents, torrents+count ); myTorrents.insert( myTorrents.end(), torrents, torrents+count );
myTorrentList->Add( myTorrents );
tr_free( torrents ); tr_free( torrents );
wxTimerEvent dummy; wxTimerEvent dummy;