File indexing completed on 2024-05-12 05:34:33
0001 /* 0002 this file is part of the oxygen gtk engine 0003 SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "oxygenfollowmousedata.h" 0009 0010 namespace Oxygen 0011 { 0012 0013 //________________________________________________________________________________ 0014 void FollowMouseData::startAnimation( const GdkRectangle& startRect, const GdkRectangle& endRect ) 0015 { 0016 0017 // copy end rect 0018 _endRect = endRect; 0019 0020 // check timeLine status 0021 if( _timeLine.isRunning() && 0022 _timeLine.value() < 1.0 && 0023 Gtk::gdk_rectangle_is_valid( &_endRect ) && 0024 Gtk::gdk_rectangle_is_valid( &_animatedRect ) ) 0025 { 0026 0027 // mark old start rect as part of dirtyRect 0028 _dirtyRect = _startRect; 0029 0030 // do some math so that the animation finishes at new endRect without discontinuity 0031 const double ratio( _timeLine.value()/(1.0-_timeLine.value() ) ); 0032 _startRect.x += double( _animatedRect.x - _endRect.x )*ratio; 0033 _startRect.y += double( _animatedRect.y - _endRect.y )*ratio; 0034 _startRect.width += double( _animatedRect.width - _endRect.width )*ratio; 0035 _startRect.height += double( _animatedRect.height - _endRect.height )*ratio; 0036 0037 0038 } else { 0039 0040 if( _timeLine.isRunning() ) _timeLine.stop(); 0041 _startRect = startRect; 0042 _timeLine.start(); 0043 0044 } 0045 0046 return; 0047 0048 } 0049 0050 //________________________________________________________________________________ 0051 void FollowMouseData::updateAnimatedRect( void ) 0052 { 0053 if( _timeLine.isRunning() && 0054 Gtk::gdk_rectangle_is_valid( &_startRect ) && 0055 Gtk::gdk_rectangle_is_valid( &_endRect ) ) 0056 { 0057 0058 _animatedRect.x = _startRect.x + double( _endRect.x - _startRect.x )*_timeLine.value(); 0059 _animatedRect.y = _startRect.y + double( _endRect.y - _startRect.y )*_timeLine.value(); 0060 _animatedRect.width = _startRect.width + double( _endRect.width - _startRect.width )*_timeLine.value(); 0061 _animatedRect.height = _startRect.height + double( _endRect.height - _startRect.height )*_timeLine.value(); 0062 0063 } else { 0064 0065 _animatedRect = Gtk::gdk_rectangle(); 0066 0067 } 0068 0069 return; 0070 0071 } 0072 0073 //________________________________________________________________________________ 0074 GdkRectangle FollowMouseData::dirtyRect( void ) 0075 { 0076 0077 GdkRectangle rect( Gtk::gdk_rectangle() ); 0078 Gtk::gdk_rectangle_union( &_startRect, &_animatedRect, &rect ); 0079 0080 // also union with dirty rect 0081 if( Gtk::gdk_rectangle_is_valid( &_dirtyRect ) ) 0082 { 0083 Gtk::gdk_rectangle_union( &_dirtyRect, &rect, &rect ); 0084 _dirtyRect = Gtk::gdk_rectangle(); 0085 } 0086 0087 return rect; 0088 0089 } 0090 0091 0092 }