Ticket #942: atlas save button.2.diff
File atlas save button.2.diff, 10.2 KB (added by , 10 years ago) |
---|
-
binaries/data/tools/atlas/toolbar/save.png
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
-
source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.cpp
Property changes on: binaries/data/tools/atlas/toolbar/save.png ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property
1 1 /* Copyright (C) 2011 Wildfire Games. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 2 * This file is part of 0 A.D. 3 * 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * 0 A.D. is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 17 18 18 #include "precompiled.h" 19 19 … … 29 29 30 30 BEGIN_EVENT_TABLE(ToolButton, wxButton) 31 31 EVT_BUTTON(wxID_ANY, ToolButton::OnClick) 32 END_EVENT_TABLE()32 END_EVENT_TABLE() 33 33 34 ToolButton::ToolButton34 ToolButton::ToolButton 35 35 (ToolManager& toolManager, wxWindow *parent, const wxString& label, const wxString& toolName, const wxSize& size, long style) 36 36 : wxButton(parent, wxID_ANY, label, wxDefaultPosition, size, style) 37 37 , m_ToolManager(toolManager) … … 67 67 68 68 BEGIN_EVENT_TABLE(ToolButtonBar, wxToolBar) 69 69 EVT_TOOL(wxID_ANY, ToolButtonBar::OnTool) 70 END_EVENT_TABLE()70 END_EVENT_TABLE() 71 71 72 ToolButtonBar::ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID, long style)73 : wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style)74 , m_ToolManager(toolManager), m_SectionLayout(sectionLayout), m_Id(baseID), m_Size(-1)72 ToolButtonBar::ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID, long style) 73 : wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) 74 , m_ToolManager(toolManager), m_SectionLayout(sectionLayout), m_Id(baseID), m_Size(-1),m_IdAction(baseID) 75 75 { 76 76 /* "msw.remap: If 1 (the default), wxToolBar bitmap colours will be remapped 77 78 77 to the current theme's values. Set this to 0 to disable this functionality, 78 for example if you're using more than 16 colours in your tool bitmaps." */ 79 79 wxSystemOptions::SetOption(wxT("msw.remap"), 0); // (has global effect) 80 80 } 81 81 82 void ToolButtonBar::AddToolAction(const wxString& shortLabel, const wxString& longLabel, 83 const wxString& iconPNGFilename, fnAction action) 84 { 85 wxFileName iconPath (_T("tools/atlas/toolbar/")); 86 iconPath.MakeAbsolute(Datafile::GetDataDirectory()); 87 iconPath.SetFullName(iconPNGFilename); 88 wxFFileInputStream fstr (iconPath.GetFullPath()); 89 if (! fstr.Ok()) 90 { 91 wxLogError(_("Failed to open toolbar icon file '%s'"), iconPath.GetFullPath().c_str()); 92 return; 93 } 94 wxImage img (fstr, wxBITMAP_TYPE_PNG); 95 if (! img.Ok()) 96 { 97 wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath().c_str()); 98 return; 99 } 100 101 if (m_Size == -1) 102 { 103 m_Size = img.GetWidth(); 104 SetToolBitmapSize(wxSize(m_Size, m_Size)); 105 } 106 107 if (img.GetWidth() != m_Size || img.GetHeight() != m_Size) 108 img = img.Scale(m_Size, m_Size); 109 110 AddTool(1000+m_IdAction, wxBitmap(img),shortLabel, longLabel); 111 m_ButtonsActions[m_IdAction] = ButtonAction(action); 112 113 ++m_IdAction; 114 } 82 115 void ToolButtonBar::AddToolButton(const wxString& shortLabel, const wxString& longLabel, 83 116 const wxString& iconPNGFilename, const wxString& toolName, 84 117 const wxString& sectionPage) … … 98 131 wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath().c_str()); 99 132 return; 100 133 } 101 134 102 135 if (m_Size == -1) 103 136 { 104 137 m_Size = img.GetWidth(); … … 110 143 111 144 AddCheckTool(m_Id, shortLabel, wxBitmap(img), wxNullBitmap, longLabel); 112 145 m_Buttons[m_Id] = Button(toolName, sectionPage); 113 146 114 147 RegisterToolBarButton(this, m_Id, toolName); 115 148 116 149 ++m_Id; … … 118 151 119 152 void ToolButtonBar::OnTool(wxCommandEvent& evt) 120 153 { 121 std::map<int, Button>::iterator it = m_Buttons.find(evt.GetId()); 122 wxCHECK_RET(it != m_Buttons.end(), _T("Invalid toolbar button")); 123 m_ToolManager.SetCurrentTool(it->second.name); 124 if (! it->second.sectionPage.IsEmpty()) 125 m_SectionLayout->SelectPage(it->second.sectionPage); 154 int action=evt.GetId(); 155 if(action>=1000) 156 { 157 //is an action 158 action-=1000; 159 160 std::map<int, ButtonAction>::iterator it = m_ButtonsActions.find(action); 161 wxCHECK_RET(it != m_ButtonsActions.end(), _T("Invalid toolbar button")); 162 it->second.m_funcion(); 163 } 164 else 165 { 166 std::map<int, Button>::iterator it = m_Buttons.find(action); 167 wxCHECK_RET(it != m_Buttons.end(), _T("Invalid toolbar button")); 168 m_ToolManager.SetCurrentTool(it->second.name); 169 if (! it->second.sectionPage.IsEmpty()) 170 m_SectionLayout->SelectPage(it->second.sectionPage); 171 } 126 172 } -
source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h
18 18 //#include "wx/tglbtn.h" 19 19 20 20 #include <map> 21 #include "boost/function.hpp" 21 22 22 23 class ITool; 23 24 class SectionLayout; 24 25 class ToolManager; 25 26 27 typedef boost::function<void()> fnAction; 28 26 29 class ToolButton : public wxButton 27 30 { 28 31 public: … … 47 50 ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID, long style); 48 51 void AddToolButton(const wxString& shortLabel, const wxString& longLabel, 49 52 const wxString& iconPNGFilename, const wxString& toolName, const wxString& sectionPage); 53 void AddToolAction(const wxString& shortLabel, const wxString& longLabel, 54 const wxString& iconPNGFilename, fnAction fn); 50 55 51 56 protected: 52 57 void OnTool(wxCommandEvent& evt); … … 54 59 private: 55 60 ToolManager& m_ToolManager; 56 61 int m_Id; 62 int m_IdAction; 57 63 int m_Size; 58 64 struct Button 59 65 { … … 62 68 wxString name; 63 69 wxString sectionPage; 64 70 }; 71 struct ButtonAction 72 { 73 ButtonAction(){} 74 ButtonAction(fnAction action):m_funcion(action){} 75 fnAction m_funcion; 76 }; 65 77 std::map<int, Button> m_Buttons; 78 std::map<int, ButtonAction> m_ButtonsActions; 66 79 SectionLayout* m_SectionLayout; 67 80 68 81 DECLARE_EVENT_TABLE(); -
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
331 331 EVT_MENU(ID_New, ScenarioEditor::OnNew) 332 332 EVT_MENU(ID_Open, ScenarioEditor::OnOpen) 333 333 EVT_MENU(ID_Save, ScenarioEditor::OnSave) 334 EVT_BUTTON(ID_Save,ScenarioEditor::OnSave) 334 335 EVT_MENU(ID_SaveAs, ScenarioEditor::OnSaveAs) 335 336 EVT_MENU(ID_ImportHeightmap, ScenarioEditor::OnImportHeightmap) 336 337 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, ScenarioEditor::OnMRUFile) … … 543 544 ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style); 544 545 // TODO: configurable small vs large icon images 545 546 547 toolbar->AddToolAction(_("Save"),_("Save"),_T("save.png"),boost::bind(&ScenarioEditor::OnToolSave,this)); 548 toolbar->AddSeparator(); 546 549 // (button label; tooltip text; image; internal tool name; section to switch to) 547 550 toolbar->AddToolButton(_("Default"), _("Default"), _T("default.png"), _T(""), _T("")); 548 551 toolbar->AddToolButton(_("Move"), _("Move/rotate object"), _T("moveobject.png"), _T("TransformObject"), _T("")/*_T("ObjectSidebar")*/); … … 713 716 } 714 717 } 715 718 719 void ScenarioEditor::OnToolSave() 720 { 721 wxCommandEvent evt(wxEVT_NULL,0); 722 this->OnSave(evt); 723 } 724 716 725 void ScenarioEditor::OnSave(wxCommandEvent& event) 717 726 { 718 727 if (m_OpenFilename.IsEmpty()) -
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h
26 26 #include "Tools/Common/Tools.h" 27 27 #include "CustomControls/FileHistory/FileHistory.h" 28 28 #include "SectionLayout.h" 29 #include "boost/bind.hpp" 29 30 30 31 class ScenarioEditor : public wxFrame 31 32 { … … 35 36 void OnTimer(wxTimerEvent& event); 36 37 void OnIdle(wxIdleEvent& event); 37 38 wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString &name); 39 40 void OnToolSave(); 38 41 39 42 void OnNew(wxCommandEvent& event); 40 43 void OnOpen(wxCommandEvent& event);