1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * d-dazzle 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 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.Animation; 20 21 private import dazzle.c.functions; 22 public import dazzle.c.types; 23 private import gdk.MonitorG; 24 private import gobject.ObjectG; 25 private import gobject.ParamSpec; 26 private import gobject.Signals; 27 private import gobject.Value; 28 private import std.algorithm; 29 30 31 /** */ 32 public class Animation : ObjectG 33 { 34 /** the main Gtk struct */ 35 protected DzlAnimation* dzlAnimation; 36 37 /** Get the main Gtk struct */ 38 public DzlAnimation* getAnimationStruct(bool transferOwnership = false) 39 { 40 if (transferOwnership) 41 ownedRef = false; 42 return dzlAnimation; 43 } 44 45 /** the main Gtk struct as a void* */ 46 protected override void* getStruct() 47 { 48 return cast(void*)dzlAnimation; 49 } 50 51 /** 52 * Sets our main struct and passes it to the parent class. 53 */ 54 public this (DzlAnimation* dzlAnimation, bool ownedRef = false) 55 { 56 this.dzlAnimation = dzlAnimation; 57 super(cast(GObject*)dzlAnimation, ownedRef); 58 } 59 60 61 /** */ 62 public static GType getType() 63 { 64 return dzl_animation_get_type(); 65 } 66 67 /** */ 68 public static uint calculateDuration(MonitorG monitor, double fromValue, double toValue) 69 { 70 return dzl_animation_calculate_duration((monitor is null) ? null : monitor.getMonitorGStruct(), fromValue, toValue); 71 } 72 73 /** 74 * Adds a new property to the set of properties to be animated during the 75 * lifetime of the animation. 76 * 77 * Side effects: None. 78 * 79 * Params: 80 * pspec = A #ParamSpec of @target or a #GtkWidget<!-- -->'s parent. 81 * value = The new value for the property at the end of the animation. 82 */ 83 public void addProperty(ParamSpec pspec, Value value) 84 { 85 dzl_animation_add_property(dzlAnimation, (pspec is null) ? null : pspec.getParamSpecStruct(), (value is null) ? null : value.getValueStruct()); 86 } 87 88 /** 89 * Start the animation. When the animation stops, the internal reference will 90 * be dropped and the animation may be finalized. 91 * 92 * Side effects: None. 93 */ 94 public void start() 95 { 96 dzl_animation_start(dzlAnimation); 97 } 98 99 /** 100 * Stops a running animation. The internal reference to the animation is 101 * dropped and therefore may cause the object to finalize. 102 * 103 * As a convenience, this function accepts %NULL for @animation but 104 * does nothing if that should occur. 105 */ 106 public void stop() 107 { 108 dzl_animation_stop(dzlAnimation); 109 } 110 111 /** 112 * The "tick" signal is emitted on each frame in the animation. 113 */ 114 gulong addOnTick(void delegate(Animation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 115 { 116 return Signals.connect(this, "tick", dlg, connectFlags ^ ConnectFlags.SWAPPED); 117 } 118 }