Atlas: Toolbar.

This was SVN commit r3190.
This commit is contained in:
Ykkrosh 2005-12-03 06:35:31 +00:00
parent 48ef5c0a32
commit 036a8d3246
12 changed files with 313 additions and 20 deletions

View File

@ -20,35 +20,52 @@ ToolButton::ToolButton
// (by the wxButton code), rather than initially using the native
// (fixed colour) button appearance.
SetSelectedAppearance(false);
RegisterToolButton(this, toolName);
}
void ToolButton::OnClick(wxCommandEvent& WXUNUSED(evt))
{
if (g_Current)
g_Current->SetSelectedAppearance(false);
// TODO: set disabled when tool is changed via other (non-button) methods
// Toggle on/off
if (g_Current == this)
{
g_Current = NULL;
SetSelectedAppearance(false);
if (m_Selected)
SetCurrentTool(_T(""));
}
else
{
g_Current = this;
SetSelectedAppearance(true);
SetCurrentTool(m_Tool);
}
}
void ToolButton::SetSelectedAppearance(bool selected)
{
m_Selected = selected;
if (selected)
SetBackgroundColour(wxColour(0xee, 0xcc, 0x55));
else
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
}
ToolButton* ToolButton::g_Current = NULL;
//////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE(ToolButtonBar, wxToolBar)
EVT_TOOL(wxID_ANY, ToolButtonBar::OnTool)
END_EVENT_TABLE()
ToolButtonBar::ToolButtonBar(wxWindow* parent, int baseID)
: wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL), m_Id(baseID)
{
}
void ToolButtonBar::AddToolButton(const wxString& shortLabel, const wxString& longLabel, const wxBitmap& bitmap, const wxString& toolName)
{
AddCheckTool(m_Id, shortLabel, bitmap, wxNullBitmap, longLabel);
m_Buttons[m_Id] = toolName;
RegisterToolBarButton(this, m_Id, toolName);
++m_Id;
}
void ToolButtonBar::OnTool(wxCommandEvent& evt)
{
std::map<int, wxString>::iterator it = m_Buttons.find(evt.GetId());
wxCHECK_RET(it != m_Buttons.end(), _T("Invalid toolbar button"));
SetCurrentTool(it->second);
}

View File

@ -5,17 +5,32 @@ class ITool;
class ToolButton : public wxButton
{
public:
static ToolButton* g_Current;
ToolButton(wxWindow *parent, const wxString& label, const wxString& toolName, const wxSize& size = wxDefaultSize, long style = 0);
void SetSelectedAppearance(bool selected);
protected:
void OnClick(wxCommandEvent& evt);
void SetSelectedAppearance(bool selected);
private:
wxString m_Tool;
bool m_Selected;
DECLARE_EVENT_TABLE();
};
class ToolButtonBar : public wxToolBar
{
public:
ToolButtonBar(wxWindow* parent, int baseID);
void AddToolButton(const wxString& shortLabel, const wxString& longLabel, const wxBitmap& bitmap, const wxString& toolName);
protected:
void OnTool(wxCommandEvent& evt);
private:
int m_Id;
std::map<int, wxString> m_Buttons;
DECLARE_EVENT_TABLE();
};

View File

@ -0,0 +1 @@
for (<*.ppm>) { /(.*)\./; `ppmtoxpm -h -n=xpm_toolbar_$1 $_ > $1.xpm` }

View File

@ -0,0 +1,41 @@
P3
# Created by Paint Shop Pro 7
16 15
255
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 0 0 0
0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 0 0 0 0 0 0 192 192 192 0 0 0 0 0 0 0 0 0 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 0 0 0 192 192 192 0 0 0 192 192 192 192 192 192
0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 192 192 192 0 0 0
0 0 0 192 192 192 192 192 192 0 0 0 0 0 0 0 0 0 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 192 192 192
192 192 192 0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 0 0 0 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
0 0 0 192 192 192 192 192 192 192 192 192 0 0 0 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 0 0 0 192 192 192 192 192 192 192 192 192
0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 0 0 0 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 0 0 0 0 0 0 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 0 0 0 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 0 0 0 0 0 0 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192

View File

@ -0,0 +1,24 @@
/* XPM */
static char *xpm_toolbar_default[] = {
/* width height ncolors chars_per_pixel */
"16 15 2 1",
/* colors */
" c #000000",
". c #C0C0C0",
/* pixels */
"................",
". ...........",
". . .........",
". . .. ........",
". . .. ......",
". .. ... ......",
". ... ..........",
". ... .........",
"...... ........",
"....... .......",
"........ ......",
"......... .....",
".......... ....",
"................",
"................"
};

View File

