From 369bbf6b96f3b85fe045eb83ce0bd46996ab3d6c Mon Sep 17 00:00:00 2001 From: unK Date: Sat, 13 Sep 2008 20:39:13 +0200 Subject: [PATCH] new feature for parser, coordinates reader --- src/window.cpp | 39 +++++++++++++++++++++++++++++++++++++-- src/window.h | 2 ++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/window.cpp b/src/window.cpp index cfa0200e..cc285ed5 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -312,7 +312,16 @@ void Window::Write(int limit, const string &str, bool clrtoeol) { waddstr(itsWindow,tmp.c_str()); 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); SetColor(colors.first, colors.second); @@ -376,7 +385,16 @@ void Window::Write(int limit, const wstring &str, bool clrtoeol) { waddwstr(itsWindow,tmp.c_str()); 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)); SetColor(colors.first, colors.second); @@ -667,6 +685,23 @@ wstring ToWString(const string &s) 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) { bool collect = false; diff --git a/src/window.h b/src/window.h index f1473e0f..8e1d4431 100644 --- a/src/window.h +++ b/src/window.h @@ -49,6 +49,7 @@ enum Where { wUp, wDown, wPageUp, wPageDown, wHome, wEnd }; typedef void (*GetStringHelper)(); typedef std::pair ColorPair; +typedef std::pair Coordinates; char * ToString(const wchar_t *); wchar_t * ToWString(const char *); @@ -126,6 +127,7 @@ class Window virtual void Add(string str) { Write(str); } // for Scrollpad class static void EnableColors(); + static Coordinates IntoCoordinates(const string &); static bool IsValidColor(const string &); static string OmitBBCodes(const string &);