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 "FlashSelectionAnimation.h" 21 22 #include "Color.h" 23 #include "PreferenceManager.h" 24 #include "Preferences.h" 25 #include "Renderer/MapRenderer.h" 26 27 #include <wx/window.h> 28 29 namespace TrenchBroom { 30 namespace View { 31 const Animation::Type FlashSelectionAnimation::AnimationType = Animation::freeType(); 32 FlashSelectionAnimation(Renderer::MapRenderer & renderer,wxWindow & view,const wxLongLong duration)33 FlashSelectionAnimation::FlashSelectionAnimation(Renderer::MapRenderer& renderer, wxWindow& view, const wxLongLong duration) : 34 Animation(AnimationType, Curve_EaseInEaseOut, duration), 35 m_renderer(renderer), 36 m_view(view) {} 37 doUpdate(const double progress)38 void FlashSelectionAnimation::doUpdate(const double progress) { 39 static const Color white(1.0f, 1.0f, 1.0f, 1.0f); 40 41 const float fltProgress = static_cast<float>(progress); 42 if (fltProgress < 1.0f) { 43 // factor ranges from 0 to 1 and then back to 0 44 const float factor = fltProgress < 0.5f ? 2.0f * fltProgress : 1.0f - 2.0f * (fltProgress - 0.5f); 45 m_renderer.overrideSelectionColors(white, factor * 0.8f); 46 } else { 47 m_renderer.restoreSelectionColors(); 48 } 49 50 m_view.Refresh(); 51 } 52 } 53 } 54