Merge pull request #4208 from unknownbrackets/ui-tweaks

Avoid flashing the console window on startup
This commit is contained in:
Henrik Rydgård 2013-10-16 02:02:29 -07:00
commit a05b6ac122
5 changed files with 57 additions and 34 deletions

View file

@ -48,7 +48,7 @@ volatile u32 ConsoleListener::logPendingReadPos = 0;
volatile u32 ConsoleListener::logPendingWritePos = 0;
#endif
ConsoleListener::ConsoleListener()
ConsoleListener::ConsoleListener() : bHidden(true)
{
#ifdef _WIN32
hConsole = NULL;
@ -58,6 +58,7 @@ ConsoleListener::ConsoleListener()
{
hTriggerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
InitializeCriticalSection(&criticalSection);
logPending = new char[LOG_PENDING_MAX];
}
++refCount;
#else
@ -98,9 +99,20 @@ bool WINAPI ConsoleHandler(DWORD msgType)
// 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(bool Hidden, int Width, int Height, const char *Title)
void ConsoleListener::Init(bool AutoOpen, int Width, int Height, const char *Title)
{
#ifdef _WIN32
openWidth_ = Width;
openHeight_ = Height;
title_ = ConvertUTF8ToWString(Title);
if (AutoOpen)
Open();
#endif
}
void ConsoleListener::Open()
{
bHidden = Hidden;
#ifdef _WIN32
if (!GetConsoleWindow())
{
@ -111,18 +123,16 @@ void ConsoleListener::Open(bool Hidden, int Width, int Height, const char *Title
// disable console close button
HMENU hMenu=GetSystemMenu(hConWnd,false);
EnableMenuItem(hMenu,SC_CLOSE,MF_GRAYED|MF_BYCOMMAND);
// Hide
if (Hidden) ShowWindow(hConWnd, SW_HIDE);
// Save the window handle that AllocConsole() created
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// Set console handler
if(SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE)){OutputDebugString(L"Console handler is installed!\n");}
// Set the console window title
SetConsoleTitle(ConvertUTF8ToWString(Title).c_str());
SetConsoleTitle(title_.c_str());
SetConsoleCP(CP_UTF8);
// Set letter space
LetterSpace(Width, LOG_MAX_DISPLAY_LINES);
LetterSpace(openWidth_, LOG_MAX_DISPLAY_LINES);
//MoveWindow(GetConsoleWindow(), 200,200, 800,800, true);
}
else
@ -131,26 +141,25 @@ void ConsoleListener::Open(bool Hidden, int Width, int Height, const char *Title
}
if (hTriggerEvent != NULL && hThread == NULL)
{
logPending = new char[LOG_PENDING_MAX];
hThread = (HANDLE)_beginthreadex(NULL, 0, &ConsoleListener::RunThread, this, 0, NULL);
}
#endif
}
void ConsoleListener::Show(bool bShow)
{
#ifdef _WIN32
if (bShow && bHidden)
{
ShowWindow(GetConsoleWindow(), SW_SHOW);
bHidden = false;
}
else if (!bShow && !bHidden)
{
ShowWindow(GetConsoleWindow(), SW_HIDE);
bHidden = true;
}
if (bShow && bHidden)
{
if (!IsOpen())
Open();
ShowWindow(GetConsoleWindow(), SW_SHOW);
bHidden = false;
}
else if (!bShow && !bHidden)
{
ShowWindow(GetConsoleWindow(), SW_HIDE);
bHidden = true;
}
#endif
}
@ -216,6 +225,7 @@ bool ConsoleListener::IsOpen()
*/
void ConsoleListener::BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#ifdef _WIN32
BOOL SB, SW;
if (BufferFirst)
@ -240,6 +250,7 @@ void ConsoleListener::BufferWidthHeight(int BufferWidth, int BufferHeight, int S
}
void ConsoleListener::LetterSpace(int Width, int Height)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#ifdef _WIN32
// Get console info
CONSOLE_SCREEN_BUFFER_INFO ConInfo;
@ -435,6 +446,8 @@ void ConsoleListener::SendToThread(LogTypes::LOG_LEVELS Level, const char *Text)
void ConsoleListener::WriteToConsole(LogTypes::LOG_LEVELS Level, const char *Text, size_t Len)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
/*
const int MAX_BYTES = 1024*10;
char Str[MAX_BYTES];
@ -488,6 +501,7 @@ void ConsoleListener::WriteToConsole(LogTypes::LOG_LEVELS Level, const char *Tex
void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool Resize)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#ifdef _WIN32
// Check size
if (Width < 8 || Height < 12) return;
@ -576,7 +590,7 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool
void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
{
#if defined(_WIN32)
if (hThread == NULL)
if (hThread == NULL && IsOpen())
WriteToConsole(Level, Text, strlen(Text));
else
SendToThread(Level, Text);
@ -608,6 +622,7 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
// Clear console screen
void ConsoleListener::ClearScreen(bool Cursor)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#if defined(_WIN32)
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;

View file

@ -30,7 +30,8 @@ public:
ConsoleListener();
~ConsoleListener();
void Open(bool Hidden = false, int Width = 200, int Height = 100, const char * Name = "DebugConsole (PPSSPP)");
void Init(bool AutoOpen = true, int Width = 200, int Height = 100, const char * Name = "DebugConsole (PPSSPP)");
void Open();
void UpdateHandle();
void Close();
bool IsOpen();
@ -63,6 +64,10 @@ private:
static char *logPending;
static volatile u32 logPendingReadPos;
static volatile u32 logPendingWritePos;
int openWidth_;
int openHeight_;
std::wstring title_;
#endif
bool bHidden;
bool bUseColor;

View file

@ -661,7 +661,7 @@ void CtrlStackTraceView::loadStackTrace()
{
auto threads = GetThreadsInfo();
u32 entry, stackTop;
u32 entry = 0, stackTop = 0;
for (size_t i = 0; i < threads.size(); i++)
{
if (threads[i].isCurrent)
@ -672,6 +672,10 @@ void CtrlStackTraceView::loadStackTrace()
}
}
frames = MIPSStackWalk::Walk(cpu->GetPC(),cpu->GetRegValue(0,31),cpu->GetRegValue(0,29),entry,stackTop);
if (entry != 0) {
frames = MIPSStackWalk::Walk(cpu->GetPC(),cpu->GetRegValue(0,31),cpu->GetRegValue(0,29),entry,stackTop);
} else {
frames.clear();
}
Update();
}

View file

@ -358,8 +358,10 @@ namespace MainWindow
// Then center if necessary.
if (g_Config.iWindowX == -1 && g_Config.iWindowY == -1) {
// Center the window.
g_Config.iWindowX = screenX + (screenWidth - g_Config.iWindowWidth) / 2;
g_Config.iWindowY = screenY + (screenHeight - g_Config.iWindowHeight) / 2;
const int primaryScreenWidth = GetSystemMetrics(SM_CXSCREEN);
const int primaryScreenHeight = GetSystemMetrics(SM_CYSCREEN);
g_Config.iWindowX = (primaryScreenWidth - g_Config.iWindowWidth) / 2;
g_Config.iWindowY = (primaryScreenHeight - g_Config.iWindowHeight) / 2;
rc.left = g_Config.iWindowX;
rc.top = g_Config.iWindowY;
rc.right = rc.left + g_Config.iWindowWidth;
@ -1554,14 +1556,11 @@ namespace MainWindow
TCHAR filename[512];
DragQueryFile(hdrop,0,filename,512);
TCHAR *type = filename+_tcslen(filename)-3;
SendMessage(hWnd, WM_COMMAND, ID_EMULATION_STOP, 0);
// Ugly, need to wait for the stop message to process in the EmuThread.
Sleep(20);
Update();
NativeMessageReceived("boot", ConvertWStringToUTF8(filename).c_str());
Core_EnableStepping(false);
}
}
break;

View file

@ -172,9 +172,9 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
// GetCurrentDirectory(MAX_PATH, modulePath); // for checking in the debugger
#ifndef _DEBUG
bool hideLog = true;
bool showLog = false;
#else
bool hideLog = false;
bool showLog = false;
#endif
VFSRegister("", new DirectoryAssetReader("assets/"));
@ -239,7 +239,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
switch (__argv[i][1])
{
case 'l':
hideLog = false;
showLog = true;
g_Config.bEnableLogging = true;
break;
case 's':
@ -265,7 +265,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
// - By default in Debug, the console should be shown by default.
// - The -l switch is expected to show the log console, REGARDLESS of config settings.
// - It should be possible to log to a file without showing the console.
LogManager::GetInstance()->GetConsoleListener()->Open(hideLog, 150, 120, "PPSSPP Debug Console");
LogManager::GetInstance()->GetConsoleListener()->Init(showLog, 150, 120, "PPSSPP Debug Console");
//Windows, API init stuff