window: support new colors also as borders
This commit is contained in:
@@ -73,7 +73,7 @@ bool browserEntryMatcher(const boost::regex &rx, const MPD::Item &item, bool fil
|
||||
|
||||
Browser::Browser() : m_local_browser(false), m_scroll_beginning(0), m_current_directory("/")
|
||||
{
|
||||
w = NC::Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.browser_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border::None);
|
||||
w = NC::Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.browser_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border());
|
||||
w.setHighlightColor(Config.main_highlight_color);
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w.centeredCursor(Config.centered_cursor);
|
||||
|
||||
@@ -57,8 +57,8 @@ Clock::Clock()
|
||||
{
|
||||
Width = Config.clock_display_seconds ? 60 : 40;
|
||||
|
||||
m_pane = NC::Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None);
|
||||
w = NC::Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, NC::Border::None);
|
||||
m_pane = NC::Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border());
|
||||
w = NC::Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, Config.main_color);
|
||||
}
|
||||
|
||||
void Clock::resize()
|
||||
|
||||
@@ -450,7 +450,7 @@ void write_bindings(NC::Scrollpad &w)
|
||||
}
|
||||
|
||||
Help::Help()
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
{
|
||||
write_bindings(w);
|
||||
w.flush();
|
||||
|
||||
@@ -35,7 +35,7 @@ using Global::MainStartY;
|
||||
Lastfm *myLastfm;
|
||||
|
||||
Lastfm::Lastfm()
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
{ }
|
||||
|
||||
void Lastfm::resize()
|
||||
|
||||
@@ -51,7 +51,7 @@ size_t Lyrics::itsWorkersNumber = 0;
|
||||
Lyrics *myLyrics;
|
||||
|
||||
Lyrics::Lyrics()
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
, Reload(0),
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
isReadyToTake(0), isDownloadInProgress(0),
|
||||
|
||||
@@ -167,7 +167,7 @@ MediaLibrary::MediaLibrary()
|
||||
itsRightColWidth = COLS-COLS/3*2-1;
|
||||
itsRightColStartX = itsLeftColWidth+itsMiddleColWidth+2;
|
||||
|
||||
Tags = NC::Menu<PrimaryTag>(0, MainStartY, itsLeftColWidth, MainHeight, Config.titles_visibility ? tagTypeToString(Config.media_lib_primary_tag) + "s" : "", Config.main_color, NC::Border::None);
|
||||
Tags = NC::Menu<PrimaryTag>(0, MainStartY, itsLeftColWidth, MainHeight, Config.titles_visibility ? tagTypeToString(Config.media_lib_primary_tag) + "s" : "", Config.main_color, NC::Border());
|
||||
Tags.setHighlightColor(Config.active_column_color);
|
||||
Tags.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Tags.centeredCursor(Config.centered_cursor);
|
||||
@@ -181,7 +181,7 @@ MediaLibrary::MediaLibrary()
|
||||
menu << Charset::utf8ToLocale(tag);
|
||||
});
|
||||
|
||||
Albums = NC::Menu<AlbumEntry>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, NC::Border::None);
|
||||
Albums = NC::Menu<AlbumEntry>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, NC::Border());
|
||||
Albums.setHighlightColor(Config.main_highlight_color);
|
||||
Albums.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Albums.centeredCursor(Config.centered_cursor);
|
||||
@@ -191,7 +191,7 @@ MediaLibrary::MediaLibrary()
|
||||
menu << Charset::utf8ToLocale(AlbumToString(menu.drawn()->value()));
|
||||
});
|
||||
|
||||
Songs = NC::Menu<MPD::Song>(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, Config.titles_visibility ? "Songs" : "", Config.main_color, NC::Border::None);
|
||||
Songs = NC::Menu<MPD::Song>(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, Config.titles_visibility ? "Songs" : "", Config.main_color, NC::Border());
|
||||
Songs.setHighlightColor(Config.main_highlight_color);
|
||||
Songs.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Songs.centeredCursor(Config.centered_cursor);
|
||||
|
||||
@@ -118,11 +118,11 @@ int main(int argc, char **argv)
|
||||
Actions::validateScreenSize();
|
||||
Actions::initializeScreens();
|
||||
|
||||
wHeader = new NC::Window(0, 0, COLS, Actions::HeaderHeight, "", Config.header_color, NC::Border::None);
|
||||
wHeader = new NC::Window(0, 0, COLS, Actions::HeaderHeight, "", Config.header_color, NC::Border());
|
||||
if (Config.header_visibility || Config.design == Design::Alternative)
|
||||
wHeader->display();
|
||||
|
||||
wFooter = new NC::Window(0, Actions::FooterStartY, COLS, Actions::FooterHeight, "", Config.statusbar_color, NC::Border::None);
|
||||
wFooter = new NC::Window(0, Actions::FooterStartY, COLS, Actions::FooterHeight, "", Config.statusbar_color, NC::Border());
|
||||
wFooter->setPromptHook(Statusbar::Helpers::mainHook);
|
||||
|
||||
// initialize global timer
|
||||
|
||||
@@ -38,7 +38,7 @@ using Global::myScreen;
|
||||
Outputs *myOutputs;
|
||||
|
||||
Outputs::Outputs()
|
||||
: Screen(NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
{
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w.centeredCursor(Config.centered_cursor);
|
||||
|
||||
@@ -52,7 +52,7 @@ Playlist::Playlist()
|
||||
, m_timer(boost::posix_time::from_time_t(0))
|
||||
, m_reload_total_length(false), m_reload_remaining(false)
|
||||
{
|
||||
w = NC::Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.playlist_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border::None);
|
||||
w = NC::Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.playlist_display_mode == DisplayMode::Columns && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::Border());
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
w.centeredCursor(Config.centered_cursor);
|
||||
w.setHighlightColor(Config.main_highlight_color);
|
||||
|
||||
@@ -64,7 +64,7 @@ PlaylistEditor::PlaylistEditor()
|
||||
RightColumnStartX = LeftColumnWidth+1;
|
||||
RightColumnWidth = COLS-LeftColumnWidth-1;
|
||||
|
||||
Playlists = NC::Menu<MPD::Playlist>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, NC::Border::None);
|
||||
Playlists = NC::Menu<MPD::Playlist>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, NC::Border());
|
||||
Playlists.setHighlightColor(Config.active_column_color);
|
||||
Playlists.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Playlists.centeredCursor(Config.centered_cursor);
|
||||
@@ -74,7 +74,7 @@ PlaylistEditor::PlaylistEditor()
|
||||
menu << Charset::utf8ToLocale(menu.drawn()->value().path());
|
||||
});
|
||||
|
||||
Content = NC::Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, NC::Border::None);
|
||||
Content = NC::Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, NC::Border());
|
||||
Content.setHighlightColor(Config.main_highlight_color);
|
||||
Content.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Content.centeredCursor(Config.centered_cursor);
|
||||
|
||||
@@ -101,7 +101,7 @@ size_t SearchEngine::ResetButton = 16;
|
||||
size_t SearchEngine::SearchButton = 15;
|
||||
|
||||
SearchEngine::SearchEngine()
|
||||
: Screen(NC::Menu<SEItem>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Menu<SEItem>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
{
|
||||
w.setHighlightColor(Config.main_highlight_color);
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
|
||||
@@ -171,6 +171,22 @@ option_parser::worker buffer(NC::Buffer &arg, ValueT &&value, TransformT &&map)
|
||||
}), defaults_to(arg, map(std::forward<ValueT>(value))));
|
||||
}
|
||||
|
||||
option_parser::worker border(NC::Border &arg, NC::Border value)
|
||||
{
|
||||
return option_parser::worker(assign<std::string>(arg, [&arg](std::string s) {
|
||||
NC::Border result;
|
||||
if (!s.empty())
|
||||
{
|
||||
try {
|
||||
result = boost::lexical_cast<NC::Color>(s);
|
||||
} catch (boost::bad_lexical_cast &) {
|
||||
throw std::runtime_error("invalid border: " + s);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}), defaults_to(arg, std::move(value)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Configuration::read(const std::vector<std::string> &config_paths)
|
||||
@@ -646,11 +662,11 @@ bool Configuration::read(const std::vector<std::string> &config_paths)
|
||||
p.add("active_column_color", assign_default(
|
||||
active_column_color, NC::Color::Red
|
||||
));
|
||||
p.add("window_border_color", assign_default(
|
||||
window_border, NC::Border::Green
|
||||
p.add("window_border_color", border(
|
||||
window_border, NC::Color::Green
|
||||
));
|
||||
p.add("active_window_border", assign_default(
|
||||
active_window_border, NC::Border::Red
|
||||
p.add("active_window_border", border(
|
||||
active_window_border, NC::Color::Red
|
||||
));
|
||||
|
||||
return std::all_of(
|
||||
|
||||
@@ -54,7 +54,7 @@ const SongInfo::Metadata SongInfo::Tags[] =
|
||||
};
|
||||
|
||||
SongInfo::SongInfo()
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
{ }
|
||||
|
||||
void SongInfo::resize()
|
||||
|
||||
@@ -90,7 +90,7 @@ TagEditor::TagEditor() : FParser(0), FParserHelper(0), FParserLegend(0), FParser
|
||||
PatternsFile = Config.ncmpcpp_directory + "patterns.list";
|
||||
SetDimensions(0, COLS);
|
||||
|
||||
Dirs = new NC::Menu< std::pair<std::string, std::string> >(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Directories" : "", Config.main_color, NC::Border::None);
|
||||
Dirs = new NC::Menu< std::pair<std::string, std::string> >(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Directories" : "", Config.main_color, NC::Border());
|
||||
Dirs->setHighlightColor(Config.active_column_color);
|
||||
Dirs->cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Dirs->centeredCursor(Config.centered_cursor);
|
||||
@@ -98,7 +98,7 @@ TagEditor::TagEditor() : FParser(0), FParserHelper(0), FParserLegend(0), FParser
|
||||
menu << Charset::utf8ToLocale(menu.drawn()->value().first);
|
||||
});
|
||||
|
||||
TagTypes = new NC::Menu<std::string>(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, Config.titles_visibility ? "Tag types" : "", Config.main_color, NC::Border::None);
|
||||
TagTypes = new NC::Menu<std::string>(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, Config.titles_visibility ? "Tag types" : "", Config.main_color, NC::Border());
|
||||
TagTypes->setHighlightColor(Config.main_highlight_color);
|
||||
TagTypes->cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
TagTypes->centeredCursor(Config.centered_cursor);
|
||||
@@ -122,7 +122,7 @@ TagEditor::TagEditor() : FParser(0), FParserHelper(0), FParserLegend(0), FParser
|
||||
TagTypes->addItem("Reset");
|
||||
TagTypes->addItem("Save");
|
||||
|
||||
Tags = new NC::Menu<MPD::MutableSong>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Tags" : "", Config.main_color, NC::Border::None);
|
||||
Tags = new NC::Menu<MPD::MutableSong>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Tags" : "", Config.main_color, NC::Border());
|
||||
Tags->setHighlightColor(Config.main_highlight_color);
|
||||
Tags->cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
Tags->centeredCursor(Config.centered_cursor);
|
||||
|
||||
@@ -49,7 +49,7 @@ using Global::MainStartY;
|
||||
TinyTagEditor *myTinyTagEditor;
|
||||
|
||||
TinyTagEditor::TinyTagEditor()
|
||||
: Screen(NC::Menu<NC::Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border::None))
|
||||
: Screen(NC::Menu<NC::Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::Border()))
|
||||
{
|
||||
w.setHighlightColor(Config.main_highlight_color);
|
||||
w.cyclicScrolling(Config.use_cyclic_scrolling);
|
||||
|
||||
@@ -50,28 +50,6 @@ NC::Color charToColor(char c)
|
||||
}
|
||||
}
|
||||
|
||||
NC::Border stringToBorder(const std::string &border)
|
||||
{
|
||||
NC::Border result = NC::Border::None;
|
||||
if (border == "black")
|
||||
result = NC::Border::Black;
|
||||
else if (border == "red")
|
||||
result = NC::Border::Red;
|
||||
else if (border == "green")
|
||||
result = NC::Border::Green;
|
||||
else if (border == "yellow")
|
||||
result = NC::Border::Yellow;
|
||||
else if (border == "blue")
|
||||
result = NC::Border::Blue;
|
||||
else if (border == "magenta")
|
||||
result = NC::Border::Magenta;
|
||||
else if (border == "cyan")
|
||||
result = NC::Border::Cyan;
|
||||
else if (border == "white")
|
||||
result = NC::Border::White;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string tagTypeToString(mpd_tag_type tag)
|
||||
{
|
||||
switch (tag)
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
|
||||
NC::Color charToColor(char c);
|
||||
|
||||
NC::Border stringToBorder(const std::string &border);
|
||||
|
||||
std::string tagTypeToString(mpd_tag_type tag);
|
||||
MPD::MutableSong::SetFunction tagTypeToSetFunction(mpd_tag_type tag);
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ const NC::Color &toColor(size_t number, size_t max, bool wrap = true)
|
||||
}
|
||||
|
||||
Visualizer::Visualizer()
|
||||
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", NC::Color::Default, NC::Border::None))
|
||||
: Screen(NC::Window(0, MainStartY, COLS, MainHeight, "", NC::Color::Default, NC::Border()))
|
||||
{
|
||||
ResetFD();
|
||||
m_samples = 44100/fps;
|
||||
|
||||
241
src/window.cpp
241
src/window.cpp
@@ -296,129 +296,6 @@ std::istream &operator>>(std::istream &is, Color &c)
|
||||
return is;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Format f)
|
||||
{
|
||||
switch (f)
|
||||
{
|
||||
case Format::None:
|
||||
os << "none";
|
||||
break;
|
||||
case Format::Bold:
|
||||
os << "bold";
|
||||
break;
|
||||
case Format::NoBold:
|
||||
os << "bold";
|
||||
break;
|
||||
case Format::Underline:
|
||||
os << "underline";
|
||||
break;
|
||||
case Format::NoUnderline:
|
||||
os << "no_underline";
|
||||
break;
|
||||
case Format::Reverse:
|
||||
os << "reverse";
|
||||
break;
|
||||
case Format::NoReverse:
|
||||
os << "no_reverse";
|
||||
break;
|
||||
case Format::AltCharset:
|
||||
os << "alt_charset";
|
||||
break;
|
||||
case Format::NoAltCharset:
|
||||
os << "no_alt_charset";
|
||||
break;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Border b)
|
||||
{
|
||||
switch (b)
|
||||
{
|
||||
case Border::None:
|
||||
os << "none";
|
||||
break;
|
||||
case Border::Black:
|
||||
os << "black";
|
||||
break;
|
||||
case Border::Red:
|
||||
os << "red";
|
||||
break;
|
||||
case Border::Green:
|
||||
os << "green";
|
||||
break;
|
||||
case Border::Yellow:
|
||||
os << "yellow";
|
||||
break;
|
||||
case Border::Blue:
|
||||
os << "blue";
|
||||
break;
|
||||
case Border::Magenta:
|
||||
os << "magenta";
|
||||
break;
|
||||
case Border::Cyan:
|
||||
os << "cyan";
|
||||
break;
|
||||
case Border::White:
|
||||
os << "white";
|
||||
break;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
std::istream &operator>>(std::istream &is, Border &b)
|
||||
{
|
||||
std::string sb;
|
||||
is >> sb;
|
||||
if (sb == "none")
|
||||
b = Border::None;
|
||||
else if (sb == "black")
|
||||
b = Border::Black;
|
||||
else if (sb == "red")
|
||||
b = Border::Red;
|
||||
else if (sb == "green")
|
||||
b = Border::Green;
|
||||
else if (sb == "yellow")
|
||||
b = Border::Yellow;
|
||||
else if (sb == "blue")
|
||||
b = Border::Blue;
|
||||
else if (sb == "magenta")
|
||||
b = Border::Magenta;
|
||||
else if (sb == "cyan")
|
||||
b = Border::Cyan;
|
||||
else if (sb == "white")
|
||||
b = Border::White;
|
||||
else
|
||||
is.setstate(std::ios::failbit);
|
||||
return is;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Scroll s)
|
||||
{
|
||||
switch (s)
|
||||
{
|
||||
case Scroll::Up:
|
||||
os << "scroll_up";
|
||||
break;
|
||||
case Scroll::Down:
|
||||
os << "scroll_down";
|
||||
break;
|
||||
case Scroll::PageUp:
|
||||
os << "scroll_page_up";
|
||||
break;
|
||||
case Scroll::PageDown:
|
||||
os << "scroll_page_down";
|
||||
break;
|
||||
case Scroll::Home:
|
||||
os << "scroll_home";
|
||||
break;
|
||||
case Scroll::End:
|
||||
os << "scroll_end";
|
||||
break;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
void initScreen(bool enable_colors)
|
||||
{
|
||||
initscr();
|
||||
@@ -475,11 +352,10 @@ Window::Window(size_t startx,
|
||||
size_t starty,
|
||||
size_t width,
|
||||
size_t height,
|
||||
const std::string &title,
|
||||
std::string title,
|
||||
Color color,
|
||||
Border border)
|
||||
: m_window(0),
|
||||
m_border_window(0),
|
||||
: m_window(nullptr),
|
||||
m_start_x(startx),
|
||||
m_start_y(starty),
|
||||
m_width(width),
|
||||
@@ -487,9 +363,9 @@ Window::Window(size_t startx,
|
||||
m_window_timeout(-1),
|
||||
m_color(color),
|
||||
m_base_color(color),
|
||||
m_border(border),
|
||||
m_border(std::move(border)),
|
||||
m_prompt_hook(0),
|
||||
m_title(title),
|
||||
m_title(std::move(title)),
|
||||
m_bold_counter(0),
|
||||
m_underline_counter(0),
|
||||
m_reverse_counter(0),
|
||||
@@ -499,15 +375,12 @@ Window::Window(size_t startx,
|
||||
|| m_start_y > size_t(LINES)
|
||||
|| m_width+m_start_x > size_t(COLS)
|
||||
|| m_height+m_start_y > size_t(LINES))
|
||||
FatalError("Constructed window is bigger than terminal size");
|
||||
throw std::logic_error("constructed window doesn't fit into the terminal");
|
||||
|
||||
if (m_border != Border::None)
|
||||
if (m_border)
|
||||
{
|
||||
m_border_window = newpad(m_height, m_width);
|
||||
wattron(m_border_window, COLOR_PAIR(int(m_border)));
|
||||
box(m_border_window, 0, 0);
|
||||
m_start_x++;
|
||||
m_start_y++;
|
||||
++m_start_x;
|
||||
++m_start_y;
|
||||
m_width -= 2;
|
||||
m_height -= 2;
|
||||
}
|
||||
@@ -525,7 +398,6 @@ Window::Window(size_t startx,
|
||||
|
||||
Window::Window(const Window &rhs)
|
||||
: m_window(dupwin(rhs.m_window))
|
||||
, m_border_window(dupwin(rhs.m_border_window))
|
||||
, m_start_x(rhs.m_start_x)
|
||||
, m_start_y(rhs.m_start_y)
|
||||
, m_width(rhs.m_width)
|
||||
@@ -548,7 +420,6 @@ Window::Window(const Window &rhs)
|
||||
|
||||
Window::Window(Window &&rhs)
|
||||
: m_window(rhs.m_window)
|
||||
, m_border_window(rhs.m_border_window)
|
||||
, m_start_x(rhs.m_start_x)
|
||||
, m_start_y(rhs.m_start_y)
|
||||
, m_width(rhs.m_width)
|
||||
@@ -567,14 +438,12 @@ Window::Window(Window &&rhs)
|
||||
, m_reverse_counter(rhs.m_reverse_counter)
|
||||
, m_alt_charset_counter(rhs.m_alt_charset_counter)
|
||||
{
|
||||
rhs.m_window = 0;
|
||||
rhs.m_border_window = 0;
|
||||
rhs.m_window = nullptr;
|
||||
}
|
||||
|
||||
Window &Window::operator=(Window rhs)
|
||||
{
|
||||
std::swap(m_window, rhs.m_window);
|
||||
std::swap(m_border_window, rhs.m_border_window);
|
||||
std::swap(m_start_x, rhs.m_start_x);
|
||||
std::swap(m_start_y, rhs.m_start_y);
|
||||
std::swap(m_width, rhs.m_width);
|
||||
@@ -598,7 +467,6 @@ Window &Window::operator=(Window rhs)
|
||||
Window::~Window()
|
||||
{
|
||||
delwin(m_window);
|
||||
delwin(m_border_window);
|
||||
}
|
||||
|
||||
void Window::setColor(Color c)
|
||||
@@ -623,41 +491,28 @@ void Window::setBaseColor(Color c)
|
||||
|
||||
void Window::setBorder(Border border)
|
||||
{
|
||||
if (border == Border::None && m_border != Border::None)
|
||||
if (!border && m_border)
|
||||
{
|
||||
delwin(m_border_window);
|
||||
m_start_x--;
|
||||
m_start_y--;
|
||||
--m_start_x;
|
||||
--m_start_y;
|
||||
m_height += 2;
|
||||
m_width += 2;
|
||||
recreate(m_width, m_height);
|
||||
}
|
||||
else if (border != Border::None && m_border == Border::None)
|
||||
else if (border && !m_border)
|
||||
{
|
||||
m_border_window = newpad(m_height, m_width);
|
||||
wattron(m_border_window, COLOR_PAIR(int(border)));
|
||||
box(m_border_window,0,0);
|
||||
m_start_x++;
|
||||
m_start_y++;
|
||||
++m_start_x;
|
||||
++m_start_y;
|
||||
m_height -= 2;
|
||||
m_width -= 2;
|
||||
recreate(m_width, m_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
wattron(m_border_window,COLOR_PAIR(int(border)));
|
||||
box(m_border_window, 0, 0);
|
||||
}
|
||||
m_border = border;
|
||||
}
|
||||
|
||||
void Window::setTitle(const std::string &new_title)
|
||||
{
|
||||
if (m_title == new_title)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (!new_title.empty() && m_title.empty())
|
||||
if (!new_title.empty() && m_title.empty())
|
||||
{
|
||||
m_start_y += 2;
|
||||
m_height -= 2;
|
||||
@@ -685,10 +540,10 @@ void Window::moveTo(size_t new_x, size_t new_y)
|
||||
{
|
||||
m_start_x = new_x;
|
||||
m_start_y = new_y;
|
||||
if (m_border != Border::None)
|
||||
if (m_border)
|
||||
{
|
||||
m_start_x++;
|
||||
m_start_y++;
|
||||
++m_start_x;
|
||||
++m_start_y;
|
||||
}
|
||||
if (!m_title.empty())
|
||||
m_start_y += 2;
|
||||
@@ -696,12 +551,8 @@ void Window::moveTo(size_t new_x, size_t new_y)
|
||||
|
||||
void Window::adjustDimensions(size_t width, size_t height)
|
||||
{
|
||||
if (m_border != Border::None)
|
||||
if (m_border)
|
||||
{
|
||||
delwin(m_border_window);
|
||||
m_border_window = newpad(height, width);
|
||||
wattron(m_border_window, COLOR_PAIR(int(m_border)));
|
||||
box(m_border_window, 0, 0);
|
||||
width -= 2;
|
||||
height -= 2;
|
||||
}
|
||||
@@ -719,20 +570,42 @@ void Window::resize(size_t new_width, size_t new_height)
|
||||
|
||||
void Window::refreshBorder() const
|
||||
{
|
||||
if (m_border != Border::None)
|
||||
prefresh(m_border_window, 0, 0, getStarty(), getStartX(), m_start_y+m_height, m_start_x+m_width);
|
||||
if (m_border)
|
||||
{
|
||||
size_t start_x = getStartX(), start_y = getStarty();
|
||||
size_t width = getWidth(), height = getHeight();
|
||||
color_set(m_border->pairNumber(), nullptr);
|
||||
attron(A_ALTCHARSET);
|
||||
// corners
|
||||
mvaddch(start_y, start_x, 'l');
|
||||
mvaddch(start_y, start_x+width-1, 'k');
|
||||
mvaddch(start_y+height-1, start_x, 'm');
|
||||
mvaddch(start_y+height-1, start_x+width-1, 'j');
|
||||
// lines
|
||||
mvhline(start_y, start_x+1, 'q', width-2);
|
||||
mvhline(start_y+height-1, start_x+1, 'q', width-2);
|
||||
mvvline(start_y+1, start_x, 'x', height-2);
|
||||
mvvline(start_y+1, start_x+width-1, 'x', height-2);
|
||||
if (!m_title.empty())
|
||||
{
|
||||
mvaddch(start_y+2, start_x, 't');
|
||||
mvaddch(start_y+2, start_x+width-1, 'u');
|
||||
}
|
||||
attroff(A_ALTCHARSET);
|
||||
}
|
||||
else
|
||||
color_set(m_base_color.pairNumber(), nullptr);
|
||||
if (!m_title.empty())
|
||||
{
|
||||
if (m_border != Border::None)
|
||||
attron(COLOR_PAIR(int(m_border)));
|
||||
else
|
||||
wcolor_set(m_border_window, m_base_color.pairNumber(), nullptr);
|
||||
mvhline(m_start_y-1, m_start_x, 0, m_width);
|
||||
// clear title line
|
||||
mvhline(m_start_y-2, m_start_x, ' ', m_width);
|
||||
attron(A_BOLD);
|
||||
mvhline(m_start_y-2, m_start_x, 32, m_width); // clear title line
|
||||
mvaddstr(m_start_y-2, m_start_x, m_title.c_str());
|
||||
attroff(COLOR_PAIR(int(m_border)) | A_BOLD);
|
||||
attroff(A_BOLD);
|
||||
// add separator
|
||||
mvhline(m_start_y-1, m_start_x, 0, m_width);
|
||||
}
|
||||
standend();
|
||||
::refresh();
|
||||
}
|
||||
|
||||
@@ -936,7 +809,7 @@ bool Window::runPromptHook(const char *arg, bool *done) const
|
||||
|
||||
size_t Window::getWidth() const
|
||||
{
|
||||
if (m_border != Border::None)
|
||||
if (m_border)
|
||||
return m_width+2;
|
||||
else
|
||||
return m_width;
|
||||
@@ -945,7 +818,7 @@ size_t Window::getWidth() const
|
||||
size_t Window::getHeight() const
|
||||
{
|
||||
size_t height = m_height;
|
||||
if (m_border != Border::None)
|
||||
if (m_border)
|
||||
height += 2;
|
||||
if (!m_title.empty())
|
||||
height += 2;
|
||||
@@ -954,7 +827,7 @@ size_t Window::getHeight() const
|
||||
|
||||
size_t Window::getStartX() const
|
||||
{
|
||||
if (m_border != Border::None)
|
||||
if (m_border)
|
||||
return m_start_x-1;
|
||||
else
|
||||
return m_start_x;
|
||||
@@ -963,8 +836,8 @@ size_t Window::getStartX() const
|
||||
size_t Window::getStarty() const
|
||||
{
|
||||
size_t starty = m_start_y;
|
||||
if (m_border != Border::None)
|
||||
starty--;
|
||||
if (m_border)
|
||||
--starty;
|
||||
if (!m_title.empty())
|
||||
starty -= 2;
|
||||
return starty;
|
||||
@@ -980,7 +853,7 @@ const Color &Window::getColor() const
|
||||
return m_color;
|
||||
}
|
||||
|
||||
Border Window::getBorder() const
|
||||
const Border &Window::getBorder() const
|
||||
{
|
||||
return m_border;
|
||||
}
|
||||
|
||||
30
src/window.h
30
src/window.h
@@ -30,6 +30,7 @@
|
||||
#include "curses.h"
|
||||
#include "gcc.h"
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
@@ -93,9 +94,6 @@
|
||||
#undef KEY_ENTER
|
||||
#define KEY_ENTER 13
|
||||
|
||||
// undefine scroll macro as it collides with Window::scroll
|
||||
#undef scroll
|
||||
|
||||
#if !defined(USE_PDCURSES) && NCURSES_MOUSE_VERSION == 1
|
||||
// NOTICE: define BUTTON5_PRESSED to be BUTTON2_PRESSED with additional mask
|
||||
// (I noticed that it sometimes returns 134217728 (2^27) instead of expected
|
||||
@@ -103,10 +101,9 @@
|
||||
# define BUTTON5_PRESSED (BUTTON2_PRESSED | (1U << 27))
|
||||
#endif // !defined(USE_PDCURSES) && NCURSES_MOUSE_VERSION == 1
|
||||
|
||||
// workaraund for win32
|
||||
#ifdef WIN32
|
||||
# define wcwidth(x) int(!iscntrl(x))
|
||||
#endif
|
||||
// undefine macros with colliding names
|
||||
#undef border
|
||||
#undef scroll
|
||||
|
||||
/// NC namespace provides set of easy-to-use
|
||||
/// wrappers over original curses library.
|
||||
@@ -196,6 +193,8 @@ private:
|
||||
|
||||
std::istream &operator>>(std::istream &is, Color &f);
|
||||
|
||||
typedef boost::optional<Color> Border;
|
||||
|
||||
/// Terminal manipulation functions
|
||||
enum class TermManip { ClearToEOL };
|
||||
|
||||
@@ -208,19 +207,9 @@ enum class Format {
|
||||
AltCharset, NoAltCharset
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Format f);
|
||||
|
||||
/// Available border colors for window
|
||||
enum class Border { None, Black, Red, Green, Yellow, Blue, Magenta, Cyan, White };
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Border b);
|
||||
std::istream &operator>>(std::istream &is, Border &b);
|
||||
|
||||
/// This indicates how much the window has to be scrolled
|
||||
enum class Scroll { Up, Down, PageUp, PageDown, Home, End };
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Scroll s);
|
||||
|
||||
/// Initializes curses screen and sets some additional attributes
|
||||
/// @param enable_colors enables colors
|
||||
void initScreen(bool enable_colors);
|
||||
@@ -262,7 +251,7 @@ struct Window
|
||||
PromptHook m_hook;
|
||||
};
|
||||
|
||||
Window() : m_window(0), m_border_window(0) { }
|
||||
Window() : m_window(nullptr) { }
|
||||
|
||||
/// Constructs an empty window with given parameters
|
||||
/// @param startx X position of left upper corner of constructed window
|
||||
@@ -273,7 +262,7 @@ struct Window
|
||||
/// @param color base color of constructed window
|
||||
/// @param border border of constructed window
|
||||
Window(size_t startx, size_t starty, size_t width, size_t height,
|
||||
const std::string &title, Color color, Border border);
|
||||
std::string title, Color color, Border border);
|
||||
|
||||
Window(const Window &rhs);
|
||||
Window(Window &&rhs);
|
||||
@@ -305,7 +294,7 @@ struct Window
|
||||
const Color &getColor() const;
|
||||
|
||||
/// @return current window's border
|
||||
Border getBorder() const;
|
||||
const Border &getBorder() const;
|
||||
|
||||
/// @return current window's timeout
|
||||
int getTimeout() const;
|
||||
@@ -465,7 +454,6 @@ protected:
|
||||
|
||||
/// internal WINDOW pointers
|
||||
WINDOW *m_window;
|
||||
WINDOW *m_border_window;
|
||||
|
||||
/// start points and dimensions
|
||||
size_t m_start_x;
|
||||
|
||||
Reference in New Issue
Block a user