@ -0,0 +1,29 @@
P3
# Created by Paint Shop Pro 7
16 15
255
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 0 0 0
0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 0 0 0 0 0 0 0 0 0
0 255 0 0 0 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 192 192 192 192 192 192 192 192 192
0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 255 0 0 0 0 0 255 0 0 0 0 0 255 0
0 128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 128 0 0 0 0 0 128 0 0 0 0 0 0 0 0 255 0
0 0 0 0 0 0 0 0 0 0 255 0 0 0 0 0 255 0 0 128 0 0 0 0 0 128 0 0 128 0 0 128 0
0 0 0 0 255 0 0 0 0 0 255 0 0 255 0 0 0 0 0 255 0 0 0 0 0 255 0 0 0 0 0 0 0
0 128 0 0 0 0 0 128 0 0 128 0 0 0 0 0 0 0 0 0 0 0 255 0 0 255 0 0 255 0
0 0 0 0 255 0 0 0 0 0 255 0 0 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 128 0
0 128 0 0 0 0 0 128 0 0 128 0 0 255 0 0 0 0 0 255 0 0 0 0 0 0 0 0 255 0
0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0
0 0 0 0 0 0 0 255 0 0 255 0 0 0 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0
0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 0 0 0 128 0 0 255 0 0 128 0
0 0 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 128 0 0 0 0
0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0
0 128 0 0 0 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 128 0 0 0 0
0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0
0 128 0 0 0 0 0 128 0 0 128 0 0 128 0 0 0 0 0 128 0 0 128 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192

View File

@ -0,0 +1,26 @@
/* XPM */
static char *xpm_toolbar_elevationedit[] = {
/* width height ncolors chars_per_pixel */
"16 15 4 1",
/* colors */
" c #000000",
". c #00FF00",
"X c #C0C0C0",
"o c #008000",
/* pixels */
"XXXXX XXXXXXX",
"XX . . XXX",
" . . . .o ",
"o o . . .o oo",
"o . .. . . o oo",
" ... . .. ",
"oo oo. . .oo oo",
"oo oo .. ooo oo",
"oo oo o.o ooo oo",
" ",
"oo oo ooo ooo oo",
"oo oo ooo ooo oo",
"oo oo ooo ooo oo",
" ",
"XXXXXXXXXXXXXXXX"
};

View File

@ -0,0 +1,32 @@
P3
# Created by Paint Shop Pro 7
16 15
255
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 255 0 0 255 0 0 0 0 0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 0 0 0
128 128 0 128 128 0 128 128 0 128 128 0 128 128 0 0 0 0 0 255 0 0 0 0 0 128 0
0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 128 128 0 128 128 0 128 128 0
128 128 0 128 128 0 0 0 0 255 255 0 0 255 0 0 0 0 0 128 0 0 128 0 0 128 0
0 128 0 0 128 0 0 128 0 0 0 0 128 128 0 128 128 0 128 128 0 128 128 0 128 128 0
0 0 0 255 255 0 0 0 0 0 0 0 0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0
0 0 0 128 128 0 128 128 0 128 128 0 128 128 0 0 0 0 255 255 0 255 255 0
0 0 0 0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 128 128 0 128 128 0
128 128 0 128 128 0 128 128 0 0 0 0 255 255 0 255 255 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 128 128 0 128 128 0
128 128 0 128 128 0 128 128 0 0 0 0 255 255 0 255 255 0 255 255 0 0 0 0
0 128 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 128 128 0 128 128 0 128 128 0
128 128 0 128 128 0 0 0 0 255 255 0 255 255 0 255 255 0 0 128 0 0 128 0
0 128 0 0 128 0 0 128 0 0 0 0 0 0 0 128 128 0 128 128 0 128 128 0 128 128 0
0 0 0 255 255 0 255 255 0 255 255 0 255 255 0 0 128 0 0 128 0 0 128 0 0 128 0
0 128 0 0 0 0 128 128 0 128 128 0 128 128 0 128 128 0 128 128 0 0 0 0 255 255 0
255 255 0 255 255 0 255 255 0 0 128 0 0 128 0 0 128 0 0 128 0 0 0 0 0 0 0
128 128 0 128 128 0 128 128 0 128 128 0 0 0 0 0 0 0 255 255 0 255 255 0
255 255 0 255 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192 192
192 192 192

View File

@ -0,0 +1,28 @@
/* XPM */
static char *xpm_toolbar_terrainpaint[] = {
/* width height ncolors chars_per_pixel */
"16 15 6 1",
/* colors */
" c #000000",
". c #00FF00",
"X c #C0C0C0",
"o c #FFFF00",
"O c #008000",
"+ c #808000",
/* pixels */
"XXXXXXXXXXXXXXXX",
" ",
".. OOOOO +++++ ",
". OOOOOO +++++ o",
". OOOOOO +++++ o",
" OOOOO ++++ oo",
" OOOOOO +++++ oo",
" ",
" OOOOO +++++ ooo",
" OOOOO +++++ ooo",
"OOOOO ++++ oooo",
"OOOOO +++++ oooo",
"OOOO ++++ oooo",
" ",
"XXXXXXXXXXXXXXXX"
};

