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 "Tool.h" 21 22 #include "IO/ResourceUtils.h" 23 24 #include <wx/bookctrl.h> 25 #include <wx/panel.h> 26 27 #include <cassert> 28 29 namespace TrenchBroom { 30 namespace View { Tool(const bool initiallyActive)31 Tool::Tool(const bool initiallyActive) : 32 m_active(initiallyActive), 33 m_book(NULL), 34 m_pageIndex(0) {} 35 ~Tool()36 Tool::~Tool() {} 37 active() const38 bool Tool::active() const { 39 return m_active; 40 } 41 activate()42 bool Tool::activate() { 43 assert(!active()); 44 if (doActivate()) { 45 m_active = true; 46 toolActivatedNotifier(this); 47 } 48 return m_active; 49 } 50 deactivate()51 bool Tool::deactivate() { 52 assert(active()); 53 if (doDeactivate()) { 54 m_active = false; 55 toolDeactivatedNotifier(this); 56 } 57 return !m_active; 58 } 59 refreshViews()60 void Tool::refreshViews() { 61 refreshViewsNotifier(this); 62 } 63 createPage(wxBookCtrlBase * book)64 void Tool::createPage(wxBookCtrlBase* book) { 65 assert(m_book == NULL); 66 67 m_book = book; 68 m_pageIndex = m_book->GetPageCount(); 69 m_book->AddPage(doCreatePage(m_book), ""); 70 } 71 showPage()72 void Tool::showPage() { 73 m_book->SetSelection(m_pageIndex); 74 } 75 icon() const76 wxBitmap Tool::icon() const { 77 return IO::loadImageResource(doGetIconName()); 78 } 79 doActivate()80 bool Tool::doActivate() { 81 return true; 82 } 83 doDeactivate()84 bool Tool::doDeactivate() { 85 return true; 86 } 87 doCreatePage(wxWindow * parent)88 wxWindow* Tool::doCreatePage(wxWindow* parent) { 89 return new wxPanel(parent); 90 } 91 doGetIconName() const92 String Tool::doGetIconName() const { 93 return "NoTool.png"; 94 } 95 } 96 } 97