1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614
|
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2008 Intel Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author:
* Emmanuele Bassi <ebassi@linux.intel.com>
*/
/**
* SECTION:clutter-animation
* @short_description: Simple implicit animations
* @See_Also: #ClutterAnimatable, #ClutterInterval, #ClutterAlpha,
* #ClutterTimeline
*
* #ClutterAnimation is an object providing simple, implicit animations
* for #GObjects.
*
* #ClutterAnimation instances will bind one or more #GObject properties
* belonging to a #GObject to a #ClutterInterval, and will then use a
* #ClutterAlpha to interpolate the property between the initial and final
* values of the interval.
*
* The duration of the animation is set using clutter_animation_set_duration().
* The easing mode of the animation is set using clutter_animation_set_mode().
*
* If you want to control the animation you should retrieve the
* #ClutterTimeline using clutter_animation_get_timeline() and then
* use #ClutterTimeline functions like clutter_timeline_start(),
* clutter_timeline_pause() or clutter_timeline_stop().
*
* A #ClutterAnimation will emit the #ClutterAnimation::completed signal
* when the #ClutterTimeline used by the animation is completed; unlike
* #ClutterTimeline, though, the #ClutterAnimation::completed will not be
* emitted if #ClutterAnimation:loop is set to %TRUE - that is, a looping
* animation never completes.
*
* If your animation depends on user control you can force its completion
* using clutter_animation_completed().
*
* If the #GObject instance bound to a #ClutterAnimation implements the
* #ClutterAnimatable interface it is possible for that instance to
* control the way the initial and final states are interpolated.
*
* #ClutterAnimations are distinguished from #ClutterBehaviours
* because the former can only control #GObject properties of a single
* #GObject instance, while the latter can control multiple properties
* using accessor functions inside the #ClutterBehaviour
* `alpha_notify` virtual function, and can control multiple #ClutterActors
* as well.
*
* For convenience, it is possible to use the clutter_actor_animate()
* function call which will take care of setting up and tearing down
* a #ClutterAnimation instance and animate an actor between its current
* state and the specified final state.
*
* #ClutterAnimation is available since Clutter 1.0.
*
* #ClutterAnimation has been deprecated in Clutter 1.12.
*
* ## Defining ClutterAnimationMode inside ClutterScript
*
* When defining a #ClutterAnimation inside a ClutterScript
* file or string the #ClutterAnimation:mode can be defined either
* using the #ClutterAnimationMode enumeration values through their
* "nick" (the short string used inside #GEnumValue), their numeric
* id, or using the following strings:
*
* - easeInQuad, easeOutQuad, easeInOutQuad
* - easeInCubic, easeOutCubic, easeInOutCubic
* - easeInQuart, easeOutQuart, easeInOutQuart
* - easeInQuint, easeOutQuint, easeInOutQuint
* - easeInSine, easeOutSine, easeInOutSine
* - easeInExpo, easeOutExpo, easeInOutExpo
* - easeInCirc, easeOutCirc, easeInOutCirc
* - easeInElastic, easeOutElastic, easeInOutElastic
* - easeInBack, easeOutBack, easeInOutBack
* - easeInBounce, easeOutBounce, easeInOutBounce
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib-object.h>
#include <gobject/gvaluecollector.h>
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include "clutter-alpha.h"
#include "clutter-animatable.h"
#include "clutter-animation.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-interval.h"
#include "clutter-marshal.h"
#include "clutter-private.h"
#include "clutter-scriptable.h"
#include "clutter-script-private.h"
#include "deprecated/clutter-animation.h"
enum
{
PROP_0,
PROP_OBJECT,
PROP_MODE,
PROP_DURATION,
PROP_LOOP,
PROP_TIMELINE,
PROP_ALPHA,
PROP_LAST
};
static GParamSpec *obj_props[PROP_LAST];
enum
{
STARTED,
COMPLETED,
LAST_SIGNAL
};
struct _ClutterAnimationPrivate
{
GObject *object;
GHashTable *properties;
ClutterAlpha *alpha;
ClutterTimeline *timeline;
guint timeline_started_id;
guint timeline_completed_id;
guint timeline_frame_id;
};
static guint animation_signals[LAST_SIGNAL] = { 0, };
static GQuark quark_object_animation = 0;
static void clutter_scriptable_init (ClutterScriptableIface *iface);
static void clutter_animation_set_alpha_internal (ClutterAnimation *animation,
ClutterAlpha *alpha);
static ClutterAlpha * clutter_animation_get_alpha_internal (ClutterAnimation *animation);
static ClutterTimeline * clutter_animation_get_timeline_internal (ClutterAnimation *animation);
G_DEFINE_TYPE_WITH_CODE (ClutterAnimation, clutter_animation, G_TYPE_OBJECT,
G_ADD_PRIVATE (ClutterAnimation)
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
clutter_scriptable_init));
static ClutterAlpha *
clutter_animation_get_alpha_internal (ClutterAnimation *animation)
{
ClutterAnimationPrivate *priv = animation->priv;
if (priv->alpha == NULL)
{
ClutterAlpha *alpha;
alpha = clutter_alpha_new ();
clutter_alpha_set_mode (alpha, CLUTTER_LINEAR);
priv->alpha = g_object_ref_sink (alpha);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_ALPHA]);
}
return priv->alpha;
}
static void
on_actor_destroy (ClutterActor *actor,
ClutterAnimation *animation)
{
ClutterAnimationPrivate *priv = animation->priv;
GObject *obj = G_OBJECT (actor);
if (obj == priv->object)
{
g_object_set_qdata (priv->object, quark_object_animation, NULL);
g_signal_handlers_disconnect_by_func (priv->object,
G_CALLBACK (on_actor_destroy),
animation);
g_object_unref (animation);
}
}
static void
clutter_animation_real_completed (ClutterAnimation *self)
{
ClutterAnimationPrivate *priv = self->priv;
ClutterAnimatable *animatable = NULL;
ClutterAnimation *animation;
ClutterTimeline *timeline;
ClutterTimelineDirection direction;
gpointer key, value;
GHashTableIter iter;
timeline = clutter_animation_get_timeline (self);
direction = clutter_timeline_get_direction (timeline);
if (CLUTTER_IS_ANIMATABLE (priv->object))
animatable = CLUTTER_ANIMATABLE (priv->object);
/* explicitly set the final state of the animation */
CLUTTER_NOTE (ANIMATION, "Set final state on object [%p]", priv->object);
g_hash_table_iter_init (&iter, priv->properties);
while (g_hash_table_iter_next (&iter, &key, &value))
{
const gchar *p_name = key;
ClutterInterval *interval = value;
GValue *p_value;
if (direction == CLUTTER_TIMELINE_FORWARD)
p_value = clutter_interval_peek_final_value (interval);
else
p_value = clutter_interval_peek_initial_value (interval);
if (animatable != NULL)
clutter_animatable_set_final_state (animatable, p_name, p_value);
else
g_object_set_property (priv->object, p_name, p_value);
}
/* at this point, if this animation was created by clutter_actor_animate()
* and friends, the animation will be attached to the object's data; since
* we want to allow developers to use g_signal_connect_after("completed")
* to concatenate a new animation, we need to remove the animation back
* pointer here, and unref() the animation. FIXME - we might want to
* provide a clutter_animation_attach()/clutter_animation_detach() pair
* to let the user reattach an animation
*/
animation = g_object_get_qdata (priv->object, quark_object_animation);
if (animation == self)
{
CLUTTER_NOTE (ANIMATION, "Unsetting animation for actor [%p]",
priv->object);
g_object_set_qdata (priv->object, quark_object_animation, NULL);
g_signal_handlers_disconnect_by_func (priv->object,
G_CALLBACK (on_actor_destroy),
animation);
CLUTTER_NOTE (ANIMATION, "Releasing the reference Animation [%p]",
animation);
g_object_unref (animation);
}
}
static void
clutter_animation_finalize (GObject *gobject)
{
ClutterAnimationPrivate *priv = CLUTTER_ANIMATION (gobject)->priv;
CLUTTER_NOTE (ANIMATION,
"Destroying properties table for Animation [%p]",
gobject);
g_hash_table_destroy (priv->properties);
G_OBJECT_CLASS (clutter_animation_parent_class)->finalize (gobject);
}
static void
clutter_animation_dispose (GObject *gobject)
{
ClutterAnimationPrivate *priv = CLUTTER_ANIMATION (gobject)->priv;
ClutterTimeline *timeline;
if (priv->alpha != NULL)
timeline = clutter_alpha_get_timeline (priv->alpha);
else
timeline = priv->timeline;
if (timeline != NULL && priv->timeline_started_id != 0)
g_signal_handler_disconnect (timeline, priv->timeline_started_id);
if (timeline != NULL && priv->timeline_completed_id != 0)
g_signal_handler_disconnect (timeline, priv->timeline_completed_id);
if (timeline != NULL && priv->timeline_frame_id != 0)
g_signal_handler_disconnect (timeline, priv->timeline_frame_id);
priv->timeline_started_id = 0;
priv->timeline_completed_id = 0;
priv->timeline_frame_id = 0;
if (priv->timeline != NULL)
{
g_object_unref (priv->timeline);
priv->timeline = NULL;
}
if (priv->alpha != NULL)
{
g_object_unref (priv->alpha);
priv->alpha = NULL;
}
if (priv->object != NULL)
{
g_object_unref (priv->object);
priv->object = NULL;
}
G_OBJECT_CLASS (clutter_animation_parent_class)->dispose (gobject);
}
static void
clutter_animation_set_property (GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterAnimation *animation = CLUTTER_ANIMATION (gobject);
switch (prop_id)
{
case PROP_OBJECT:
clutter_animation_set_object (animation, g_value_get_object (value));
break;
case PROP_MODE:
clutter_animation_set_mode (animation, g_value_get_ulong (value));
break;
case PROP_DURATION:
clutter_animation_set_duration (animation, g_value_get_uint (value));
break;
case PROP_LOOP:
clutter_animation_set_loop (animation, g_value_get_boolean (value));
break;
case PROP_TIMELINE:
clutter_animation_set_timeline (animation, g_value_get_object (value));
break;
case PROP_ALPHA:
clutter_animation_set_alpha_internal (animation, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static void
clutter_animation_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterAnimation *animation = CLUTTER_ANIMATION (gobject);
ClutterAnimationPrivate *priv = animation->priv;
switch (prop_id)
{
case PROP_OBJECT:
g_value_set_object (value, priv->object);
break;
case PROP_MODE:
g_value_set_ulong (value, clutter_animation_get_mode (animation));
break;
case PROP_DURATION:
g_value_set_uint (value, clutter_animation_get_duration (animation));
break;
case PROP_LOOP:
g_value_set_boolean (value, clutter_animation_get_loop (animation));
break;
case PROP_TIMELINE:
g_value_set_object (value, clutter_animation_get_timeline (animation));
break;
case PROP_ALPHA:
g_value_set_object (value, clutter_animation_get_alpha_internal (animation));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static gboolean
clutter_animation_parse_custom_node (ClutterScriptable *scriptable,
ClutterScript *script,
GValue *value,
const gchar *name,
JsonNode *node)
{
if (strncmp (name, "mode", 4) == 0)
{
gulong mode;
mode = _clutter_script_resolve_animation_mode (node);
g_value_init (value, G_TYPE_ULONG);
g_value_set_ulong (value, mode);
return TRUE;
}
return FALSE;
}
static void
clutter_scriptable_init (ClutterScriptableIface *iface)
{
iface->parse_custom_node = clutter_animation_parse_custom_node;
}
static void
clutter_animation_class_init (ClutterAnimationClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
quark_object_animation =
g_quark_from_static_string ("clutter-actor-animation");
klass->completed = clutter_animation_real_completed;
gobject_class->set_property = clutter_animation_set_property;
gobject_class->get_property = clutter_animation_get_property;
gobject_class->dispose = clutter_animation_dispose;
gobject_class->finalize = clutter_animation_finalize;
/**
* ClutterAnimation:object:
*
* The #GObject to which the animation applies.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
obj_props[PROP_OBJECT] =
g_param_spec_object ("object",
P_("Object"),
P_("Object to which the animation applies"),
G_TYPE_OBJECT,
CLUTTER_PARAM_READWRITE);
/**
* ClutterAnimation:mode:
*
* The animation mode, either a value from #ClutterAnimationMode
* or a value returned by clutter_alpha_register_func(). The
* default value is %CLUTTER_LINEAR.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
obj_props[PROP_MODE] =
g_param_spec_ulong ("mode",
P_("Mode"),
P_("The mode of the animation"),
0, G_MAXULONG,
CLUTTER_LINEAR,
CLUTTER_PARAM_READWRITE);
/**
* ClutterAnimation:duration:
*
* The duration of the animation, expressed in milliseconds.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
obj_props[PROP_DURATION] =
g_param_spec_uint ("duration",
P_("Duration"),
P_("Duration of the animation, in milliseconds"),
0, G_MAXUINT,
0,
CLUTTER_PARAM_READWRITE);
/**
* ClutterAnimation:loop:
*
* Whether the animation should loop.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
obj_props[PROP_LOOP] =
g_param_spec_boolean ("loop",
P_("Loop"),
P_("Whether the animation should loop"),
FALSE,
CLUTTER_PARAM_READWRITE);
/**
* ClutterAnimation:timeline:
*
* The #ClutterTimeline used by the animation.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
obj_props[PROP_TIMELINE] =
g_param_spec_object ("timeline",
P_("Timeline"),
P_("The timeline used by the animation"),
CLUTTER_TYPE_TIMELINE,
CLUTTER_PARAM_READWRITE);
/**
* ClutterAnimation:alpha:
*
* The #ClutterAlpha used by the animation.
*
* Since: 1.0
*
* Deprecated: 1.10: Use the #ClutterAnimation:timeline property and
* the #ClutterTimeline:progress-mode property instead.
*/
obj_props[PROP_ALPHA] =
g_param_spec_object ("alpha",
P_("Alpha"),
P_("The alpha used by the animation"),
CLUTTER_TYPE_ALPHA,
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_properties (gobject_class,
PROP_LAST,
obj_props);
/**
* ClutterAnimation::started:
* @animation: the animation that emitted the signal
*
* The ::started signal is emitted once the animation has been
* started
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
animation_signals[STARTED] =
g_signal_new (I_("started"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterAnimationClass, started),
NULL, NULL,
_clutter_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* ClutterAnimation::completed:
* @animation: the animation that emitted the signal
*
* The ::completed signal is emitted once the animation has
* been completed.
*
* The @animation instance is guaranteed to be valid for the entire
* duration of the signal emission chain.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
animation_signals[COMPLETED] =
g_signal_new (I_("completed"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterAnimationClass, completed),
NULL, NULL,
_clutter_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
clutter_animation_init (ClutterAnimation *self)
{
self->priv = clutter_animation_get_instance_private (self);
self->priv->properties =
g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_object_unref);
}
static inline void
clutter_animation_bind_property_internal (ClutterAnimation *animation,
const gchar *property_name,
GParamSpec *pspec,
ClutterInterval *interval)
{
ClutterAnimationPrivate *priv = animation->priv;
if (!clutter_interval_validate (interval, pspec))
{
g_warning ("Cannot bind property '%s': the interval is out "
"of bounds",
property_name);
return;
}
g_hash_table_insert (priv->properties,
g_strdup (property_name),
g_object_ref_sink (interval));
}
static inline void
clutter_animation_update_property_internal (ClutterAnimation *animation,
const gchar *property_name,
GParamSpec *pspec,
ClutterInterval *interval)
{
ClutterAnimationPrivate *priv = animation->priv;
if (!clutter_interval_validate (interval, pspec))
{
g_warning ("Cannot bind property '%s': the interval is out "
"of bounds",
property_name);
return;
}
g_hash_table_replace (priv->properties,
g_strdup (property_name),
g_object_ref_sink (interval));
}
static GParamSpec *
clutter_animation_validate_bind (ClutterAnimation *animation,
const char *property_name,
GType argtype)
{
ClutterAnimationPrivate *priv;
GParamSpec *pspec;
GType pspec_type;
priv = animation->priv;
if (G_UNLIKELY (!priv->object))
{
g_warning ("Cannot bind property '%s': the animation has no "
"object set. You need to call clutter_animation_set_object() "
"first to be able to bind a property",
property_name);
return NULL;
}
if (G_UNLIKELY (clutter_animation_has_property (animation, property_name)))
{
g_warning ("Cannot bind property '%s': the animation already has "
"a bound property with the same name",
property_name);
return NULL;
}
if (CLUTTER_IS_ANIMATABLE (priv->object))
{
ClutterAnimatable *animatable = CLUTTER_ANIMATABLE (priv->object);
pspec = clutter_animatable_find_property (animatable, property_name);
}
else
{
GObjectClass *klass = G_OBJECT_GET_CLASS (priv->object);
pspec = g_object_class_find_property (klass, property_name);
}
if (pspec == NULL)
{
g_warning ("Cannot bind property '%s': objects of type '%s' have "
"no such property",
property_name,
g_type_name (G_OBJECT_TYPE (priv->object)));
return NULL;
}
if (!(pspec->flags & G_PARAM_WRITABLE))
{
g_warning ("Cannot bind property '%s': the property is not writable",
property_name);
return NULL;
}
pspec_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
if (g_value_type_transformable (argtype, pspec_type))
return pspec;
else
{
g_warning ("Cannot bind property '%s': the interval value of "
"type '%s' is not compatible with the property value "
"of type '%s'",
property_name,
g_type_name (argtype),
g_type_name (pspec_type));
return NULL;
}
}
/**
* clutter_animation_bind_interval:
* @animation: a #ClutterAnimation
* @property_name: the property to control
* @interval: (transfer full): a #ClutterInterval
*
* Binds @interval to the @property_name of the #GObject
* attached to @animation. The #ClutterAnimation will take
* ownership of the passed #ClutterInterval. For more information
* about animations, see clutter_actor_animate().
*
* If you need to update the interval instance use
* clutter_animation_update_interval() instead.
*
* Return value: (transfer none): The animation itself.
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
ClutterAnimation *
clutter_animation_bind_interval (ClutterAnimation *animation,
const gchar *property_name,
ClutterInterval *interval)
{
GParamSpec *pspec;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
g_return_val_if_fail (CLUTTER_IS_INTERVAL (interval), NULL);
pspec = clutter_animation_validate_bind (animation, property_name,
clutter_interval_get_value_type (interval));
if (pspec == NULL)
return NULL;
clutter_animation_bind_property_internal (animation, property_name,
pspec,
interval);
return animation;
}
/**
* clutter_animation_bind:
* @animation: a #ClutterAnimation
* @property_name: the property to control
* @final: The final value of the property
*
* Adds a single property with name @property_name to the
* animation @animation. For more information about animations,
* see clutter_actor_animate().
*
* This method returns the animation primarily to make chained
* calls convenient in language bindings.
*
* Return value: (transfer none): The animation itself.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
ClutterAnimation *
clutter_animation_bind (ClutterAnimation *animation,
const gchar *property_name,
const GValue *final)
{
ClutterAnimationPrivate *priv;
GParamSpec *pspec;
ClutterInterval *interval;
GType type;
GValue initial = G_VALUE_INIT;
GValue real_final = G_VALUE_INIT;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
priv = animation->priv;
type = G_VALUE_TYPE (final);
pspec = clutter_animation_validate_bind (animation, property_name, type);
if (pspec == NULL)
return NULL;
g_value_init (&real_final, G_PARAM_SPEC_VALUE_TYPE (pspec));
if (!g_value_transform (final, &real_final))
{
g_value_unset (&real_final);
g_warning ("Unable to transform the value of type '%s' to a value "
"of '%s' compatible with the property '%s'of the object "
"of type '%s'",
g_type_name (type),
g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
property_name,
G_OBJECT_TYPE_NAME (priv->object));
return NULL;
}
g_value_init (&initial, G_PARAM_SPEC_VALUE_TYPE (pspec));
if (CLUTTER_IS_ANIMATABLE (priv->object))
clutter_animatable_get_initial_state (CLUTTER_ANIMATABLE (priv->object),
property_name,
&initial);
else
g_object_get_property (priv->object, property_name, &initial);
interval = clutter_interval_new_with_values (G_PARAM_SPEC_VALUE_TYPE (pspec),
&initial,
&real_final);
g_value_unset (&initial);
g_value_unset (&real_final);
clutter_animation_bind_property_internal (animation, property_name,
pspec,
interval);
return animation;
}
/**
* clutter_animation_unbind_property:
* @animation: a #ClutterAnimation
* @property_name: name of the property
*
* Removes @property_name from the list of animated properties.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_unbind_property (ClutterAnimation *animation,
const gchar *property_name)
{
ClutterAnimationPrivate *priv;
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_return_if_fail (property_name != NULL);
priv = animation->priv;
if (!clutter_animation_has_property (animation, property_name))
{
g_warning ("Cannot unbind property '%s': the animation has "
"no bound property with that name",
property_name);
return;
}
g_hash_table_remove (priv->properties, property_name);
}
/**
* clutter_animation_has_property:
* @animation: a #ClutterAnimation
* @property_name: name of the property
*
* Checks whether @animation is controlling @property_name.
*
* Return value: %TRUE if the property is animated by the
* #ClutterAnimation, %FALSE otherwise
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
gboolean
clutter_animation_has_property (ClutterAnimation *animation,
const gchar *property_name)
{
ClutterAnimationPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), FALSE);
g_return_val_if_fail (property_name != NULL, FALSE);
priv = animation->priv;
return g_hash_table_lookup (priv->properties, property_name) != NULL;
}
/**
* clutter_animation_update_interval:
* @animation: a #ClutterAnimation
* @property_name: name of the property
* @interval: a #ClutterInterval
*
* Changes the @interval for @property_name. The #ClutterAnimation
* will take ownership of the passed #ClutterInterval.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_update_interval (ClutterAnimation *animation,
const gchar *property_name,
ClutterInterval *interval)
{
ClutterAnimationPrivate *priv;
GParamSpec *pspec;
GType pspec_type, int_type;
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_return_if_fail (property_name != NULL);
g_return_if_fail (CLUTTER_IS_INTERVAL (interval));
priv = animation->priv;
if (!clutter_animation_has_property (animation, property_name))
{
g_warning ("Cannot update property '%s': the animation has "
"no bound property with that name",
property_name);
return;
}
if (CLUTTER_IS_ANIMATABLE (priv->object))
{
ClutterAnimatable *animatable = CLUTTER_ANIMATABLE (priv->object);
pspec = clutter_animatable_find_property (animatable, property_name);
}
else
{
GObjectClass *klass = G_OBJECT_GET_CLASS (priv->object);
pspec = g_object_class_find_property (klass, property_name);
}
if (pspec == NULL)
{
g_warning ("Cannot update property '%s': objects of type '%s' have "
"no such property",
property_name,
g_type_name (G_OBJECT_TYPE (priv->object)));
return;
}
pspec_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
int_type = clutter_interval_get_value_type (interval);
if (!g_value_type_compatible (int_type, pspec_type) ||
!g_value_type_transformable (int_type, pspec_type))
{
g_warning ("Cannot update property '%s': the interval value of "
"type '%s' is not compatible with the property value "
"of type '%s'",
property_name,
g_type_name (int_type),
g_type_name (pspec_type));
return;
}
clutter_animation_update_property_internal (animation, property_name,
pspec,
interval);
}
/**
* clutter_animation_update:
* @animation: a #ClutterAnimation
* @property_name: name of the property
* @final: The final value of the property
*
* Updates the @final value of the interval for @property_name
*
* Return value: (transfer none): The animation itself.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
ClutterAnimation *
clutter_animation_update (ClutterAnimation *animation,
const gchar *property_name,
const GValue *final)
{
ClutterInterval *interval;
GType int_type;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
g_return_val_if_fail (final != NULL, NULL);
g_return_val_if_fail (G_VALUE_TYPE (final) != G_TYPE_INVALID, NULL);
interval = clutter_animation_get_interval (animation, property_name);
if (interval == NULL)
{
g_warning ("Cannot update property '%s': the animation has "
"no bound property with that name",
property_name);
return NULL;
}
int_type = clutter_interval_get_value_type (interval);
if (!g_value_type_compatible (G_VALUE_TYPE (final), int_type) ||
!g_value_type_transformable (G_VALUE_TYPE (final), int_type))
{
g_warning ("Cannot update property '%s': the interval value of "
"type '%s' is not compatible with the property value "
"of type '%s'",
property_name,
g_type_name (int_type),
g_type_name (G_VALUE_TYPE (final)));
return NULL;
}
clutter_interval_set_final_value (interval, final);
return animation;
}
/**
* clutter_animation_get_interval:
* @animation: a #ClutterAnimation
* @property_name: name of the property
*
* Retrieves the #ClutterInterval associated to @property_name
* inside @animation.
*
* Return value: (transfer none): a #ClutterInterval or %NULL if no
* property with the same name was found. The returned interval is
* owned by the #ClutterAnimation and should not be unreferenced
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
ClutterInterval *
clutter_animation_get_interval (ClutterAnimation *animation,
const gchar *property_name)
{
ClutterAnimationPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
priv = animation->priv;
return g_hash_table_lookup (priv->properties, property_name);
}
static void
on_timeline_started (ClutterTimeline *timeline,
ClutterAnimation *animation)
{
g_signal_emit (animation, animation_signals[STARTED], 0);
}
static void
on_timeline_completed (ClutterTimeline *timeline,
ClutterAnimation *animation)
{
CLUTTER_NOTE (ANIMATION, "Timeline [%p] complete", timeline);
if (!clutter_animation_get_loop (animation))
g_signal_emit (animation, animation_signals[COMPLETED], 0);
}
static void
on_timeline_frame (ClutterTimeline *timeline,
gint elapsed,
ClutterAnimation *animation)
{
ClutterAnimationPrivate *priv;
GList *properties, *p;
gdouble alpha_value;
gboolean is_animatable = FALSE;
ClutterAnimatable *animatable = NULL;
/* make sure the animation survives the notification */
g_object_ref (animation);
priv = animation->priv;
if (priv->alpha != NULL)
alpha_value = clutter_alpha_get_alpha (priv->alpha);
else
alpha_value = clutter_timeline_get_progress (priv->timeline);
if (CLUTTER_IS_ANIMATABLE (priv->object))
{
animatable = CLUTTER_ANIMATABLE (priv->object);
is_animatable = TRUE;
}
g_object_freeze_notify (priv->object);
properties = g_hash_table_get_keys (priv->properties);
for (p = properties; p != NULL; p = p->next)
{
const gchar *p_name = p->data;
ClutterInterval *interval;
GValue value = G_VALUE_INIT;
gboolean apply;
interval = g_hash_table_lookup (priv->properties, p_name);
g_assert (CLUTTER_IS_INTERVAL (interval));
g_value_init (&value, clutter_interval_get_value_type (interval));
if (is_animatable)
{
apply = clutter_animatable_interpolate_value (animatable, p_name,
interval,
alpha_value,
&value);
}
else
{
apply = clutter_interval_compute_value (interval,
alpha_value,
&value);
}
if (apply)
{
if (is_animatable)
clutter_animatable_set_final_state (animatable, p_name, &value);
else
g_object_set_property (priv->object, p_name, &value);
}
g_value_unset (&value);
}
g_list_free (properties);
g_object_thaw_notify (priv->object);
g_object_unref (animation);
}
static ClutterTimeline *
clutter_animation_get_timeline_internal (ClutterAnimation *animation)
{
ClutterAnimationPrivate *priv = animation->priv;
ClutterTimeline *timeline;
if (priv->timeline != NULL)
return priv->timeline;
if (priv->alpha != NULL)
{
timeline = clutter_alpha_get_timeline (priv->alpha);
if (timeline != NULL)
return timeline;
}
timeline = g_object_new (CLUTTER_TYPE_TIMELINE, NULL);
priv->timeline_started_id =
g_signal_connect (timeline, "started",
G_CALLBACK (on_timeline_started),
animation);
priv->timeline_completed_id =
g_signal_connect (timeline, "completed",
G_CALLBACK (on_timeline_completed),
animation);
priv->timeline_frame_id =
g_signal_connect (timeline, "new-frame",
G_CALLBACK (on_timeline_frame),
animation);
if (priv->alpha != NULL)
{
clutter_alpha_set_timeline (priv->alpha, timeline);
/* the alpha owns the timeline now */
g_object_unref (timeline);
}
priv->timeline = timeline;
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_TIMELINE]);
return priv->timeline;
}
static void
clutter_animation_set_alpha_internal (ClutterAnimation *animation,
ClutterAlpha *alpha)
{
ClutterAnimationPrivate *priv;
ClutterTimeline *timeline;
priv = animation->priv;
if (priv->alpha == alpha)
return;
g_object_freeze_notify (G_OBJECT (animation));
if (priv->alpha != NULL)
timeline = clutter_alpha_get_timeline (priv->alpha);
else
timeline = NULL;
/* disconnect the old timeline first */
if (timeline != NULL && priv->timeline_started_id != 0)
{
g_signal_handler_disconnect (timeline, priv->timeline_started_id);
priv->timeline_started_id = 0;
}
if (timeline != NULL && priv->timeline_completed_id != 0)
{
g_signal_handler_disconnect (timeline, priv->timeline_completed_id);
priv->timeline_completed_id = 0;
}
/* then we need to disconnect the signal handler from the old alpha */
if (timeline != NULL && priv->timeline_frame_id != 0)
{
g_signal_handler_disconnect (timeline, priv->timeline_frame_id);
priv->timeline_frame_id = 0;
}
if (priv->alpha != NULL)
{
/* this will take care of any reference we hold on the timeline */
g_object_unref (priv->alpha);
priv->alpha = NULL;
}
if (alpha == NULL)
goto out;
priv->alpha = g_object_ref_sink (alpha);
/* if the alpha has a timeline then we use it, otherwise we create one */
timeline = clutter_alpha_get_timeline (priv->alpha);
if (timeline != NULL)
{
priv->timeline_started_id =
g_signal_connect (timeline, "started",
G_CALLBACK (on_timeline_started),
animation);
priv->timeline_completed_id =
g_signal_connect (timeline, "completed",
G_CALLBACK (on_timeline_completed),
animation);
priv->timeline_frame_id =
g_signal_connect (timeline, "new-frame",
G_CALLBACK (on_timeline_frame),
animation);
}
else
{
/* FIXME - add a create_timeline_internal() because this does
* not look very good
*/
(void) clutter_animation_get_timeline_internal (animation);
}
out:
/* emit all relevant notifications */
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_MODE]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_DURATION]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_LOOP]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_ALPHA]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_TIMELINE]);
g_object_thaw_notify (G_OBJECT (animation));
}
/**
* clutter_animation_new:
*
* Creates a new #ClutterAnimation instance. You should set the
* #GObject to be animated using clutter_animation_set_object(),
* set the duration with clutter_animation_set_duration() and the
* easing mode using clutter_animation_set_mode().
*
* Use clutter_animation_bind() or clutter_animation_bind_interval()
* to define the properties to be animated. The interval and the
* animated properties can be updated at runtime.
*
* The clutter_actor_animate() and relative family of functions provide
* an easy way to animate a #ClutterActor and automatically manage the
* lifetime of a #ClutterAnimation instance, so you should consider using
* those functions instead of manually creating an animation.
*
* Return value: the newly created #ClutterAnimation. Use g_object_unref()
* to release the associated resources
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
ClutterAnimation *
clutter_animation_new (void)
{
return g_object_new (CLUTTER_TYPE_ANIMATION, NULL);
}
/**
* clutter_animation_set_object:
* @animation: a #ClutterAnimation
* @object: a #GObject
*
* Attaches @animation to @object. The #ClutterAnimation will take a
* reference on @object.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_set_object (ClutterAnimation *animation,
GObject *object)
{
ClutterAnimationPrivate *priv;
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_return_if_fail (object == NULL || G_IS_OBJECT (object));
priv = animation->priv;
if (priv->object != NULL)
{
g_object_set_qdata (priv->object, quark_object_animation, NULL);
g_object_unref (priv->object);
priv->object = NULL;
}
if (object != NULL)
priv->object = g_object_ref (object);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_OBJECT]);
}
/**
* clutter_animation_get_object:
* @animation: a #ClutterAnimation
*
* Retrieves the #GObject attached to @animation.
*
* Return value: (transfer none): a #GObject
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
GObject *
clutter_animation_get_object (ClutterAnimation *animation)
{
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
return animation->priv->object;
}
/**
* clutter_animation_set_mode:
* @animation: a #ClutterAnimation
* @mode: an animation mode logical id
*
* Sets the animation @mode of @animation. The animation @mode is
* a logical id, either coming from the #ClutterAnimationMode enumeration
* or the return value of clutter_alpha_register_func().
*
* This function will also set #ClutterAnimation:alpha if needed.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_set_mode (ClutterAnimation *animation,
gulong mode)
{
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_object_freeze_notify (G_OBJECT (animation));
if (animation->priv->alpha != NULL || mode > CLUTTER_ANIMATION_LAST)
{
ClutterAlpha *alpha;
if (animation->priv->alpha == NULL)
alpha = clutter_animation_get_alpha_internal (animation);
else
alpha = animation->priv->alpha;
clutter_alpha_set_mode (alpha, mode);
}
else
{
ClutterTimeline *timeline;
timeline = clutter_animation_get_timeline_internal (animation);
clutter_timeline_set_progress_mode (timeline, mode);
}
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_MODE]);
g_object_thaw_notify (G_OBJECT (animation));
}
/**
* clutter_animation_get_mode:
* @animation: a #ClutterAnimation
*
* Retrieves the animation mode of @animation, as set by
* clutter_animation_set_mode().
*
* Return value: the mode for the animation
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
gulong
clutter_animation_get_mode (ClutterAnimation *animation)
{
ClutterTimeline *timeline;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), CLUTTER_LINEAR);
if (animation->priv->alpha != NULL)
return clutter_alpha_get_mode (animation->priv->alpha);
timeline = clutter_animation_get_timeline_internal (animation);
return clutter_timeline_get_progress_mode (timeline);
}
/**
* clutter_animation_set_duration:
* @animation: a #ClutterAnimation
* @msecs: the duration in milliseconds
*
* Sets the duration of @animation in milliseconds.
*
* This function will set #ClutterAnimation:alpha and
* #ClutterAnimation:timeline if needed.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_set_duration (ClutterAnimation *animation,
guint msecs)
{
ClutterTimeline *timeline;
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_object_freeze_notify (G_OBJECT (animation));
timeline = clutter_animation_get_timeline_internal (animation);
clutter_timeline_set_duration (timeline, msecs);
clutter_timeline_rewind (timeline);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_DURATION]);
g_object_thaw_notify (G_OBJECT (animation));
}
/**
* clutter_animation_set_loop:
* @animation: a #ClutterAnimation
* @loop: %TRUE if the animation should loop
*
* Sets whether @animation should loop over itself once finished.
*
* A looping #ClutterAnimation will not emit the #ClutterAnimation::completed
* signal when finished.
*
* This function will set #ClutterAnimation:alpha and
* #ClutterAnimation:timeline if needed.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_set_loop (ClutterAnimation *animation,
gboolean loop)
{
ClutterTimeline *timeline;
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_object_freeze_notify (G_OBJECT (animation));
timeline = clutter_animation_get_timeline_internal (animation);
clutter_timeline_set_repeat_count (timeline, loop ? -1 : 0);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_LOOP]);
g_object_thaw_notify (G_OBJECT (animation));
}
/**
* clutter_animation_get_loop:
* @animation: a #ClutterAnimation
*
* Retrieves whether @animation is looping.
*
* Return value: %TRUE if the animation is looping
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
gboolean
clutter_animation_get_loop (ClutterAnimation *animation)
{
ClutterTimeline *timeline;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), FALSE);
timeline = clutter_animation_get_timeline_internal (animation);
return clutter_timeline_get_repeat_count (timeline) != 0;
}
/**
* clutter_animation_get_duration:
* @animation: a #ClutterAnimation
*
* Retrieves the duration of @animation, in milliseconds.
*
* Return value: the duration of the animation
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
guint
clutter_animation_get_duration (ClutterAnimation *animation)
{
ClutterTimeline *timeline;
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), 0);
timeline = clutter_animation_get_timeline_internal (animation);
return clutter_timeline_get_duration (timeline);
}
/**
* clutter_animation_set_timeline:
* @animation: a #ClutterAnimation
* @timeline: (allow-none): a #ClutterTimeline, or %NULL to unset the
* current #ClutterTimeline
*
* Sets the #ClutterTimeline used by @animation.
*
* This function will take a reference on the passed @timeline.
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_set_timeline (ClutterAnimation *animation,
ClutterTimeline *timeline)
{
ClutterAnimationPrivate *priv;
ClutterTimeline *cur_timeline;
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_return_if_fail (timeline == NULL || CLUTTER_IS_TIMELINE (timeline));
priv = animation->priv;
if (priv->alpha != NULL)
cur_timeline = clutter_alpha_get_timeline (priv->alpha);
else
cur_timeline = priv->timeline;
if (cur_timeline == timeline)
return;
g_object_freeze_notify (G_OBJECT (animation));
if (cur_timeline != NULL && priv->timeline_started_id != 0)
g_signal_handler_disconnect (cur_timeline, priv->timeline_started_id);
if (cur_timeline != NULL && priv->timeline_completed_id != 0)
g_signal_handler_disconnect (cur_timeline, priv->timeline_completed_id);
if (cur_timeline != NULL && priv->timeline_frame_id != 0)
g_signal_handler_disconnect (cur_timeline, priv->timeline_frame_id);
priv->timeline_started_id = 0;
priv->timeline_completed_id = 0;
priv->timeline_frame_id = 0;
/* Release previously set timeline if any */
g_clear_object (&priv->timeline);
if (priv->alpha != NULL)
clutter_alpha_set_timeline (priv->alpha, timeline);
else
{
/* Hold a reference to the timeline if it's not reffed by the priv->alpha */
priv->timeline = timeline;
if (priv->timeline)
g_object_ref (priv->timeline);
}
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_TIMELINE]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_DURATION]);
g_object_notify_by_pspec (G_OBJECT (animation), obj_props[PROP_LOOP]);
if (timeline != NULL)
{
priv->timeline_started_id =
g_signal_connect (timeline, "started",
G_CALLBACK (on_timeline_started),
animation);
priv->timeline_completed_id =
g_signal_connect (timeline, "completed",
G_CALLBACK (on_timeline_completed),
animation);
priv->timeline_frame_id =
g_signal_connect (timeline, "new-frame",
G_CALLBACK (on_timeline_frame),
animation);
}
g_object_thaw_notify (G_OBJECT (animation));
}
/**
* clutter_animation_get_timeline:
* @animation: a #ClutterAnimation
*
* Retrieves the #ClutterTimeline used by @animation
*
* Return value: (transfer none): the timeline used by the animation
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
ClutterTimeline *
clutter_animation_get_timeline (ClutterAnimation *animation)
{
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
return clutter_animation_get_timeline_internal (animation);
}
/**
* clutter_animation_set_alpha:
* @animation: a #ClutterAnimation
* @alpha: a #ClutterAlpha, or %NULL to unset the current #ClutterAlpha
*
* Sets @alpha as the #ClutterAlpha used by @animation.
*
* If @alpha is not %NULL, the #ClutterAnimation will take ownership
* of the #ClutterAlpha instance.
*
* Since: 1.0
*
* Deprecated: 1.10: Use clutter_animation_get_timeline() and
* clutter_timeline_set_progress_mode() instead.
*/
void
clutter_animation_set_alpha (ClutterAnimation *animation,
ClutterAlpha *alpha)
{
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_return_if_fail (alpha == NULL || CLUTTER_IS_ALPHA (alpha));
clutter_animation_set_alpha_internal (animation, alpha);
}
/**
* clutter_animation_get_alpha:
* @animation: a #ClutterAnimation
*
* Retrieves the #ClutterAlpha used by @animation.
*
* Return value: (transfer none): the alpha object used by the animation
*
* Since: 1.0
*
* Deprecated: 1.10: Use clutter_animation_get_timeline() and
* clutter_timeline_get_progress_mode() instead.
*/
ClutterAlpha *
clutter_animation_get_alpha (ClutterAnimation *animation)
{
g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL);
return clutter_animation_get_alpha_internal (animation);
}
/**
* clutter_animation_completed:
* @animation: a #ClutterAnimation
*
* Emits the ::completed signal on @animation
*
* When using this function with a #ClutterAnimation created
* by the clutter_actor_animate() family of functions, @animation
* will be unreferenced and it will not be valid anymore,
* unless g_object_ref() was called before calling this function
* or unless a reference was taken inside a handler for the
* #ClutterAnimation::completed signal
*
* Since: 1.0
* Deprecated: 1.12: Use #ClutterPropertyTransition instead
*/
void
clutter_animation_completed (ClutterAnimation *animation)
{
g_return_if_fail (CLUTTER_IS_ANIMATION (animation));
g_signal_emit (animation, animation_signals[COMPLETED], 0);
}
/*
* starts the timeline
*/
static void
clutter_animation_start (ClutterAnimation *animation)
{
ClutterTimeline *timeline;
timeline = clutter_animation_get_timeline_internal (animation);
if (G_LIKELY (timeline != NULL))
clutter_timeline_start (timeline);
else
{
/* sanity check */
g_warning (G_STRLOC ": no timeline found, unable to start the animation");
}
}
static void
clutter_animation_setup_property (ClutterAnimation *animation,
const gchar *property_name,
const GValue *value,
GParamSpec *pspec,
gboolean is_fixed)
{
ClutterAnimationPrivate *priv = animation->priv;
GValue real_value = G_VALUE_INIT;
if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
{
g_warning ("Cannot bind property '%s': the property is "
"construct-only",
property_name);
return;
}
if (!(pspec->flags & G_PARAM_WRITABLE))
{
g_warning ("Cannot bind property '%s': the property is "
"not writable",
property_name);
return;
}
/* initialize the real value that will be used to store the
* final state of the animation
*/
g_value_init (&real_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
/* if it's not the same type of the GParamSpec value, try to
* convert it using the GValue transformation API, otherwise
* just copy it
*/
if (!g_type_is_a (G_VALUE_TYPE (value), G_VALUE_TYPE (&real_value)))
{
/* are these two types compatible (can be directly copied)? */
if (g_value_type_compatible (G_VALUE_TYPE (value),
G_VALUE_TYPE (&real_value)))
{
g_value_copy (value, &real_value);
goto done;
}
/* are these two type transformable? */
if (g_value_type_transformable (G_VALUE_TYPE (value),
G_VALUE_TYPE (&real_value)))
{
if (g_value_transform (value, &real_value))
goto done;
}
/* if not compatible and not transformable then we can't do much */
g_warning ("%s: Unable to convert from %s to %s for "
"the property '%s' of object %s",
G_STRLOC,
g_type_name (G_VALUE_TYPE (value)),
g_type_name (G_VALUE_TYPE (&real_value)),
property_name,
G_OBJECT_TYPE_NAME (priv->object));
g_value_unset (&real_value);
return;
}
else
g_value_copy (value, &real_value);
done:
/* create an interval and bind it to the property, in case
* it's not a fixed property, otherwise just set it
*/
if (G_LIKELY (!is_fixed))
{
ClutterInterval *interval;
GValue cur_value = G_VALUE_INIT;
g_value_init (&cur_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
if (CLUTTER_IS_ANIMATABLE (priv->object))
clutter_animatable_get_initial_state (CLUTTER_ANIMATABLE (priv->object),
property_name,
&cur_value);
else
g_object_get_property (priv->object, property_name, &cur_value);
interval =
clutter_interval_new_with_values (G_PARAM_SPEC_VALUE_TYPE (pspec),
&cur_value,
&real_value);
if (!clutter_animation_has_property (animation, property_name))
clutter_animation_bind_property_internal (animation, property_name,
pspec,
interval);
else
clutter_animation_update_property_internal (animation, property_name,
pspec,
interval);
g_value_unset (&cur_value);
}
else
{
if (CLUTTER_IS_ANIMATABLE (priv->object))
clutter_animatable_set_final_state (CLUTTER_ANIMATABLE (priv->object),
property_name,
&real_value);
else
g_object_set_property (priv->object, property_name, &real_value);
}
g_value_unset (&real_value);
}
static void
clutter_animation_setupv (ClutterAnimation *animation,
gint n_properties,
const gchar * const properties[],
const GValue *values)
{
ClutterAnimationPrivate *priv = animation->priv;
ClutterAnimatable *animatable = NULL;
GObjectClass *klass = NULL;
gint i;
if (CLUTTER_IS_ANIMATABLE (priv->object))
animatable = CLUTTER_ANIMATABLE (priv->object);
else
klass = G_OBJECT_GET_CLASS (priv->object);
for (i = 0; i < n_properties; i++)
{
const gchar *property_name = properties[i];
GParamSpec *pspec;
gboolean is_fixed = FALSE;
if (g_str_has_prefix (property_name, "fixed::"))
{
property_name += 7; /* strlen("fixed::") */
is_fixed = TRUE;
}
if (animatable != NULL)
pspec = clutter_animatable_find_property (animatable, property_name);
else
pspec = g_object_class_find_property (klass, property_name);
if (pspec == NULL)
{
g_warning ("Cannot bind property '%s': objects of type '%s' do "
"not have this property",
property_name,
g_type_name (G_OBJECT_TYPE (priv->object)));
break;
}
clutter_animation_setup_property (animation, property_name,
&values[i],
pspec,
is_fixed);
}
}
static const struct
{
const gchar *name;
GConnectFlags flags;
} signal_prefixes[] =
{
{ "::", 0 },
{ "-swapped::", G_CONNECT_SWAPPED },
{ "-after::", G_CONNECT_AFTER },
{ "-swapped-after::", G_CONNECT_SWAPPED | G_CONNECT_AFTER }
};
static gboolean
clutter_animation_has_signal_prefix (const gchar *property_name,
GConnectFlags *flags,
int *offset)
{
int i;
if (!g_str_has_prefix (property_name, "signal"))
return FALSE;
for (i = 0; i < G_N_ELEMENTS (signal_prefixes); i++)
if (g_str_has_prefix (property_name + 6, signal_prefixes[i].name))
{
*offset = strlen (signal_prefixes[i].name) + 6;
*flags = signal_prefixes[i].flags;
return TRUE;
}
return FALSE;
}
static void
clutter_animation_setup_valist (ClutterAnimation *animation,
const gchar *first_property_name,
va_list var_args)
{
ClutterAnimationPrivate *priv = animation->priv;
ClutterAnimatable *animatable = NULL;
GObjectClass *klass = NULL;
const gchar *property_name;
if (CLUTTER_IS_ANIMATABLE (priv->object))
animatable = CLUTTER_ANIMATABLE (priv->object);
else
klass = G_OBJECT_GET_CLASS (priv->object);
property_name = first_property_name;
while (property_name != NULL)
{
GParamSpec *pspec;
GValue final = G_VALUE_INIT;
gchar *error = NULL;
gboolean is_fixed = FALSE;
GConnectFlags flags;
int offset;
if (clutter_animation_has_signal_prefix (property_name,
&flags,
&offset))
{
const gchar *signal_name = property_name + offset;
GCallback callback = va_arg (var_args, GCallback);
gpointer userdata = va_arg (var_args, gpointer);
g_signal_connect_data (animation, signal_name,
callback, userdata,
NULL, flags);
}
else
{
if (g_str_has_prefix (property_name, "fixed::"))
{
property_name += 7; /* strlen("fixed::") */
is_fixed = TRUE;
}
if (animatable != NULL)
pspec = clutter_animatable_find_property (animatable,
property_name);
else
pspec = g_object_class_find_property (klass, property_name);
if (pspec == NULL)
{
g_warning ("Cannot bind property '%s': objects of type '%s' do "
"not have this property",
property_name,
g_type_name (G_OBJECT_TYPE (priv->object)));
break;
}
G_VALUE_COLLECT_INIT (&final, G_PARAM_SPEC_VALUE_TYPE (pspec),
var_args, 0,
&error);
if (error)
{
g_warning ("%s: %s", G_STRLOC, error);
g_free (error);
break;
}
clutter_animation_setup_property (animation, property_name,
&final,
pspec,
is_fixed);
g_value_unset (&final);
}
property_name = va_arg (var_args, gchar*);
}
}
static ClutterAnimation *
animation_create_for_actor (ClutterActor *actor)
{
ClutterAnimation *animation;
GObject *object = G_OBJECT (actor);
animation = g_object_get_qdata (object, quark_object_animation);
if (animation == NULL)
{
animation = clutter_animation_new ();
clutter_animation_set_object (animation, object);
g_object_set_qdata (object, quark_object_animation, animation);
/* use the ::destroy signal to get a notification
* that the actor went away mid-animation
*/
g_signal_connect (object, "destroy",
G_CALLBACK (on_actor_destroy),
animation);
CLUTTER_NOTE (ANIMATION,
"Created new Animation [%p] for actor [%p]",
animation,
actor);
}
else
{
CLUTTER_NOTE (ANIMATION,
"Reusing Animation [%p] for actor [%p]",
animation,
actor);
}
return animation;
}
/**
* clutter_actor_animate_with_alpha:
* @actor: a #ClutterActor
* @alpha: a #ClutterAlpha
* @first_property_name: the name of a property
* @...: a %NULL terminated list of property names and
* property values
*
* Animates the given list of properties of @actor between the current
* value for each property and a new final value. The animation has a
* definite behaviour given by the passed @alpha.
*
* See clutter_actor_animate() for further details.
*
* This function is useful if you want to use an existing #ClutterAlpha
* to animate @actor.
*
* Return value: (transfer none): a #ClutterAnimation object. The object is owned by the
* #ClutterActor and should not be unreferenced with g_object_unref()
*
* Since: 1.0
*
* Deprecated: 1.10: Use clutter_actor_animate_with_timeline() instead
*/
ClutterAnimation *
clutter_actor_animate_with_alpha (ClutterActor *actor,
ClutterAlpha *alpha,
const gchar *first_property_name,
...)
{
ClutterAnimation *animation;
ClutterTimeline *timeline;
va_list args;
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), NULL);
g_return_val_if_fail (first_property_name != NULL, NULL);
timeline = clutter_alpha_get_timeline (alpha);
if (timeline == NULL)
{
g_warning ("The passed ClutterAlpha does not have an "
"associated ClutterTimeline.");
return NULL;
}
animation = animation_create_for_actor (actor);
clutter_animation_set_alpha_internal (animation, alpha);
va_start (args, first_property_name);
clutter_animation_setup_valist (animation, first_property_name, args);
va_end (args);
clutter_animation_start (animation);
return animation;
}
/**
* clutter_actor_animate_with_timeline:
* @actor: a #ClutterActor
* @mode: an animation mode logical id
* @timeline: a #ClutterTimeline
* @first_property_name: the name of a property
* @...: a %NULL terminated list of property names and
* property values
*
* Animates the given list of properties of @actor between the current
* value for each property and a new final value. The animation has a
* definite duration given by @timeline and a speed given by the @mode.
*
* See clutter_actor_animate() for further details.
*
* This function is useful if you want to use an existing timeline
* to animate @actor.
*
* Return value: (transfer none): a #ClutterAnimation object. The object is
* owned by the #ClutterActor and should not be unreferenced with
* g_object_unref()
*
* Since: 1.0
* Deprecated: 1.12: Use the implicit transition for animatable properties
* in #ClutterActor instead.
*/
ClutterAnimation *
clutter_actor_animate_with_timeline (ClutterActor *actor,
gulong mode,
ClutterTimeline *timeline,
const gchar *first_property_name,
...)
{
ClutterAnimation *animation;
va_list args;
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), NULL);
g_return_val_if_fail (first_property_name != NULL, NULL);
animation = animation_create_for_actor (actor);
clutter_animation_set_mode (animation, mode);
clutter_animation_set_timeline (animation, timeline);
va_start (args, first_property_name);
clutter_animation_setup_valist (animation, first_property_name, args);
va_end (args);
clutter_animation_start (animation);
return animation;
}
/**
* clutter_actor_animate:
* @actor: a #ClutterActor
* @mode: an animation mode logical id
* @duration: duration of the animation, in milliseconds
* @first_property_name: the name of a property
* @...: a %NULL terminated list of property names and
* property values
*
* Animates the given list of properties of @actor between the current
* value for each property and a new final value. The animation has a
* definite duration and a speed given by the @mode.
*
* For example, this:
*
* |[<!-- language="C" -->
* clutter_actor_animate (rectangle, CLUTTER_LINEAR, 250,
* "width", 100.0,
* "height", 100.0,
* NULL);
* ]|
*
* will make width and height properties of the #ClutterActor "rectangle"
* grow linearly between the current value and 100 pixels, in 250 milliseconds.
*
* The animation @mode is a logical id, either from the #ClutterAnimationMode
* enumeration of from clutter_alpha_register_func().
*
* All the properties specified will be animated between the current value
* and the final value. If a property should be set at the beginning of
* the animation but not updated during the animation, it should be prefixed
* by the "fixed::" string, for instance:
*
* |[<!-- language="C" -->
* clutter_actor_animate (actor, CLUTTER_EASE_IN_SINE, 100,
* "rotation-angle-z", 360.0,
* "fixed::rotation-center-z", ¢er,
* NULL);
* ]|
*
* Will animate the "rotation-angle-z" property between the current value
* and 360 degrees, and set the "rotation-center-z" property to the fixed
* value of the #ClutterVertex "center".
*
* This function will implicitly create a #ClutterAnimation object which
* will be assigned to the @actor and will be returned to the developer
* to control the animation or to know when the animation has been
* completed.
*
* If a name argument starts with "signal::", "signal-after::",
* "signal-swapped::" or "signal-swapped-after::" the two following arguments
* are used as callback function and data for a signal handler installed on
* the #ClutterAnimation object for the specified signal name, for instance:
*
* |[<!-- language="C" -->
* static void
* on_animation_completed (ClutterAnimation *animation,
* ClutterActor *actor)
* {
* clutter_actor_hide (actor);
* }
*
* clutter_actor_animate (actor, CLUTTER_EASE_IN_CUBIC, 100,
* "opacity", 0,
* "signal::completed", on_animation_completed, actor,
* NULL);
* ]|
*
* or, to automatically destroy an actor at the end of the animation:
*
* |[<!-- language="C" -->
* clutter_actor_animate (actor, CLUTTER_EASE_IN_CUBIC, 100,
* "opacity", 0,
* "signal-swapped-after::completed",
* clutter_actor_destroy,
* actor,
* NULL);
* ]|
*
* The "signal::" modifier is the equivalent of using g_signal_connect();
* the "signal-after::" modifier is the equivalent of using
* g_signal_connect_after() or g_signal_connect_data() with the
* %G_CONNECT_AFTER; the "signal-swapped::" modifier is the equivalent
* of using g_signal_connect_swapped() or g_signal_connect_data() with the
* %G_CONNECT_SWAPPED flah; finally, the "signal-swapped-after::" modifier
* is the equivalent of using g_signal_connect_data() with both the
* %G_CONNECT_AFTER and %G_CONNECT_SWAPPED flags. The clutter_actor_animate()
* function will not keep track of multiple connections to the same signal,
* so it is your responsability to avoid them when calling
* clutter_actor_animate() multiple times on the same actor.
*
* Calling this function on an actor that is already being animated
* will cause the current animation to change with the new final values,
* the new easing mode and the new duration - that is, this code:
*
* |[<!-- language="C" -->
* clutter_actor_animate (actor, CLUTTER_LINEAR, 250,
* "width", 100.0,
* "height", 100.0,
* NULL);
* clutter_actor_animate (actor, CLUTTER_EASE_IN_CUBIC, 500,
* "x", 100.0,
* "y", 100.0,
* "width", 200.0,
* NULL);
* ]|
*
* is the equivalent of:
*
* |[<!-- language="C" -->
* clutter_actor_animate (actor, CLUTTER_EASE_IN_CUBIC, 500,
* "x", 100.0,
* "y", 100.0,
* "width", 200.0,
* "height", 100.0,
* NULL);
* ]|
*
* Unless the animation is looping, the #ClutterAnimation created by
* clutter_actor_animate() will become invalid as soon as it is
* complete.
*
* Since the created #ClutterAnimation instance attached to @actor
* is guaranteed to be valid throughout the #ClutterAnimation::completed
* signal emission chain, you will not be able to create a new animation
* using clutter_actor_animate() on the same @actor from within the
* #ClutterAnimation::completed signal handler unless you use
* g_signal_connect_after() to connect the callback function, for instance:
*
* |[<!-- language="C" -->
* static void
* on_animation_completed (ClutterAnimation *animation,
* ClutterActor *actor)
* {
* clutter_actor_animate (actor, CLUTTER_EASE_OUT_CUBIC, 250,
* "x", 500.0,
* "y", 500.0,
* NULL);
* }
*
* ...
* animation = clutter_actor_animate (actor, CLUTTER_EASE_IN_CUBIC, 250,
* "x", 100.0,
* "y", 100.0,
* NULL);
* g_signal_connect (animation, "completed",
* G_CALLBACK (on_animation_completed),
* actor);
* ...
* ]|
*
* Return value: (transfer none): a #ClutterAnimation object. The object is
* owned by the #ClutterActor and should not be unreferenced with
* g_object_unref()
*
* Since: 1.0
* Deprecated: 1.12: Use the implicit transition for animatable properties
* in #ClutterActor instead.
*/
ClutterAnimation *
clutter_actor_animate (ClutterActor *actor,
gulong mode,
guint duration,
const gchar *first_property_name,
...)
{
ClutterAnimation *animation;
va_list args;
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (mode != CLUTTER_CUSTOM_MODE, NULL);
g_return_val_if_fail (duration > 0, NULL);
g_return_val_if_fail (first_property_name != NULL, NULL);
animation = animation_create_for_actor (actor);
clutter_animation_set_mode (animation, mode);
clutter_animation_set_duration (animation, duration);
va_start (args, first_property_name);
clutter_animation_setup_valist (animation, first_property_name, args);
va_end (args);
clutter_animation_start (animation);
return animation;
}
/**
* clutter_actor_animatev:
* @actor: a #ClutterActor
* @mode: an animation mode logical id
* @duration: duration of the animation, in milliseconds
* @n_properties: number of property names and values
* @properties: (array length=n_properties) (element-type utf8): a vector
* containing the property names to set
* @values: (array length=n_properties): a vector containing the
* property values to set
*
* Animates the given list of properties of @actor between the current
* value for each property and a new final value. The animation has a
* definite duration and a speed given by the @mode.
*
* This is the vector-based variant of clutter_actor_animate(), useful
* for language bindings.
*
* Unlike clutter_actor_animate(), this function will not
* allow you to specify "signal::" names and callbacks.
*
* Return value: (transfer none): a #ClutterAnimation object. The object is
* owned by the #ClutterActor and should not be unreferenced with
* g_object_unref()
*
* Since: 1.0
* Deprecated: 1.12: Use the implicit transition for animatable properties
* in #ClutterActor instead.
*/
ClutterAnimation *
clutter_actor_animatev (ClutterActor *actor,
gulong mode,
guint duration,
gint n_properties,
const gchar * const properties[],
const GValue *values)
{
ClutterAnimation *animation;
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (mode != CLUTTER_CUSTOM_MODE, NULL);
g_return_val_if_fail (duration > 0, NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (values != NULL, NULL);
animation = animation_create_for_actor (actor);
clutter_animation_set_mode (animation, mode);
clutter_animation_set_duration (animation, duration);
clutter_animation_setupv (animation, n_properties, properties, values);
clutter_animation_start (animation);
return animation;
}
/**
* clutter_actor_animate_with_timelinev:
* @actor: a #ClutterActor
* @mode: an animation mode logical id
* @timeline: a #ClutterTimeline
* @n_properties: number of property names and values
* @properties: (array length=n_properties) (element-type utf8): a vector
* containing the property names to set
* @values: (array length=n_properties): a vector containing the
* property values to set
*
* Animates the given list of properties of @actor between the current
* value for each property and a new final value. The animation has a
* definite duration given by @timeline and a speed given by the @mode.
*
* See clutter_actor_animate() for further details.
*
* This function is useful if you want to use an existing timeline
* to animate @actor.
*
* This is the vector-based variant of clutter_actor_animate_with_timeline(),
* useful for language bindings.
*
* Unlike clutter_actor_animate_with_timeline(), this function
* will not allow you to specify "signal::" names and callbacks.
*
* Return value: (transfer none): a #ClutterAnimation object. The object is
* owned by the #ClutterActor and should not be unreferenced with
* g_object_unref()
*
* Since: 1.0
* Deprecated: 1.12: Use the implicit transition for animatable properties
* in #ClutterActor instead.
*/
ClutterAnimation *
clutter_actor_animate_with_timelinev (ClutterActor *actor,
gulong mode,
ClutterTimeline *timeline,
gint n_properties,
const gchar * const properties[],
const GValue *values)
{
ClutterAnimation *animation;
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (CLUTTER_IS_TIMELINE (timeline), NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (values != NULL, NULL);
animation = animation_create_for_actor (actor);
clutter_animation_set_mode (animation, mode);
clutter_animation_set_timeline (animation, timeline);
clutter_animation_setupv (animation, n_properties, properties, values);
clutter_animation_start (animation);
return animation;
}
/**
* clutter_actor_animate_with_alphav:
* @actor: a #ClutterActor
* @alpha: a #ClutterAlpha
* @n_properties: number of property names and values
* @properties: (array length=n_properties) (element-type utf8): a vector
* containing the property names to set
* @values: (array length=n_properties): a vector containing the
* property values to set
*
* Animates the given list of properties of @actor between the current
* value for each property and a new final value. The animation has a
* definite behaviour given by the passed @alpha.
*
* See clutter_actor_animate() for further details.
*
* This function is useful if you want to use an existing #ClutterAlpha
* to animate @actor.
*
* This is the vector-based variant of clutter_actor_animate_with_alpha(),
* useful for language bindings.
*
* Unlike clutter_actor_animate_with_alpha(), this function will
* not allow you to specify "signal::" names and callbacks.
*
* Return value: (transfer none): a #ClutterAnimation object. The object is owned by the
* #ClutterActor and should not be unreferenced with g_object_unref()
*
* Since: 1.0
*
* Deprecated: 1.10: Use clutter_actor_animate_with_timelinev() instead
*/
ClutterAnimation *
clutter_actor_animate_with_alphav (ClutterActor *actor,
ClutterAlpha *alpha,
gint n_properties,
const gchar * const properties[],
const GValue *values)
{
ClutterAnimation *animation;
ClutterTimeline *timeline;
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
g_return_val_if_fail (CLUTTER_IS_ALPHA (alpha), NULL);
g_return_val_if_fail (properties != NULL, NULL);
g_return_val_if_fail (values != NULL, NULL);
timeline = clutter_alpha_get_timeline (alpha);
if (timeline == NULL)
{
g_warning ("The passed ClutterAlpha does not have an "
"associated ClutterTimeline.");
return NULL;
}
animation = animation_create_for_actor (actor);
clutter_animation_set_alpha_internal (animation, alpha);
clutter_animation_setupv (animation, n_properties, properties, values);
clutter_animation_start (animation);
return animation;
}
/**
* clutter_actor_get_animation:
* @actor: a #ClutterActor
*
* Retrieves the #ClutterAnimation used by @actor, if clutter_actor_animate()
* has been called on @actor.
*
* Return value: (transfer none): a #ClutterAnimation, or %NULL
*
* Since: 1.0
* Deprecated: 1.12: Use the implicit transition for animatable properties
* in #ClutterActor instead, and clutter_actor_get_transition() to retrieve
* the transition.
*/
ClutterAnimation *
clutter_actor_get_animation (ClutterActor *actor)
{
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
return g_object_get_qdata (G_OBJECT (actor), quark_object_animation);
}
/**
* clutter_actor_detach_animation:
* @actor: a #ClutterActor
*
* Detaches the #ClutterAnimation used by @actor, if clutter_actor_animate()
* has been called on @actor.
*
* Once the animation has been detached, it loses a reference. If it was
* the only reference then the #ClutterAnimation becomes invalid.
*
* The #ClutterAnimation::completed signal will not be emitted.
*
* Since: 1.4
* Deprecated: 1.12: Use the implicit transition for animatable properties
* in #ClutterActor instead, and clutter_actor_remove_transition() to
* remove the transition.
*/
void
clutter_actor_detach_animation (ClutterActor *actor)
{
ClutterAnimation *animation;
ClutterAnimationPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR (actor));
animation = g_object_get_qdata (G_OBJECT (actor), quark_object_animation);
if (animation == NULL)
return;
priv = animation->priv;
g_assert (priv->object == G_OBJECT (actor));
/* we can't call get_timeline_internal() here because it would be
* pointless to create a timeline on an animation we want to detach
*/
if (priv->alpha != NULL)
{
ClutterTimeline *timeline;
timeline = clutter_alpha_get_timeline (priv->alpha);
if (timeline != NULL)
clutter_timeline_stop (timeline);
}
/* disconnect the ::destroy handler added by animation_create_for_actor() */
g_signal_handlers_disconnect_by_func (actor,
G_CALLBACK (on_actor_destroy),
animation);
clutter_animation_set_object (animation, NULL);
/* drop the reference on the animation */
g_object_unref (animation);
}
|