From bf2cb1c4d85b8212c481777aa846b182ca3014a4 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Wed, 2 Jul 2014 10:15:54 -0500 Subject: Color in the console Allow each gui_print command to specify a color Change LOGERR to use the error color Theme should specify colors for error, warning, and highlight Change-Id: Ie8ece34111f604e25fcb79e5b731cd4e61038ff9 --- gui/console.cpp | 64 ++++++++++++++++++++++++++++++---------- gui/devices/1024x600/res/ui.xml | 3 ++ gui/devices/1024x768/res/ui.xml | 3 ++ gui/devices/1080x1920/res/ui.xml | 3 ++ gui/devices/1200x1920/res/ui.xml | 3 ++ gui/devices/1280x800/res/ui.xml | 3 ++ gui/devices/1600x2560/res/ui.xml | 3 ++ gui/devices/1920x1200/res/ui.xml | 3 ++ gui/devices/240x240/res/ui.xml | 3 ++ gui/devices/2560x1600/res/ui.xml | 3 ++ gui/devices/320x480/res/ui.xml | 3 ++ gui/devices/480x800/res/ui.xml | 3 ++ gui/devices/480x854/res/ui.xml | 3 ++ gui/devices/540x960/res/ui.xml | 3 ++ gui/devices/720x1280/res/ui.xml | 3 ++ gui/devices/800x1280/res/ui.xml | 3 ++ gui/devices/800x480/res/ui.xml | 3 ++ gui/gui.h | 1 + gui/objects.hpp | 1 + 19 files changed, 99 insertions(+), 15 deletions(-) (limited to 'gui') diff --git a/gui/console.cpp b/gui/console.cpp index 848a34472..b1f16c48a 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -27,18 +27,10 @@ extern "C" { static std::vector gConsole; +static std::vector gConsoleColor; -extern "C" void gui_print(const char *fmt, ...) +extern "C" void __gui_print(const char *color, char *buf) { - char buf[512]; // We're going to limit a single request to 512 bytes - - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, 512, fmt, ap); - va_end(ap); - - fputs(buf, stdout); - char *start, *next; if (buf[0] == '\n' && strlen(buf) < 2) { @@ -52,6 +44,7 @@ extern "C" void gui_print(const char *fmt, ...) { *next = '\0'; gConsole.push_back(start); + gConsoleColor.push_back(color); start = ++next; } @@ -60,8 +53,39 @@ extern "C" void gui_print(const char *fmt, ...) } // The text after last \n (or whole string if there is no \n) - if(*start) + if(*start) { gConsole.push_back(start); + gConsoleColor.push_back(color); + } +} + +extern "C" void gui_print(const char *fmt, ...) +{ + char buf[512]; // We're going to limit a single request to 512 bytes + + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, 512, fmt, ap); + va_end(ap); + + fputs(buf, stdout); + + __gui_print("normal", buf); + return; +} + +extern "C" void gui_print_color(const char *color, const char *fmt, ...) +{ + char buf[512]; // We're going to limit a single request to 512 bytes + + va_list ap; + va_start(ap, fmt); + vsnprintf(buf, 512, fmt, ap); + va_end(ap); + + fputs(buf, stdout); + + __gui_print(color, buf); return; } @@ -171,9 +195,6 @@ int GUIConsole::RenderConsole(void) gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha); gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH); - // Render the lines - gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha); - // Don't try to continue to render without data int prevCount = mLastCount; mLastCount = gConsole.size(); @@ -186,14 +207,17 @@ int GUIConsole::RenderConsole(void) // may different in different console windows for (int i = prevCount; i < mLastCount; i++) { string curr_line = gConsole[i]; + string curr_color = gConsoleColor[i]; int line_char_width; for(;;) { line_char_width = gr_maxExW(curr_line.c_str(), fontResource, mConsoleW); if (line_char_width < curr_line.size()) { rConsole.push_back(curr_line.substr(0, line_char_width)); + rConsoleColor.push_back(curr_color); curr_line = curr_line.substr(line_char_width); } else { rConsole.push_back(curr_line); + rConsoleColor.push_back(curr_color); break; } } @@ -219,8 +243,18 @@ int GUIConsole::RenderConsole(void) unsigned int line; for (line = 0; line < mMaxRows; line++) { - if ((start + (int) line) >= 0 && (start + (int) line) < (int) RenderCount) + if ((start + (int) line) >= 0 && (start + (int) line) < (int) RenderCount) { + if (rConsoleColor[start + line] == "normal") { + gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha); + } else { + COLOR mFontColor; + std::string color = rConsoleColor[start + line]; + ConvertStrToColor(color, &mFontColor); + mFontColor.alpha = 255; + gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha); + } gr_textExW(mConsoleX, mStartY + (line * mFontHeight), rConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX); + } } return (mSlideout ? RenderSlideout() : 0); } diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml index c0880a76a..d54771941 100755 --- a/gui/devices/1024x600/res/ui.xml +++ b/gui/devices/1024x600/res/ui.xml @@ -129,6 +129,9 @@ + + + diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml index 3409972d9..f404b466d 100644 --- a/gui/devices/1024x768/res/ui.xml +++ b/gui/devices/1024x768/res/ui.xml @@ -129,6 +129,9 @@ + + + diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml index 21498a76e..28130b7db 100644 --- a/gui/devices/1080x1920/res/ui.xml +++ b/gui/devices/1080x1920/res/ui.xml @@ -122,6 +122,9 @@ + + + diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml index 9faff14d6..d19813947 100644 --- a/gui/devices/1200x1920/res/ui.xml +++ b/gui/devices/1200x1920/res/ui.xml @@ -125,6 +125,9 @@ + + + diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml index eeb59231f..21fc3b7a8 100644 --- a/gui/devices/1280x800/res/ui.xml +++ b/gui/devices/1280x800/res/ui.xml @@ -129,6 +129,9 @@ + + + diff --git a/gui/devices/1600x2560/res/ui.xml b/gui/devices/1600x2560/res/ui.xml index a8e919def..b6ca28c7e 100644 --- a/gui/devices/1600x2560/res/ui.xml +++ b/gui/devices/1600x2560/res/ui.xml @@ -125,6 +125,9 @@ + + + diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml index 4573dedb2..5ee5b4646 100644 --- a/gui/devices/1920x1200/res/ui.xml +++ b/gui/devices/1920x1200/res/ui.xml @@ -129,6 +129,9 @@ + + + diff --git a/gui/devices/240x240/res/ui.xml b/gui/devices/240x240/res/ui.xml index c353d0198..ac98dbad8 100644 --- a/gui/devices/240x240/res/ui.xml +++ b/gui/devices/240x240/res/ui.xml @@ -116,6 +116,9 @@ + + + diff --git a/gui/devices/2560x1600/res/ui.xml b/gui/devices/2560x1600/res/ui.xml index 531e43f1c..25b86194f 100644 --- a/gui/devices/2560x1600/res/ui.xml +++ b/gui/devices/2560x1600/res/ui.xml @@ -129,6 +129,9 @@ + + + diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml index e29245aba..369b9941e 100644 --- a/gui/devices/320x480/res/ui.xml +++ b/gui/devices/320x480/res/ui.xml @@ -118,6 +118,9 @@ + + + diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml index 54069f930..72b44e51f 100644 --- a/gui/devices/480x800/res/ui.xml +++ b/gui/devices/480x800/res/ui.xml @@ -117,6 +117,9 @@ + + + diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml index 48fe8d6d5..5026f4016 100644 --- a/gui/devices/480x854/res/ui.xml +++ b/gui/devices/480x854/res/ui.xml @@ -116,6 +116,9 @@ + + + diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml index 665e6762a..bd39a18f2 100644 --- a/gui/devices/540x960/res/ui.xml +++ b/gui/devices/540x960/res/ui.xml @@ -117,6 +117,9 @@ + + + diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml index 3d69a352e..c9e68629a 100644 --- a/gui/devices/720x1280/res/ui.xml +++ b/gui/devices/720x1280/res/ui.xml @@ -122,6 +122,9 @@ + + + diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml index 7194373d4..b4cbb508e 100755 --- a/gui/devices/800x1280/res/ui.xml +++ b/gui/devices/800x1280/res/ui.xml @@ -118,6 +118,9 @@ + + + diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml index ac9abc984..272bf6491 100755 --- a/gui/devices/800x480/res/ui.xml +++ b/gui/devices/800x480/res/ui.xml @@ -129,6 +129,9 @@ + + + diff --git a/gui/gui.h b/gui/gui.h index 10bf6ce2a..a927cf39a 100644 --- a/gui/gui.h +++ b/gui/gui.h @@ -25,6 +25,7 @@ int gui_loadResources(); int gui_start(); int gui_startPage(const char* page_name); void gui_print(const char *fmt, ...); +void gui_print_color(const char *color, const char *fmt, ...); #endif // _GUI_HEADER diff --git a/gui/objects.hpp b/gui/objects.hpp index 02417154a..486e2e704 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -350,6 +350,7 @@ protected: int mSlideout; SlideoutState mSlideoutState; std::vector rConsole; + std::vector rConsoleColor; bool mRender; protected: -- cgit v1.2.3