Improve behavior of the console window on windows. Remove coloring from logwindow for the time being. Now you can use wxGetApp if you #include Main.h, and GetCFrame, etc...

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2694 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman
2009-03-20 18:25:36 +00:00
parent 7d910a5e4a
commit eacb9ccd80
15 changed files with 231 additions and 160 deletions

View File

@ -545,10 +545,6 @@
RelativePath=".\Src\ConsoleListener.cpp"
>
</File>
<File
RelativePath=".\Src\ConsoleListener.h"
>
</File>
<File
RelativePath=".\Src\LogManager.cpp"
>

View File

@ -15,7 +15,6 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <string> // System: To be able to add strings with "+"
#include <stdio.h>
#ifdef _WIN32
@ -28,9 +27,19 @@
#include "LogManager.h" // Common
/* Start console window - width and height is the size of console window */
ConsoleListener::ConsoleListener(int Width, int Height, char * Name) :
Listener("console")
// Inits as a Listener
ConsoleListener::ConsoleListener() : Listener("console")
{
}
ConsoleListener::~ConsoleListener()
{
Close();
}
// Open console window - width and height is the size of console window
// Name is the window title
void ConsoleListener::Open(int Width, int Height, char * Name)
{
#ifdef _WIN32
// Open the console window and create the window handle for GetStdHandle()
@ -46,29 +55,38 @@ ConsoleListener::ConsoleListener(int Width, int Height, char * Name) :
COORD co = {Width, Height};
SetConsoleScreenBufferSize(m_hStdOut, co);
/* Set the window size in number of letters. The height is hardcoded here
because it can be changed with MoveWindow() later */
/* 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);
#endif
}
/* Close the console window and close the eventual file handle */
ConsoleListener::~ConsoleListener()
// Close the console window and close the eventual file handle
void ConsoleListener::Close()
{
#ifdef _WIN32
FreeConsole(); // Close the console window
if (m_hStdOut == NULL)
return;
FreeConsole();
m_hStdOut = NULL;
#else
fflush(NULL);
#endif
}
bool ConsoleListener::IsOpen()
{
#ifdef _WIN32
return (m_hStdOut != NULL);
#else
return true;
#endif
}
// Logs the message to screen
void ConsoleListener::Log(LogTypes::LOG_LEVELS level, const char *text)
{
#if defined(_WIN32)
DWORD cCharsWritten; // We will get a value back here
WORD color;
@ -101,8 +119,7 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS level, const char *text)
}
SetConsoleTextAttribute(m_hStdOut, color);
WriteConsole(m_hStdOut, text, (DWORD)strlen(text),
&cCharsWritten, NULL);
WriteConsole(m_hStdOut, text, (DWORD)strlen(text), &cCharsWritten, NULL);
#else
fprintf(stderr, "%s", text);
#endif
@ -132,8 +149,8 @@ void ConsoleListener::ClearScreen()
}
/* Get window handle of console window to be able to resize it. We use
GetConsoleTitle() and FindWindow() to locate the console window handle. */
// Get window handle of console window to be able to resize it. We use
// GetConsoleTitle() and FindWindow() to locate the console window handle.
#if defined(_WIN32)
HWND GetHwnd(void)
{
@ -163,4 +180,3 @@ HWND GetHwnd(void)
return(hwndFound);
}
#endif // _WIN32

View File

