Explorar el Código

Set console background color on windows in SetConsoleTextAttribute, otherwise text background will be black, which looks strange if the terminal color is not black.

ZuBsPaCe hace 9 años
padre
commit
42beb83178
Se han modificado 1 ficheros con 8 adiciones y 5 borrados
  1. 8 5
      platform/windows/os_windows.cpp

+ 8 - 5
platform/windows/os_windows.cpp

@@ -1796,7 +1796,8 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l
 		CONSOLE_SCREEN_BUFFER_INFO sbi; //original
 		GetConsoleScreenBufferInfo(hCon, &sbi);
 
-		SetConsoleTextAttribute(hCon, sbi.wAttributes);
+		WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+		WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
 
 		uint32_t basecol = 0;
 		switch(p_type) {
@@ -1805,6 +1806,8 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l
 			case ERR_SCRIPT: basecol = FOREGROUND_RED | FOREGROUND_BLUE; break;
 		}
 
+		basecol |= current_bg;
+
 		if (p_rationale && p_rationale[0]) {
 
 			SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
@@ -1814,13 +1817,13 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l
 				case ERR_SCRIPT: print("SCRIPT ERROR: "); break;
 			}
 
-			SetConsoleTextAttribute(hCon, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
+			SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
 			print(" %s\n", p_rationale);
 
 			SetConsoleTextAttribute(hCon, basecol);
 			print("At: ");
 
-			SetConsoleTextAttribute(hCon, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
+			SetConsoleTextAttribute(hCon, current_fg | current_bg);
 			print(" %s:%i\n", p_file, p_line);
 
 		} else {
@@ -1832,13 +1835,13 @@ void OS_Windows::print_error(const char* p_function, const char* p_file, int p_l
 				case ERR_SCRIPT: print("SCRIPT ERROR: %s: ", p_function); break;
 			}
 
-			SetConsoleTextAttribute(hCon, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
+			SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
 			print(" %s\n", p_code);
 
 			SetConsoleTextAttribute(hCon, basecol);
 			print("At: ");
 
-			SetConsoleTextAttribute(hCon, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
+			SetConsoleTextAttribute(hCon, current_fg | current_bg);
 			print(" %s:%i\n", p_file, p_line);
 		}