Ticket #942: atlas save button.diff
File atlas save button.diff, 7.1 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
71 71 72 72 ToolButtonBar::ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID, long style) 73 73 : wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style) 74 , m_ToolManager(toolManager), m_SectionLayout(sectionLayout), m_Id(baseID), m_Size(-1) 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 77 to the current theme's values. Set this to 0 to disable this functionality, … … 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) … … 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
543 543 ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style); 544 544 // TODO: configurable small vs large icon images 545 545 546 toolbar->AddToolAction(_("Save"),_("Save"),_T("save.png"),boost::bind(&ScenarioEditor::OnToolSave,this)); 547 toolbar->AddSeparator(); 546 548 // (button label; tooltip text; image; internal tool name; section to switch to) 547 549 toolbar->AddToolButton(_("Default"), _("Default"), _T("default.png"), _T(""), _T("")); 548 550 toolbar->AddToolButton(_("Move"), _("Move/rotate object"), _T("moveobject.png"), _T("TransformObject"), _T("")/*_T("ObjectSidebar")*/); … … 713 715 } 714 716 } 715 717 718 void ScenarioEditor::OnToolSave() 719 { 720 wxCommandEvent evt(wxEVT_NULL,0); 721 this->OnSave(evt); 722 } 723 716 724 void ScenarioEditor::OnSave(wxCommandEvent& event) 717 725 { 718 726 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);