optimization of scrolling and redrawing windows
This commit is contained in:
@@ -504,7 +504,6 @@ bool GetSongInfo(Song &s)
|
||||
|
||||
void GetDirectory(string dir)
|
||||
{
|
||||
pthread_t bolder;
|
||||
browsed_dir_scroll_begin = 0;
|
||||
if (browsed_dir != dir)
|
||||
mBrowser->Reset();
|
||||
|
||||
168
src/menu.cpp
168
src/menu.cpp
@@ -73,6 +73,9 @@ void Menu::AddOption(const string &str, LOCATION location, HAVE_SEPARATOR separa
|
||||
new_option->is_static = 0;
|
||||
new_option->is_bold = 0;
|
||||
itsOptions.push_back(new_option);
|
||||
|
||||
if (itsOptions.size() > itsBeginning && itsOptions.size() <= itsBeginning+itsHeight)
|
||||
NeedsRedraw.push_back(itsOptions.size()-1);
|
||||
}
|
||||
|
||||
void Menu::AddBoldOption(const string &str, LOCATION location, HAVE_SEPARATOR separator)
|
||||
@@ -84,6 +87,9 @@ void Menu::AddBoldOption(const string &str, LOCATION location, HAVE_SEPARATOR se
|
||||
new_option->is_static = 0;
|
||||
new_option->is_bold = 1;
|
||||
itsOptions.push_back(new_option);
|
||||
|
||||
if (itsOptions.size() > itsBeginning && itsOptions.size() <= itsBeginning+itsHeight)
|
||||
NeedsRedraw.push_back(itsOptions.size()-1);
|
||||
}
|
||||
|
||||
void Menu::AddStaticOption(const string &str, LOCATION location, HAVE_SEPARATOR separator)
|
||||
@@ -96,6 +102,9 @@ void Menu::AddStaticOption(const string &str, LOCATION location, HAVE_SEPARATOR
|
||||
new_option->is_bold = 0;
|
||||
itsOptions.push_back(new_option);
|
||||
itsStaticsNumber++;
|
||||
|
||||
if (itsOptions.size() > itsBeginning && itsOptions.size() <= itsBeginning+itsHeight)
|
||||
NeedsRedraw.push_back(itsOptions.size()-1);
|
||||
}
|
||||
|
||||
void Menu::AddStaticBoldOption(const string &str, LOCATION location, HAVE_SEPARATOR separator)
|
||||
@@ -108,6 +117,9 @@ void Menu::AddStaticBoldOption(const string &str, LOCATION location, HAVE_SEPARA
|
||||
new_option->is_bold = 1;
|
||||
itsOptions.push_back(new_option);
|
||||
itsStaticsNumber++;
|
||||
|
||||
if (itsOptions.size() > itsBeginning && itsOptions.size() <= itsBeginning+itsHeight)
|
||||
NeedsRedraw.push_back(itsOptions.size()-1);
|
||||
}
|
||||
|
||||
void Menu::AddSeparator()
|
||||
@@ -117,11 +129,14 @@ void Menu::AddSeparator()
|
||||
|
||||
void Menu::UpdateOption(int index, string str, LOCATION location, HAVE_SEPARATOR separator)
|
||||
{
|
||||
index--;
|
||||
try
|
||||
{
|
||||
itsOptions.at(index-1)->location = location;
|
||||
itsOptions.at(index-1)->content = str;
|
||||
itsOptions.at(index-1)->have_separator = separator;
|
||||
itsOptions.at(index)->location = location;
|
||||
itsOptions.at(index)->content = str;
|
||||
itsOptions.at(index)->have_separator = separator;
|
||||
if (index >= itsBeginning && index < itsBeginning+itsHeight)
|
||||
NeedsRedraw.push_back(index);
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
@@ -130,9 +145,12 @@ void Menu::UpdateOption(int index, string str, LOCATION location, HAVE_SEPARATOR
|
||||
|
||||
void Menu::BoldOption(int index, IS_BOLD bold)
|
||||
{
|
||||
index--;
|
||||
try
|
||||
{
|
||||
itsOptions.at(index-1)->is_bold = bold;
|
||||
itsOptions.at(index)->is_bold = bold;
|
||||
if (index >= itsBeginning && index < itsBeginning+itsHeight)
|
||||
NeedsRedraw.push_back(index);
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
@@ -141,13 +159,14 @@ void Menu::BoldOption(int index, IS_BOLD bold)
|
||||
|
||||
void Menu::MakeStatic(int index, IS_STATIC stat)
|
||||
{
|
||||
index--;
|
||||
try
|
||||
{
|
||||
if (stat && !itsOptions.at(index-1)->is_static)
|
||||
if (stat && !itsOptions.at(index)->is_static)
|
||||
itsStaticsNumber++;
|
||||
if (!stat && itsOptions.at(index-1)->is_static)
|
||||
if (!stat && itsOptions.at(index)->is_static)
|
||||
itsStaticsNumber--;
|
||||
itsOptions.at(index-1)->is_static = stat;
|
||||
itsOptions.at(index)->is_static = stat;
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
@@ -191,19 +210,50 @@ void Menu::DeleteOption(int no)
|
||||
}
|
||||
delete itsOptions[no-1];
|
||||
itsOptions.erase(itsOptions.begin()+no-1);
|
||||
|
||||
if (itsHighlight > itsOptions.size()-1)
|
||||
itsHighlight = itsOptions.size()-1;
|
||||
|
||||
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
||||
if (itsBeginning > MaxBeginning)
|
||||
{
|
||||
itsBeginning = MaxBeginning;
|
||||
NeedsRedraw.push_back(itsHighlight);
|
||||
Refresh();
|
||||
redraw_screen();
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<Option *>::const_iterator it = itsOptions.begin()+itsHighlight;
|
||||
NeedsRedraw.reserve(itsHeight);
|
||||
int i = itsHighlight;
|
||||
for (; i < itsBeginning+itsHeight && it != itsOptions.end(); i++, it++)
|
||||
NeedsRedraw.push_back(i);
|
||||
for (; i < itsBeginning+itsHeight; i++)
|
||||
mvwhline(itsWindow, i, 0, 32, itsWidth);
|
||||
}
|
||||
|
||||
/*if (itsBeginning > 0 && itsBeginning == itsOptions.size()-itsHeight)
|
||||
itsBeginning--;
|
||||
Go(UP);*/
|
||||
Window::Clear();
|
||||
//Window::Clear();
|
||||
}
|
||||
|
||||
void Menu::Display()
|
||||
void Menu::redraw_screen()
|
||||
{
|
||||
vector<Option *>::const_iterator it = itsOptions.begin()+itsBeginning;
|
||||
NeedsRedraw.reserve(itsHeight);
|
||||
for (int i = itsBeginning; i < itsBeginning+itsHeight && it != itsOptions.end(); i++, it++)
|
||||
NeedsRedraw.push_back(i);
|
||||
}
|
||||
|
||||
void Menu::Display(bool redraw_whole_window)
|
||||
{
|
||||
Window::show_border();
|
||||
Refresh();
|
||||
Refresh(redraw_whole_window);
|
||||
}
|
||||
|
||||
void Menu::Refresh()
|
||||
void Menu::Refresh(bool redraw_whole_window)
|
||||
{
|
||||
if (!itsOptions.empty() && is_static())
|
||||
if (itsHighlight == 0)
|
||||
@@ -211,14 +261,18 @@ void Menu::Refresh()
|
||||
else
|
||||
Go(UP);
|
||||
|
||||
if (MaxChoice() < GetChoice() && !Empty())
|
||||
Highlight(MaxChoice());
|
||||
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
||||
if (itsBeginning > MaxBeginning)
|
||||
itsBeginning = MaxBeginning;
|
||||
|
||||
if (itsHighlight > itsBeginning+itsHeight)
|
||||
Highlight(itsBeginning+itsHeight);
|
||||
if (itsHighlight > itsOptions.size()-1)
|
||||
Highlight(itsOptions.size());
|
||||
|
||||
if (redraw_whole_window)
|
||||
redraw_screen();
|
||||
|
||||
int line = 0;
|
||||
int last;
|
||||
/*int last;
|
||||
|
||||
if (itsOptions.size() < itsHeight)
|
||||
last = itsOptions.size();
|
||||
@@ -241,28 +295,39 @@ void Menu::Refresh()
|
||||
}
|
||||
}
|
||||
itsBeginning -= check;
|
||||
last -= check;
|
||||
last -= check;*/
|
||||
|
||||
for (int i = itsBeginning; i < last; i++)
|
||||
for (vector<int>::const_iterator it = NeedsRedraw.begin(); it != NeedsRedraw.end(); it++)
|
||||
{
|
||||
if (i == itsHighlight && itsHighlightEnabled)
|
||||
try
|
||||
{
|
||||
itsOptions.at(*it);
|
||||
}
|
||||
catch (std::out_of_range)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
line = *it-itsBeginning;
|
||||
|
||||
if (*it == itsHighlight && itsHighlightEnabled)
|
||||
{
|
||||
Reverse(1);
|
||||
SetColor(itsHighlightColor);
|
||||
}
|
||||
if (itsOptions[i]->is_bold)
|
||||
if (itsOptions[*it]->is_bold)
|
||||
Bold(1);
|
||||
|
||||
int ch = itsOptions[i]->have_separator ? 0 : 32;
|
||||
int ch = itsOptions[*it]->have_separator ? 0 : 32;
|
||||
mvwhline(itsWindow,line, 0, ch, itsWidth);
|
||||
|
||||
int strlength = itsOptions[i]->location != lLeft && BBEnabled ? count_length(itsOptions[i]->content) : itsOptions[i]->content.length();
|
||||
int strlength = itsOptions[*it]->location != lLeft && BBEnabled ? count_length(itsOptions[*it]->content) : itsOptions[*it]->content.length();
|
||||
|
||||
if (strlength)
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (itsOptions[i]->location == lCenter)
|
||||
if (itsOptions[*it]->location == lCenter)
|
||||
{
|
||||
for (; x < (itsWidth-strlength-(!ch ? 4 : 0))/2; x++);
|
||||
if (!ch)
|
||||
@@ -273,7 +338,7 @@ void Menu::Refresh()
|
||||
x += 2;
|
||||
}
|
||||
}
|
||||
if (itsOptions[i]->location == lRight)
|
||||
if (itsOptions[*it]->location == lRight)
|
||||
{
|
||||
for (; x < (itsWidth-strlength); x++)
|
||||
if (!ch)
|
||||
@@ -285,9 +350,16 @@ void Menu::Refresh()
|
||||
}
|
||||
}
|
||||
|
||||
WriteXY(x, line, itsOptions[i]->content, 0);
|
||||
# ifdef UTF8_ENABLED
|
||||
wstring option = ToWString(itsOptions[*it]->content);
|
||||
int bbcodes_length = CountBBCodes(option);
|
||||
WriteXY(x, line, option.substr(0, itsWidth+bbcodes_length), 0);
|
||||
# else
|
||||
int bbcodes_length = CountBBCodes(itsOptions[*it]->content);
|
||||
WriteXY(x, line, itsOptions[*it]->content.substr(0, itsWidth+bbcodes_length), 0);
|
||||
# endif
|
||||
|
||||
if (!ch && (itsOptions[i]->location == lCenter || itsOptions[i]->location == lLeft))
|
||||
if (!ch && (itsOptions[*it]->location == lCenter || itsOptions[*it]->location == lLeft))
|
||||
{
|
||||
x += strlength;
|
||||
AltCharset(1);
|
||||
@@ -297,14 +369,15 @@ void Menu::Refresh()
|
||||
}
|
||||
line++;
|
||||
|
||||
if (i == itsHighlight && itsHighlightEnabled)
|
||||
if (*it == itsHighlight && itsHighlightEnabled)
|
||||
{
|
||||
Reverse(0);
|
||||
SetColor(itsBaseColor);
|
||||
}
|
||||
if (itsOptions[i]->is_bold)
|
||||
if (itsOptions[*it]->is_bold)
|
||||
Bold(0);
|
||||
}
|
||||
NeedsRedraw.clear();
|
||||
wrefresh(itsWindow);
|
||||
}
|
||||
|
||||
@@ -312,20 +385,26 @@ void Menu::Go(WHERE where)
|
||||
{
|
||||
if (Empty()) return;
|
||||
int MaxHighlight = itsOptions.size()-1;
|
||||
int MaxBeginning;
|
||||
if (itsOptions.size() < itsHeight)
|
||||
MaxBeginning = 0;
|
||||
else MaxBeginning = itsOptions.size()-itsHeight;
|
||||
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
||||
int MaxCurrentHighlight = itsBeginning+itsHeight-1;
|
||||
idlok(itsWindow, 1);
|
||||
scrollok(itsWindow, 1);
|
||||
switch (where)
|
||||
{
|
||||
case UP:
|
||||
{
|
||||
if (itsHighlight <= itsBeginning && itsHighlight > 0) itsBeginning--; // for scrolling
|
||||
if (itsHighlight <= itsBeginning && itsHighlight > 0)
|
||||
{
|
||||
itsBeginning--; // for scrolling
|
||||
wscrl(itsWindow, -1);
|
||||
}
|
||||
if (itsHighlight == 0)
|
||||
break;
|
||||
else
|
||||
itsHighlight--;
|
||||
{
|
||||
NeedsRedraw.push_back(itsHighlight--);
|
||||
NeedsRedraw.push_back(itsHighlight);
|
||||
}
|
||||
if (is_static())
|
||||
{
|
||||
if (itsHighlight == 0)
|
||||
@@ -337,11 +416,18 @@ void Menu::Go(WHERE where)
|
||||
}
|
||||
case DOWN:
|
||||
{
|
||||
if (itsHighlight >= MaxCurrentHighlight && itsHighlight < MaxHighlight) itsBeginning++; // scroll
|
||||
if (itsHighlight >= MaxCurrentHighlight && itsHighlight < MaxHighlight)
|
||||
{
|
||||
itsBeginning++; // scroll
|
||||
wscrl(itsWindow, 1);
|
||||
}
|
||||
if (itsHighlight == MaxHighlight)
|
||||
break;
|
||||
else
|
||||
itsHighlight++;
|
||||
{
|
||||
NeedsRedraw.push_back(itsHighlight++);
|
||||
NeedsRedraw.push_back(itsHighlight);
|
||||
}
|
||||
if (is_static())
|
||||
{
|
||||
if (itsHighlight == MaxHighlight)
|
||||
@@ -367,6 +453,7 @@ void Menu::Go(WHERE where)
|
||||
else
|
||||
Go(UP);
|
||||
}
|
||||
redraw_screen();
|
||||
break;
|
||||
}
|
||||
case PAGE_DOWN:
|
||||
@@ -385,6 +472,7 @@ void Menu::Go(WHERE where)
|
||||
else
|
||||
Go(DOWN);
|
||||
}
|
||||
redraw_screen();
|
||||
break;
|
||||
}
|
||||
case HOME:
|
||||
@@ -398,6 +486,7 @@ void Menu::Go(WHERE where)
|
||||
else
|
||||
Go(UP);
|
||||
}
|
||||
redraw_screen();
|
||||
break;
|
||||
}
|
||||
case END:
|
||||
@@ -411,15 +500,22 @@ void Menu::Go(WHERE where)
|
||||
else
|
||||
Go(DOWN);
|
||||
}
|
||||
redraw_screen();
|
||||
break;
|
||||
}
|
||||
}
|
||||
idlok(itsWindow, 0);
|
||||
scrollok(itsWindow, 0);
|
||||
}
|
||||
|
||||
void Menu::Highlight(int which)
|
||||
{
|
||||
if (which <= itsOptions.size())
|
||||
{
|
||||
NeedsRedraw.push_back(itsHighlight);
|
||||
itsHighlight = which-1;
|
||||
NeedsRedraw.push_back(itsHighlight);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
|
||||
10
src/menu.h
10
src/menu.h
@@ -59,15 +59,15 @@ class Menu : public Window
|
||||
string GetCurrentOption() const;
|
||||
string GetOption(int i) const;
|
||||
|
||||
virtual void Display();
|
||||
virtual void Refresh();
|
||||
virtual void Display(bool = 0);
|
||||
virtual void Refresh(bool = 0);
|
||||
virtual void Go(WHERE);
|
||||
void Highlight(int);
|
||||
virtual void Reset();
|
||||
virtual void Clear(bool clear_screen = 1);
|
||||
|
||||
void HighlightColor(COLOR col) { itsHighlightColor = col; }
|
||||
void Highlighting(bool hl) { itsHighlightEnabled = hl; Refresh(); }
|
||||
void HighlightColor(COLOR col) { itsHighlightColor = col; NeedsRedraw.push_back(itsHighlight); }
|
||||
void Highlighting(bool hl) { itsHighlightEnabled = hl; NeedsRedraw.push_back(itsHighlight); Refresh(); }
|
||||
|
||||
int GetRealChoice() const;
|
||||
virtual int GetChoice() const { return itsHighlight+1; }
|
||||
@@ -81,10 +81,12 @@ class Menu : public Window
|
||||
|
||||
protected:
|
||||
vector<Option *> itsOptions;
|
||||
vector<int> NeedsRedraw;
|
||||
|
||||
int itsStaticsNumber;
|
||||
int count_length(string);
|
||||
|
||||
void redraw_screen();
|
||||
bool is_static() { return itsOptions[itsHighlight]->is_static; }
|
||||
|
||||
int itsChoice;
|
||||
|
||||
@@ -127,6 +127,8 @@ bool block_library_update = 0;
|
||||
bool search_case_sensitive = 1;
|
||||
bool search_mode_match = 1;
|
||||
|
||||
bool redraw_me = 0;
|
||||
|
||||
extern string EMPTY_TAG;
|
||||
extern string UNKNOWN_ARTIST;
|
||||
extern string UNKNOWN_TITLE;
|
||||
@@ -428,7 +430,8 @@ int main(int argc, char *argv[])
|
||||
block_library_update = 1;
|
||||
}
|
||||
|
||||
wCurrent->Refresh();
|
||||
wCurrent->Refresh(redraw_me);
|
||||
redraw_me = 0;
|
||||
|
||||
wCurrent->ReadKey(input);
|
||||
if (input == ERR)
|
||||
@@ -444,7 +447,6 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
case csPlaylist:
|
||||
mPlaylist->Highlighting(1);
|
||||
mPlaylist->Refresh();
|
||||
break;
|
||||
|
||||
case csBrowser:
|
||||
@@ -477,6 +479,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int in;
|
||||
|
||||
redraw_me = 1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
wCurrent->ReadKey(in);
|
||||
@@ -529,17 +533,17 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (wCurrent != sHelp)
|
||||
wCurrent->Hide();
|
||||
wCurrent->Display();
|
||||
wCurrent->Display(redraw_me);
|
||||
if (current_screen == csLibrary)
|
||||
{
|
||||
mLibArtists->Hide();
|
||||
mLibArtists->Display();
|
||||
mLibArtists->Display(redraw_me);
|
||||
mvvline(main_start_y, lib_albums_start_x-1, 0, main_height);
|
||||
mLibAlbums->Hide();
|
||||
mLibAlbums->Display();
|
||||
mLibAlbums->Display(redraw_me);
|
||||
mvvline(main_start_y, lib_songs_start_x-1, 0, main_height);
|
||||
mLibSongs->Hide();
|
||||
mLibSongs->Display();
|
||||
mLibSongs->Display(redraw_me);
|
||||
}
|
||||
|
||||
header_update_status = 1;
|
||||
@@ -754,6 +758,7 @@ int main(int argc, char *argv[])
|
||||
wCurrent->Clear();
|
||||
wCurrent = wPrev;
|
||||
current_screen = prev_screen;
|
||||
redraw_me = 1;
|
||||
if (current_screen == csLibrary)
|
||||
{
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
@@ -768,11 +773,11 @@ int main(int argc, char *argv[])
|
||||
# else
|
||||
wCurrent = wPrev;
|
||||
# endif
|
||||
mLibArtists->Display();
|
||||
mLibArtists->Display(redraw_me);
|
||||
mvvline(main_start_y, lib_albums_start_x-1, 0, main_height);
|
||||
mLibAlbums->Display();
|
||||
mLibAlbums->Display(redraw_me);
|
||||
mvvline(main_start_y, lib_songs_start_x-1, 0, main_height);
|
||||
mLibSongs->Display();
|
||||
mLibSongs->Display(redraw_me);
|
||||
}
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
break;
|
||||
@@ -1380,6 +1385,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (current_screen == csPlaylist && now_playing >= 0)
|
||||
mPlaylist->Highlight(now_playing+1);
|
||||
redraw_me = 1;
|
||||
break;
|
||||
}
|
||||
case 'r': // switch repeat state
|
||||
@@ -1409,15 +1415,18 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
case csPlaylist:
|
||||
{
|
||||
if (GetSongInfo(*vPlaylist[id]))
|
||||
if (!mPlaylist->Empty())
|
||||
{
|
||||
wCurrent = mTagEditor;
|
||||
wPrev = mPlaylist;
|
||||
current_screen = csTagEditor;
|
||||
prev_screen = csPlaylist;
|
||||
if (GetSongInfo(*vPlaylist[id]))
|
||||
{
|
||||
wCurrent = mTagEditor;
|
||||
wPrev = mPlaylist;
|
||||
current_screen = csTagEditor;
|
||||
prev_screen = csPlaylist;
|
||||
}
|
||||
else
|
||||
ShowMessage("Cannot read file!");
|
||||
}
|
||||
else
|
||||
ShowMessage("Cannot read file!");
|
||||
break;
|
||||
}
|
||||
case csBrowser:
|
||||
@@ -1502,6 +1511,7 @@ int main(int argc, char *argv[])
|
||||
ShowMessage("Deleting all songs except now playing one...");
|
||||
mpd_playlist_queue_commit(conn);
|
||||
ShowMessage("Songs deleted!");
|
||||
redraw_me = 1;
|
||||
break;
|
||||
}
|
||||
case 'c': // clear playlist
|
||||
@@ -1580,6 +1590,7 @@ int main(int argc, char *argv[])
|
||||
wCurrent = sHelp;
|
||||
wCurrent->Hide();
|
||||
current_screen = csHelp;
|
||||
redraw_me = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1592,6 +1603,7 @@ int main(int argc, char *argv[])
|
||||
wCurrent = mPlaylist;
|
||||
wCurrent->Hide();
|
||||
current_screen = csPlaylist;
|
||||
redraw_me = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1629,6 +1641,7 @@ int main(int argc, char *argv[])
|
||||
wCurrent = mBrowser;
|
||||
wCurrent->Hide();
|
||||
current_screen = csBrowser;
|
||||
redraw_me = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1643,6 +1656,7 @@ int main(int argc, char *argv[])
|
||||
wCurrent = mSearcher;
|
||||
wCurrent->Hide();
|
||||
current_screen = csSearcher;
|
||||
redraw_me = 1;
|
||||
if (!vSearched.empty())
|
||||
{
|
||||
wCurrent->WriteXY(0, 0, "Updating list...");
|
||||
@@ -1700,6 +1714,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
wCurrent = mLibArtists;
|
||||
current_screen = csLibrary;
|
||||
redraw_me = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -96,13 +96,13 @@ void Scrollpad::recreate_win()
|
||||
Write(itsContent.c_str());
|
||||
}
|
||||
|
||||
void Scrollpad::Display()
|
||||
void Scrollpad::Display(bool stub)
|
||||
{
|
||||
Window::show_border();
|
||||
Refresh();
|
||||
Refresh(stub);
|
||||
}
|
||||
|
||||
void Scrollpad::Refresh()
|
||||
void Scrollpad::Refresh(bool stub)
|
||||
{
|
||||
prefresh(itsWindow,itsBeginning,0,itsStartY,itsStartX,itsStartY+itsHeight-1,itsStartX+itsWidth);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ class Scrollpad: public Window
|
||||
Scrollpad(int startx, int starty, int width, int height, string title, COLOR color, BORDER border) : Window(startx, starty, width, height, title, color, border), itsBeginning(0), itsRealHeight(1), itsXPos(0) { delwin(itsWindow); itsWindow = newpad(0,0); }
|
||||
virtual ~Scrollpad() {}
|
||||
virtual void Add(string);
|
||||
virtual void Display();
|
||||
virtual void Refresh();
|
||||
virtual void Display(bool = 0);
|
||||
virtual void Refresh(bool = 0);
|
||||
virtual void Go(WHERE);
|
||||
virtual void MoveTo(int newx, int newy) { reallocate_win(newx, newy); }
|
||||
virtual void Resize(int, int);
|
||||
|
||||
@@ -75,6 +75,8 @@ extern bool block_statusbar_update;
|
||||
extern bool block_playlist_update;
|
||||
extern bool block_library_update;
|
||||
|
||||
extern bool redraw_me;
|
||||
|
||||
long long playlist_old_id = -1;
|
||||
|
||||
int old_playing;
|
||||
@@ -85,11 +87,8 @@ void TraceMpdStatus()
|
||||
now = time(NULL);
|
||||
|
||||
if (now == timer+Config.playlist_disable_highlight_delay && current_screen == csPlaylist)
|
||||
{
|
||||
mPlaylist->Highlighting(!Config.playlist_disable_highlight_delay);
|
||||
mPlaylist->Refresh();
|
||||
}
|
||||
|
||||
|
||||
if (block_statusbar_update_delay > 0)
|
||||
{
|
||||
if (now >= block_delay+block_statusbar_update_delay)
|
||||
@@ -151,7 +150,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
|
||||
{
|
||||
if (playlist_length < vPlaylist.size())
|
||||
{
|
||||
mPlaylist->Clear(!playlist_length && current_screen != csLibrary);
|
||||
mPlaylist->Clear(!playlist_length && current_screen == csPlaylist);
|
||||
for (vector<Song *>::iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
|
||||
delete *it;
|
||||
vPlaylist.clear();
|
||||
@@ -177,7 +176,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
|
||||
{
|
||||
if (!playlist_length || mPlaylist->MaxChoice() < mPlaylist->GetHeight())
|
||||
mPlaylist->Hide();
|
||||
mPlaylist->Refresh();
|
||||
mPlaylist->Refresh(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -208,7 +207,10 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
|
||||
}
|
||||
|
||||
if (vPlaylist.empty())
|
||||
{
|
||||
mPlaylist->Reset();
|
||||
ShowMessage("Cleared playlist!");
|
||||
}
|
||||
|
||||
if (current_screen == csBrowser)
|
||||
{
|
||||
|
||||
@@ -199,13 +199,13 @@ void Window::show_border() const
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Window::Display()
|
||||
void Window::Display(bool stub)
|
||||
{
|
||||
show_border();
|
||||
wrefresh(itsWindow);
|
||||
}
|
||||
|
||||
void Window::Refresh()
|
||||
void Window::Refresh(bool stub)
|
||||
{
|
||||
wrefresh(itsWindow);
|
||||
}
|
||||
@@ -619,6 +619,88 @@ string OmitBBCodes(const string &str)
|
||||
return result;
|
||||
}
|
||||
|
||||
int CountBBCodes(const string &str)
|
||||
{
|
||||
if (str.empty())
|
||||
return 0;
|
||||
bool collect = false;
|
||||
int length = 0;
|
||||
string color;
|
||||
for (string::const_iterator it = str.begin(); it != str.end(); it++)
|
||||
{
|
||||
if (*it != '[' && !collect);
|
||||
else
|
||||
collect = 1;
|
||||
|
||||
if (collect)
|
||||
{
|
||||
if (*it != '[')
|
||||
{
|
||||
color += *it;
|
||||
length++;
|
||||
}
|
||||
else
|
||||
{
|
||||
length -= color.length();
|
||||
length++;
|
||||
color = *it;
|
||||
}
|
||||
}
|
||||
|
||||
if (*it == ']' || it+1 == str.end())
|
||||
collect = 0;
|
||||
|
||||
if (!collect)
|
||||
{
|
||||
if (!is_valid_color(color))
|
||||
length -= color.length();
|
||||
color.clear();
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
int CountBBCodes(const wstring &str)
|
||||
{
|
||||
if (str.empty())
|
||||
return 0;
|
||||
bool collect = false;
|
||||
int length = 0;
|
||||
wstring color;
|
||||
for (wstring::const_iterator it = str.begin(); it != str.end(); it++)
|
||||
{
|
||||
if (*it != '[' && !collect);
|
||||
else
|
||||
collect = 1;
|
||||
|
||||
if (collect)
|
||||
{
|
||||
if (*it != '[')
|
||||
{
|
||||
color += *it;
|
||||
length++;
|
||||
}
|
||||
else
|
||||
{
|
||||
length -= color.length();
|
||||
length++;
|
||||
color = *it;
|
||||
}
|
||||
}
|
||||
|
||||
if (*it == ']' || it+1 == str.end())
|
||||
collect = 0;
|
||||
|
||||
if (!collect)
|
||||
{
|
||||
if (!is_valid_color(ToString(color)))
|
||||
length -= color.length();
|
||||
color.clear();
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
wchar_t * ToWString(const char *s)
|
||||
{
|
||||
wchar_t *ws = (wchar_t *)calloc(strlen(s)+1, sizeof(wchar_t));
|
||||
|
||||
@@ -53,6 +53,8 @@ wstring ToWString(const string &);
|
||||
|
||||
bool is_valid_color(const string &);
|
||||
string OmitBBCodes(const string &);
|
||||
int CountBBCodes(const string &);
|
||||
int CountBBCodes(const wstring &);
|
||||
|
||||
class Window
|
||||
{
|
||||
@@ -68,8 +70,8 @@ class Window
|
||||
virtual void SetTitle(string);
|
||||
virtual void MoveTo(int, int);
|
||||
virtual void Resize(int, int);
|
||||
virtual void Display();
|
||||
virtual void Refresh();
|
||||
virtual void Display(bool = 0);
|
||||
virtual void Refresh(bool = 0);
|
||||
virtual void Clear();
|
||||
virtual void Hide(char = 32) const;
|
||||
virtual void Bold(bool) const;
|
||||
|
||||
Reference in New Issue
Block a user