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