new feature for parser, coordinates reader

This commit is contained in:
unK
2008-09-13 20:39:13 +02:00
parent 831f9ab405
commit 369bbf6b96
2 changed files with 39 additions and 2 deletions

View File

@@ -312,7 +312,16 @@ void Window::Write(int limit, const string &str, bool clrtoeol)
{ {
waddstr(itsWindow,tmp.c_str()); waddstr(itsWindow,tmp.c_str());
tmp.clear(); tmp.clear();
if (IsValidColor(color))
if (isdigit(color[2]))
{
int x, y;
getyx(itsWindow, y, x);
Coordinates coords = IntoCoordinates(color);
wmove(itsWindow, coords.second == -1 ? y : coords.second, coords.first);
limit -= coords.first-x;
}
else if (IsValidColor(color))
{ {
ColorPair colors = IntoColor(color); ColorPair colors = IntoColor(color);
SetColor(colors.first, colors.second); SetColor(colors.first, colors.second);
@@ -376,7 +385,16 @@ void Window::Write(int limit, const wstring &str, bool clrtoeol)
{ {
waddwstr(itsWindow,tmp.c_str()); waddwstr(itsWindow,tmp.c_str());
tmp.clear(); tmp.clear();
if (IsValidColor(ToString(color)))
if (isdigit(color[2]))
{
int x, y;
getyx(itsWindow, y, x);
Coordinates coords = IntoCoordinates(ToString(color));
wmove(itsWindow, coords.second == -1 ? y : coords.second, coords.first);
limit -= coords.first-x;
}
else if (IsValidColor(ToString(color)))
{ {
ColorPair colors = IntoColor(ToString(color)); ColorPair colors = IntoColor(ToString(color));
SetColor(colors.first, colors.second); SetColor(colors.first, colors.second);
@@ -667,6 +685,23 @@ wstring ToWString(const string &s)
return result; return result;
} }
Coordinates Window::IntoCoordinates(const string &s)
{
Coordinates result;
unsigned int sep = s.find(",");
if (sep != string::npos)
{
result.first = atoi(s.substr(2, sep-2).c_str());
result.second = atoi(s.substr(sep+1).c_str());
}
else
{
result.first = atoi(s.substr(2).c_str());
result.second = -1;
}
return result;
}
string Window::OmitBBCodes(const string &str) string Window::OmitBBCodes(const string &str)
{ {
bool collect = false; bool collect = false;

View File

@@ -49,6 +49,7 @@ enum Where { wUp, wDown, wPageUp, wPageDown, wHome, wEnd };
typedef void (*GetStringHelper)(); typedef void (*GetStringHelper)();
typedef std::pair<Color, Color> ColorPair; typedef std::pair<Color, Color> ColorPair;
typedef std::pair<int, int> Coordinates;
char * ToString(const wchar_t *); char * ToString(const wchar_t *);
wchar_t * ToWString(const char *); wchar_t * ToWString(const char *);
@@ -126,6 +127,7 @@ class Window
virtual void Add(string str) { Write(str); } // for Scrollpad class virtual void Add(string str) { Write(str); } // for Scrollpad class
static void EnableColors(); static void EnableColors();
static Coordinates IntoCoordinates(const string &);
static bool IsValidColor(const string &); static bool IsValidColor(const string &);
static string OmitBBCodes(const string &); static string OmitBBCodes(const string &);