another code clean-ups
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "lyrics.h"
|
#include "lyrics.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include "ncmpcpp.h"
|
#include "ncmpcpp.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#ifdef HAVE_CURL_CURL_H
|
#ifdef HAVE_CURL_CURL_H
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
# include "curl/curl.h"
|
# include "curl/curl.h"
|
||||||
|
|||||||
74
src/menu.h
74
src/menu.h
@@ -48,7 +48,7 @@ class Menu : public Window
|
|||||||
typedef string (*ItemDisplayer) (const T &, void *, const Menu<T> *);
|
typedef string (*ItemDisplayer) (const T &, void *, const Menu<T> *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Menu(int startx, int starty, int width, int height, string title, Color color, Border border) : Window(startx, starty, width, height, title, color, border), itsItemDisplayer(0), itsItemDisplayerUserdata(0), itsSelectedPrefix("[.r]"), itsSelectedSuffix("[/r]"), itsStaticsNumber(0), itsBeginning(0), itsHighlight(0), itsHighlightColor(itsBaseColor), itsHighlightEnabled(1) { }
|
Menu(int, int, int, int, const string &, Color, Border);
|
||||||
Menu(const Menu &);
|
Menu(const Menu &);
|
||||||
virtual ~Menu();
|
virtual ~Menu();
|
||||||
|
|
||||||
@@ -126,6 +126,19 @@ class Menu : public Window
|
|||||||
bool itsHighlightEnabled;
|
bool itsHighlightEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Menu<T>::Menu(int startx, int starty, int width, int height, const string &title, Color color, Border border) :
|
||||||
|
Window(startx, starty, width, height, title, color, border),
|
||||||
|
itsItemDisplayer(0),
|
||||||
|
itsItemDisplayerUserdata(0),
|
||||||
|
itsSelectedPrefix("[.r]"),
|
||||||
|
itsSelectedSuffix("[/r]"),
|
||||||
|
itsStaticsNumber(0),
|
||||||
|
itsBeginning(0),
|
||||||
|
itsHighlight(0),
|
||||||
|
itsHighlightColor(itsBaseColor),
|
||||||
|
itsHighlightEnabled(1) { }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
Menu<T>::Menu(const Menu &m) : Window(m)
|
Menu<T>::Menu(const Menu &m) : Window(m)
|
||||||
{
|
{
|
||||||
@@ -355,7 +368,13 @@ void Menu<T>::Refresh(bool redraw_whole_window)
|
|||||||
int ch = itsOptions[*it]->have_separator ? 0 : 32;
|
int ch = itsOptions[*it]->have_separator ? 0 : 32;
|
||||||
mvwhline(itsWindow,line, 0, ch, itsWidth);
|
mvwhline(itsWindow,line, 0, ch, itsWidth);
|
||||||
|
|
||||||
string option = DisplayOption(itsOptions[*it]->item);
|
string option;
|
||||||
|
|
||||||
|
if (itsOptions[*it]->selected)
|
||||||
|
option += itsSelectedPrefix;
|
||||||
|
option += DisplayOption(itsOptions[*it]->item);
|
||||||
|
if (itsOptions[*it]->selected)
|
||||||
|
option += itsSelectedSuffix;
|
||||||
|
|
||||||
int strlength = itsOptions[*it]->location != lLeft && BBEnabled ? Window::RealLength(option) : option.length();
|
int strlength = itsOptions[*it]->location != lLeft && BBEnabled ? Window::RealLength(option) : option.length();
|
||||||
|
|
||||||
@@ -386,10 +405,7 @@ void Menu<T>::Refresh(bool redraw_whole_window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itsOptions[*it]->selected)
|
WriteXY(x, line, itsWidth, TO_WSTRING(option), 0);
|
||||||
WriteXY(x, line, itsWidth, TO_WSTRING(itsSelectedPrefix + option + itsSelectedSuffix), 0);
|
|
||||||
else
|
|
||||||
WriteXY(x, line, itsWidth, TO_WSTRING(option), 0);
|
|
||||||
|
|
||||||
if (!ch && (itsOptions[*it]->location == lCenter || itsOptions[*it]->location == lLeft))
|
if (!ch && (itsOptions[*it]->location == lCenter || itsOptions[*it]->location == lLeft))
|
||||||
{
|
{
|
||||||
@@ -415,7 +431,9 @@ void Menu<T>::Refresh(bool redraw_whole_window)
|
|||||||
template <class T>
|
template <class T>
|
||||||
void Menu<T>::Go(Where where)
|
void Menu<T>::Go(Where where)
|
||||||
{
|
{
|
||||||
if (Empty()) return;
|
if (Empty())
|
||||||
|
return;
|
||||||
|
|
||||||
int MaxHighlight = itsOptions.size()-1;
|
int MaxHighlight = itsOptions.size()-1;
|
||||||
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
||||||
int MaxCurrentHighlight = itsBeginning+itsHeight-1;
|
int MaxCurrentHighlight = itsBeginning+itsHeight-1;
|
||||||
@@ -431,7 +449,9 @@ void Menu<T>::Go(Where where)
|
|||||||
wscrl(itsWindow, -1);
|
wscrl(itsWindow, -1);
|
||||||
}
|
}
|
||||||
if (itsHighlight == 0)
|
if (itsHighlight == 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NeedsRedraw.push_back(itsHighlight--);
|
NeedsRedraw.push_back(itsHighlight--);
|
||||||
@@ -439,10 +459,7 @@ void Menu<T>::Go(Where where)
|
|||||||
}
|
}
|
||||||
if (is_static())
|
if (is_static())
|
||||||
{
|
{
|
||||||
if (itsHighlight == 0)
|
itsHighlight == 0 ? Go(wDown) : Go(wUp);
|
||||||
Go(wDown);
|
|
||||||
else
|
|
||||||
Go(wUp);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -454,7 +471,9 @@ void Menu<T>::Go(Where where)
|
|||||||
wscrl(itsWindow, 1);
|
wscrl(itsWindow, 1);
|
||||||
}
|
}
|
||||||
if (itsHighlight == MaxHighlight)
|
if (itsHighlight == MaxHighlight)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NeedsRedraw.push_back(itsHighlight++);
|
NeedsRedraw.push_back(itsHighlight++);
|
||||||
@@ -462,10 +481,7 @@ void Menu<T>::Go(Where where)
|
|||||||
}
|
}
|
||||||
if (is_static())
|
if (is_static())
|
||||||
{
|
{
|
||||||
if (itsHighlight == MaxHighlight)
|
itsHighlight == MaxHighlight ? Go(wUp) : Go(wDown);
|
||||||
Go(wUp);
|
|
||||||
else
|
|
||||||
Go(wDown);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -476,14 +492,12 @@ void Menu<T>::Go(Where where)
|
|||||||
if (itsBeginning < 0)
|
if (itsBeginning < 0)
|
||||||
{
|
{
|
||||||
itsBeginning = 0;
|
itsBeginning = 0;
|
||||||
if (itsHighlight < 0) itsHighlight = 0;
|
if (itsHighlight < 0)
|
||||||
|
itsHighlight = 0;
|
||||||
}
|
}
|
||||||
if (is_static())
|
if (is_static())
|
||||||
{
|
{
|
||||||
if (itsHighlight == 0)
|
itsHighlight == 0 ? Go(wDown) : Go(wUp);
|
||||||
Go(wDown);
|
|
||||||
else
|
|
||||||
Go(wUp);
|
|
||||||
}
|
}
|
||||||
redraw_screen();
|
redraw_screen();
|
||||||
break;
|
break;
|
||||||
@@ -495,14 +509,12 @@ void Menu<T>::Go(Where where)
|
|||||||
if (itsBeginning > MaxBeginning)
|
if (itsBeginning > MaxBeginning)
|
||||||
{
|
{
|
||||||
itsBeginning = MaxBeginning;
|
itsBeginning = MaxBeginning;
|
||||||
if (itsHighlight > MaxHighlight) itsHighlight = MaxHighlight;
|
if (itsHighlight > MaxHighlight)
|
||||||
|
itsHighlight = MaxHighlight;
|
||||||
}
|
}
|
||||||
if (is_static())
|
if (is_static())
|
||||||
{
|
{
|
||||||
if (itsHighlight == MaxHighlight)
|
itsHighlight == MaxHighlight ? Go(wUp) : Go(wDown);
|
||||||
Go(wUp);
|
|
||||||
else
|
|
||||||
Go(wDown);
|
|
||||||
}
|
}
|
||||||
redraw_screen();
|
redraw_screen();
|
||||||
break;
|
break;
|
||||||
@@ -513,10 +525,7 @@ void Menu<T>::Go(Where where)
|
|||||||
itsBeginning = 0;
|
itsBeginning = 0;
|
||||||
if (is_static())
|
if (is_static())
|
||||||
{
|
{
|
||||||
if (itsHighlight == 0)
|
itsHighlight == 0 ? Go(wDown) : Go(wUp);
|
||||||
Go(wDown);
|
|
||||||
else
|
|
||||||
Go(wUp);
|
|
||||||
}
|
}
|
||||||
redraw_screen();
|
redraw_screen();
|
||||||
break;
|
break;
|
||||||
@@ -527,10 +536,7 @@ void Menu<T>::Go(Where where)
|
|||||||
itsBeginning = MaxBeginning;
|
itsBeginning = MaxBeginning;
|
||||||
if (is_static())
|
if (is_static())
|
||||||
{
|
{
|
||||||
if (itsHighlight == MaxHighlight)
|
itsHighlight == MaxHighlight ? Go(wUp) : Go(wDown);
|
||||||
Go(wUp);
|
|
||||||
else
|
|
||||||
Go(wDown);
|
|
||||||
}
|
}
|
||||||
redraw_screen();
|
redraw_screen();
|
||||||
break;
|
break;
|
||||||
@@ -698,7 +704,7 @@ bool Menu<T>::IsStatic(int option) const
|
|||||||
template <class T>
|
template <class T>
|
||||||
Window * Menu<T>::EmptyClone() const
|
Window * Menu<T>::EmptyClone() const
|
||||||
{
|
{
|
||||||
return new Menu(GetStartX(),GetStartY(),GetWidth(),GetHeight(),itsTitle,itsBaseColor,itsBorder);
|
return new Menu(GetStartX(), GetStartY(), GetWidth(), GetHeight(), itsTitle, itsBaseColor, itsBorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|||||||
14
src/misc.cpp
14
src/misc.cpp
@@ -21,8 +21,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
using std::stringstream;
|
|
||||||
|
|
||||||
int Abs(int num)
|
int Abs(int num)
|
||||||
{
|
{
|
||||||
return (num < 0 ? -num : num);
|
return (num < 0 ? -num : num);
|
||||||
@@ -38,17 +36,17 @@ int StrToInt(string str)
|
|||||||
return atoi(str.c_str());
|
return atoi(str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
string IntoStr(int liczba)
|
string IntoStr(int l)
|
||||||
{
|
{
|
||||||
stringstream ss;
|
std::stringstream ss;
|
||||||
ss << liczba;
|
ss << l;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
string IntoStr(double liczba, int precision)
|
string IntoStr(double l, int precision)
|
||||||
{
|
{
|
||||||
stringstream ss;
|
std::stringstream ss;
|
||||||
ss << std::fixed << std::setprecision(precision) << liczba;
|
ss << std::fixed << std::setprecision(precision) << l;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ MPDConnection *Mpd;
|
|||||||
time_t timer;
|
time_t timer;
|
||||||
|
|
||||||
int now_playing = -1;
|
int now_playing = -1;
|
||||||
int playing_song_scroll_begin = 0;
|
|
||||||
int browsed_dir_scroll_begin = 0;
|
int browsed_dir_scroll_begin = 0;
|
||||||
int stats_scroll_begin = 0;
|
int stats_scroll_begin = 0;
|
||||||
|
|
||||||
@@ -182,7 +181,7 @@ int main(int argc, char *argv[])
|
|||||||
if (!ConnectToMPD())
|
if (!ConnectToMPD())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
setlocale(LC_ALL,"");
|
setlocale(LC_ALL, "");
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
cbreak();
|
cbreak();
|
||||||
@@ -476,7 +475,6 @@ int main(int argc, char *argv[])
|
|||||||
Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->GetOption());
|
Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->GetOption());
|
||||||
Mpd->StartFieldSearch(MPD_TAG_ITEM_ALBUM);
|
Mpd->StartFieldSearch(MPD_TAG_ITEM_ALBUM);
|
||||||
Mpd->CommitSearch(list);
|
Mpd->CommitSearch(list);
|
||||||
//sort(list.begin(), list.end());
|
|
||||||
}
|
}
|
||||||
for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
|
for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,18 @@
|
|||||||
|
|
||||||
#include "scrollpad.h"
|
#include "scrollpad.h"
|
||||||
|
|
||||||
|
Scrollpad::Scrollpad(int startx, int starty, int width, int height, const 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);
|
||||||
|
SetColor(itsColor);
|
||||||
|
keypad(itsWindow, 1);
|
||||||
|
}
|
||||||
|
|
||||||
Scrollpad::Scrollpad(const Scrollpad &s) : Window(s)
|
Scrollpad::Scrollpad(const Scrollpad &s) : Window(s)
|
||||||
{
|
{
|
||||||
itsContent = s.itsContent;
|
itsContent = s.itsContent;
|
||||||
@@ -126,12 +138,13 @@ void Scrollpad::Recreate()
|
|||||||
itsWindow = newpad(itsRealHeight, itsWidth);
|
itsWindow = newpad(itsRealHeight, itsWidth);
|
||||||
SetTimeout(itsWindowTimeout);
|
SetTimeout(itsWindowTimeout);
|
||||||
SetColor(itsBaseColor, itsBgColor);
|
SetColor(itsBaseColor, itsBgColor);
|
||||||
|
keypad(itsWindow, 1);
|
||||||
Write(itsContent.c_str());
|
Write(itsContent.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scrollpad::Refresh(bool)
|
void Scrollpad::Refresh(bool)
|
||||||
{
|
{
|
||||||
prefresh(itsWindow,itsBeginning,0,itsStartY,itsStartX,itsStartY+itsHeight-1,itsStartX+itsWidth);
|
prefresh(itsWindow, itsBeginning, 0, itsStartY, itsStartX, itsStartY+itsHeight-1, itsStartX+itsWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scrollpad::Resize(int width, int height)
|
void Scrollpad::Resize(int width, int height)
|
||||||
@@ -140,8 +153,8 @@ void Scrollpad::Resize(int width, int height)
|
|||||||
{
|
{
|
||||||
delwin(itsWinBorder);
|
delwin(itsWinBorder);
|
||||||
itsWinBorder = newpad(height, width);
|
itsWinBorder = newpad(height, width);
|
||||||
wattron(itsWinBorder,COLOR_PAIR(itsBorder));
|
wattron(itsWinBorder, COLOR_PAIR(itsBorder));
|
||||||
box(itsWinBorder,0,0);
|
box(itsWinBorder, 0, 0);
|
||||||
width -= 2;
|
width -= 2;
|
||||||
height -= 2;
|
height -= 2;
|
||||||
}
|
}
|
||||||
@@ -215,14 +228,15 @@ void Scrollpad::Clear(bool clear_screen)
|
|||||||
wclear(itsWindow);
|
wclear(itsWindow);
|
||||||
delwin(itsWindow);
|
delwin(itsWindow);
|
||||||
itsWindow = newpad(itsHeight, itsWidth);
|
itsWindow = newpad(itsHeight, itsWidth);
|
||||||
SetColor(itsColor, itsBgColor);
|
|
||||||
SetTimeout(itsWindowTimeout);
|
SetTimeout(itsWindowTimeout);
|
||||||
|
SetColor(itsColor, itsBgColor);
|
||||||
|
keypad(itsWindow, 1);
|
||||||
if (clear_screen)
|
if (clear_screen)
|
||||||
Window::Clear();
|
Window::Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Window * Scrollpad::EmptyClone() const
|
Window * Scrollpad::EmptyClone() const
|
||||||
{
|
{
|
||||||
return new Scrollpad(GetStartX(),GetStartY(),GetWidth(),GetHeight(),itsTitle,itsBaseColor,itsBorder);
|
return new Scrollpad(GetStartX(), GetStartY(), GetWidth(), GetHeight(), itsTitle, itsBaseColor, itsBorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
class Scrollpad: public Window
|
class Scrollpad: public Window
|
||||||
{
|
{
|
||||||
public:
|
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, int, int, int, const string &, Color, Border);
|
||||||
Scrollpad(const Scrollpad &);
|
Scrollpad(const Scrollpad &);
|
||||||
virtual ~Scrollpad() {}
|
virtual ~Scrollpad() {}
|
||||||
virtual void Add(string);
|
virtual void Add(string);
|
||||||
@@ -36,6 +36,7 @@ class Scrollpad: public Window
|
|||||||
virtual void Clear(bool clear_screen = 1);
|
virtual void Clear(bool clear_screen = 1);
|
||||||
virtual Window * Clone() const { return new Scrollpad(*this); }
|
virtual Window * Clone() const { return new Scrollpad(*this); }
|
||||||
virtual Window * EmptyClone() const;
|
virtual Window * EmptyClone() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Recreate();
|
virtual void Recreate();
|
||||||
string itsContent;
|
string itsContent;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
const string config_file = config_dir + "config";
|
const string config_file = config_dir + "config";
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
#ifndef HAVE_SETTINGS_H
|
#ifndef HAVE_SETTINGS_H
|
||||||
#define HAVE_SETTINGS_H
|
#define HAVE_SETTINGS_H
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#include "libmpdclient.h"
|
#include "libmpdclient.h"
|
||||||
#include "ncmpcpp.h"
|
#include "ncmpcpp.h"
|
||||||
|
|
||||||
|
|||||||
@@ -40,26 +40,13 @@ extern Menu<string> *mEditorDirs;
|
|||||||
extern Window *wHeader;
|
extern Window *wHeader;
|
||||||
extern Window *wFooter;
|
extern Window *wFooter;
|
||||||
|
|
||||||
extern SongList vSearched;
|
|
||||||
|
|
||||||
extern time_t timer;
|
extern time_t timer;
|
||||||
|
|
||||||
extern int now_playing;
|
extern int now_playing;
|
||||||
extern int playing_song_scroll_begin;
|
|
||||||
|
|
||||||
extern int lock_statusbar_delay;
|
extern int lock_statusbar_delay;
|
||||||
|
|
||||||
extern string browsed_dir;
|
extern string browsed_dir;
|
||||||
|
|
||||||
extern string player_state;
|
|
||||||
extern string volume_state;
|
|
||||||
extern string switch_state;
|
|
||||||
|
|
||||||
extern string mpd_repeat;
|
|
||||||
extern string mpd_random;
|
|
||||||
extern string mpd_crossfade;
|
|
||||||
extern string mpd_db_updating;
|
|
||||||
|
|
||||||
extern NcmpcppScreen current_screen;
|
extern NcmpcppScreen current_screen;
|
||||||
extern NcmpcppScreen prev_screen;
|
extern NcmpcppScreen prev_screen;
|
||||||
|
|
||||||
@@ -80,6 +67,7 @@ bool repeat_one_allowed = 0;
|
|||||||
long long playlist_old_id = -1;
|
long long playlist_old_id = -1;
|
||||||
|
|
||||||
int old_playing;
|
int old_playing;
|
||||||
|
int playing_song_scroll_begin = 0;
|
||||||
|
|
||||||
time_t time_of_statusbar_lock;
|
time_t time_of_statusbar_lock;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#ifdef HAVE_TAGLIB_H
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "id3v2tag.h"
|
#include "id3v2tag.h"
|
||||||
#include "textidentificationframe.h"
|
#include "textidentificationframe.h"
|
||||||
#include "mpegfile.h"
|
#include "mpegfile.h"
|
||||||
|
|||||||
140
src/window.cpp
140
src/window.cpp
@@ -20,7 +20,23 @@
|
|||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
Window::Window(int startx, int starty, int width, int height, const string &title, Color color, Border border) : itsWindow(0), itsWinBorder(0), itsGetStringHelper(0), itsStartX(startx), itsStartY(starty), itsWidth(width), itsHeight(height), itsWindowTimeout(-1), 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, const string &title, Color color, Border border) :
|
||||||
|
itsWindow(0),
|
||||||
|
itsWinBorder(0),
|
||||||
|
itsGetStringHelper(0),
|
||||||
|
itsStartX(startx),
|
||||||
|
itsStartY(starty),
|
||||||
|
itsWidth(width),
|
||||||
|
itsHeight(height),
|
||||||
|
itsWindowTimeout(-1),
|
||||||
|
BBEnabled(1),
|
||||||
|
AutoRefreshEnabled(1),
|
||||||
|
itsTitle(title),
|
||||||
|
itsColor(color),
|
||||||
|
itsBaseColor(color),
|
||||||
|
itsBgColor(clDefault),
|
||||||
|
itsBaseBgColor(clDefault),
|
||||||
|
itsBorder(border)
|
||||||
{
|
{
|
||||||
if (itsStartX < 0) itsStartX = 0;
|
if (itsStartX < 0) itsStartX = 0;
|
||||||
if (itsStartY < 0) itsStartY = 0;
|
if (itsStartY < 0) itsStartY = 0;
|
||||||
@@ -28,8 +44,8 @@ Window::Window(int startx, int starty, int width, int height, const string &titl
|
|||||||
if (itsBorder != brNone)
|
if (itsBorder != brNone)
|
||||||
{
|
{
|
||||||
itsWinBorder = newpad(itsHeight, itsWidth);
|
itsWinBorder = newpad(itsHeight, itsWidth);
|
||||||
wattron(itsWinBorder,COLOR_PAIR(itsBorder));
|
wattron(itsWinBorder, COLOR_PAIR(itsBorder));
|
||||||
box(itsWinBorder,0,0);
|
box(itsWinBorder, 0, 0);
|
||||||
itsStartX++;
|
itsStartX++;
|
||||||
itsStartY++;
|
itsStartY++;
|
||||||
itsWidth -= 2;
|
itsWidth -= 2;
|
||||||
@@ -47,6 +63,7 @@ Window::Window(int startx, int starty, int width, int height, const string &titl
|
|||||||
itsWindow = newwin(0, 0, 0, 0);
|
itsWindow = newwin(0, 0, 0, 0);
|
||||||
|
|
||||||
SetColor(itsColor);
|
SetColor(itsColor);
|
||||||
|
keypad(itsWindow, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Window(const Window &w)
|
Window::Window(const Window &w)
|
||||||
@@ -78,9 +95,9 @@ Window::~Window()
|
|||||||
void Window::SetColor(Color col, Color background)
|
void Window::SetColor(Color col, Color background)
|
||||||
{
|
{
|
||||||
if (col != clDefault)
|
if (col != clDefault)
|
||||||
wattron(itsWindow,COLOR_PAIR(background*8+col));
|
wattron(itsWindow, COLOR_PAIR(background*8+col));
|
||||||
else
|
else
|
||||||
wattroff(itsWindow,COLOR_PAIR(itsColor));
|
wattroff(itsWindow, COLOR_PAIR(itsColor));
|
||||||
itsColor = col;
|
itsColor = col;
|
||||||
itsBgColor = background;
|
itsBgColor = background;
|
||||||
}
|
}
|
||||||
@@ -104,8 +121,8 @@ void Window::SetBorder(Border border)
|
|||||||
}
|
}
|
||||||
else if (border != brNone && itsBorder == brNone)
|
else if (border != brNone && itsBorder == brNone)
|
||||||
{
|
{
|
||||||
itsWinBorder = newpad(itsHeight,itsWidth);
|
itsWinBorder = newpad(itsHeight, itsWidth);
|
||||||
wattron(itsWinBorder,COLOR_PAIR(border));
|
wattron(itsWinBorder, COLOR_PAIR(border));
|
||||||
box(itsWinBorder,0,0);
|
box(itsWinBorder,0,0);
|
||||||
itsStartX++;
|
itsStartX++;
|
||||||
itsStartY++;
|
itsStartY++;
|
||||||
@@ -116,7 +133,7 @@ void Window::SetBorder(Border border)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
wattron(itsWinBorder,COLOR_PAIR(border));
|
wattron(itsWinBorder,COLOR_PAIR(border));
|
||||||
box(itsWinBorder,0,0);
|
box(itsWinBorder, 0, 0);
|
||||||
}
|
}
|
||||||
itsBorder = border;
|
itsBorder = border;
|
||||||
}
|
}
|
||||||
@@ -148,6 +165,7 @@ void Window::Recreate()
|
|||||||
itsWindow = newwin(itsHeight, itsWidth, itsStartY, itsStartX);
|
itsWindow = newwin(itsHeight, itsWidth, itsStartY, itsStartX);
|
||||||
SetTimeout(itsWindowTimeout);
|
SetTimeout(itsWindowTimeout);
|
||||||
SetColor(itsColor, itsBgColor);
|
SetColor(itsColor, itsBgColor);
|
||||||
|
keypad(itsWindow, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::MoveTo(int newx, int newy)
|
void Window::MoveTo(int newx, int newy)
|
||||||
@@ -175,8 +193,8 @@ void Window::Resize(int width, int height)
|
|||||||
{
|
{
|
||||||
delwin(itsWinBorder);
|
delwin(itsWinBorder);
|
||||||
itsWinBorder = newpad(height, width);
|
itsWinBorder = newpad(height, width);
|
||||||
wattron(itsWinBorder,COLOR_PAIR(itsBorder));
|
wattron(itsWinBorder, COLOR_PAIR(itsBorder));
|
||||||
box(itsWinBorder,0,0);
|
box(itsWinBorder, 0, 0);
|
||||||
width -= 2;
|
width -= 2;
|
||||||
height -= 2;
|
height -= 2;
|
||||||
}
|
}
|
||||||
@@ -195,7 +213,7 @@ void Window::ShowBorder() const
|
|||||||
if (itsBorder != brNone)
|
if (itsBorder != brNone)
|
||||||
{
|
{
|
||||||
refresh();
|
refresh();
|
||||||
prefresh(itsWinBorder,0,0,GetStartY(),GetStartX(),itsStartY+itsHeight,itsStartX+itsWidth);
|
prefresh(itsWinBorder, 0, 0, GetStartY(), GetStartX(), itsStartY+itsHeight, itsStartX+itsWidth);
|
||||||
}
|
}
|
||||||
if (!itsTitle.empty())
|
if (!itsTitle.empty())
|
||||||
{
|
{
|
||||||
@@ -264,7 +282,7 @@ void Window::SetTimeout(int timeout)
|
|||||||
|
|
||||||
void Window::ReadKey(int &input) const
|
void Window::ReadKey(int &input) const
|
||||||
{
|
{
|
||||||
keypad(itsWindow, TRUE); input = wgetch(itsWindow); keypad(itsWindow, FALSE);
|
input = wgetch(itsWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::ReadKey() const
|
void Window::ReadKey() const
|
||||||
@@ -288,8 +306,7 @@ void Window::Write(int limit, const string &str, bool clrtoeol)
|
|||||||
tmp += *it;
|
tmp += *it;
|
||||||
limit--;
|
limit--;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (collect)
|
|
||||||
{
|
{
|
||||||
if (*it != '[')
|
if (*it != '[')
|
||||||
{
|
{
|
||||||
@@ -361,8 +378,7 @@ void Window::Write(int limit, const wstring &str, bool clrtoeol)
|
|||||||
tmp += *it;
|
tmp += *it;
|
||||||
limit -= wcwidth(*it);
|
limit -= wcwidth(*it);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (collect)
|
|
||||||
{
|
{
|
||||||
if (*it != '[')
|
if (*it != '[')
|
||||||
{
|
{
|
||||||
@@ -419,21 +435,21 @@ void Window::Write(int limit, const wstring &str, bool clrtoeol)
|
|||||||
|
|
||||||
void Window::WriteXY(int x, int y, int limit, const wstring &str, bool cleartoeol)
|
void Window::WriteXY(int x, int y, int limit, const wstring &str, bool cleartoeol)
|
||||||
{
|
{
|
||||||
wmove(itsWindow,y,x);
|
wmove(itsWindow, y, x);
|
||||||
Write(limit, str, cleartoeol);
|
Write(limit, str, cleartoeol);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Window::WriteXY(int x, int y, int limit, const string &str, bool cleartoeol)
|
void Window::WriteXY(int x, int y, int limit, const string &str, bool cleartoeol)
|
||||||
{
|
{
|
||||||
wmove(itsWindow,y,x);
|
wmove(itsWindow, y, x);
|
||||||
Write(limit, str, cleartoeol);
|
Write(limit, str, cleartoeol);
|
||||||
}
|
}
|
||||||
|
|
||||||
string Window::GetString(const string &base, unsigned int length, int width) const
|
string Window::GetString(const string &base, unsigned int length, int width) const
|
||||||
{
|
{
|
||||||
int input, beginning, maxbeginning, minx, x, y, maxx;
|
int input, beginning, maxbeginning, minx, x, y, maxx;
|
||||||
getyx(itsWindow,y,x);
|
getyx(itsWindow, y, x);
|
||||||
minx = maxx = x;
|
minx = maxx = x;
|
||||||
|
|
||||||
width--;
|
width--;
|
||||||
@@ -443,7 +459,6 @@ string Window::GetString(const string &base, unsigned int length, int width) con
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
keypad(itsWindow, 1);
|
|
||||||
wstring tmp = ToWString(base);
|
wstring tmp = ToWString(base);
|
||||||
|
|
||||||
string tmp_in;
|
string tmp_in;
|
||||||
@@ -470,7 +485,7 @@ string Window::GetString(const string &base, unsigned int length, int width) con
|
|||||||
if (itsGetStringHelper)
|
if (itsGetStringHelper)
|
||||||
itsGetStringHelper();
|
itsGetStringHelper();
|
||||||
|
|
||||||
wmove(itsWindow,y,x);
|
wmove(itsWindow, y, x);
|
||||||
input = wgetch(itsWindow);
|
input = wgetch(itsWindow);
|
||||||
|
|
||||||
switch (input)
|
switch (input)
|
||||||
@@ -554,7 +569,6 @@ string Window::GetString(const string &base, unsigned int length, int width) con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (input != 10);
|
while (input != 10);
|
||||||
keypad(itsWindow, 0);
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
return ToString(tmp);
|
return ToString(tmp);
|
||||||
}
|
}
|
||||||
@@ -814,85 +828,3 @@ size_t Window::Length(const wstring &ws)
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*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 (!IsValidColor(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 (!IsValidColor(ToString(color)))
|
|
||||||
length -= color.length();
|
|
||||||
color.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,14 +57,9 @@ typedef void (*GetStringHelper)();
|
|||||||
typedef std::pair<Color, Color> ColorPair;
|
typedef std::pair<Color, Color> ColorPair;
|
||||||
typedef std::pair<int, int> Coordinates;
|
typedef std::pair<int, int> Coordinates;
|
||||||
|
|
||||||
//char * ToString(const wchar_t *);
|
|
||||||
//wchar_t * ToWString(const char *);
|
|
||||||
string ToString(const wstring &);
|
string ToString(const wstring &);
|
||||||
wstring ToWString(const string &);
|
wstring ToWString(const string &);
|
||||||
|
|
||||||
//int CountBBCodes(const string &);
|
|
||||||
//int CountBBCodes(const wstring &);
|
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user