From 036a8d324612f055c463a034d8e2c6fcd3f6b171 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sat, 3 Dec 2005 06:35:31 +0000 Subject: [PATCH] Atlas: Toolbar. This was SVN commit r3190. --- .../CustomControls/Buttons/ToolButton.cpp | 45 +++++++++----- .../CustomControls/Buttons/ToolButton.h | 23 ++++++-- .../Misc/Graphics/Toolbar/createxpm.pl | 1 + .../AtlasUI/Misc/Graphics/Toolbar/default.ppm | 41 +++++++++++++ .../AtlasUI/Misc/Graphics/Toolbar/default.xpm | 24 ++++++++ .../Misc/Graphics/Toolbar/elevationedit.ppm | 29 ++++++++++ .../Misc/Graphics/Toolbar/elevationedit.xpm | 26 +++++++++ .../Misc/Graphics/Toolbar/terrainpaint.ppm | 32 ++++++++++ .../Misc/Graphics/Toolbar/terrainpaint.xpm | 28 +++++++++ .../AtlasUI/ScenarioEditor/ScenarioEditor.cpp | 21 ++++++- .../ScenarioEditor/Tools/Common/Tools.cpp | 58 +++++++++++++++++++ .../ScenarioEditor/Tools/Common/Tools.h | 5 +- 12 files changed, 313 insertions(+), 20 deletions(-) create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/createxpm.pl create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.ppm create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.xpm create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.ppm create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.xpm create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.ppm create mode 100644 source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.xpm diff --git a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp index f4441ca58e..0270a75f6c 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp +++ b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp @@ -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::iterator it = m_Buttons.find(evt.GetId()); + wxCHECK_RET(it != m_Buttons.end(), _T("Invalid toolbar button")); + SetCurrentTool(it->second); +} diff --git a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h index 31eff46665..6cacc3249f 100644 --- a/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h +++ b/source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h @@ -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 m_Buttons; + + DECLARE_EVENT_TABLE(); +}; \ No newline at end of file diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/createxpm.pl b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/createxpm.pl new file mode 100644 index 0000000000..f966fdf7cd --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/createxpm.pl @@ -0,0 +1 @@ +for (<*.ppm>) { /(.*)\./; `ppmtoxpm -h -n=xpm_toolbar_$1 $_ > $1.xpm` } \ No newline at end of file diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.ppm b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.ppm new file mode 100644 index 0000000000..989778ad9f --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.ppm @@ -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 diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.xpm b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.xpm new file mode 100644 index 0000000000..f2598a9955 --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/default.xpm @@ -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 */ +"................", +". ...........", +". . .........", +". . .. ........", +". . .. ......", +". .. ... ......", +". ... ..........", +". ... .........", +"...... ........", +"....... .......", +"........ ......", +"......... .....", +".......... ....", +"................", +"................" +}; diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.ppm b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.ppm new file mode 100644 index 0000000000..9365edef7b --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.ppm @@ -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 diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.xpm b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.xpm new file mode 100644 index 0000000000..3356301946 --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/elevationedit.xpm @@ -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" +}; diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.ppm b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.ppm new file mode 100644 index 0000000000..c033a9aed1 --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.ppm @@ -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 diff --git a/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.xpm b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.xpm new file mode 100644 index 0000000000..8112ab3d84 --- /dev/null +++ b/source/tools/atlas/AtlasUI/Misc/Graphics/Toolbar/terrainpaint.xpm @@ -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" +}; diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index 32661d756e..88cf57c1b1 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -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: diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp index 39d4d941d3..54ffe1c1ac 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.cpp @@ -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 toolbarButtons_t; +typedef std::vector 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); diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h index f4a19611a1..380501ddf6 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/Common/Tools.h @@ -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); //////////////////////////////////////////////////////////////////////////