code clean-ups

This commit is contained in:
unK
2008-09-02 03:53:13 +02:00
parent 184df520b9
commit a37882f62a
10 changed files with 141 additions and 144 deletions

View File

@@ -20,9 +20,9 @@
#include "window.h"
std::pair<COLOR, COLOR> Window::into_color(const string &str)
ColorPair Window::into_color(const string &str)
{
std::pair<COLOR, COLOR> colors;
ColorPair colors;
if (str == "[/]")
{

View File

@@ -81,7 +81,7 @@ int Menu::count_length(string str)
return length;
}
void Menu::AddOption(const string &str, LOCATION location, HAVE_SEPARATOR separator)
void Menu::AddOption(const string &str, Location location, bool separator)
{
Option *new_option = new Option;
new_option->content = str;
@@ -93,7 +93,7 @@ void Menu::AddOption(const string &str, LOCATION location, HAVE_SEPARATOR separa
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, bool separator)
{
Option *new_option = new Option;
new_option->content = str;
@@ -106,7 +106,7 @@ void Menu::AddBoldOption(const string &str, LOCATION location, HAVE_SEPARATOR se
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, bool separator)
{
Option *new_option = new Option;
new_option->content = str;
@@ -120,7 +120,7 @@ void Menu::AddStaticOption(const string &str, LOCATION location, HAVE_SEPARATOR
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, bool separator)
{
Option *new_option = new Option;
new_option->content = str;
@@ -140,7 +140,7 @@ void Menu::AddSeparator()
AddStaticOption("", lLeft, 1);
}
void Menu::UpdateOption(int index, string str, LOCATION location, HAVE_SEPARATOR separator)
void Menu::UpdateOption(int index, string str, Location location, bool separator)
{
index--;
try
@@ -156,7 +156,7 @@ void Menu::UpdateOption(int index, string str, LOCATION location, HAVE_SEPARATOR
}
}
void Menu::BoldOption(int index, IS_BOLD bold)
void Menu::BoldOption(int index, bool bold)
{
index--;
try
@@ -170,7 +170,7 @@ void Menu::BoldOption(int index, IS_BOLD bold)
}
}
void Menu::MakeStatic(int index, IS_STATIC stat)
void Menu::MakeStatic(int index, bool stat)
{
index--;
try
@@ -312,7 +312,7 @@ void Menu::Refresh(bool redraw_whole_window)
if (line < 0 || line+1 > itsHeight) // do not draw if line should be invisible anyway
continue;
COLOR old_basecolor = itsBaseColor;
Color old_basecolor = itsBaseColor;
if (*it == itsHighlight && itsHighlightEnabled)
{
@@ -387,7 +387,7 @@ void Menu::Refresh(bool redraw_whole_window)
wrefresh(itsWindow);
}
void Menu::Go(WHERE where)
void Menu::Go(Where where)
{
if (Empty()) return;
int MaxHighlight = itsOptions.size()-1;

View File

@@ -25,11 +25,7 @@
#include <stdexcept>
typedef bool IS_STATIC;
typedef bool HAVE_SEPARATOR;
typedef bool IS_BOLD;
enum LOCATION { lLeft, lCenter, lRight };
enum Location { lLeft, lCenter, lRight };
struct Option
{
@@ -39,33 +35,33 @@ struct Option
bool is_bold;
bool selected;
bool have_separator;
LOCATION location;
Location location;
};
class Menu : public Window
{
public:
Menu(int startx, int starty, int width, int height, string title, COLOR color, BORDER border) : Window(startx, starty, width, height, title, color, border), itsSelectedPrefix("[r]"), itsSelectedSuffix("[/r]"), itsStaticsNumber(0), itsBeginning(0), itsHighlight(0), itsHighlightColor(itsBaseColor), itsHighlightEnabled(1) { SetColor(color); }
Menu(int startx, int starty, int width, int height, string title, Color color, Border border) : Window(startx, starty, width, height, title, color, border), itsSelectedPrefix("[r]"), itsSelectedSuffix("[/r]"), itsStaticsNumber(0), itsBeginning(0), itsHighlight(0), itsHighlightColor(itsBaseColor), itsHighlightEnabled(1) { SetColor(color); }
Menu(const Menu &);
virtual ~Menu();
virtual void Add(string str) { AddOption(str); }
void AddOption(const string &, LOCATION = lLeft, HAVE_SEPARATOR = 0);
void AddBoldOption(const string &str, LOCATION location = lLeft, HAVE_SEPARATOR sep = 0);
void AddStaticOption(const string &str, LOCATION location = lLeft, HAVE_SEPARATOR sep = 0);
void AddStaticBoldOption(const string &str, LOCATION location = lLeft, HAVE_SEPARATOR sep = 0);
void AddOption(const string &, Location = lLeft, bool separator = 0);
void AddBoldOption(const string &str, Location location = lLeft, bool separator = 0);
void AddStaticOption(const string &str, Location location = lLeft, bool separator = 0);
void AddStaticBoldOption(const string &str, Location location = lLeft, bool separator = 0);
void AddSeparator();
void UpdateOption(int, string, LOCATION = lLeft, HAVE_SEPARATOR = 0);
void BoldOption(int, IS_BOLD);
void MakeStatic(int, IS_STATIC);
void UpdateOption(int, string, Location = lLeft, bool separator = 0);
void BoldOption(int, bool);
void MakeStatic(int, bool);
void DeleteOption(int);
void Swap(int, int);
string GetCurrentOption() const;
string GetOption(int i) const;
virtual void Display(bool = 0);
virtual void Refresh(bool = 0);
virtual void Go(WHERE);
virtual void Display(bool redraw_whole_window = 0);
virtual void Refresh(bool redraw_whole_window = 0);
virtual void Go(Where);
void Highlight(int);
virtual void Reset();
virtual void Clear(bool clear_screen = 1);
@@ -77,7 +73,7 @@ class Menu : public Window
void SetSelectSuffix(string str) { itsSelectedSuffix = str; }
void GetSelectedList(vector<int> &);
void HighlightColor(COLOR col) { itsHighlightColor = col; NeedsRedraw.push_back(itsHighlight); }
void HighlightColor(Color col) { itsHighlightColor = col; NeedsRedraw.push_back(itsHighlight); }
void Highlighting(bool hl) { itsHighlightEnabled = hl; NeedsRedraw.push_back(itsHighlight); Refresh(); }
int GetRealChoice() const;
@@ -106,7 +102,7 @@ class Menu : public Window
int itsBeginning;
int itsHighlight;
COLOR itsHighlightColor;
Color itsHighlightColor;
bool itsHighlightEnabled;
};

View File

@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
curs_set(0);
if (Config.colors_enabled)
EnableColors();
Window::EnableColors();
int main_start_y = 2;
int main_height = LINES-4;
@@ -329,6 +329,7 @@ int main(int argc, char *argv[])
int footer_height = Config.statusbar_visibility ? 2 : 1;
wFooter = new Window(0, footer_start_y, COLS, footer_height, "", Config.statusbar_color, brNone);
wFooter->GetGetStringHelper(TraceMpdStatus);
wFooter->Display();
wCurrent = mPlaylist;
@@ -882,9 +883,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New title:[/b] ", 1);
if (s.GetTitle() == UNKNOWN_TITLE)
s.SetTitle(wFooter->GetString("", TraceMpdStatus));
s.SetTitle(wFooter->GetString());
else
s.SetTitle(wFooter->GetString(s.GetTitle(), TraceMpdStatus));
s.SetTitle(wFooter->GetString(s.GetTitle()));
mTagEditor->UpdateOption(option, "[b]Title:[/b] " + s.GetTitle());
break;
}
@@ -892,9 +893,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New artist:[/b] ", 1);
if (s.GetArtist() == UNKNOWN_ARTIST)
s.SetArtist(wFooter->GetString("", TraceMpdStatus));
s.SetArtist(wFooter->GetString());
else
s.SetArtist(wFooter->GetString(s.GetArtist(), TraceMpdStatus));
s.SetArtist(wFooter->GetString(s.GetArtist()));
mTagEditor->UpdateOption(option, "[b]Artist:[/b] " + s.GetArtist());
break;
}
@@ -902,9 +903,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New album:[/b] ", 1);
if (s.GetAlbum() == UNKNOWN_ALBUM)
s.SetAlbum(wFooter->GetString("", TraceMpdStatus));
s.SetAlbum(wFooter->GetString());
else
s.SetAlbum(wFooter->GetString(s.GetAlbum(), TraceMpdStatus));
s.SetAlbum(wFooter->GetString(s.GetAlbum()));
mTagEditor->UpdateOption(option, "[b]Album:[/b] " + s.GetAlbum());
break;
}
@@ -912,9 +913,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New year:[/b] ", 1);
if (s.GetYear() == EMPTY_TAG)
s.SetYear(wFooter->GetString(4, TraceMpdStatus));
s.SetYear(wFooter->GetString(4));
else
s.SetYear(wFooter->GetString(s.GetYear(), 4, TraceMpdStatus));
s.SetYear(wFooter->GetString(s.GetYear(), 4));
mTagEditor->UpdateOption(option, "[b]Year:[/b] " + s.GetYear());
break;
}
@@ -922,9 +923,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New track:[/b] ", 1);
if (s.GetTrack() == EMPTY_TAG)
s.SetTrack(wFooter->GetString(3, TraceMpdStatus));
s.SetTrack(wFooter->GetString(3));
else
s.SetTrack(wFooter->GetString(s.GetTrack(), 3, TraceMpdStatus));
s.SetTrack(wFooter->GetString(s.GetTrack(), 3));
mTagEditor->UpdateOption(option, "[b]Track:[/b] " + s.GetTrack());
break;
}
@@ -932,9 +933,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New genre:[/b] ", 1);
if (s.GetGenre() == EMPTY_TAG)
s.SetGenre(wFooter->GetString("", TraceMpdStatus));
s.SetGenre(wFooter->GetString());
else
s.SetGenre(wFooter->GetString(s.GetGenre(), TraceMpdStatus));
s.SetGenre(wFooter->GetString(s.GetGenre()));
mTagEditor->UpdateOption(option, "[b]Genre:[/b] " + s.GetGenre());
break;
}
@@ -942,9 +943,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]New comment:[/b] ", 1);
if (s.GetComment() == EMPTY_TAG)
s.SetComment(wFooter->GetString("", TraceMpdStatus));
s.SetComment(wFooter->GetString());
else
s.SetComment(wFooter->GetString(s.GetComment(), TraceMpdStatus));
s.SetComment(wFooter->GetString(s.GetComment()));
mTagEditor->UpdateOption(option, "[b]Comment:[/b] " + s.GetComment());
break;
}
@@ -1021,9 +1022,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Filename:[/b] ", 1);
if (s.GetShortFilename() == EMPTY_TAG)
s.SetShortFilename(wFooter->GetString("", TraceMpdStatus));
s.SetShortFilename(wFooter->GetString());
else
s.SetShortFilename(wFooter->GetString(s.GetShortFilename(), TraceMpdStatus));
s.SetShortFilename(wFooter->GetString(s.GetShortFilename()));
mSearcher->UpdateOption(option, "[b]Filename:[/b] " + s.GetShortFilename());
break;
}
@@ -1031,9 +1032,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Title:[/b] ", 1);
if (s.GetTitle() == UNKNOWN_TITLE)
s.SetTitle(wFooter->GetString("", TraceMpdStatus));
s.SetTitle(wFooter->GetString());
else
s.SetTitle(wFooter->GetString(s.GetTitle(), TraceMpdStatus));
s.SetTitle(wFooter->GetString(s.GetTitle()));
mSearcher->UpdateOption(option, "[b]Title:[/b] " + s.GetTitle());
break;
}
@@ -1041,9 +1042,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Artist:[/b] ", 1);
if (s.GetArtist() == UNKNOWN_ARTIST)
s.SetArtist(wFooter->GetString("", TraceMpdStatus));
s.SetArtist(wFooter->GetString());
else
s.SetArtist(wFooter->GetString(s.GetArtist(), TraceMpdStatus));
s.SetArtist(wFooter->GetString(s.GetArtist()));
mSearcher->UpdateOption(option, "[b]Artist:[/b] " + s.GetArtist());
break;
}
@@ -1051,9 +1052,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Album:[/b] ", 1);
if (s.GetAlbum() == UNKNOWN_ALBUM)
s.SetAlbum(wFooter->GetString("", TraceMpdStatus));
s.SetAlbum(wFooter->GetString());
else
s.SetAlbum(wFooter->GetString(s.GetAlbum(), TraceMpdStatus));
s.SetAlbum(wFooter->GetString(s.GetAlbum()));
mSearcher->UpdateOption(option, "[b]Album:[/b] " + s.GetAlbum());
break;
}
@@ -1061,9 +1062,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Year:[/b] ", 1);
if (s.GetYear() == EMPTY_TAG)
s.SetYear(wFooter->GetString(4, TraceMpdStatus));
s.SetYear(wFooter->GetString(4));
else
s.SetYear(wFooter->GetString(s.GetYear(), 4, TraceMpdStatus));
s.SetYear(wFooter->GetString(s.GetYear(), 4));
mSearcher->UpdateOption(option, "[b]Year:[/b] " + s.GetYear());
break;
}
@@ -1071,9 +1072,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Track:[/b] ", 1);
if (s.GetTrack() == EMPTY_TAG)
s.SetTrack(wFooter->GetString(3, TraceMpdStatus));
s.SetTrack(wFooter->GetString(3));
else
s.SetTrack(wFooter->GetString(s.GetTrack(), 3, TraceMpdStatus));
s.SetTrack(wFooter->GetString(s.GetTrack(), 3));
mSearcher->UpdateOption(option, "[b]Track:[/b] " + s.GetTrack());
break;
}
@@ -1081,9 +1082,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Genre:[/b] ", 1);
if (s.GetGenre() == EMPTY_TAG)
s.SetGenre(wFooter->GetString("", TraceMpdStatus));
s.SetGenre(wFooter->GetString());
else
s.SetGenre(wFooter->GetString(s.GetGenre(), TraceMpdStatus));
s.SetGenre(wFooter->GetString(s.GetGenre()));
mSearcher->UpdateOption(option, "[b]Genre:[/b] " + s.GetGenre());
break;
}
@@ -1091,9 +1092,9 @@ int main(int argc, char *argv[])
{
wFooter->WriteXY(0, Config.statusbar_visibility, "[b]Comment:[/b] ", 1);
if (s.GetComment() == EMPTY_TAG)
s.SetComment(wFooter->GetString("", TraceMpdStatus));
s.SetComment(wFooter->GetString());
else
s.SetComment(wFooter->GetString(s.GetComment(), TraceMpdStatus));
s.SetComment(wFooter->GetString(s.GetComment()));
mSearcher->UpdateOption(option, "[b]Comment:[/b] " + s.GetComment());
break;
}
@@ -1534,7 +1535,7 @@ int main(int argc, char *argv[])
{
LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Save playlist as: ", 1);
string playlist_name = wFooter->GetString("", TraceMpdStatus);
string playlist_name = wFooter->GetString();
UNLOCK_STATUSBAR;
if (playlist_name.find("/") != string::npos)
{
@@ -1674,7 +1675,7 @@ int main(int argc, char *argv[])
{
LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Add: ", 1);
string path = wFooter->GetString("", TraceMpdStatus);
string path = wFooter->GetString();
UNLOCK_STATUSBAR;
if (!path.empty())
{
@@ -1789,7 +1790,7 @@ int main(int argc, char *argv[])
{
LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Set crossfade to: ", 1);
string crossfade = wFooter->GetString(3, TraceMpdStatus);
string crossfade = wFooter->GetString(3);
UNLOCK_STATUSBAR;
int cf = StrToInt(crossfade);
if (cf > 0)
@@ -1846,7 +1847,7 @@ int main(int argc, char *argv[])
}
LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Position to go (in %): ", 1);
string position = wFooter->GetString(3, TraceMpdStatus);
string position = wFooter->GetString(3);
int newpos = atoi(position.c_str());
if (newpos > 0 && newpos < 100 && !position.empty())
Mpd->Seek(vPlaylist[now_playing]->GetTotalLength()*newpos/100.0);
@@ -2016,7 +2017,7 @@ int main(int argc, char *argv[])
{
LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Save playlist as: ", 1);
string playlist = wFooter->GetString("", TraceMpdStatus);
string playlist = wFooter->GetString();
UNLOCK_STATUSBAR;
if (!playlist.empty())
{
@@ -2100,7 +2101,7 @@ int main(int argc, char *argv[])
Menu *mCurrent = static_cast<Menu *>(wCurrent);
LOCK_STATUSBAR;
wFooter->WriteXY(0, Config.statusbar_visibility, "Find " + how + ": ", 1);
string findme = wFooter->GetString("", TraceMpdStatus);
string findme = wFooter->GetString();
UNLOCK_STATUSBAR;
timer = time(NULL);
if (findme.empty())

View File

@@ -151,7 +151,7 @@ void Scrollpad::Resize(int width, int height)
}
}
void Scrollpad::Go(WHERE where)
void Scrollpad::Go(Where where)
{
int MaxBeginning;
@@ -197,7 +197,7 @@ void Scrollpad::Go(WHERE where)
}
}
void Scrollpad::SetBorder(BORDER border)
void Scrollpad::SetBorder(Border border)
{
if (have_to_recreate(border))
recreate_win();

View File

@@ -26,16 +26,16 @@
class Scrollpad: public Window
{
public:
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(itsHeight,itsWidth); }
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(itsHeight,itsWidth); }
Scrollpad(const Scrollpad &);
virtual ~Scrollpad() {}
virtual void Add(string);
virtual void Display(bool = 0);
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 Resize(int, int);
virtual void SetBorder(BORDER);
virtual void SetBorder(Border);
virtual void SetTitle(string);
virtual void Clear();
virtual Window * Clone() { return new Scrollpad(*this); }

View File

@@ -213,7 +213,7 @@ string GetConfigLineValue(const string &line)
return "";
}
string IntoStr(COLOR color)
string IntoStr(Color color)
{
string result = "";
@@ -237,9 +237,9 @@ string IntoStr(COLOR color)
return result;
}
COLOR IntoColor(const string &color)
Color IntoColor(const string &color)
{
COLOR result = clDefault;
Color result = clDefault;
if (color == "black")
result = clBlack;

View File

@@ -96,16 +96,16 @@ struct ncmpcpp_config
string selected_item_prefix;
string selected_item_suffix;
COLOR empty_tags_color;
COLOR header_color;
COLOR volume_color;
COLOR state_line_color;
COLOR state_flags_color;
COLOR main_color;
COLOR main_highlight_color;
COLOR progressbar_color;
COLOR statusbar_color;
COLOR active_column_color;
Color empty_tags_color;
Color header_color;
Color volume_color;
Color state_line_color;
Color state_flags_color;
Color main_color;
Color main_highlight_color;
Color progressbar_color;
Color statusbar_color;
Color active_column_color;
bool colors_enabled;
bool set_window_title;
@@ -126,8 +126,8 @@ void DefaultKeys(ncmpcpp_keys &);
void DefaultConfiguration(ncmpcpp_config &);
void GetKeys(string, int *);
string GetLineValue(const string &);
string IntoStr(COLOR);
COLOR IntoColor(const string &);
string IntoStr(Color);
Color IntoColor(const string &);
void ReadKeys(ncmpcpp_keys &);
void ReadConfiguration(ncmpcpp_config &);

View File

@@ -20,7 +20,7 @@
#include "window.h"
Window::Window(int startx, int starty, int width, int height, string title, COLOR color, BORDER border) : itsWindow(0), itsWinBorder(0), itsStartX(startx), itsStartY(starty), itsWidth(width), itsHeight(height), BBEnabled(1), AutoRefreshEnabled(1), itsTitle(title), itsColor(color), itsBaseColor(color), itsBgColor(clDefault), itsBaseBgColor(clDefault), itsBorder(border)
Window::Window(int startx, int starty, int width, int height, string title, Color color, Border border) : itsWindow(0), itsWinBorder(0), itsGetStringHelper(0), itsStartX(startx), itsStartY(starty), itsWidth(width), itsHeight(height), BBEnabled(1), AutoRefreshEnabled(1), itsTitle(title), itsColor(color), itsBaseColor(color), itsBgColor(clDefault), itsBaseBgColor(clDefault), itsBorder(border)
{
if (itsStartX < 0) itsStartX = 0;
if (itsStartY < 0) itsStartY = 0;
@@ -53,6 +53,7 @@ Window::Window(const Window &w)
{
itsWindow = dupwin(w.itsWindow);
itsWinBorder = dupwin(w.itsWinBorder);
itsGetStringHelper = w.itsGetStringHelper;
itsStartX = w.itsStartX;
itsStartY = w.itsStartY;
itsWidth = w.itsWidth;
@@ -74,7 +75,7 @@ Window::~Window()
delwin(itsWinBorder);
}
void Window::SetColor(COLOR col, COLOR background)
void Window::SetColor(Color col, Color background)
{
if (col != clDefault)
wattron(itsWindow,COLOR_PAIR(background*8+col));
@@ -84,13 +85,13 @@ void Window::SetColor(COLOR col, COLOR background)
itsBgColor = background;
}
void Window::SetBaseColor(COLOR col, COLOR background)
void Window::SetBaseColor(Color col, Color background)
{
itsBaseColor = col;
itsBaseBgColor = background;
}
bool Window::have_to_recreate(BORDER border)
bool Window::have_to_recreate(Border border)
{
if (border == brNone && itsBorder != brNone)
{
@@ -132,7 +133,7 @@ bool Window::have_to_recreate(string newtitle)
return false;
}
void Window::SetBorder(BORDER border)
void Window::SetBorder(Border border)
{
if (have_to_recreate(border))
recreate_win();
@@ -279,7 +280,7 @@ void Window::ReadKey() const
wgetch(itsWindow);
}
void Window::Write(int limit, const string &str, CLEAR_TO_EOL clrtoeol)
void Window::Write(int limit, const string &str, bool clrtoeol)
{
if (BBEnabled && !str.empty())
{
@@ -319,7 +320,7 @@ void Window::Write(int limit, const string &str, CLEAR_TO_EOL clrtoeol)
tmp.clear();
if (is_valid_color(color))
{
std::pair<COLOR, COLOR> colors = into_color(color);
ColorPair colors = into_color(color);
SetColor(colors.first, colors.second);
}
else
@@ -342,7 +343,7 @@ void Window::Write(int limit, const string &str, CLEAR_TO_EOL clrtoeol)
}
#ifdef UTF8_ENABLED
void Window::Write(int limit, const wstring &str, CLEAR_TO_EOL clrtoeol)
void Window::Write(int limit, const wstring &str, bool clrtoeol)
{
if (BBEnabled)
{
@@ -382,7 +383,7 @@ void Window::Write(int limit, const wstring &str, CLEAR_TO_EOL clrtoeol)
tmp.clear();
if (is_valid_color(ToString(color)))
{
std::pair<COLOR, COLOR> colors = into_color(ToString(color));
ColorPair colors = into_color(ToString(color));
SetColor(colors.first, colors.second);
}
else
@@ -404,21 +405,21 @@ void Window::Write(int limit, const wstring &str, CLEAR_TO_EOL clrtoeol)
wrefresh(itsWindow);
}
void Window::WriteXY(int x, int y, int limit, const wstring &str, CLEAR_TO_EOL cleartoeol)
void Window::WriteXY(int x, int y, int limit, const wstring &str, bool cleartoeol)
{
wmove(itsWindow,y,x);
Write(limit, str, cleartoeol);
}
#endif
void Window::WriteXY(int x, int y, int limit, const string &str, CLEAR_TO_EOL cleartoeol)
void Window::WriteXY(int x, int y, int limit, const string &str, bool cleartoeol)
{
wmove(itsWindow,y,x);
Write(limit, str, cleartoeol);
}
string Window::GetString(const string &base, unsigned int length, void (*given_function)()) const
string Window::GetString(const string &base, unsigned int length) const
{
curs_set(1);
@@ -445,8 +446,8 @@ string Window::GetString(const string &base, unsigned int length, void (*given_f
do
{
if (given_function)
given_function();
if (itsGetStringHelper)
itsGetStringHelper();
wmove(itsWindow,y,x);
input = wgetch(itsWindow);
@@ -578,29 +579,26 @@ string Window::GetTitle() const
return itsTitle;
}
COLOR Window::GetColor() const
Color Window::GetColor() const
{
return itsColor;
}
BORDER Window::GetBorder() const
Border Window::GetBorder() const
{
return itsBorder;
}
void EnableColors()
void Window::EnableColors()
{
if (has_colors())
{
start_color();
use_default_colors();
int num = 1;
if (use_default_colors() != ERR)
for (int i = -1; i < 8; i++)
for (int j = 0; j < 8; j++)
init_pair(num++, j, i);
else
for (int i = 1; i <= 8; i++)
init_pair(i, i, COLOR_BLACK);
}
}

View File

@@ -35,17 +35,16 @@
# define TO_STRING(x) x
#endif
typedef bool CLEAR_TO_EOL;
using std::string;
using std::wstring;
using std::vector;
enum COLOR { clDefault, clBlack, clRed, clGreen, clYellow, clBlue, clMagenta, clCyan, clWhite };
enum BORDER { brNone, brBlack, brRed, brGreen, brYellow, brBlue, brMagenta, brCyan, brWhite };
enum WHERE { UP, DOWN, PAGE_UP, PAGE_DOWN, HOME, END };
enum Color { clDefault, clBlack, clRed, clGreen, clYellow, clBlue, clMagenta, clCyan, clWhite };
enum Border { brNone, brBlack, brRed, brGreen, brYellow, brBlue, brMagenta, brCyan, brWhite };
enum Where { UP, DOWN, PAGE_UP, PAGE_DOWN, HOME, END };
void EnableColors();
typedef void (*GetStringHelper)();
typedef std::pair<Color, Color> ColorPair;
char * ToString(const wchar_t *);
wchar_t * ToWString(const char *);
@@ -60,13 +59,14 @@ int CountBBCodes(const wstring &);
class Window
{
public:
Window(int, int, int, int, string, COLOR, BORDER);
Window(int, int, int, int, string, Color, Border);
Window(const Window &);
virtual ~Window();
virtual WINDOW *RawWin() { return itsWindow; }
virtual void SetColor(COLOR, COLOR = clDefault);
virtual void SetBaseColor(COLOR, COLOR = clDefault);
virtual void SetBorder(BORDER);
virtual void GetGetStringHelper(GetStringHelper helper) { itsGetStringHelper = helper; }
virtual void SetColor(Color, Color = clDefault);
virtual void SetBaseColor(Color, Color = clDefault);
virtual void SetBorder(Border);
virtual void EnableBB() { BBEnabled = 1; }
virtual void DisableBB() { BBEnabled = 0; }
virtual void SetTitle(string);
@@ -84,19 +84,18 @@ class Window
virtual void AutoRefresh(bool val) { AutoRefreshEnabled = val; }
virtual void ReadKey(int &) const;
virtual void ReadKey() const;
virtual void Write(const string &s, CLEAR_TO_EOL cte = 0) { Write(0xFFFF, s, cte); }
virtual void Write(int, const string &, CLEAR_TO_EOL = 0);
virtual void WriteXY(int x, int y, const string &s, CLEAR_TO_EOL ete = 0) { WriteXY(x, y, 0xFFFF, s, ete); }
virtual void WriteXY(int, int, int, const string &, CLEAR_TO_EOL = 0);
virtual void Write(const string &s, bool cte = 0) { Write(0xFFFF, s, cte); }
virtual void Write(int, const string &, bool = 0);
virtual void WriteXY(int x, int y, const string &s, bool ete = 0) { WriteXY(x, y, 0xFFFF, s, ete); }
virtual void WriteXY(int, int, int, const string &, bool = 0);
#ifdef UTF8_ENABLED
virtual void Write(const wstring &s, CLEAR_TO_EOL cte = 0) { Write(0xFFFF, s, cte); }
virtual void Write(int, const wstring &, CLEAR_TO_EOL = 0);
virtual void WriteXY(int x, int y, const wstring &s, CLEAR_TO_EOL ete = 0) { WriteXY(x, y, 0xFFFF, s, ete); }
virtual void WriteXY(int, int, int, const wstring &, CLEAR_TO_EOL = 0);
virtual void Write(const wstring &s, bool cte = 0) { Write(0xFFFF, s, cte); }
virtual void Write(int, const wstring &, bool = 0);
virtual void WriteXY(int x, int y, const wstring &s, bool ete = 0) { WriteXY(x, y, 0xFFFF, s, ete); }
virtual void WriteXY(int, int, int, const wstring &, bool = 0);
#endif
virtual string GetString(int num, void (*ptr)() = NULL) const { return GetString("", num, ptr); }
virtual string GetString(const string &str, void (*ptr)()) const { return GetString(str, -1, ptr); }
virtual string GetString(const string &, unsigned int = -1, void (*)() = NULL) const;
virtual string GetString(const string &, unsigned int = -1) const;
virtual string GetString(unsigned int length = -1) const { return GetString("", length); }
virtual void Scrollable(bool) const;
virtual void GetXY(int &, int &) const;
virtual void GotoXY(int, int) const;
@@ -105,25 +104,28 @@ class Window
virtual int GetStartX() const;
virtual int GetStartY() const;
virtual string GetTitle() const;
virtual COLOR GetColor() const;
virtual BORDER GetBorder() const;
virtual Color GetColor() const;
virtual Border GetBorder() const;
virtual Window * Clone() { return new Window(*this); }
virtual Window * EmptyClone();
virtual void Go(WHERE) { } // for Menu and Scrollpad class
virtual void Go(Where) { } // for Menu and Scrollpad class
virtual int GetChoice() const { return -1; } // for Menu class
virtual void Add(string str) { Write(str); } // for Scrollpad class
static void EnableColors();
protected:
virtual bool have_to_recreate(string);
virtual bool have_to_recreate(BORDER);
virtual bool have_to_recreate(Border);
virtual bool reallocate_win(int, int);
virtual void recreate_win();
virtual void show_border() const;
virtual std::pair<COLOR, COLOR> into_color(const string &);
//bool is_valid_color(const string &);
virtual ColorPair into_color(const string &);
WINDOW *itsWindow;
WINDOW *itsWinBorder;
GetStringHelper itsGetStringHelper;
int itsStartX;
int itsStartY;
int itsWidth;
@@ -131,12 +133,12 @@ class Window
bool BBEnabled;
bool AutoRefreshEnabled;
string itsTitle;
std::stack< std::pair<COLOR, COLOR> > itsColors;
COLOR itsColor;
COLOR itsBaseColor;
COLOR itsBgColor;
COLOR itsBaseBgColor;
BORDER itsBorder;
std::stack<ColorPair> itsColors;
Color itsColor;
Color itsBaseColor;
Color itsBgColor;
Color itsBaseBgColor;
Border itsBorder;
};
#endif