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
diff --git a/gui/console.cpp b/gui/console.cpp
index 848a344..b1f16c4 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -27,18 +27,10 @@
 
 
 static std::vector<std::string> gConsole;
+static std::vector<std::string> 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 @@
 		{
 			*next = '\0';
 			gConsole.push_back(start);
+			gConsoleColor.push_back(color);
 
 			start = ++next;
 		}
@@ -60,8 +53,39 @@
 	}
 
 	// 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 @@
 	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 @@
 	// 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 @@
 	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 c0880a7..d547719 100755
--- a/gui/devices/1024x600/res/ui.xml
+++ b/gui/devices/1024x600/res/ui.xml
@@ -129,6 +129,9 @@
 		<variable name="console_x" value="25" />
 		<variable name="console_width" value="974" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml
index 3409972..f404b46 100644
--- a/gui/devices/1024x768/res/ui.xml
+++ b/gui/devices/1024x768/res/ui.xml
@@ -129,6 +129,9 @@
 		<variable name="console_x" value="25" />
 		<variable name="console_width" value="974" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml
index 21498a7..28130b7 100644
--- a/gui/devices/1080x1920/res/ui.xml
+++ b/gui/devices/1080x1920/res/ui.xml
@@ -122,6 +122,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="1080" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="705" />
diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml
index 9faff14..d198139 100644
--- a/gui/devices/1200x1920/res/ui.xml
+++ b/gui/devices/1200x1920/res/ui.xml
@@ -125,6 +125,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="1200" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="705" />
diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml
index eeb5923..21fc3b7 100644
--- a/gui/devices/1280x800/res/ui.xml
+++ b/gui/devices/1280x800/res/ui.xml
@@ -129,6 +129,9 @@
 		<variable name="console_x" value="25" />
 		<variable name="console_width" value="1230" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/1600x2560/res/ui.xml b/gui/devices/1600x2560/res/ui.xml
index a8e919d..b6ca28c 100644
--- a/gui/devices/1600x2560/res/ui.xml
+++ b/gui/devices/1600x2560/res/ui.xml
@@ -125,6 +125,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="1600" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="938" />
diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml
index 4573ded..5ee5b46 100644
--- a/gui/devices/1920x1200/res/ui.xml
+++ b/gui/devices/1920x1200/res/ui.xml
@@ -129,6 +129,9 @@
 		<variable name="console_x" value="50" />
 		<variable name="console_width" value="1820" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/240x240/res/ui.xml b/gui/devices/240x240/res/ui.xml
index c353d01..ac98dba 100644
--- a/gui/devices/240x240/res/ui.xml
+++ b/gui/devices/240x240/res/ui.xml
@@ -116,6 +116,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="240" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="120" />
diff --git a/gui/devices/2560x1600/res/ui.xml b/gui/devices/2560x1600/res/ui.xml
index 531e43f..25b8619 100644
--- a/gui/devices/2560x1600/res/ui.xml
+++ b/gui/devices/2560x1600/res/ui.xml
@@ -129,6 +129,9 @@
 		<variable name="console_x" value="50" />
 		<variable name="console_width" value="2460" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml
index e29245a..369b994 100644
--- a/gui/devices/320x480/res/ui.xml
+++ b/gui/devices/320x480/res/ui.xml
@@ -118,6 +118,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="320" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="192" />
diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml
index 54069f9..72b44e5 100644
--- a/gui/devices/480x800/res/ui.xml
+++ b/gui/devices/480x800/res/ui.xml
@@ -117,6 +117,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="480" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml
index 48fe8d6..5026f40 100644
--- a/gui/devices/480x854/res/ui.xml
+++ b/gui/devices/480x854/res/ui.xml
@@ -116,6 +116,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="480" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="320" />
diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml
index 665e676..bd39a18 100644
--- a/gui/devices/540x960/res/ui.xml
+++ b/gui/devices/540x960/res/ui.xml
@@ -117,6 +117,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="540" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="380" />
diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml
index 3d69a35..c9e6862 100644
--- a/gui/devices/720x1280/res/ui.xml
+++ b/gui/devices/720x1280/res/ui.xml
@@ -122,6 +122,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="720" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="470" />
diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml
index 7194373..b4cbb50 100755
--- a/gui/devices/800x1280/res/ui.xml
+++ b/gui/devices/800x1280/res/ui.xml
@@ -118,6 +118,9 @@
 		<variable name="console_x" value="0" />
 		<variable name="console_width" value="800" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="470" />
diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml
index ac9abc9..272bf64 100755
--- a/gui/devices/800x480/res/ui.xml
+++ b/gui/devices/800x480/res/ui.xml
@@ -129,6 +129,9 @@
 		<variable name="console_x" value="25" />
 		<variable name="console_width" value="750" />
 		<variable name="console_foreground" value="#A0A0A0" />
+		<variable name="warning" value="#F8F8A0" />
+		<variable name="error" value="#FF4040" />
+		<variable name="highlight" value="#33B5E5" />
 		<variable name="console_background" value="#303030" />
 		<variable name="console_scroll" value="#303030" />
 		<variable name="console_action_height" value="230" />
diff --git a/gui/gui.h b/gui/gui.h
index 10bf6ce..a927cf3 100644
--- a/gui/gui.h
+++ b/gui/gui.h
@@ -25,6 +25,7 @@
 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 0241715..486e2e7 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -350,6 +350,7 @@
 	int mSlideout;
 	SlideoutState mSlideoutState;
 	std::vector<std::string> rConsole;
+	std::vector<std::string> rConsoleColor;
 	bool mRender;
 
 protected: