summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorJohn Peterson <jpeterson57@gmail.com>2009-08-29 06:08:14 +0000
committerJohn Peterson <jpeterson57@gmail.com>2009-08-29 06:08:14 +0000
commit508051ec8d74d4315a7992e632a4e2b5b6fed417 (patch)
treecfc717e7593a773ab47cc88cf13ff3b168463d8f /Source/Core/Common
parent90d979554c63ff869c286a244ecc01ee3519d05d (diff)
GUI: Resize console and its buffer
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4090 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/Src/ConsoleListener.cpp170
-rw-r--r--Source/Core/Common/Src/Log.h1
-rw-r--r--Source/Core/Common/Src/LogManager.h10
3 files changed, 138 insertions, 43 deletions
diff --git a/Source/Core/Common/Src/ConsoleListener.cpp b/Source/Core/Common/Src/ConsoleListener.cpp
index d31d1a5000..3021f455f2 100644
--- a/Source/Core/Common/Src/ConsoleListener.cpp
+++ b/Source/Core/Common/Src/ConsoleListener.cpp
@@ -15,9 +15,14 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Include
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
#include <algorithm> // min
#include <string> // System: To be able to add strings with "+"
#include <stdio.h>
+#include <math.h>
#ifdef _WIN32
#include <windows.h>
#else
@@ -26,12 +31,16 @@
#include "Common.h"
#include "LogManager.h" // Common
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Main
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
ConsoleListener::ConsoleListener()
{
#ifdef _WIN32
- m_hStdOut = NULL;
+ hConsole = NULL;
#endif
}
@@ -43,26 +52,28 @@ ConsoleListener::~ConsoleListener()
// 100, 100, "Dolphin Log Console"
// Open console window - width and height is the size of console window
// Name is the window title
-void ConsoleListener::Open(int width, int height, const char *title)
+void ConsoleListener::Open(int Width, int Height, const char *Title)
{
#ifdef _WIN32
// Open the console window and create the window handle for GetStdHandle()
AllocConsole();
// Save the window handle that AllocConsole() created
- m_hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+ hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// Set the console window title
- SetConsoleTitle(title);
+ SetConsoleTitle(Title);
- // Set the total letter space
- COORD co = {width, 3000}; // Big scrollback.
- SetConsoleScreenBufferSize(m_hStdOut, co);
+ // Set the total letter space to MAX_BYTES
+ int LWidth = Width / 8;
+ int LBufHeight = floor((float)(MAX_BYTES / (LWidth + 1)));
+ COORD co = {LWidth, LBufHeight};
+ SetConsoleScreenBufferSize(hConsole, co);
/* Set the window size in number of letters. The height is hard coded here
because it can be changed with MoveWindow() later */
- SMALL_RECT coo = {0,0, (width - 1), 50}; // Top, left, right, bottom
- SetConsoleWindowInfo(m_hStdOut, TRUE, &coo);
+ SMALL_RECT coo = {0,0, (LWidth - 1), 50}; // Top, left, right, bottom
+ SetConsoleWindowInfo(hConsole, TRUE, &coo);
#endif
}
@@ -70,10 +81,10 @@ void ConsoleListener::Open(int width, int height, const char *title)
void ConsoleListener::Close()
{
#ifdef _WIN32
- if (m_hStdOut == NULL)
+ if (hConsole == NULL)
return;
FreeConsole();
- m_hStdOut = NULL;
+ hConsole = NULL;
#else
fflush(NULL);
#endif
@@ -82,53 +93,130 @@ void ConsoleListener::Close()
bool ConsoleListener::IsOpen()
{
#ifdef _WIN32
- return (m_hStdOut != NULL);
+ return (hConsole != NULL);
#else
return true;
#endif
}
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Size
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+void ConsoleListener::LetterSpace(int Width, int Height)
+{
+#ifdef _WIN32
+
+ // Get console info
+ CONSOLE_SCREEN_BUFFER_INFO ConInfo;
+ GetConsoleScreenBufferInfo(hConsole, &ConInfo);
+
+ // Change the screen buffer window size
+ SMALL_RECT coo = {0,0, Width, Height}; // top, left, right, bottom
+ bool SW = SetConsoleWindowInfo(hConsole, TRUE, &coo);
+
+ // Change screen buffer to the screen buffer window size
+ COORD Co = {Width + 1, Height + 1};
+ bool SB = SetConsoleScreenBufferSize(hConsole, Co);
+
+ // Resize the window too
+ MoveWindow(GetConsoleWindow(), 200,200, (Width*8 + 50),(Height*12 + 50), true);
+
+ // Logging
+ //printf("LetterSpace(): L:%i T:%i Iconic:%i\n", ConsoleLeft, ConsoleTop, ConsoleIconic);
+#endif
+}
+void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool Resize)
+{
+#ifdef _WIN32
+ hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ // Get console info
+ CONSOLE_SCREEN_BUFFER_INFO ConInfo;
+ GetConsoleScreenBufferInfo(hConsole, &ConInfo);
+ // Letter space
+ int LWidth = floor((float)(Width / 8));
+ int LHeight = floor((float)(Height / 12));
+ int LBufHeight = floor((float)(MAX_BYTES / (LWidth + 1)));
+
+ // Read the current text
+ char Str[MAX_BYTES];
+ DWORD dwConSize = ConInfo.dwSize.X * ConInfo.dwSize.Y;
+ DWORD cCharsRead = 0;
+ COORD coordScreen = { 0, 0 };
+ ReadConsoleOutputCharacter(hConsole, Str, dwConSize, coordScreen, &cCharsRead);
+
+ // Change the screen buffer window size
+ SMALL_RECT coo = {0,0, LWidth, LHeight}; // top, left, right, bottom
+ bool bW = SetConsoleWindowInfo(hConsole, TRUE, &coo);
+ // Change screen buffer to the screen buffer window size
+ COORD Co = {LWidth + 1, LBufHeight};
+ bool bB = SetConsoleScreenBufferSize(hConsole, Co);
+
+ // Redraw the text
+ DWORD cCharsWritten = 0;
+ WriteConsoleOutputCharacter(hConsole, Str, cCharsRead, coordScreen, &cCharsWritten);
+
+ // Resize the window too
+ if (Resize) MoveWindow(GetConsoleWindow(), Left,Top, (Width + 50),(Height + 50), true);
+
+ // Logging
+ //Log(LogTypes::LNOTICE, StringFromFormat("\n\n\n\nMaxBytes: %i, WxH:%ix%i, Consize: %i, Read: %i, Written: %i\n\n", MAX_BYTES, LWidth, LHeight, dwConSize, cCharsRead, cCharsWritten).c_str());
+#endif
+}
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+
-// Logs the message to screen
-void ConsoleListener::Log(LogTypes::LOG_LEVELS level, const char *text)
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Write
+// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
+//void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text, ...)
+void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
{
#if defined(_WIN32)
- DWORD cCharsWritten; // We will get a value back here
- WORD color;
+ /*
+ const int MAX_BYTES = 1024*10;
+ char Str[MAX_BYTES];
+ va_list ArgPtr;
+ int Cnt;
+ va_start(ArgPtr, Text);
+ Cnt = vsnprintf(Str, MAX_BYTES, Text, ArgPtr);
+ va_end(ArgPtr);
+ */
+ DWORD cCharsWritten;
+ WORD Color;
- switch (level)
+ switch (Level)
{
case NOTICE_LEVEL: // light green
- color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
+ Color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
break;
-
case ERROR_LEVEL: // light red
- color = FOREGROUND_RED | FOREGROUND_INTENSITY;
+ Color = FOREGROUND_RED | FOREGROUND_INTENSITY;
break;
-
case WARNING_LEVEL: // light yellow
- color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
+ Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
break;
-
case INFO_LEVEL: // cyan
- color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
+ Color = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
break;
-
case DEBUG_LEVEL: // gray
- color = FOREGROUND_INTENSITY;
+ Color = FOREGROUND_INTENSITY;
break;
-
default: // off-white
- color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
+ Color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
break;
}
- if (strlen(text) > 10) {
- // first 10 chars white
- SetConsoleTextAttribute(m_hStdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
- WriteConsole(m_hStdOut, text, 10, &cCharsWritten, NULL);
- text += 10;
+ if (Level != CUSTOM_LEVEL && strlen(Text) > 10)
+ {
+ // First 10 chars white
+ SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
+ WriteConsole(hConsole, Text, 10, &cCharsWritten, NULL);
+ Text += 10;
}
- SetConsoleTextAttribute(m_hStdOut, color);
- WriteConsole(m_hStdOut, text, (DWORD)strlen(text), &cCharsWritten, NULL);
+ SetConsoleTextAttribute(hConsole, Color);
+ WriteConsole(hConsole, Text, (DWORD)strlen(Text), &cCharsWritten, NULL);
#else
fprintf(stderr, "%s", text);
#endif
@@ -146,12 +234,14 @@ void ConsoleListener::ClearScreen()
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize,
- coordScreen, &cCharsWritten);
+ dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
+ // Write space to the entire console
+ FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
- FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize,
- coordScreen, &cCharsWritten);
+ FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
+ // Reset cursor
SetConsoleCursorPosition(hConsole, coordScreen);
#endif
}
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+
diff --git a/Source/Core/Common/Src/Log.h b/Source/Core/Common/Src/Log.h
index a24f7e65f0..21bbbbf1cc 100644
--- a/Source/Core/Common/Src/Log.h
+++ b/Source/Core/Common/Src/Log.h
@@ -23,6 +23,7 @@
#define WARNING_LEVEL 3 // Something is suspicious.
#define INFO_LEVEL 4 // General information.
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
+#define CUSTOM_LEVEL 6 // Custom log
namespace LogTypes
{
diff --git a/Source/Core/Common/Src/LogManager.h b/Source/Core/Common/Src/LogManager.h
index 05db8ed834..28845ba054 100644
--- a/Source/Core/Common/Src/LogManager.h
+++ b/Source/Core/Common/Src/LogManager.h
@@ -77,15 +77,19 @@ public:
const char * Name = "Console");
void Close();
bool IsOpen();
- void Log(LogTypes::LOG_LEVELS, const char *text);
+ void LetterSpace(int Width, int Height);
+ void PixelSpace(int Left, int Top, int Width, int Height, bool);
+ void Log(LogTypes::LOG_LEVELS, const char *Text);
+ //void Log(LogTypes::LOG_LEVELS, const char *Text, ...);
void ClearScreen();
- const char *getName() const { return "console"; }
+ const char *getName() const { return "Console"; }
private:
#ifdef _WIN32
HWND GetHwnd(void);
- HANDLE m_hStdOut;
+ HANDLE hConsole;
+ static const int MAX_BYTES = 1024 * 30;
#endif
};