@ -70,10 +70,13 @@ private:
class ConsoleListener : public Listener
{
public:
ConsoleListener(int Width = 150, int Height = 100,
char * Name = "Console");
ConsoleListener();
~ConsoleListener();
void Open(int Width = 100, int Height = 100,
char * Name = "Console");
void Close();
bool IsOpen();
void Log(LogTypes::LOG_LEVELS, const char *text);
void ClearScreen();

View File

@ -79,6 +79,7 @@ void SConfig::SaveSettings()
ini.Set("Interface", "ShowToolbar", m_InterfaceToolbar);
ini.Set("Interface", "ShowStatusbar", m_InterfaceStatusbar);
ini.Set("Interface", "ShowLogWindow", m_InterfaceLogWindow);
ini.Set("Interface", "ShowConsole", m_InterfaceConsole);
// Core
ini.Set("Core", "HLEBios", m_LocalCoreStartupParameter.bHLEBios);
@ -179,7 +180,8 @@ void SConfig::LoadSettings()
ini.Get("Interface", "Language", (int*)&m_InterfaceLanguage, 0);
ini.Get("Interface", "ShowToolbar", &m_InterfaceToolbar, true);
ini.Get("Interface", "ShowStatusbar", &m_InterfaceStatusbar, true);
ini.Get("Interface", "ShowLogWindow", &m_InterfaceLogWindow, true);
ini.Get("Interface", "ShowLogWindow", &m_InterfaceLogWindow, false);
ini.Get("Interface", "ShowConsole", &m_InterfaceConsole, false);
// Core
ini.Get("Core", "HLEBios", &m_LocalCoreStartupParameter.bHLEBios, true);

View File

@ -65,6 +65,7 @@ struct SConfig
bool m_InterfaceToolbar;
bool m_InterfaceStatusbar;
bool m_InterfaceLogWindow;
bool m_InterfaceConsole;
// save settings
void SaveSettings();

View File

@ -272,8 +272,9 @@ EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
EVT_MENU(IDM_TOGGLE_DUALCORE, CFrame::OnToggleDualCore)
EVT_MENU(IDM_TOGGLE_SKIPIDLE, CFrame::OnToggleSkipIdle)
EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
EVT_MENU(IDM_TOGGLE_LOGWINDOW, CFrame::OnToggleLogWindow)
EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
EVT_MENU(IDM_TOGGLE_LOGWINDOW, CFrame::OnToggleLogWindow)
EVT_MENU(IDM_TOGGLE_CONSOLE, CFrame::OnToggleConsole)
EVT_MENU_RANGE(IDM_LOADSLOT1, IDM_LOADSLOT10, CFrame::OnLoadState)
EVT_MENU_RANGE(IDM_SAVESLOT1, IDM_SAVESLOT10, CFrame::OnSaveState)
@ -334,6 +335,11 @@ CFrame::CFrame(bool showLogWindow,
// Give it a menu bar
CreateMenu();
// Give it a console
ConsoleListener *console = LogManager::GetInstance()->getConsoleListener();
if (SConfig::GetInstance().m_InterfaceConsole)
console->Open();
// This panel is the parent for rendering and it holds the gamelistctrl
//m_Panel = new wxPanel(this, IDM_MPANEL);
m_Panel = new CPanel(this, IDM_MPANEL);

View File

@ -25,6 +25,7 @@
#include <wx/wx.h> // wxWidgets
#include <wx/busyinfo.h>
#include <wx/mstream.h>
#include <wx/listctrl.h>
////////////////////////////////
#include "CDUtils.h"
#include "LogWindow.h"
@ -45,6 +46,7 @@ inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length)
// Class declarations
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class CGameListCtrl;
class CLogWindow;
class CFrame : public wxFrame
{
public:
@ -74,6 +76,8 @@ class CFrame : public wxFrame
void DoStop();
bool bRenderToMain;
void UpdateGUI();
void ToggleLogWindow(bool check);
void ToggleConsole(bool check);
// ---------------------------------------
// Wiimote leds
@ -203,8 +207,9 @@ class CFrame : public wxFrame
void OnToggleThrottle(wxCommandEvent& event);
void OnResize(wxSizeEvent& event);
void OnToggleToolbar(wxCommandEvent& event);
void OnToggleLogWindow(wxCommandEvent& event);
void OnToggleStatusbar(wxCommandEvent& event);
void OnToggleLogWindow(wxCommandEvent& event);
void OnToggleConsole(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent& event); void OnKeyUp(wxKeyEvent& event);
void OnDoubleClick(wxMouseEvent& event); void OnMotion(wxMouseEvent& event);

View File

@ -152,12 +152,14 @@ void CFrame::CreateMenu()
// Tools menu
wxMenu* toolsMenu = new wxMenu;
toolsMenu->AppendCheckItem(IDM_TOGGLE_TOOLBAR, _T("View &Toolbar"));
toolsMenu->AppendCheckItem(IDM_TOGGLE_TOOLBAR, _T("Show &Toolbar"));
toolsMenu->Check(IDM_TOGGLE_TOOLBAR, SConfig::GetInstance().m_InterfaceToolbar);
toolsMenu->AppendCheckItem(IDM_TOGGLE_STATUSBAR, _T("View &Statusbar"));
toolsMenu->AppendCheckItem(IDM_TOGGLE_STATUSBAR, _T("Show &Statusbar"));
toolsMenu->Check(IDM_TOGGLE_STATUSBAR, SConfig::GetInstance().m_InterfaceStatusbar);
toolsMenu->AppendCheckItem(IDM_TOGGLE_LOGWINDOW, _T("View &Logwindow"));
toolsMenu->AppendCheckItem(IDM_TOGGLE_LOGWINDOW, _T("Show &Logwindow"));
toolsMenu->Check(IDM_TOGGLE_LOGWINDOW, m_bLogWindow);
toolsMenu->AppendCheckItem(IDM_TOGGLE_CONSOLE, _T("Show &Console"));
toolsMenu->Check(IDM_TOGGLE_CONSOLE, SConfig::GetInstance().m_InterfaceConsole);
toolsMenu->AppendSeparator();
toolsMenu->Append(IDM_MEMCARD, _T("&Memcard Manager"));
toolsMenu->Append(IDM_CHEATS, _T("Action &Replay Manager"));
@ -731,7 +733,7 @@ void CFrame::OnSaveState(wxCommandEvent& event)
}
// Let us enable and disable the toolbar
// Enable and disable the toolbar
void CFrame::OnToggleToolbar(wxCommandEvent& event)
{
wxToolBarBase* toolBar = GetToolBar();
@ -749,7 +751,7 @@ void CFrame::OnToggleToolbar(wxCommandEvent& event)
this->SendSizeEvent();
}
// Let us enable and disable the status bar
// Enable and disable the status bar
void CFrame::OnToggleStatusbar(wxCommandEvent& event)
{
if (SConfig::GetInstance().m_InterfaceStatusbar = event.IsChecked() == true)
@ -760,17 +762,40 @@ void CFrame::OnToggleStatusbar(wxCommandEvent& event)
this->SendSizeEvent();
}
// Let us enable and disable the log window
// Enable and disable the log window
void CFrame::OnToggleLogWindow(wxCommandEvent& event)
{
if (SConfig::GetInstance().m_InterfaceLogWindow = event.IsChecked() == true)
ToggleLogWindow(event.IsChecked());
}
void CFrame::ToggleLogWindow(bool check)
{
if (SConfig::GetInstance().m_InterfaceLogWindow = check == true)
m_LogWindow->Show();
else
m_LogWindow->Hide();
this->SendSizeEvent();
// Make sure the check is updated (if wxw isn't calling this func)
GetMenuBar()->FindItem(IDM_TOGGLE_LOGWINDOW)->Check(check);
}
// Enable and disable the console
void CFrame::OnToggleConsole(wxCommandEvent& event)
{
ToggleConsole(event.IsChecked());
}
void CFrame::ToggleConsole(bool check)
{
ConsoleListener *console = LogManager::GetInstance()->getConsoleListener();
if (SConfig::GetInstance().m_InterfaceConsole = check == true)
console->Open();
else
console->Close();
// Make sure the check is updated (if wxw isn't calling this func)
GetMenuBar()->FindItem(IDM_TOGGLE_CONSOLE)->Check(check);
}
// Update the enabled/disabled status
void CFrame::UpdateGUI()

View File

@ -85,8 +85,9 @@ enum
IDM_TOGGLE_DUALCORE, // Other
IDM_TOGGLE_SKIPIDLE,
IDM_TOGGLE_TOOLBAR,
IDM_TOGGLE_LOGWINDOW,
IDM_TOGGLE_STATUSBAR,
IDM_TOGGLE_LOGWINDOW,
IDM_TOGGLE_CONSOLE,
IDM_NOTIFYMAPLOADED,
IDM_OPENCONTAININGFOLDER,
IDM_SETDEFAULTGCM,

View File

@ -91,7 +91,9 @@ void CLogWindow::CreateGUIControls()
// Right side: Log viewer and submit row
m_log = new wxTextCtrl(this, IDM_LOG, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
wxTE_RICH2 | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
// FIXME See note in UpdateLog()
//m_log->SetBackgroundColour(*wxBLACK);
//m_log->SetFont(DebuggerFont);
m_cmdline = new wxTextCtrl(this, IDM_SUBMITCMD, wxEmptyString, wxDefaultPosition, wxDefaultSize,
@ -152,7 +154,7 @@ void CLogWindow::LoadSettings()
ini.Get("LogWindow", "w", &w, GetSize().GetWidth());
ini.Get("LogWindow", "h", &h, GetSize().GetHeight());
SetSize(x, y, w, h);
ini.Get("Options", "Verbosity", &verbosity, 2);
ini.Get("Options", "Verbosity", &verbosity, 0);
m_verbosity->SetSelection(verbosity);
ini.Get("Options", "WriteToFile", &m_writeFile, true);
m_writeFileCB->SetValue(m_writeFile);
@ -298,6 +300,10 @@ void CLogWindow::OnOptionsCheck(wxCommandEvent& event)
m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_console);
}
}
if (m_writeConsole && !m_console->IsOpen())
wxGetApp().GetCFrame()->ToggleConsole(true);
else if (!m_writeConsole && m_console->IsOpen())
wxGetApp().GetCFrame()->ToggleConsole(false);
break;
}
SaveSettings();
@ -333,36 +339,45 @@ void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
void CLogWindow::NotifyUpdate()
{
UpdateChecks();
UpdateLog();
//UpdateLog();
}
void CLogWindow::UpdateLog()
{
m_logTimer->Stop();
for (unsigned int i = 0; i < msgQueue.size(); i++)
u32 msgQueueSize = msgQueue.size();
for (u32 i = 0; i < msgQueueSize; i++)
{
switch (msgQueue.front().first)
{
// AGGH why is this not working
case ERROR_LEVEL: // red
m_log->SetDefaultStyle(wxTextAttr(wxColour(255, 0, 0), wxColour(0, 0, 0)));
break;
case WARNING_LEVEL: // yellow
m_log->SetDefaultStyle(wxTextAttr(wxColour(255, 255, 0), wxColour(0, 0, 0)));
break;
case NOTICE_LEVEL: // green
m_log->SetDefaultStyle(wxTextAttr(wxColour(0, 255, 0), wxColour(0, 0, 0)));
break;
case INFO_LEVEL: // cyan
m_log->SetDefaultStyle(wxTextAttr(wxColour(0, 255, 255), wxColour(0, 0, 0)));
break;
case DEBUG_LEVEL: // light gray
m_log->SetDefaultStyle(wxTextAttr(wxColour(211, 211, 211), wxColour(0, 0, 0)));
break;
default: // white
m_log->SetDefaultStyle(wxTextAttr(wxColour(255, 255, 255), wxColour(0, 0, 0)));
break;
}
// FIXME This looks horrible on windows: SetForegroundColour changes
// ALL text in the control, and SetDefaultStyle doesn't work at all
// switch (msgQueue.front().first)
// {
// // red
// case ERROR_LEVEL:
// m_log->SetForegroundColour(*wxRED);
// break;
// // yellow
// case WARNING_LEVEL:
// m_log->SetForegroundColour(wxColour(255, 255, 0));
// break;
// // green
// case NOTICE_LEVEL:
// m_log->SetForegroundColour(*wxGREEN);
// break;
// // cyan
// case INFO_LEVEL:
// m_log->SetForegroundColour(*wxCYAN);
// break;
// // light gray
// case DEBUG_LEVEL:
// m_log->SetForegroundColour(wxColour(211, 211, 211));
// break;
// // white
// default:
// m_log->SetForegroundColour(*wxWHITE);
// break;
// }
m_log->AppendText(msgQueue.front().second);
msgQueue.pop();
}

View File

@ -17,6 +17,7 @@
#ifndef LOGWINDOW_H_
#define LOGWINDOW_H_
#include "Main.h" // for wxGetApp
#include "LogManager.h"
#include "IniFile.h"
#include <queue>

View File

@ -42,7 +42,6 @@
#include "Globals.h" // Local
#include "Main.h"
#include "Frame.h"
#include "ConfigManager.h"
#include "CodeWindow.h"
#include "LogWindow.h"
@ -300,8 +299,12 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*
(yes_no)?wxYES_NO:wxOK);
}
#endif
//////////////////////////////////
// Accessor for the main window class
CFrame* DolphinApp::GetCFrame()
{
return main_frame;
}
// OK, this thread boundary is DANGEROUS on linux
// wxPostEvent / wxAddPendingEvent is the solution.

View File

@ -18,15 +18,18 @@
#ifndef __MAIN_H_
#define __MAIN_H_
// Define a new application
class DolphinApp
: public wxApp
{
public:
#include "Frame.h"
bool OnInit();
void OnEndSession();
// Define a new application
class CFrame;
class DolphinApp : public wxApp
{
public:
bool OnInit();
void OnEndSession();
CFrame* GetCFrame();
};
DECLARE_APP(DolphinApp);
#endif