2010-05-20 12:23:13 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
|
|
|
*
|
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
#include "common/wxGuiTools.h"
|
|
|
|
#include "common/StringHelpers.h"
|
2010-05-20 12:23:13 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxWindowTextWriter Implementations
|
|
|
|
// --------------------------------------------------------------------------------------
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter::pxWindowTextWriter(wxDC& dc)
|
|
|
|
: m_dc(dc)
|
2010-06-04 08:00:19 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_curpos = wxPoint();
|
|
|
|
m_align = wxALIGN_CENTER;
|
|
|
|
m_leading = 0;
|
2010-06-04 08:00:19 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
OnFontChanged();
|
2010-06-04 08:00:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-20 12:23:13 +00:00
|
|
|
void pxWindowTextWriter::OnFontChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::SetWeight(wxFontWeight weight)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
wxFont curfont(m_dc.GetFont());
|
|
|
|
curfont.SetWeight(weight);
|
|
|
|
m_dc.SetFont(curfont);
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::SetStyle(wxFontStyle style)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
wxFont curfont(m_dc.GetFont());
|
|
|
|
curfont.SetStyle(style);
|
|
|
|
m_dc.SetFont(curfont);
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::Normal()
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
wxFont curfont(m_dc.GetFont());
|
|
|
|
curfont.SetStyle(wxFONTSTYLE_NORMAL);
|
|
|
|
curfont.SetWeight(wxFONTWEIGHT_NORMAL);
|
|
|
|
m_dc.SetFont(curfont);
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::SetPos(const wxPoint& pos)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_curpos = pos;
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::MovePos(const wxSize& delta)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_curpos += delta;
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::SetY(int ypos)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_curpos.y = ypos;
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::MoveY(int ydelta)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_curpos.y += ydelta;
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
void pxWindowTextWriter::_DoWriteLn(const wxString& msg)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
int tWidth, tHeight;
|
|
|
|
m_dc.GetMultiLineTextExtent(msg, &tWidth, &tHeight);
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
wxPoint dispos(m_curpos);
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
if (m_align & wxALIGN_CENTER_HORIZONTAL)
|
|
|
|
{
|
|
|
|
dispos.x = (m_dc.GetSize().GetWidth() - tWidth) / 2;
|
|
|
|
}
|
|
|
|
else if (m_align & wxALIGN_RIGHT)
|
|
|
|
{
|
|
|
|
dispos.x = m_dc.GetSize().GetWidth() - tWidth;
|
|
|
|
}
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
m_dc.DrawText(msg, dispos);
|
|
|
|
m_curpos.y += tHeight + m_leading;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Splits incoming multi-line strings into pieces, and dispatches each line individually
|
|
|
|
// to the text writer.
|
2021-09-06 18:28:26 +00:00
|
|
|
void pxWindowTextWriter::_DoWrite(const wxChar* msg)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
pxAssert(msg);
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
wxArrayString parts;
|
|
|
|
SplitString(parts, msg, L'\n');
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
for (size_t i = 0; i < parts.GetCount(); ++i)
|
|
|
|
_DoWriteLn(parts[i]);
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::SetFont(const wxFont& font)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_dc.SetFont(font);
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::Align(const wxAlignment& align)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
m_align = align;
|
|
|
|
m_curpos.x = 0;
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::WriteLn()
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
_DoWriteLn(L"");
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::WriteLn(const wxChar* fmt)
|
2010-05-20 12:23:13 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
_DoWrite(fmt);
|
|
|
|
return *this;
|
2010-05-20 12:23:13 +00:00
|
|
|
}
|
2010-06-02 15:58:34 +00:00
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::FormatLn(const wxChar* fmt, ...)
|
2010-06-02 15:58:34 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
_DoWrite(pxsFmtV(fmt, args));
|
|
|
|
va_end(args);
|
|
|
|
return *this;
|
2010-06-02 15:58:34 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 18:28:26 +00:00
|
|
|
pxWindowTextWriter& pxWindowTextWriter::WriteLn(const wxString fmt)
|
2014-08-02 11:34:44 +00:00
|
|
|
{
|
2021-09-06 18:28:26 +00:00
|
|
|
_DoWrite(fmt.wc_str());
|
|
|
|
return *this;
|
2014-08-02 11:34:44 +00:00
|
|
|
}
|