1 /* 2 * this file is part of the oxygen gtk engine 3 * Copyright (c) 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or(at your option ) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 18 * MA 02110-1301, USA. 19 */ 20 21 #include "oxygenfollowmousedata.h" 22 23 namespace Oxygen 24 { 25 26 //________________________________________________________________________________ startAnimation(const GdkRectangle & startRect,const GdkRectangle & endRect)27 void FollowMouseData::startAnimation( const GdkRectangle& startRect, const GdkRectangle& endRect ) 28 { 29 30 // copy end rect 31 _endRect = endRect; 32 33 // check timeLine status 34 if( _timeLine.isRunning() && 35 _timeLine.value() < 1.0 && 36 Gtk::gdk_rectangle_is_valid( &_endRect ) && 37 Gtk::gdk_rectangle_is_valid( &_animatedRect ) ) 38 { 39 40 // mark old start rect as part of dirtyRect 41 _dirtyRect = _startRect; 42 43 // do some math so that the animation finishes at new endRect without discontinuity 44 const double ratio( _timeLine.value()/(1.0-_timeLine.value() ) ); 45 _startRect.x += double( _animatedRect.x - _endRect.x )*ratio; 46 _startRect.y += double( _animatedRect.y - _endRect.y )*ratio; 47 _startRect.width += double( _animatedRect.width - _endRect.width )*ratio; 48 _startRect.height += double( _animatedRect.height - _endRect.height )*ratio; 49 50 51 } else { 52 53 if( _timeLine.isRunning() ) _timeLine.stop(); 54 _startRect = startRect; 55 _timeLine.start(); 56 57 } 58 59 return; 60 61 } 62 63 //________________________________________________________________________________ updateAnimatedRect(void)64 void FollowMouseData::updateAnimatedRect( void ) 65 { 66 if( _timeLine.isRunning() && 67 Gtk::gdk_rectangle_is_valid( &_startRect ) && 68 Gtk::gdk_rectangle_is_valid( &_endRect ) ) 69 { 70 71 _animatedRect.x = _startRect.x + double( _endRect.x - _startRect.x )*_timeLine.value(); 72 _animatedRect.y = _startRect.y + double( _endRect.y - _startRect.y )*_timeLine.value(); 73 _animatedRect.width = _startRect.width + double( _endRect.width - _startRect.width )*_timeLine.value(); 74 _animatedRect.height = _startRect.height + double( _endRect.height - _startRect.height )*_timeLine.value(); 75 76 } else { 77 78 _animatedRect = Gtk::gdk_rectangle(); 79 80 } 81 82 return; 83 84 } 85 86 //________________________________________________________________________________ dirtyRect(void)87 GdkRectangle FollowMouseData::dirtyRect( void ) 88 { 89 90 GdkRectangle rect( Gtk::gdk_rectangle() ); 91 Gtk::gdk_rectangle_union( &_startRect, &_animatedRect, &rect ); 92 93 // also union with dirty rect 94 if( Gtk::gdk_rectangle_is_valid( &_dirtyRect ) ) 95 { 96 Gtk::gdk_rectangle_union( &_dirtyRect, &rect, &rect ); 97 _dirtyRect = Gtk::gdk_rectangle(); 98 } 99 100 return rect; 101 102 } 103 104 105 } 106