1/* 2* Copyright (c) 2018 (https://github.com/phase1geo/Minder) 3* 4* This program is free software; you can redistribute it and/or 5* modify it under the terms of the GNU General Public 6* License as published by the Free Software Foundation; either 7* version 2 of the License, or (at your option) any later version. 8* 9* This program is distributed in the hope that it will be useful, 10* but WITHOUT ANY WARRANTY; without even the implied warranty of 11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12* General Public License for more details. 13* 14* You should have received a copy of the GNU General Public 15* License along with this program; if not, write to the 16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17* Boston, MA 02110-1301 USA 18* 19* Authored by: Trevor Williams <phase1geo@gmail.com> 20*/ 21 22using GLib; 23 24public class AnimatorNodes : AnimatorAction { 25 26 uint _num; 27 private AnimatorPositions _pos; 28 29 /* Default constructor */ 30 public AnimatorNodes( DrawArea da, Array<Node> n, string name = "unnamed" ) { 31 base( name ); 32 _num = n.length; 33 _pos = new AnimatorPositions( da, n ); 34 } 35 36 /* Returns the NODES types */ 37 public override AnimationType type() { 38 return( (_num > 1) ? AnimationType.NODES : AnimationType.NODE ); 39 } 40 41 /* Captures the end state */ 42 public override void capture( DrawArea da ) { 43 _pos.gather_new_positions(); 44 } 45 46 /* Adjusts all of the node positions for the given frame */ 47 public override void adjust( DrawArea da ) { 48 double divisor = index / frames; 49 index++; 50 for( int i=0; i<_pos.length(); i++ ) { 51 double dx = _pos.new_x( i ) - _pos.old_x( i ); 52 double dy = _pos.new_y( i ) - _pos.old_y( i ); 53 double x = _pos.old_x( i ) + (dx * divisor); 54 double y = _pos.old_y( i ) + (dy * divisor); 55 _pos.node( i ).posx = x; 56 _pos.node( i ).posy = y; 57 _pos.node( i ).side = _pos.node( i ).layout.get_side( _pos.node( i ) ); 58 } 59 } 60 61} 62 63