Ticket #942: atlas save button.2.diff

File atlas save button.2.diff, 10.2 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
     
    11/* Copyright (C) 2011 Wildfire Games.
    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  */
     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*/
    1717
    1818#include "precompiled.h"
    1919
     
    2929
    3030BEGIN_EVENT_TABLE(ToolButton, wxButton)
    3131    EVT_BUTTON(wxID_ANY, ToolButton::OnClick)
    32 END_EVENT_TABLE()
     32    END_EVENT_TABLE()
    3333
    34 ToolButton::ToolButton
     34    ToolButton::ToolButton
    3535    (ToolManager& toolManager, wxWindow *parent, const wxString& label, const wxString& toolName, const wxSize& size, long style)
    3636    : wxButton(parent, wxID_ANY, label, wxDefaultPosition, size, style)
    3737    , m_ToolManager(toolManager)
     
    6767
    6868BEGIN_EVENT_TABLE(ToolButtonBar, wxToolBar)
    6969    EVT_TOOL(wxID_ANY, ToolButtonBar::OnTool)
    70 END_EVENT_TABLE()
     70    END_EVENT_TABLE()
    7171
    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)
    7575{
    7676    /* "msw.remap: If 1 (the default), wxToolBar bitmap colours will be remapped
    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." */
     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." */
    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)
     
    98131        wxLogError(_("Failed to load toolbar icon image '%s'"), iconPath.GetFullPath().c_str());
    99132        return;
    100133    }
    101    
     134
    102135    if (m_Size == -1)
    103136    {
    104137        m_Size = img.GetWidth();
     
    110143
    111144    AddCheckTool(m_Id, shortLabel, wxBitmap(img), wxNullBitmap, longLabel);
    112145    m_Buttons[m_Id] = Button(toolName, sectionPage);
    113    
     146
    114147    RegisterToolBarButton(this, m_Id, toolName);
    115148
    116149    ++m_Id;
     
    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_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    }
    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_funcion(action){}
     75        fnAction m_funcion;
     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

     
    331331    EVT_MENU(ID_New, ScenarioEditor::OnNew)
    332332    EVT_MENU(ID_Open, ScenarioEditor::OnOpen)
    333333    EVT_MENU(ID_Save, ScenarioEditor::OnSave)
     334    EVT_BUTTON(ID_Save,ScenarioEditor::OnSave)
    334335    EVT_MENU(ID_SaveAs, ScenarioEditor::OnSaveAs)
    335336    EVT_MENU(ID_ImportHeightmap, ScenarioEditor::OnImportHeightmap)
    336337    EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, ScenarioEditor::OnMRUFile)
     
    543544    ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style);
    544545    // TODO: configurable small vs large icon images
    545546
     547    toolbar->AddToolAction(_("Save"),_("Save"),_T("save.png"),boost::bind(&ScenarioEditor::OnToolSave,this));
     548    toolbar->AddSeparator();
    546549    // (button label; tooltip text; image; internal tool name; section to switch to)
    547550    toolbar->AddToolButton(_("Default"),       _("Default"),                   _T("default.png"),          _T(""),                 _T(""));
    548551    toolbar->AddToolButton(_("Move"),          _("Move/rotate object"),        _T("moveobject.png"),       _T("TransformObject"),  _T("")/*_T("ObjectSidebar")*/);
     
    713716    }
    714717}
    715718
     719void ScenarioEditor::OnToolSave()
     720{
     721    wxCommandEvent evt(wxEVT_NULL,0);
     722    this->OnSave(evt);
     723}
     724
    716725void ScenarioEditor::OnSave(wxCommandEvent& event)
    717726{
    718727    if (m_OpenFilename.IsEmpty())
  • source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.h

     
    2626#include "Tools/Common/Tools.h"
    2727#include "CustomControls/FileHistory/FileHistory.h"
    2828#include "SectionLayout.h"
     29#include "boost/bind.hpp"
    2930
    3031class ScenarioEditor : public wxFrame
    3132{
     
    3536    void OnTimer(wxTimerEvent& event);
    3637    void OnIdle(wxIdleEvent& event);
    3738    wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString &name);
     39
     40    void OnToolSave();
    3841   
    3942    void OnNew(wxCommandEvent& event);
    4043    void OnOpen(wxCommandEvent& event);