2012-11-15 00:39:56 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
|
|
#include <wx/listctrl.h>
|
2013-06-30 10:46:29 +02:00
|
|
|
#include <fstream>
|
|
|
|
|
#include <vector>
|
2014-06-02 19:27:24 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
#include "Ini.h"
|
|
|
|
|
#include "Utilities/Thread.h"
|
|
|
|
|
#include "Utilities/StrFmt.h"
|
|
|
|
|
#include "Emu/ConLog.h"
|
|
|
|
|
#include "Gui/ConLogFrame.h"
|
|
|
|
|
|
|
|
|
|
#include "Utilities/BEType.h"
|
|
|
|
|
#include "Emu/Memory/Memory.h"
|
|
|
|
|
#include "Emu/System.h"
|
|
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
LogFrame* ConLogFrame;
|
2013-06-30 10:46:29 +02:00
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(LogFrame, wxPanel)
|
2012-11-15 00:39:56 +01:00
|
|
|
EVT_CLOSE(LogFrame::OnQuit)
|
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
LogFrame::LogFrame(wxWindow* parent)
|
|
|
|
|
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(600, 500))
|
2014-01-31 19:40:18 +01:00
|
|
|
, ThreadBase("LogThread")
|
2012-11-15 00:39:56 +01:00
|
|
|
, m_log(*new wxListView(this))
|
|
|
|
|
{
|
2014-06-07 09:54:02 +02:00
|
|
|
m_log.InsertColumn(0, "Thread");
|
2012-11-15 00:39:56 +01:00
|
|
|
m_log.InsertColumn(1, "Log");
|
|
|
|
|
m_log.SetBackgroundColour(wxColour("Black"));
|
|
|
|
|
|
2014-04-13 03:31:59 +02:00
|
|
|
wxBoxSizer* s_main = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
s_main->Add(&m_log, 1, wxEXPAND);
|
|
|
|
|
SetSizer(s_main);
|
2013-06-30 10:46:29 +02:00
|
|
|
Layout();
|
2013-11-27 20:16:19 +01:00
|
|
|
|
2012-11-15 00:39:56 +01:00
|
|
|
Show();
|
|
|
|
|
ThreadBase::Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogFrame::~LogFrame()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool LogFrame::Close(bool force)
|
|
|
|
|
{
|
2014-01-31 19:40:18 +01:00
|
|
|
Stop(false);
|
|
|
|
|
ConLogFrame = nullptr;
|
2013-06-30 10:46:29 +02:00
|
|
|
return wxWindowBase::Close(force);
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LogFrame::Task()
|
|
|
|
|
{
|
|
|
|
|
while(!TestDestroy())
|
|
|
|
|
{
|
|
|
|
|
if(!LogBuffer.HasNewPacket())
|
|
|
|
|
{
|
|
|
|
|
Sleep(1);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2013-06-30 10:46:29 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wxThread::Yield();
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
|
|
|
|
|
const LogPacket item = LogBuffer.Pop();
|
|
|
|
|
|
2014-04-02 17:57:50 +02:00
|
|
|
wxListView& m_log = this->m_log; //makes m_log capturable by the lambda
|
|
|
|
|
//queue adding the log message to the gui element in the main thread
|
|
|
|
|
wxTheApp->GetTopWindow()->GetEventHandler()->CallAfter([item, &m_log]()
|
2012-11-15 00:39:56 +01:00
|
|
|
{
|
2014-04-02 17:57:50 +02:00
|
|
|
while (m_log.GetItemCount() > max_item_count)
|
|
|
|
|
{
|
|
|
|
|
m_log.DeleteItem(0);
|
|
|
|
|
wxThread::Yield();
|
|
|
|
|
}
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-04-02 17:57:50 +02:00
|
|
|
const int cur_item = m_log.GetItemCount();
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-04-02 17:57:50 +02:00
|
|
|
m_log.InsertItem(cur_item, fmt::FromUTF8(item.m_prefix));
|
|
|
|
|
m_log.SetItem(cur_item, 1, fmt::FromUTF8(item.m_text));
|
|
|
|
|
m_log.SetItemTextColour(cur_item, fmt::FromUTF8(item.m_colour));
|
|
|
|
|
m_log.SetColumnWidth(0, -1);
|
|
|
|
|
m_log.SetColumnWidth(1, -1);
|
|
|
|
|
});
|
2012-11-15 00:39:56 +01:00
|
|
|
|
2014-02-21 17:13:57 +01:00
|
|
|
#ifdef _WIN32
|
2012-11-15 00:39:56 +01:00
|
|
|
::SendMessage((HWND)m_log.GetHWND(), WM_VSCROLL, SB_BOTTOM, 0);
|
2014-02-21 17:13:57 +01:00
|
|
|
#endif
|
2012-11-15 00:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LogBuffer.Flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LogFrame::OnQuit(wxCloseEvent& event)
|
|
|
|
|
{
|
2014-01-31 19:40:18 +01:00
|
|
|
Stop(false);
|
|
|
|
|
ConLogFrame = nullptr;
|
2012-11-15 00:39:56 +01:00
|
|
|
event.Skip();
|
2013-11-19 11:30:58 +01:00
|
|
|
}
|