1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "MoveObjectsToolPage.h" 21 22 #include "View/MapDocument.h" 23 #include "View/ViewConstants.h" 24 25 #include <wx/button.h> 26 #include <wx/sizer.h> 27 #include <wx/stattext.h> 28 #include <wx/textctrl.h> 29 30 namespace TrenchBroom { 31 namespace View { MoveObjectsToolPage(wxWindow * parent,MapDocumentWPtr document)32 MoveObjectsToolPage::MoveObjectsToolPage(wxWindow* parent, MapDocumentWPtr document) : 33 wxPanel(parent), 34 m_document(document) { 35 createGui(); 36 } 37 createGui()38 void MoveObjectsToolPage::createGui() { 39 wxStaticText* text = new wxStaticText(this, wxID_ANY, "Move objects by"); 40 m_offset = new wxTextCtrl(this, wxID_ANY, "0.0 0.0 0.0"); 41 m_button = new wxButton(this, wxID_ANY, "Apply", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); 42 43 m_button->Bind(wxEVT_UPDATE_UI, &MoveObjectsToolPage::OnUpdateButton, this); 44 m_button->Bind(wxEVT_BUTTON, &MoveObjectsToolPage::OnApply, this); 45 46 wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); 47 sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL); 48 sizer->AddSpacer(LayoutConstants::NarrowHMargin); 49 sizer->Add(m_offset, 0, wxALIGN_CENTER_VERTICAL); 50 sizer->AddSpacer(LayoutConstants::NarrowHMargin); 51 sizer->Add(m_button, 0, wxALIGN_CENTER_VERTICAL); 52 53 SetSizer(sizer); 54 } 55 OnUpdateButton(wxUpdateUIEvent & event)56 void MoveObjectsToolPage::OnUpdateButton(wxUpdateUIEvent& event) { 57 if (IsBeingDeleted()) return; 58 59 MapDocumentSPtr document = lock(m_document); 60 event.Enable(document->hasSelectedNodes()); 61 } 62 OnApply(wxCommandEvent & event)63 void MoveObjectsToolPage::OnApply(wxCommandEvent& event) { 64 if (IsBeingDeleted()) return; 65 66 const Vec3 delta = Vec3::parse(m_offset->GetValue().ToStdString()); 67 68 MapDocumentSPtr document = lock(m_document); 69 document->translateObjects(delta); 70 } 71 } 72 } 73