0ad/source/tools/atlas/AtlasUI/ColourTester/ColourTesterColourCtrl.cpp
Ykkrosh f2b662d12d Build: generate Atlas project files (with "update-workspaces --atlas") (for VS2003 only).
Premake: allow slight separation of files' locations on disk vs in the
project tree.
Atlas: require fewer include directories.

This was SVN commit r2956.
2005-10-17 01:11:12 +00:00

105 lines
2.7 KiB
C++

#include "stdafx.h"
#include "ColourTesterColourCtrl.h"
#include "ColourTesterImageCtrl.h"
#include "General/Datafile.h"
#include <sstream>
//////////////////////////////////////////////////////////////////////////
// A couple of buttons:
class ColouredButton : public wxButton
{
public:
ColouredButton(wxWindow* parent, const wxColour& colour, const wxColour& textColor,
const wxString& caption, ColourTesterImageCtrl* imgctrl)
: wxButton(parent, wxID_ANY, caption),
m_ImageCtrl(imgctrl), m_Colour(colour)
{
SetBackgroundColour(m_Colour);
SetForegroundColour(textColor);
}
void OnButton(wxCommandEvent& WXUNUSED(event))
{
m_ImageCtrl->SetColour(m_Colour);
}
private:
wxColour m_Colour;
ColourTesterImageCtrl* m_ImageCtrl;
DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(ColouredButton, wxButton)
EVT_BUTTON(wxID_ANY, ColouredButton::OnButton)
END_EVENT_TABLE()
class CustomColourButton : public wxButton
{
public:
CustomColourButton(wxWindow* parent, const wxString& caption, ColourTesterImageCtrl* imgctrl)
: wxButton(parent, wxID_ANY, caption),
m_ImageCtrl(imgctrl), m_Colour(127,127,127)
{
SetBackgroundColour(m_Colour);
}
void OnButton(wxCommandEvent& WXUNUSED(event))
{
wxColour c = wxGetColourFromUser(this, m_Colour);
if (c.Ok())
{
m_Colour = c;
m_ImageCtrl->SetColour(m_Colour);
SetBackgroundColour(m_Colour);
}
}
private:
wxColour m_Colour;
ColourTesterImageCtrl* m_ImageCtrl;
DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(CustomColourButton, wxButton)
EVT_BUTTON(wxID_ANY, CustomColourButton::OnButton)
END_EVENT_TABLE()
//////////////////////////////////////////////////////////////////////////
ColourTesterColourCtrl::ColourTesterColourCtrl(wxWindow* parent, ColourTesterImageCtrl* imgctrl)
: wxPanel(parent, wxID_ANY)
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxHORIZONTAL);
wxGridSizer* presetColourSizer = new wxGridSizer(2);
mainSizer->Add(presetColourSizer);
AtObj colours (Datafile::ReadList("playercolours"));
for (AtIter c = colours["colour"]; c.defined(); ++c)
{
wxColour back;
{
int r,g,b;
std::wstringstream s;
s << (std::wstring)c["@rgb"];
s >> r >> g >> b;
back = wxColour(r,g,b);
}
wxColour text (0, 0, 0);
if (c["@buttontext"].defined())
{
int r,g,b;
std::wstringstream s;
s << (std::wstring)c["@buttontext"];
s >> r >> g >> b;
text = wxColour(r,g,b);
}
presetColourSizer->Add(new ColouredButton(this, back, text, c["@name"], imgctrl));
}
presetColourSizer->Add(new CustomColourButton(this, _("Custom"), imgctrl));
SetSizer(mainSizer);
mainSizer->SetSizeHints(this);
}