View File

@ -4,12 +4,19 @@
#include "wx/glcanvas.h"
#include "wx/evtloop.h"
#include "wx/tooltip.h"
#include "SnapSplitterWindow/SnapSplitterWindow.h"
#include "HighResTimer/HighResTimer.h"
#include "Buttons/ToolButton.h"
#include "GameInterface/MessagePasser.h"
#include "GameInterface/Messages.h"
#include "Misc/Graphics/Toolbar/default.xpm"
#include "Misc/Graphics/Toolbar/terrainpaint.xpm"
#include "Misc/Graphics/Toolbar/elevationedit.xpm"
#include "tools/Common/Tools.h"
//#define UI_ONLY
@ -310,6 +317,8 @@ enum
ID_Wireframe,
ID_MessageTrace,
ID_Screenshot,
ID_Toolbar // must be last in the list
};
BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame)
@ -336,6 +345,8 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent)
{
// wxLog::SetTraceMask(wxTraceMessages);
wxToolTip::Enable(true);
//////////////////////////////////////////////////////////////////////////
// Menu
@ -379,10 +390,18 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent)
menuMisc->Append(ID_Screenshot, _("&Screenshot"));
}
// Toolbar:
ToolButtonBar* toolbar = new ToolButtonBar(this, ID_Toolbar);
toolbar->AddToolButton(_("Default"), _("Default"), wxBitmap(xpm_toolbar_default), _T(""));
toolbar->AddToolButton(_("Elevation"), _("Alter terrain elevation"), wxBitmap(xpm_toolbar_elevationedit), _T("AlterElevation"));
toolbar->AddToolButton(_("Paint Terrain"), _("Paint terrain texture"), wxBitmap(xpm_toolbar_terrainpaint), _T("PaintTerrain"));
toolbar->Realize();
SetToolBar(toolbar);
//////////////////////////////////////////////////////////////////////////
// Main window
//SnapSplitterWindow* splitter = new SnapSplitterWindow(this);
m_SectionLayout.SetWindow(this);
// Set up GL canvas:

View File

@ -2,6 +2,7 @@
#include "Tools.h"
#include "GameInterface/Messages.h"
#include "CustomControls/Buttons/ToolButton.h"
class DummyTool : public ITool
{
@ -13,6 +14,9 @@ class DummyTool : public ITool
} dummy;
static ITool* g_CurrentTool = &dummy;
static wxString g_CurrentToolName;
void SetActive(bool active, const wxString& name);
ITool& GetCurrentTool()
{
@ -27,6 +31,8 @@ void SetCurrentTool(const wxString& name, void* initData)
delete g_CurrentTool;
}
SetActive(false, g_CurrentToolName);
ITool* tool = NULL;
if (name.Len())
{
@ -39,8 +45,60 @@ void SetCurrentTool(const wxString& name, void* initData)
g_CurrentTool = &dummy;
else
g_CurrentTool = tool;
g_CurrentToolName = name;
SetActive(true, g_CurrentToolName);
}
//////////////////////////////////////////////////////////////////////////
struct toolbarButton
{
wxString name;
wxToolBar* toolbar;
int id;
};
struct toolButton
{
wxString name;
ToolButton* button;
};
typedef std::vector<toolbarButton> toolbarButtons_t;
typedef std::vector<toolButton> toolButtons_t;
static toolbarButtons_t toolbarButtons;
static toolButtons_t toolButtons;
void SetActive(bool active, const wxString& name)
{
for (toolbarButtons_t::iterator it = toolbarButtons.begin(); it != toolbarButtons.end(); ++it)
if (it->name == name)
it->toolbar->ToggleTool(it->id, active);
for (toolButtons_t::iterator it = toolButtons.begin(); it != toolButtons.end(); ++it)
if (it->name == name)
it->button->SetSelectedAppearance(active);
}
void RegisterToolButton(ToolButton* button, const wxString& toolName)
{
toolButton b;
b.name = toolName;
b.button = button;
toolButtons.push_back(b);
}
void RegisterToolBarButton(wxToolBar* toolbar, int buttonId, const wxString& toolName)
{
toolbarButton b;
b.name = toolName;
b.toolbar = toolbar;
b.id = buttonId;
toolbarButtons.push_back(b);
}
//////////////////////////////////////////////////////////////////////////
IMPLEMENT_CLASS(WorldCommand, AtlasWindowCommand);

View File

@ -23,7 +23,10 @@ public:
extern ITool& GetCurrentTool();
extern void SetCurrentTool(const wxString& name, void* initData = NULL);
// should usually only be used by tool buttons. (TODO: not true)
class ToolButton;
extern void RegisterToolButton(ToolButton* button, const wxString& toolName);
extern void RegisterToolBarButton(wxToolBar* toolbar, int buttonId, const wxString& toolName);
//////////////////////////////////////////////////////////////////////////