Ticket #942: atlas save button.3.diff

File atlas save button.3.diff, 7.7 KB (added by trompetin17, 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
     
    7171
    7272ToolButtonBar::ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID, long style)
    7373: 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)
    7575{
    7676    /* "msw.remap: If 1 (the default), wxToolBar bitmap colours will be remapped
    7777       to the current theme's values. Set this to 0 to disable this functionality,
     
    7979    wxSystemOptions::SetOption(wxT("msw.remap"), 0); // (has global effect)
    8080}
    8181
     82void 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}
    82115void ToolButtonBar::AddToolButton(const wxString& shortLabel, const wxString& longLabel,
    83116                                  const wxString& iconPNGFilename, const wxString& toolName,
    84117                                  const wxString& sectionPage)
     
    86119    wxFileName iconPath (_T("tools/atlas/toolbar/"));
    87120    iconPath.MakeAbsolute(Datafile::GetDataDirectory());
    88121    iconPath.SetFullName(iconPNGFilename);
    89     wxFFileInputStream fstr (iconPath.GetFullPath());
    90     if (! fstr.Ok())
     122    wxFFileInputStream fstr(iconPath.GetFullPath());
     123    if (!fstr.Ok())
    91124    {
    92125        wxLogError(_("Failed to open toolbar icon file '%s'"), iconPath.GetFullPath().c_str());
    93126        return;
    94127    }
    95     wxImage img (fstr, wxBITMAP_TYPE_PNG);
    96     if (! img.Ok())
     128    wxImage img(fstr, wxBITMAP_TYPE_PNG);
     129    if (!img.Ok())
    97130    {
    98131        wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath().c_str());
    99132        return;
     
    118151
    119152void ToolButtonBar::OnTool(wxCommandEvent& evt)
    120153{
    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_function();
     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    }
    126172}
  • source/tools/atlas/AtlasUI/CustomControls/Buttons/ToolButton.h

     
    1818//#include "wx/tglbtn.h"
    1919
    2020#include <map>
     21#include <boost/function.hpp>
    2122
    2223class ITool;
    2324class SectionLayout;
    2425class ToolManager;
    2526
     27typedef boost::function<void()> fnAction;
     28
    2629class ToolButton : public wxButton
    2730{
    2831public:
     
    4750    ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID, long style);
    4851    void AddToolButton(const wxString& shortLabel, const wxString& longLabel,
    4952        const wxString& iconPNGFilename, const wxString& toolName, const wxString& sectionPage);
     53    void AddToolAction(const wxString& shortLabel, const wxString& longLabel,
     54        const wxString& iconPNGFilename, fnAction fn);
    5055
    5156protected:
    5257    void OnTool(wxCommandEvent& evt);
     
    5459private:
    5560    ToolManager& m_ToolManager;
    5661    int m_Id;
     62    int m_IdAction;
    5763    int m_Size;
    5864    struct Button
    5965    {
     
    6268        wxString name;
    6369        wxString sectionPage;
    6470    };
     71    struct ButtonAction
     72    {
     73        ButtonAction(){}
     74        ButtonAction(fnAction action):m_function(action){}
     75        fnAction m_function;
     76    };
    6577    std::map<int, Button> m_Buttons;
     78    std::map<int, ButtonAction> m_ButtonsActions;
    6679    SectionLayout* m_SectionLayout;
    6780
    6881    DECLARE_EVENT_TABLE();
  • source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp

     
    4646#include "Tools/Common/Brushes.h"
    4747#include "Tools/Common/MiscState.h"
    4848
     49#include <boost/bind.hpp>
     50
    4951static HighResTimer g_Timer;
    5052
    5153using namespace AtlasMessage;
     
    543545    ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style);
    544546    // TODO: configurable small vs large icon images
    545547
     548    toolbar->AddToolAction(_("Save"), _("Save"), _T("save.png"), boost::bind(&ScenarioEditor::OnToolSave,this));
     549    toolbar->AddSeparator();
    546550    // (button label; tooltip text; image; internal tool name; section to switch to)
    547551    toolbar->AddToolButton(_("Default"),       _("Default"),                   _T("default.png"),          _T(""),                 _T(""));
    548552    toolbar->AddToolButton(_("Move"),          _("Move/rotate object"),        _T("moveobject.png"),       _T("TransformObject"),  _T("")/*_T("ObjectSidebar")*/);
     
    713717    }
    714718}
    715719
     720void ScenarioEditor::OnToolSave()
     721{
     722    wxCommandEvent evt(wxEVT_NULL,0);
     723    this->OnSave(evt);
     724}
     725
    716726void ScenarioEditor::OnSave(wxCommandEvent& event)
    717727{
    718728    if (m_OpenFilename.IsEmpty())
  • source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h

     
    3535    void OnTimer(wxTimerEvent& event);
    3636    void OnIdle(wxIdleEvent& event);
    3737    wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString &name);
     38
     39    void OnToolSave();
    3840   
    3941    void OnNew(wxCommandEvent& event);
    4042    void OnOpen(wxCommandEvent& event);