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
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
|
/*************************************************************************/
/* control.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "control.h"
#include "project_settings.h"
#include "scene/main/canvas_layer.h"
#include "scene/main/viewport.h"
#include "servers/visual_server.h"
#include "message_queue.h"
#include "os/keyboard.h"
#include "os/os.h"
#include "print_string.h"
#include "scene/gui/label.h"
#include "scene/gui/panel.h"
#include "scene/scene_string_names.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif
#include <stdio.h>
Dictionary Control::_edit_get_state() const {
Dictionary s;
s["rotation"] = get_rotation();
s["scale"] = get_scale();
s["pivot"] = get_pivot_offset();
Array anchors;
anchors.push_back(get_anchor(MARGIN_LEFT));
anchors.push_back(get_anchor(MARGIN_TOP));
anchors.push_back(get_anchor(MARGIN_RIGHT));
anchors.push_back(get_anchor(MARGIN_BOTTOM));
s["anchors"] = anchors;
Array margins;
margins.push_back(get_margin(MARGIN_LEFT));
margins.push_back(get_margin(MARGIN_TOP));
margins.push_back(get_margin(MARGIN_RIGHT));
margins.push_back(get_margin(MARGIN_BOTTOM));
s["margins"] = margins;
return s;
}
void Control::_edit_set_state(const Dictionary &p_state) {
Dictionary state = p_state;
set_rotation(state["rotation"]);
set_scale(state["scale"]);
set_pivot_offset(state["pivot"]);
Array anchors = state["anchors"];
data.anchor[MARGIN_LEFT] = anchors[0];
data.anchor[MARGIN_TOP] = anchors[1];
data.anchor[MARGIN_RIGHT] = anchors[2];
data.anchor[MARGIN_BOTTOM] = anchors[3];
Array margins = state["margins"];
data.margin[MARGIN_LEFT] = margins[0];
data.margin[MARGIN_TOP] = margins[1];
data.margin[MARGIN_RIGHT] = margins[2];
data.margin[MARGIN_BOTTOM] = margins[3];
_size_changed();
}
void Control::_edit_set_position(const Point2 &p_position) {
set_position(p_position);
};
Point2 Control::_edit_get_position() const {
return get_position();
};
void Control::_edit_set_scale(const Size2 &p_scale) {
set_scale(p_scale);
}
Size2 Control::_edit_get_scale() const {
return data.scale;
}
void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)));
set_size(p_edit_rect.size.snapped(Vector2(1, 1)));
}
Rect2 Control::_edit_get_rect() const {
return Rect2(Point2(), get_size());
}
bool Control::_edit_use_rect() const {
return true;
}
void Control::_edit_set_rotation(float p_rotation) {
set_rotation(p_rotation);
}
float Control::_edit_get_rotation() const {
return get_rotation();
}
bool Control::_edit_use_rotation() const {
return true;
}
void Control::_edit_set_pivot(const Point2 &p_pivot) {
Vector2 delta_pivot = p_pivot - get_pivot_offset();
Vector2 move = Vector2((cos(data.rotation) - 1.0) * delta_pivot.x - sin(data.rotation) * delta_pivot.y, sin(data.rotation) * delta_pivot.x + (cos(data.rotation) - 1.0) * delta_pivot.y);
set_position(get_position() + move);
set_pivot_offset(p_pivot);
}
Point2 Control::_edit_get_pivot() const {
return get_pivot_offset();
}
bool Control::_edit_use_pivot() const {
return true;
}
void Control::set_custom_minimum_size(const Size2 &p_custom) {
if (p_custom == data.custom_minimum_size)
return;
data.custom_minimum_size = p_custom;
minimum_size_changed();
}
Size2 Control::get_custom_minimum_size() const {
return data.custom_minimum_size;
}
void Control::_update_minimum_size_cache() {
Size2 minsize = get_minimum_size();
minsize.x = MAX(minsize.x, data.custom_minimum_size.x);
minsize.y = MAX(minsize.y, data.custom_minimum_size.y);
data.minimum_size_cache = minsize;
data.minimum_size_valid = true;
minimum_size_changed();
}
Size2 Control::get_combined_minimum_size() const {
if (!data.minimum_size_valid) {
const_cast<Control *>(this)->_update_minimum_size_cache();
}
return data.minimum_size_cache;
}
Size2 Control::_edit_get_minimum_size() const {
return get_combined_minimum_size();
}
Transform2D Control::_get_internal_transform() const {
Transform2D rot_scale;
rot_scale.set_rotation_and_scale(data.rotation, data.scale);
Transform2D offset;
offset.set_origin(-data.pivot_offset);
return offset.affine_inverse() * (rot_scale * offset);
}
bool Control::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
if (!name.begins_with("custom")) {
return false;
}
if (p_value.get_type() == Variant::NIL) {
if (name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
data.icon_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
} else if (name.begins_with("custom_shaders/")) {
String dname = name.get_slicec('/', 1);
data.shader_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
} else if (name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
data.style_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
} else if (name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/', 1);
if (data.font_override.has(dname)) {
_unref_font(data.font_override[dname]);
}
data.font_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
} else if (name.begins_with("custom_colors/")) {
String dname = name.get_slicec('/', 1);
data.color_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
data.constant_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
} else
return false;
} else {
if (name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
notification(NOTIFICATION_THEME_CHANGED);
add_icon_override(dname, p_value);
} else if (name.begins_with("custom_shaders/")) {
String dname = name.get_slicec('/', 1);
add_shader_override(dname, p_value);
notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
add_style_override(dname, p_value);
notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/', 1);
add_font_override(dname, p_value);
notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_colors/")) {
String dname = name.get_slicec('/', 1);
add_color_override(dname, p_value);
notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
add_constant_override(dname, p_value);
notification(NOTIFICATION_THEME_CHANGED);
} else
return false;
}
return true;
}
void Control::_update_minimum_size() {
if (!is_inside_tree())
return;
Size2 minsize = get_combined_minimum_size();
if (minsize.x > data.size_cache.x ||
minsize.y > data.size_cache.y) {
_size_changed();
}
data.updating_last_minimum_size = false;
if (minsize != data.last_minimum_size) {
data.last_minimum_size = minsize;
emit_signal(SceneStringNames::get_singleton()->minimum_size_changed);
}
}
bool Control::_get(const StringName &p_name, Variant &r_ret) const {
String sname = p_name;
if (!sname.begins_with("custom")) {
return false;
}
if (sname.begins_with("custom_icons/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.icon_override.has(name) ? Variant(data.icon_override[name]) : Variant();
} else if (sname.begins_with("custom_shaders/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.shader_override.has(name) ? Variant(data.shader_override[name]) : Variant();
} else if (sname.begins_with("custom_styles/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.style_override.has(name) ? Variant(data.style_override[name]) : Variant();
} else if (sname.begins_with("custom_fonts/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.font_override.has(name) ? Variant(data.font_override[name]) : Variant();
} else if (sname.begins_with("custom_colors/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.color_override.has(name) ? Variant(data.color_override[name]) : Variant();
} else if (sname.begins_with("custom_constants/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
} else
return false;
return true;
}
void Control::_get_property_list(List<PropertyInfo> *p_list) const {
Ref<Theme> theme;
if (data.theme.is_valid()) {
theme = data.theme;
} else {
theme = Theme::get_default();
}
{
List<StringName> names;
theme->get_icon_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
if (data.icon_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture", hint));
}
}
{
List<StringName> names;
theme->get_shader_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
if (data.shader_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph", hint));
}
}
{
List<StringName> names;
theme->get_stylebox_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
if (data.style_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", hint));
}
}
{
List<StringName> names;
theme->get_font_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
if (data.font_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", hint));
}
}
{
List<StringName> names;
theme->get_color_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
if (data.color_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", hint));
}
}
{
List<StringName> names;
theme->get_constant_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
if (data.constant_override.has(E->get()))
hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", hint));
}
}
}
Control *Control::get_parent_control() const {
return data.parent;
}
void Control::_resize(const Size2 &p_size) {
_size_changed();
}
//moved theme configuration here, so controls can set up even if still not inside active scene
void Control::add_child_notify(Node *p_child) {
Control *child_c = Object::cast_to<Control>(p_child);
if (!child_c)
return;
if (child_c->data.theme.is_null() && data.theme_owner) {
_propagate_theme_changed(child_c, data.theme_owner); //need to propagate here, since many controls may require setting up stuff
}
}
void Control::remove_child_notify(Node *p_child) {
Control *child_c = Object::cast_to<Control>(p_child);
if (!child_c)
return;
if (child_c->data.theme_owner && child_c->data.theme.is_null()) {
_propagate_theme_changed(child_c, NULL);
}
}
void Control::_update_canvas_item_transform() {
Transform2D xform = _get_internal_transform();
xform[2] += get_position();
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
}
void Control::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_ENTER_TREE: {
} break;
case NOTIFICATION_POST_ENTER_TREE: {
data.minimum_size_valid = false;
_size_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
get_viewport()->_gui_remove_control(this);
} break;
case NOTIFICATION_ENTER_CANVAS: {
data.parent = Object::cast_to<Control>(get_parent());
if (is_set_as_toplevel()) {
data.SI = get_viewport()->_gui_add_subwindow_control(this);
if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
data.theme_owner = data.parent->data.theme_owner;
notification(NOTIFICATION_THEME_CHANGED);
}
} else {
Node *parent = this; //meh
Control *parent_control = NULL;
bool subwindow = false;
while (parent) {
parent = parent->get_parent();
if (!parent)
break;
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
if (ci && ci->is_set_as_toplevel()) {
subwindow = true;
break;
}
parent_control = Object::cast_to<Control>(parent);
if (parent_control) {
break;
} else if (ci) {
} else {
break;
}
}
if (parent_control) {
//do nothing, has a parent control
if (data.theme.is_null() && parent_control->data.theme_owner) {
data.theme_owner = parent_control->data.theme_owner;
notification(NOTIFICATION_THEME_CHANGED);
}
} else if (subwindow) {
//is a subwindow (process input before other controls for that canvas)
data.SI = get_viewport()->_gui_add_subwindow_control(this);
} else {
//is a regular root control
data.RI = get_viewport()->_gui_add_root_control(this);
}
data.parent_canvas_item = get_parent_item();
if (data.parent_canvas_item) {
data.parent_canvas_item->connect("item_rect_changed", this, "_size_changed");
} else {
//connect viewport
get_viewport()->connect("size_changed", this, "_size_changed");
}
}
/*
if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
data.theme_owner=data.parent->data.theme_owner;
notification(NOTIFICATION_THEME_CHANGED);
}
*/
} break;
case NOTIFICATION_EXIT_CANVAS: {
if (data.parent_canvas_item) {
data.parent_canvas_item->disconnect("item_rect_changed", this, "_size_changed");
data.parent_canvas_item = NULL;
} else if (!is_set_as_toplevel()) {
//disconnect viewport
get_viewport()->disconnect("size_changed", this, "_size_changed");
}
if (data.MI) {
get_viewport()->_gui_remove_modal_control(data.MI);
data.MI = NULL;
}
if (data.SI) {
get_viewport()->_gui_remove_subwindow_control(data.SI);
data.SI = NULL;
}
if (data.RI) {
get_viewport()->_gui_remove_root_control(data.RI);
data.RI = NULL;
}
data.parent = NULL;
data.parent_canvas_item = NULL;
/*
if (data.theme_owner && data.theme.is_null()) {
data.theme_owner=NULL;
notification(NOTIFICATION_THEME_CHANGED);
}
*/
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
// some parents need to know the order of the childrens to draw (like TabContainer)
// update if necessary
if (data.parent)
data.parent->update();
update();
if (data.SI) {
get_viewport()->_gui_set_subwindow_order_dirty();
}
if (data.RI) {
get_viewport()->_gui_set_root_order_dirty();
}
} break;
case NOTIFICATION_RESIZED: {
emit_signal(SceneStringNames::get_singleton()->resized);
} break;
case NOTIFICATION_DRAW: {
_update_canvas_item_transform();
VisualServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
//emit_signal(SceneStringNames::get_singleton()->draw);
} break;
case NOTIFICATION_MOUSE_ENTER: {
emit_signal(SceneStringNames::get_singleton()->mouse_entered);
} break;
case NOTIFICATION_MOUSE_EXIT: {
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
} break;
case NOTIFICATION_FOCUS_ENTER: {
emit_signal(SceneStringNames::get_singleton()->focus_entered);
update();
} break;
case NOTIFICATION_FOCUS_EXIT: {
emit_signal(SceneStringNames::get_singleton()->focus_exited);
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
update();
} break;
case NOTIFICATION_MODAL_CLOSE: {
emit_signal("modal_closed");
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
if (get_viewport() != NULL)
get_viewport()->_gui_hid_control(this);
if (is_inside_tree()) {
_modal_stack_remove();
}
//remove key focus
//remove modalness
} else {
data.minimum_size_valid = false;
_size_changed();
}
} break;
case SceneTree::NOTIFICATION_WM_UNFOCUS_REQUEST: {
get_viewport()->_gui_unfocus_control(this);
} break;
}
}
bool Control::clips_input() const {
return false;
}
bool Control::has_point(const Point2 &p_point) const {
if (get_script_instance()) {
Variant v = p_point;
const Variant *p = &v;
Variant::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->has_point, &p, 1, ce);
if (ce.error == Variant::CallError::CALL_OK) {
return ret;
}
}
/*if (has_stylebox("mask")) {
Ref<StyleBox> mask = get_stylebox("mask");
return mask->test_mask(p_point,Rect2(Point2(),get_size()));
}*/
return Rect2(Point2(), get_size()).has_point(p_point);
}
void Control::set_drag_forwarding(Control *p_target) {
if (p_target)
data.drag_owner = p_target->get_instance_id();
else
data.drag_owner = 0;
}
Variant Control::get_drag_data(const Point2 &p_point) {
if (data.drag_owner) {
Object *obj = ObjectDB::get_instance(data.drag_owner);
if (obj) {
Control *c = Object::cast_to<Control>(obj);
return c->call("get_drag_data_fw", p_point, this);
}
}
if (get_script_instance()) {
Variant v = p_point;
const Variant *p = &v;
Variant::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce);
if (ce.error == Variant::CallError::CALL_OK)
return ret;
}
return Variant();
}
bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
if (data.drag_owner) {
Object *obj = ObjectDB::get_instance(data.drag_owner);
if (obj) {
Control *c = Object::cast_to<Control>(obj);
return c->call("can_drop_data_fw", p_point, p_data, this);
}
}
if (get_script_instance()) {
Variant v = p_point;
const Variant *p[2] = { &v, &p_data };
Variant::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce);
if (ce.error == Variant::CallError::CALL_OK)
return ret;
}
return Variant();
}
void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
if (data.drag_owner) {
Object *obj = ObjectDB::get_instance(data.drag_owner);
if (obj) {
Control *c = Object::cast_to<Control>(obj);
c->call("drop_data_fw", p_point, p_data, this);
return;
}
}
if (get_script_instance()) {
Variant v = p_point;
const Variant *p[2] = { &v, &p_data };
Variant::CallError ce;
Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce);
if (ce.error == Variant::CallError::CALL_OK)
return;
}
}
void Control::force_drag(const Variant &p_data, Control *p_control) {
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
get_viewport()->_gui_force_drag(this, p_data, p_control);
}
void Control::set_drag_preview(Control *p_control) {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->_gui_set_drag_preview(this, p_control);
}
bool Control::is_window_modal_on_top() const {
if (!is_inside_tree())
return false;
return get_viewport()->_gui_is_modal_on_top(this);
}
uint64_t Control::get_modal_frame() const {
return data.modal_frame;
}
Size2 Control::get_minimum_size() const {
ScriptInstance *si = const_cast<Control *>(this)->get_script_instance();
if (si) {
Variant::CallError ce;
Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, NULL, 0, ce);
if (ce.error == Variant::CallError::CALL_OK)
return s;
}
return Size2();
}
Ref<Texture> Control::get_icon(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
const Ref<Texture> *tex = data.icon_override.getptr(p_name);
if (tex)
return *tex;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_icon(p_name, class_name)) {
return theme_owner->data.theme->get_icon(p_name, class_name);
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->get_icon(p_name, type);
}
Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
if (sdr)
return *sdr;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_shader(p_name, class_name)) {
return theme_owner->data.theme->get_shader(p_name, class_name);
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->get_shader(p_name, type);
}
Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
if (style)
return *style;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
StringName class_name = type;
while (theme_owner) {
while (class_name != StringName()) {
if (theme_owner->data.theme->has_stylebox(p_name, class_name)) {
return theme_owner->data.theme->get_stylebox(p_name, class_name);
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
class_name = type;
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
while (class_name != StringName()) {
if (Theme::get_default()->has_stylebox(p_name, class_name))
return Theme::get_default()->get_stylebox(p_name, class_name);
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
return Theme::get_default()->get_stylebox(p_name, type);
}
Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
const Ref<Font> *font = data.font_override.getptr(p_name);
if (font)
return *font;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_font(p_name, class_name)) {
return theme_owner->data.theme->get_font(p_name, class_name);
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
if (theme_owner->data.theme->get_default_theme_font().is_valid())
return theme_owner->data.theme->get_default_theme_font();
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->get_font(p_name, type);
}
Color Control::get_color(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
const Color *color = data.color_override.getptr(p_name);
if (color)
return *color;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_color(p_name, class_name)) {
return theme_owner->data.theme->get_color(p_name, class_name);
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->get_color(p_name, type);
}
int Control::get_constant(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
const int *constant = data.constant_override.getptr(p_name);
if (constant)
return *constant;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_constant(p_name, class_name)) {
return theme_owner->data.theme->get_constant(p_name, class_name);
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->get_constant(p_name, type);
}
bool Control::has_icon_override(const StringName &p_name) const {
const Ref<Texture> *tex = data.icon_override.getptr(p_name);
if (tex)
return true;
else
return false;
}
bool Control::has_shader_override(const StringName &p_name) const {
const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
if (sdr)
return true;
else
return false;
}
bool Control::has_stylebox_override(const StringName &p_name) const {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
if (style)
return true;
else
return false;
}
bool Control::has_font_override(const StringName &p_name) const {
const Ref<Font> *font = data.font_override.getptr(p_name);
if (font)
return true;
else
return false;
}
bool Control::has_color_override(const StringName &p_name) const {
const Color *color = data.color_override.getptr(p_name);
if (color)
return true;
else
return false;
}
bool Control::has_constant_override(const StringName &p_name) const {
const int *constant = data.constant_override.getptr(p_name);
if (constant)
return true;
else
return false;
}
bool Control::has_icon(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
if (has_icon_override(p_name) == true)
return true;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_icon(p_name, class_name)) {
return true;
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->has_icon(p_name, type);
}
bool Control::has_shader(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
if (has_shader_override(p_name) == true)
return true;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_shader(p_name, class_name)) {
return true;
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->has_shader(p_name, type);
}
bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
if (has_stylebox_override(p_name) == true)
return true;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_stylebox(p_name, class_name)) {
return true;
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->has_stylebox(p_name, type);
}
bool Control::has_font(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
if (has_font_override(p_name) == true)
return true;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_font(p_name, class_name)) {
return true;
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->has_font(p_name, type);
}
bool Control::has_color(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
if (has_color_override(p_name) == true)
return true;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_color(p_name, class_name)) {
return true;
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->has_color(p_name, type);
}
bool Control::has_constant(const StringName &p_name, const StringName &p_type) const {
if (p_type == StringName() || p_type == "") {
if (has_constant_override(p_name) == true)
return true;
}
StringName type = p_type ? p_type : get_class_name();
// try with custom themes
Control *theme_owner = data.theme_owner;
while (theme_owner) {
StringName class_name = type;
while (class_name != StringName()) {
if (theme_owner->data.theme->has_constant(p_name, class_name)) {
return true;
}
class_name = ClassDB::get_parent_class_nocheck(class_name);
}
Control *parent = Object::cast_to<Control>(theme_owner->get_parent());
if (parent)
theme_owner = parent->data.theme_owner;
else
theme_owner = NULL;
}
return Theme::get_default()->has_constant(p_name, type);
}
Size2 Control::get_parent_area_size() const {
ERR_FAIL_COND_V(!is_inside_tree(), Size2());
Size2 parent_size;
if (data.parent_canvas_item) {
parent_size = data.parent_canvas_item->_edit_get_rect().size;
} else {
parent_size = get_viewport()->get_visible_rect().size;
}
return parent_size;
}
void Control::_size_changed() {
if (!is_inside_tree())
return;
Size2 parent_size = get_parent_area_size();
float margin_pos[4];
for (int i = 0; i < 4; i++) {
float area = parent_size[i & 1];
margin_pos[i] = data.margin[i] + (data.anchor[i] * area);
}
Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]);
Size2 new_size_cache = Point2(margin_pos[2], margin_pos[3]) - new_pos_cache;
Size2 minimum_size = get_combined_minimum_size();
if (minimum_size.width > new_size_cache.width) {
if (data.h_grow == GROW_DIRECTION_BEGIN) {
new_pos_cache.x += new_size_cache.width - minimum_size.width;
} else if (data.h_grow == GROW_DIRECTION_BOTH) {
new_pos_cache.x += 0.5 * (new_size_cache.width - minimum_size.width);
}
new_size_cache.width = minimum_size.width;
}
if (minimum_size.height > new_size_cache.height) {
if (data.v_grow == GROW_DIRECTION_BEGIN) {
new_pos_cache.y += new_size_cache.height - minimum_size.height;
} else if (data.v_grow == GROW_DIRECTION_BOTH) {
new_pos_cache.y += 0.5 * (new_size_cache.height - minimum_size.height);
}
new_size_cache.height = minimum_size.height;
}
// We use a little workaround to avoid flickering when moving the pivot with _edit_set_pivot()
if (Math::abs(Math::sin(data.rotation * 4.0f)) < 0.00001f && get_viewport()->is_snap_controls_to_pixels_enabled()) {
new_size_cache = new_size_cache.floor();
new_pos_cache = new_pos_cache.floor();
}
bool pos_changed = new_pos_cache != data.pos_cache;
bool size_changed = new_size_cache != data.size_cache;
data.pos_cache = new_pos_cache;
data.size_cache = new_size_cache;
if (size_changed) {
notification(NOTIFICATION_RESIZED);
}
if (pos_changed || size_changed) {
item_rect_changed(size_changed);
_change_notify_margins();
_notify_transform();
}
if (pos_changed && !size_changed) {
_update_canvas_item_transform(); //move because it won't be updated
}
}
float Control::_get_parent_range(int p_idx) const {
if (!is_inside_tree()) {
return 0;
}
if (data.parent_canvas_item) {
return data.parent_canvas_item->_edit_get_rect().size[p_idx & 1];
} else {
return get_viewport()->get_visible_rect().size[p_idx & 1];
}
return 0;
}
float Control::_get_range(int p_idx) const {
p_idx &= 1;
float parent_range = _get_parent_range(p_idx);
float from = _a2s(data.margin[p_idx], data.anchor[p_idx], parent_range);
float to = _a2s(data.margin[p_idx + 2], data.anchor[p_idx + 2], parent_range);
return to - from;
}
float Control::_s2a(float p_val, float p_anchor, float p_range) const {
return p_val - (p_anchor * p_range);
}
float Control::_a2s(float p_val, float p_anchor, float p_range) const {
return Math::floor(p_val + (p_anchor * p_range));
}
void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bool p_push_opposite_anchor) {
float parent_range = _get_parent_range((p_margin == MARGIN_LEFT || p_margin == MARGIN_RIGHT) ? 0 : 1);
float previous_margin_pos = data.margin[p_margin] + data.anchor[p_margin] * parent_range;
float previous_opposite_margin_pos = data.margin[(p_margin + 2) % 4] + data.anchor[(p_margin + 2) % 4] * parent_range;
data.anchor[p_margin] = CLAMP(p_anchor, 0.0, 1.0);
if (((p_margin == MARGIN_LEFT || p_margin == MARGIN_TOP) && data.anchor[p_margin] > data.anchor[(p_margin + 2) % 4]) ||
((p_margin == MARGIN_RIGHT || p_margin == MARGIN_BOTTOM) && data.anchor[p_margin] < data.anchor[(p_margin + 2) % 4])) {
if (p_push_opposite_anchor) {
data.anchor[(p_margin + 2) % 4] = data.anchor[p_margin];
} else {
data.anchor[p_margin] = data.anchor[(p_margin + 2) % 4];
}
}
if (!p_keep_margin) {
data.margin[p_margin] = _s2a(previous_margin_pos, data.anchor[p_margin], parent_range);
if (p_push_opposite_anchor) {
data.margin[(p_margin + 2) % 4] = _s2a(previous_opposite_margin_pos, data.anchor[(p_margin + 2) % 4], parent_range);
}
}
if (is_inside_tree()) {
_size_changed();
}
update();
_change_notify();
}
void Control::_set_anchor(Margin p_margin, float p_anchor) {
#ifdef TOOLS_ENABLED
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
set_anchor(p_margin, p_anchor, EDITOR_DEF("editors/2d/keep_margins_when_changing_anchors", false));
} else {
set_anchor(p_margin, p_anchor, false);
}
#else
set_anchor(p_margin, p_anchor, false);
#endif
}
void Control::set_anchor_and_margin(Margin p_margin, float p_anchor, float p_pos, bool p_push_opposite_anchor) {
set_anchor(p_margin, p_anchor, false, p_push_opposite_anchor);
set_margin(p_margin, p_pos);
}
void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) {
//Left
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
case PRESET_CENTER_LEFT:
case PRESET_TOP_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_LEFT_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
set_anchor(MARGIN_LEFT, ANCHOR_BEGIN, p_keep_margin);
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
set_anchor(MARGIN_LEFT, 0.5, p_keep_margin);
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
case PRESET_RIGHT_WIDE:
set_anchor(MARGIN_LEFT, ANCHOR_END, p_keep_margin);
break;
}
// Top
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
case PRESET_CENTER_TOP:
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_TOP_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
set_anchor(MARGIN_TOP, ANCHOR_BEGIN, p_keep_margin);
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
set_anchor(MARGIN_TOP, 0.5, p_keep_margin);
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
case PRESET_BOTTOM_WIDE:
set_anchor(MARGIN_TOP, ANCHOR_END, p_keep_margin);
break;
}
// Right
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
case PRESET_CENTER_LEFT:
case PRESET_LEFT_WIDE:
set_anchor(MARGIN_RIGHT, ANCHOR_BEGIN, p_keep_margin);
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
set_anchor(MARGIN_RIGHT, 0.5, p_keep_margin);
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
case PRESET_TOP_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
set_anchor(MARGIN_RIGHT, ANCHOR_END, p_keep_margin);
break;
}
// Bottom
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
case PRESET_CENTER_TOP:
case PRESET_TOP_WIDE:
set_anchor(MARGIN_BOTTOM, ANCHOR_BEGIN, p_keep_margin);
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
set_anchor(MARGIN_BOTTOM, 0.5, p_keep_margin);
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
set_anchor(MARGIN_BOTTOM, ANCHOR_END, p_keep_margin);
break;
}
}
void Control::set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
// Calculate the size if the node is not resized
Size2 min_size = get_minimum_size();
Size2 new_size = get_size();
if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_HEIGHT) {
new_size.x = min_size.x;
}
if (p_resize_mode == PRESET_MODE_MINSIZE || p_resize_mode == PRESET_MODE_KEEP_WIDTH) {
new_size.y = min_size.y;
}
float pw = _get_parent_range(0);
float ph = _get_parent_range(1);
//Left
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
case PRESET_CENTER_LEFT:
case PRESET_TOP_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_LEFT_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
data.margin[0] = pw * (0.0 - data.anchor[0]) + p_margin;
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
data.margin[0] = pw * (0.5 - data.anchor[0]) - new_size.x / 2;
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
case PRESET_RIGHT_WIDE:
data.margin[0] = pw * (1.0 - data.anchor[0]) - new_size.x - p_margin;
break;
}
// Top
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
case PRESET_CENTER_TOP:
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_TOP_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
data.margin[1] = ph * (0.0 - data.anchor[1]) + p_margin;
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
data.margin[1] = ph * (0.5 - data.anchor[1]) - new_size.y / 2;
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
case PRESET_BOTTOM_WIDE:
data.margin[1] = ph * (1.0 - data.anchor[1]) - new_size.y - p_margin;
break;
}
// Right
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_BOTTOM_LEFT:
case PRESET_CENTER_LEFT:
case PRESET_LEFT_WIDE:
data.margin[2] = pw * (0.0 - data.anchor[2]) + new_size.x + p_margin;
break;
case PRESET_CENTER_TOP:
case PRESET_CENTER_BOTTOM:
case PRESET_CENTER:
case PRESET_VCENTER_WIDE:
data.margin[2] = pw * (0.5 - data.anchor[2]) + new_size.x / 2;
break;
case PRESET_TOP_RIGHT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_RIGHT:
case PRESET_TOP_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_HCENTER_WIDE:
case PRESET_WIDE:
data.margin[2] = pw * (1.0 - data.anchor[2]) - p_margin;
break;
}
// Bottom
switch (p_preset) {
case PRESET_TOP_LEFT:
case PRESET_TOP_RIGHT:
case PRESET_CENTER_TOP:
case PRESET_TOP_WIDE:
data.margin[3] = ph * (0.0 - data.anchor[3]) + new_size.y + p_margin;
break;
case PRESET_CENTER_LEFT:
case PRESET_CENTER_RIGHT:
case PRESET_CENTER:
case PRESET_HCENTER_WIDE:
data.margin[3] = ph * (0.5 - data.anchor[3]) + new_size.y / 2;
break;
case PRESET_BOTTOM_LEFT:
case PRESET_BOTTOM_RIGHT:
case PRESET_CENTER_BOTTOM:
case PRESET_LEFT_WIDE:
case PRESET_RIGHT_WIDE:
case PRESET_BOTTOM_WIDE:
case PRESET_VCENTER_WIDE:
case PRESET_WIDE:
data.margin[3] = ph * (1.0 - data.anchor[3]) - p_margin;
break;
}
_size_changed();
}
void Control::set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode, int p_margin) {
set_anchors_preset(p_preset);
set_margins_preset(p_preset, p_resize_mode, p_margin);
}
float Control::get_anchor(Margin p_margin) const {
return data.anchor[p_margin];
}
void Control::_change_notify_margins() {
// this avoids sending the whole object data again on a change
_change_notify("margin_left");
_change_notify("margin_top");
_change_notify("margin_right");
_change_notify("margin_bottom");
_change_notify("rect_position");
_change_notify("rect_size");
}
void Control::set_margin(Margin p_margin, float p_value) {
data.margin[p_margin] = p_value;
_size_changed();
}
void Control::set_begin(const Size2 &p_point) {
data.margin[0] = p_point.x;
data.margin[1] = p_point.y;
_size_changed();
}
void Control::set_end(const Size2 &p_point) {
data.margin[2] = p_point.x;
data.margin[3] = p_point.y;
_size_changed();
}
float Control::get_margin(Margin p_margin) const {
return data.margin[p_margin];
}
Size2 Control::get_begin() const {
return Size2(data.margin[0], data.margin[1]);
}
Size2 Control::get_end() const {
return Size2(data.margin[2], data.margin[3]);
}
Point2 Control::get_global_position() const {
return get_global_transform().get_origin();
}
void Control::set_global_position(const Point2 &p_point) {
Transform2D inv;
if (data.parent_canvas_item) {
inv = data.parent_canvas_item->get_global_transform().affine_inverse();
}
set_position(inv.xform(p_point));
}
void Control::set_position(const Size2 &p_point) {
float pw = _get_parent_range(0);
float ph = _get_parent_range(1);
float x = _a2s(data.margin[0], data.anchor[0], pw);
float y = _a2s(data.margin[1], data.anchor[1], ph);
float x2 = _a2s(data.margin[2], data.anchor[2], pw);
float y2 = _a2s(data.margin[3], data.anchor[3], ph);
Size2 ret = Size2(x2 - x, y2 - y);
Size2 min = get_combined_minimum_size();
Size2 size = Size2(MAX(min.width, ret.width), MAX(min.height, ret.height));
float w = size.x;
float h = size.y;
x = p_point.x;
y = p_point.y;
data.margin[0] = _s2a(x, data.anchor[0], pw);
data.margin[1] = _s2a(y, data.anchor[1], ph);
data.margin[2] = _s2a(x + w, data.anchor[2], pw);
data.margin[3] = _s2a(y + h, data.anchor[3], ph);
_size_changed();
}
void Control::set_size(const Size2 &p_size) {
Size2 new_size = p_size;
Size2 min = get_combined_minimum_size();
if (new_size.x < min.x)
new_size.x = min.x;
if (new_size.y < min.y)
new_size.y = min.y;
float pw = _get_parent_range(0);
float ph = _get_parent_range(1);
float x = _a2s(data.margin[0], data.anchor[0], pw);
float y = _a2s(data.margin[1], data.anchor[1], ph);
float w = new_size.width;
float h = new_size.height;
data.margin[2] = _s2a(x + w, data.anchor[2], pw);
data.margin[3] = _s2a(y + h, data.anchor[3], ph);
_size_changed();
}
Size2 Control::get_position() const {
return data.pos_cache;
}
Size2 Control::get_size() const {
return data.size_cache;
}
Rect2 Control::get_global_rect() const {
return Rect2(get_global_position(), get_size());
}
Rect2 Control::get_window_rect() const {
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
Rect2 gr = get_global_rect();
gr.position += get_viewport()->get_visible_rect().position;
return gr;
}
Rect2 Control::get_rect() const {
return Rect2(get_position(), get_size());
}
void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) {
ERR_FAIL_COND(p_icon.is_null());
data.icon_override[p_name] = p_icon;
notification(NOTIFICATION_THEME_CHANGED);
update();
}
void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) {
ERR_FAIL_COND(p_shader.is_null());
data.shader_override[p_name] = p_shader;
notification(NOTIFICATION_THEME_CHANGED);
update();
}
void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
ERR_FAIL_COND(p_style.is_null());
data.style_override[p_name] = p_style;
notification(NOTIFICATION_THEME_CHANGED);
update();
}
void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_font) {
ERR_FAIL_COND(p_font.is_null());
if (data.font_override.has(p_name)) {
_unref_font(data.font_override[p_name]);
}
data.font_override[p_name] = p_font;
if (p_font.is_valid()) {
_ref_font(p_font);
}
notification(NOTIFICATION_THEME_CHANGED);
update();
}
void Control::add_color_override(const StringName &p_name, const Color &p_color) {
data.color_override[p_name] = p_color;
notification(NOTIFICATION_THEME_CHANGED);
update();
}
void Control::add_constant_override(const StringName &p_name, int p_constant) {
data.constant_override[p_name] = p_constant;
notification(NOTIFICATION_THEME_CHANGED);
update();
}
void Control::set_focus_mode(FocusMode p_focus_mode) {
if (is_inside_tree() && p_focus_mode == FOCUS_NONE && data.focus_mode != FOCUS_NONE && has_focus())
release_focus();
data.focus_mode = p_focus_mode;
}
static Control *_next_control(Control *p_from) {
if (p_from->is_set_as_toplevel())
return NULL; // can't go above
Control *parent = Object::cast_to<Control>(p_from->get_parent());
if (!parent) {
return NULL;
}
int next = p_from->get_position_in_parent();
ERR_FAIL_INDEX_V(next, parent->get_child_count(), NULL);
for (int i = (next + 1); i < parent->get_child_count(); i++) {
Control *c = Object::cast_to<Control>(parent->get_child(i));
if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
continue;
return c;
}
//no next in parent, try the same in parent
return _next_control(parent);
}
Control *Control::find_next_valid_focus() const {
Control *from = const_cast<Control *>(this);
while (true) {
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_next.is_empty()) {
Node *n = get_node(data.focus_next);
if (n) {
from = Object::cast_to<Control>(n);
if (!from) {
ERR_EXPLAIN("Next focus node is not a control: " + n->get_name());
ERR_FAIL_V(NULL);
}
} else {
return NULL;
}
if (from->is_visible() && from->get_focus_mode() != FOCUS_NONE)
return from;
}
// find next child
Control *next_child = NULL;
for (int i = 0; i < from->get_child_count(); i++) {
Control *c = Object::cast_to<Control>(from->get_child(i));
if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
}
next_child = c;
break;
}
if (next_child) {
from = next_child;
} else {
next_child = _next_control(from);
if (!next_child) { //nothing else.. go up and find either window or subwindow
next_child = const_cast<Control *>(this);
while (next_child && !next_child->is_set_as_toplevel()) {
next_child = cast_to<Control>(next_child->get_parent());
}
if (!next_child) {
next_child = const_cast<Control *>(this);
while (next_child) {
if (next_child->data.SI || next_child->data.RI)
break;
next_child = next_child->get_parent_control();
}
}
}
}
if (next_child == this) // no next control->
return (get_focus_mode() == FOCUS_ALL) ? next_child : NULL;
if (next_child) {
if (next_child->get_focus_mode() == FOCUS_ALL)
return next_child;
from = next_child;
} else
break;
}
return NULL;
}
static Control *_prev_control(Control *p_from) {
Control *child = NULL;
for (int i = p_from->get_child_count() - 1; i >= 0; i--) {
Control *c = Object::cast_to<Control>(p_from->get_child(i));
if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel())
continue;
child = c;
break;
}
if (!child)
return p_from;
//no prev in parent, try the same in parent
return _prev_control(child);
}
Control *Control::find_prev_valid_focus() const {
Control *from = const_cast<Control *>(this);
while (true) {
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_prev.is_empty()) {
Node *n = get_node(data.focus_prev);
if (n) {
from = Object::cast_to<Control>(n);
if (!from) {
ERR_EXPLAIN("Prev focus node is not a control: " + n->get_name());
ERR_FAIL_V(NULL);
}
} else {
return NULL;
}
if (from->is_visible() && from->get_focus_mode() != FOCUS_NONE)
return from;
}
// find prev child
Control *prev_child = NULL;
if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) {
//find last of the children
prev_child = _prev_control(from);
} else {
for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) {
Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i));
if (!c || !c->is_visible_in_tree() || c->is_set_as_toplevel()) {
continue;
}
prev_child = c;
break;
}
if (!prev_child) {
prev_child = Object::cast_to<Control>(from->get_parent());
} else {
prev_child = _prev_control(prev_child);
}
}
if (prev_child == this) // no prev control->
return (get_focus_mode() == FOCUS_ALL) ? prev_child : NULL;
if (prev_child->get_focus_mode() == FOCUS_ALL)
return prev_child;
from = prev_child;
}
return NULL;
}
Control::FocusMode Control::get_focus_mode() const {
return data.focus_mode;
}
bool Control::has_focus() const {
return is_inside_tree() && get_viewport()->_gui_control_has_focus(this);
}
void Control::grab_focus() {
if (!is_inside_tree()) {
ERR_FAIL_COND(!is_inside_tree());
}
if (data.focus_mode == FOCUS_NONE)
return;
get_viewport()->_gui_control_grab_focus(this);
}
void Control::release_focus() {
ERR_FAIL_COND(!is_inside_tree());
if (!has_focus())
return;
get_viewport()->_gui_remove_focus();
update();
}
bool Control::is_toplevel_control() const {
return is_inside_tree() && (!data.parent_canvas_item && !data.RI && is_set_as_toplevel());
}
void Control::show_modal(bool p_exclusive) {
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND(!data.SI);
if (is_visible_in_tree())
hide();
ERR_FAIL_COND(data.MI != NULL);
show();
raise();
data.modal_exclusive = p_exclusive;
data.MI = get_viewport()->_gui_show_modal(this);
data.modal_frame = Engine::get_singleton()->get_frames_drawn();
}
void Control::_modal_set_prev_focus_owner(ObjectID p_prev) {
data.modal_prev_focus_owner = p_prev;
}
void Control::_modal_stack_remove() {
ERR_FAIL_COND(!is_inside_tree());
if (!data.MI)
return;
get_viewport()->_gui_remove_from_modal_stack(data.MI, data.modal_prev_focus_owner);
data.MI = NULL;
data.modal_prev_focus_owner = 0;
}
void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign) {
Control *c = Object::cast_to<Control>(p_at);
if (c && c != p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated
return;
for (int i = 0; i < p_at->get_child_count(); i++) {
CanvasItem *child = Object::cast_to<CanvasItem>(p_at->get_child(i));
if (child) {
_propagate_theme_changed(child, p_owner, p_assign);
}
}
if (c) {
if (p_assign) {
c->data.theme_owner = p_owner;
}
c->notification(NOTIFICATION_THEME_CHANGED);
c->update();
}
}
void Control::_theme_changed() {
_propagate_theme_changed(this, this, false);
}
void Control::set_theme(const Ref<Theme> &p_theme) {
if (data.theme == p_theme)
return;
if (data.theme.is_valid()) {
data.theme->disconnect("changed", this, "_theme_changed");
}
data.theme = p_theme;
if (!p_theme.is_null()) {
data.theme_owner = this;
_propagate_theme_changed(this, this);
} else {
Control *parent = cast_to<Control>(get_parent());
if (parent && parent->data.theme_owner) {
_propagate_theme_changed(this, parent->data.theme_owner);
} else {
_propagate_theme_changed(this, NULL);
}
}
if (data.theme.is_valid()) {
data.theme->connect("changed", this, "_theme_changed");
}
}
void Control::accept_event() {
if (is_inside_tree())
get_viewport()->_gui_accept_event();
}
Ref<Theme> Control::get_theme() const {
return data.theme;
}
void Control::set_tooltip(const String &p_tooltip) {
data.tooltip = p_tooltip;
}
String Control::get_tooltip(const Point2 &p_pos) const {
return data.tooltip;
}
void Control::set_default_cursor_shape(CursorShape p_shape) {
data.default_cursor = p_shape;
}
Control::CursorShape Control::get_default_cursor_shape() const {
return data.default_cursor;
}
Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
return data.default_cursor;
}
Transform2D Control::get_transform() const {
Transform2D xform = _get_internal_transform();
xform[2] += get_position();
return xform;
}
String Control::_get_tooltip() const {
return data.tooltip;
}
void Control::set_focus_neighbour(Margin p_margin, const NodePath &p_neighbour) {
ERR_FAIL_INDEX(p_margin, 4);
data.focus_neighbour[p_margin] = p_neighbour;
}
NodePath Control::get_focus_neighbour(Margin p_margin) const {
ERR_FAIL_INDEX_V(p_margin, 4, NodePath());
return data.focus_neighbour[p_margin];
}
void Control::set_focus_next(const NodePath &p_next) {
data.focus_next = p_next;
}
NodePath Control::get_focus_next() const {
return data.focus_next;
}
void Control::set_focus_previous(const NodePath &p_prev) {
data.focus_prev = p_prev;
}
NodePath Control::get_focus_previous() const {
return data.focus_prev;
}
#define MAX_NEIGHBOUR_SEARCH_COUNT 512
Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
if (p_count >= MAX_NEIGHBOUR_SEARCH_COUNT)
return NULL;
if (!data.focus_neighbour[p_margin].is_empty()) {
Control *c = NULL;
Node *n = get_node(data.focus_neighbour[p_margin]);
if (n) {
c = Object::cast_to<Control>(n);
if (!c) {
ERR_EXPLAIN("Neighbour focus node is not a control: " + n->get_name());
ERR_FAIL_V(NULL);
}
} else {
return NULL;
}
bool valid = true;
if (!c->is_visible())
valid = false;
if (c->get_focus_mode() == FOCUS_NONE)
valid = false;
if (valid)
return c;
c = c->_get_focus_neighbour(p_margin, p_count + 1);
return c;
}
float dist = 1e7;
Control *result = NULL;
Point2 points[4];
Transform2D xform = get_global_transform();
Rect2 rect = _edit_get_rect();
points[0] = xform.xform(rect.position);
points[1] = xform.xform(rect.position + Point2(rect.size.x, 0));
points[2] = xform.xform(rect.position + rect.size);
points[3] = xform.xform(rect.position + Point2(0, rect.size.y));
const Vector2 dir[4] = {
Vector2(-1, 0),
Vector2(0, -1),
Vector2(1, 0),
Vector2(0, 1)
};
Vector2 vdir = dir[p_margin];
float maxd = -1e7;
for (int i = 0; i < 4; i++) {
float d = vdir.dot(points[i]);
if (d > maxd)
maxd = d;
}
Node *base = this;
while (base) {
Control *c = Object::cast_to<Control>(base);
if (c) {
if (c->data.SI)
break;
if (c->data.RI)
break;
}
base = base->get_parent();
}
if (!base)
return NULL;
_window_find_focus_neighbour(vdir, base, points, maxd, dist, &result);
return result;
}
void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, float p_min, float &r_closest_dist, Control **r_closest) {
if (Object::cast_to<Viewport>(p_at))
return; //bye
Control *c = Object::cast_to<Control>(p_at);
if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) {
Point2 points[4];
Transform2D xform = c->get_global_transform();
Rect2 rect = c->_edit_get_rect();
points[0] = xform.xform(rect.position);
points[1] = xform.xform(rect.position + Point2(rect.size.x, 0));
points[2] = xform.xform(rect.position + rect.size);
points[3] = xform.xform(rect.position + Point2(0, rect.size.y));
float min = 1e7;
for (int i = 0; i < 4; i++) {
float d = p_dir.dot(points[i]);
if (d < min)
min = d;
}
if (min > (p_min - CMP_EPSILON)) {
for (int i = 0; i < 4; i++) {
Vector2 la = p_points[i];
Vector2 lb = p_points[(i + 1) % 4];
for (int j = 0; j < 4; j++) {
Vector2 fa = points[j];
Vector2 fb = points[(j + 1) % 4];
Vector2 pa, pb;
float d = Geometry::get_closest_points_between_segments(la, lb, fa, fb, pa, pb);
//float d = Geometry::get_closest_distance_between_segments(Vector3(la.x,la.y,0),Vector3(lb.x,lb.y,0),Vector3(fa.x,fa.y,0),Vector3(fb.x,fb.y,0));
if (d < r_closest_dist) {
r_closest_dist = d;
*r_closest = c;
}
}
}
}
}
for (int i = 0; i < p_at->get_child_count(); i++) {
Node *child = p_at->get_child(i);
Control *childc = Object::cast_to<Control>(child);
if (childc && childc->data.SI)
continue; //subwindow, ignore
_window_find_focus_neighbour(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
}
}
void Control::set_h_size_flags(int p_flags) {
if (data.h_size_flags == p_flags)
return;
data.h_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
int Control::get_h_size_flags() const {
return data.h_size_flags;
}
void Control::set_v_size_flags(int p_flags) {
if (data.v_size_flags == p_flags)
return;
data.v_size_flags = p_flags;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
void Control::set_stretch_ratio(float p_ratio) {
if (data.expand == p_ratio)
return;
data.expand = p_ratio;
emit_signal(SceneStringNames::get_singleton()->size_flags_changed);
}
float Control::get_stretch_ratio() const {
return data.expand;
}
void Control::grab_click_focus() {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->_gui_grab_click_focus(this);
}
void Control::minimum_size_changed() {
if (!is_inside_tree() || data.block_minimum_size_adjust)
return;
Control *invalidate = this;
//invalidate cache upwards
while (invalidate && invalidate->data.minimum_size_valid) {
invalidate->data.minimum_size_valid = false;
if (invalidate->is_set_as_toplevel())
break; // do not go further up
invalidate = invalidate->data.parent;
}
if (!is_visible_in_tree())
return;
if (data.updating_last_minimum_size)
return;
data.updating_last_minimum_size = true;
MessageQueue::get_singleton()->push_call(this, "_update_minimum_size");
}
int Control::get_v_size_flags() const {
return data.v_size_flags;
}
void Control::set_mouse_filter(MouseFilter p_filter) {
ERR_FAIL_INDEX(p_filter, 3);
data.mouse_filter = p_filter;
}
Control::MouseFilter Control::get_mouse_filter() const {
return data.mouse_filter;
}
void Control::set_pass_on_modal_close_click(bool p_pass_on) {
data.pass_on_modal_close_click = p_pass_on;
}
bool Control::pass_on_modal_close_click() const {
return data.pass_on_modal_close_click;
}
Control *Control::get_focus_owner() const {
ERR_FAIL_COND_V(!is_inside_tree(), NULL);
return get_viewport()->_gui_get_focus_owner();
}
void Control::warp_mouse(const Point2 &p_to_pos) {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->warp_mouse(get_global_transform().xform(p_to_pos));
}
bool Control::is_text_field() const {
/*
if (get_script_instance()) {
Variant v=p_point;
const Variant *p[2]={&v,&p_data};
Variant::CallError ce;
Variant ret = get_script_instance()->call("is_text_field",p,2,ce);
if (ce.error==Variant::CallError::CALL_OK)
return ret;
}
*/
return false;
}
void Control::set_rotation(float p_radians) {
data.rotation = p_radians;
update();
_notify_transform();
_change_notify("rect_rotation");
}
float Control::get_rotation() const {
return data.rotation;
}
void Control::set_rotation_degrees(float p_degrees) {
set_rotation(Math::deg2rad(p_degrees));
}
float Control::get_rotation_degrees() const {
return Math::rad2deg(get_rotation());
}
//needed to update the control if the font changes..
void Control::_ref_font(Ref<Font> p_sc) {
if (!data.font_refcount.has(p_sc)) {
data.font_refcount[p_sc] = 1;
p_sc->connect("changed", this, "_font_changed");
} else {
data.font_refcount[p_sc] += 1;
}
}
void Control::_unref_font(Ref<Font> p_sc) {
ERR_FAIL_COND(!data.font_refcount.has(p_sc));
data.font_refcount[p_sc]--;
if (data.font_refcount[p_sc] == 0) {
p_sc->disconnect("changed", this, "_font_changed");
data.font_refcount.erase(p_sc);
}
}
void Control::_font_changed() {
update();
notification(NOTIFICATION_THEME_CHANGED);
minimum_size_changed(); //fonts affect minimum size pretty much almost always
}
void Control::set_pivot_offset(const Vector2 &p_pivot) {
data.pivot_offset = p_pivot;
update();
_notify_transform();
_change_notify("rect_pivot_offset");
}
Vector2 Control::get_pivot_offset() const {
return data.pivot_offset;
}
void Control::set_scale(const Vector2 &p_scale) {
data.scale = p_scale;
update();
_notify_transform();
}
Vector2 Control::get_scale() const {
return data.scale;
}
Control *Control::get_root_parent_control() const {
const CanvasItem *ci = this;
const Control *root = this;
while (ci) {
const Control *c = Object::cast_to<Control>(ci);
if (c) {
root = c;
if (c->data.RI || c->data.MI || c->is_toplevel_control())
break;
}
ci = ci->get_parent_item();
}
return const_cast<Control *>(root);
}
void Control::set_block_minimum_size_adjust(bool p_block) {
data.block_minimum_size_adjust = p_block;
}
bool Control::is_minimum_size_adjust_blocked() const {
return data.block_minimum_size_adjust;
}
void Control::set_disable_visibility_clip(bool p_ignore) {
data.disable_visibility_clip = p_ignore;
update();
}
bool Control::is_visibility_clip_disabled() const {
return data.disable_visibility_clip;
}
void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
Node::get_argument_options(p_function, p_idx, r_options);
if (p_idx == 0) {
List<StringName> sn;
String pf = p_function;
if (pf == "add_color_override" || pf == "has_color" || pf == "has_color_override" || pf == "get_color") {
Theme::get_default()->get_color_list(get_class(), &sn);
} else if (pf == "add_style_override" || pf == "has_style" || pf == "has_style_override" || pf == "get_style") {
Theme::get_default()->get_stylebox_list(get_class(), &sn);
} else if (pf == "add_font_override" || pf == "has_font" || pf == "has_font_override" || pf == "get_font") {
Theme::get_default()->get_font_list(get_class(), &sn);
} else if (pf == "add_constant_override" || pf == "has_constant" || pf == "has_constant_override" || pf == "get_constant") {
Theme::get_default()->get_constant_list(get_class(), &sn);
}
sn.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = sn.front(); E; E = E->next()) {
r_options->push_back("\"" + E->get() + "\"");
}
}
}
void Control::set_clip_contents(bool p_clip) {
data.clip_contents = p_clip;
update();
}
bool Control::is_clipping_contents() {
return data.clip_contents;
}
void Control::set_h_grow_direction(GrowDirection p_direction) {
data.h_grow = p_direction;
_size_changed();
}
Control::GrowDirection Control::get_h_grow_direction() const {
return data.h_grow;
}
void Control::set_v_grow_direction(GrowDirection p_direction) {
data.v_grow = p_direction;
_size_changed();
}
Control::GrowDirection Control::get_v_grow_direction() const {
return data.v_grow;
}
void Control::_bind_methods() {
//ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
ClassDB::bind_method(D_METHOD("_size_changed"), &Control::_size_changed);
ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size);
ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event);
ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size);
ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);
ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_margin"), &Control::set_anchors_preset, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_margins_preset", "preset", "resize_mode", "margin"), &Control::set_margins_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
ClassDB::bind_method(D_METHOD("set_anchors_and_margins_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_margins_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
ClassDB::bind_method(D_METHOD("set_anchor", "margin", "anchor", "keep_margin", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true));
ClassDB::bind_method(D_METHOD("_set_anchor", "margin", "anchor"), &Control::_set_anchor);
ClassDB::bind_method(D_METHOD("get_anchor", "margin"), &Control::get_anchor);
ClassDB::bind_method(D_METHOD("set_margin", "margin", "offset"), &Control::set_margin);
ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_margin, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_begin", "position"), &Control::set_begin);
ClassDB::bind_method(D_METHOD("set_end", "position"), &Control::set_end);
ClassDB::bind_method(D_METHOD("set_position", "position"), &Control::set_position);
ClassDB::bind_method(D_METHOD("set_size", "size"), &Control::set_size);
ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size);
ClassDB::bind_method(D_METHOD("set_global_position", "position"), &Control::set_global_position);
ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation);
ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Control::set_rotation_degrees);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin);
ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position);
ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size);
ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation);
ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Control::get_rotation_degrees);
ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_size);
ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position);
ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect);
ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect);
ClassDB::bind_method(D_METHOD("show_modal", "exclusive"), &Control::show_modal, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_focus_mode", "mode"), &Control::set_focus_mode);
ClassDB::bind_method(D_METHOD("get_focus_mode"), &Control::get_focus_mode);
ClassDB::bind_method(D_METHOD("has_focus"), &Control::has_focus);
ClassDB::bind_method(D_METHOD("grab_focus"), &Control::grab_focus);
ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus);
ClassDB::bind_method(D_METHOD("get_focus_owner"), &Control::get_focus_owner);
ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);
ClassDB::bind_method(D_METHOD("set_stretch_ratio", "ratio"), &Control::set_stretch_ratio);
ClassDB::bind_method(D_METHOD("get_stretch_ratio"), &Control::get_stretch_ratio);
ClassDB::bind_method(D_METHOD("set_v_size_flags", "flags"), &Control::set_v_size_flags);
ClassDB::bind_method(D_METHOD("get_v_size_flags"), &Control::get_v_size_flags);
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme);
ClassDB::bind_method(D_METHOD("add_icon_override", "name", "texture"), &Control::add_icon_override);
ClassDB::bind_method(D_METHOD("add_shader_override", "name", "shader"), &Control::add_shader_override);
ClassDB::bind_method(D_METHOD("add_stylebox_override", "name", "stylebox"), &Control::add_style_override);
ClassDB::bind_method(D_METHOD("add_font_override", "name", "font"), &Control::add_font_override);
ClassDB::bind_method(D_METHOD("add_color_override", "name", "color"), &Control::add_color_override);
ClassDB::bind_method(D_METHOD("add_constant_override", "name", "constant"), &Control::add_constant_override);
ClassDB::bind_method(D_METHOD("get_icon", "name", "type"), &Control::get_icon, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_stylebox", "name", "type"), &Control::get_stylebox, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_font", "name", "type"), &Control::get_font, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_color", "name", "type"), &Control::get_color, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_constant", "name", "type"), &Control::get_constant, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_icon_override", "name"), &Control::has_icon_override);
ClassDB::bind_method(D_METHOD("has_shader_override", "name"), &Control::has_shader_override);
ClassDB::bind_method(D_METHOD("has_stylebox_override", "name"), &Control::has_stylebox_override);
ClassDB::bind_method(D_METHOD("has_font_override", "name"), &Control::has_font_override);
ClassDB::bind_method(D_METHOD("has_color_override", "name"), &Control::has_color_override);
ClassDB::bind_method(D_METHOD("has_constant_override", "name"), &Control::has_constant_override);
ClassDB::bind_method(D_METHOD("has_icon", "name", "type"), &Control::has_icon, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_stylebox", "name", "type"), &Control::has_stylebox, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_font", "name", "type"), &Control::has_font, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_color", "name", "type"), &Control::has_color, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_constant", "name", "type"), &Control::has_constant, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control);
ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction);
ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction);
ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction);
ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &Control::set_tooltip);
ClassDB::bind_method(D_METHOD("get_tooltip", "at_position"), &Control::get_tooltip, DEFVAL(Point2()));
ClassDB::bind_method(D_METHOD("_get_tooltip"), &Control::_get_tooltip);
ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Control::set_default_cursor_shape);
ClassDB::bind_method(D_METHOD("get_default_cursor_shape"), &Control::get_default_cursor_shape);
ClassDB::bind_method(D_METHOD("get_cursor_shape", "position"), &Control::get_cursor_shape, DEFVAL(Point2()));
ClassDB::bind_method(D_METHOD("set_focus_neighbour", "margin", "neighbour"), &Control::set_focus_neighbour);
ClassDB::bind_method(D_METHOD("get_focus_neighbour", "margin"), &Control::get_focus_neighbour);
ClassDB::bind_method(D_METHOD("set_focus_next", "next"), &Control::set_focus_next);
ClassDB::bind_method(D_METHOD("get_focus_next"), &Control::get_focus_next);
ClassDB::bind_method(D_METHOD("set_focus_previous", "previous"), &Control::set_focus_previous);
ClassDB::bind_method(D_METHOD("get_focus_previous"), &Control::get_focus_previous);
ClassDB::bind_method(D_METHOD("force_drag", "data", "preview"), &Control::force_drag);
ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter);
ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter);
ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents);
ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents);
ClassDB::bind_method(D_METHOD("grab_click_focus"), &Control::grab_click_focus);
ClassDB::bind_method(D_METHOD("set_drag_forwarding", "target"), &Control::set_drag_forwarding);
ClassDB::bind_method(D_METHOD("set_drag_preview", "control"), &Control::set_drag_preview);
ClassDB::bind_method(D_METHOD("warp_mouse", "to_position"), &Control::warp_mouse);
ClassDB::bind_method(D_METHOD("minimum_size_changed"), &Control::minimum_size_changed);
ClassDB::bind_method(D_METHOD("_theme_changed"), &Control::_theme_changed);
ClassDB::bind_method(D_METHOD("_font_changed"), &Control::_font_changed);
BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "get_drag_data", PropertyInfo(Variant::VECTOR2, "position")));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
BIND_VMETHOD(MethodInfo("drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
ADD_GROUP("Anchor", "anchor_");
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_LEFT);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_RIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.01"), "_set_anchor", "get_anchor", MARGIN_BOTTOM);
ADD_GROUP("Margin", "margin_");
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_LEFT);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_top", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_TOP);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_RIGHT);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM);
ADD_GROUP("Grow Direction", "grow_");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Begin,End,Both"), "set_h_grow_direction", "get_h_grow_direction");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Begin,End,Both"), "set_v_grow_direction", "get_v_grow_direction");
ADD_GROUP("Rect", "rect_");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_global_position", PROPERTY_HINT_NONE, "", 0), "set_global_position", "get_global_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_degrees", "get_rotation_degrees");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
ADD_GROUP("Hint", "hint_");
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "hint_tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "_get_tooltip");
ADD_GROUP("Focus", "focus_");
ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_left", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_LEFT);
ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_top", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_TOP);
ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_right", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_RIGHT);
ADD_PROPERTYINZ(PropertyInfo(Variant::NODE_PATH, "focus_neighbour_bottom", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_neighbour", "get_focus_neighbour", MARGIN_BOTTOM);
ADD_PROPERTYNZ(PropertyInfo(Variant::NODE_PATH, "focus_next", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_next", "get_focus_next");
ADD_PROPERTYNZ(PropertyInfo(Variant::NODE_PATH, "focus_previous", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Control"), "set_focus_previous", "get_focus_previous");
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
ADD_GROUP("Mouse", "mouse_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,Ibeam,Pointing hand,Cross,Wait,Busy,Drag,Can drop,Forbidden,Vertical resize,Horizontal resize,Secondary diagonal resize,Main diagonal resize,Move,Vertial split,Horizontal split,Help"), "set_default_cursor_shape", "get_default_cursor_shape");
ADD_GROUP("Size Flags", "size_flags_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_GROUP("", "");
BIND_ENUM_CONSTANT(FOCUS_NONE);
BIND_ENUM_CONSTANT(FOCUS_CLICK);
BIND_ENUM_CONSTANT(FOCUS_ALL);
BIND_CONSTANT(NOTIFICATION_RESIZED);
BIND_CONSTANT(NOTIFICATION_MOUSE_ENTER);
BIND_CONSTANT(NOTIFICATION_MOUSE_EXIT);
BIND_CONSTANT(NOTIFICATION_FOCUS_ENTER);
BIND_CONSTANT(NOTIFICATION_FOCUS_EXIT);
BIND_CONSTANT(NOTIFICATION_THEME_CHANGED);
BIND_CONSTANT(NOTIFICATION_MODAL_CLOSE);
BIND_CONSTANT(NOTIFICATION_SCROLL_BEGIN);
BIND_CONSTANT(NOTIFICATION_SCROLL_END);
BIND_ENUM_CONSTANT(CURSOR_ARROW);
BIND_ENUM_CONSTANT(CURSOR_IBEAM);
BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND);
BIND_ENUM_CONSTANT(CURSOR_CROSS);
BIND_ENUM_CONSTANT(CURSOR_WAIT);
BIND_ENUM_CONSTANT(CURSOR_BUSY);
BIND_ENUM_CONSTANT(CURSOR_DRAG);
BIND_ENUM_CONSTANT(CURSOR_CAN_DROP);
BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN);
BIND_ENUM_CONSTANT(CURSOR_VSIZE);
BIND_ENUM_CONSTANT(CURSOR_HSIZE);
BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE);
BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE);
BIND_ENUM_CONSTANT(CURSOR_MOVE);
BIND_ENUM_CONSTANT(CURSOR_VSPLIT);
BIND_ENUM_CONSTANT(CURSOR_HSPLIT);
BIND_ENUM_CONSTANT(CURSOR_HELP);
BIND_ENUM_CONSTANT(PRESET_TOP_LEFT);
BIND_ENUM_CONSTANT(PRESET_TOP_RIGHT);
BIND_ENUM_CONSTANT(PRESET_BOTTOM_LEFT);
BIND_ENUM_CONSTANT(PRESET_BOTTOM_RIGHT);
BIND_ENUM_CONSTANT(PRESET_CENTER_LEFT);
BIND_ENUM_CONSTANT(PRESET_CENTER_TOP);
BIND_ENUM_CONSTANT(PRESET_CENTER_RIGHT);
BIND_ENUM_CONSTANT(PRESET_CENTER_BOTTOM);
BIND_ENUM_CONSTANT(PRESET_CENTER);
BIND_ENUM_CONSTANT(PRESET_LEFT_WIDE);
BIND_ENUM_CONSTANT(PRESET_TOP_WIDE);
BIND_ENUM_CONSTANT(PRESET_RIGHT_WIDE);
BIND_ENUM_CONSTANT(PRESET_BOTTOM_WIDE);
BIND_ENUM_CONSTANT(PRESET_VCENTER_WIDE);
BIND_ENUM_CONSTANT(PRESET_HCENTER_WIDE);
BIND_ENUM_CONSTANT(PRESET_WIDE);
BIND_ENUM_CONSTANT(PRESET_MODE_MINSIZE);
BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_WIDTH);
BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT);
BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE);
BIND_ENUM_CONSTANT(SIZE_FILL);
BIND_ENUM_CONSTANT(SIZE_EXPAND);
BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL);
BIND_ENUM_CONSTANT(SIZE_SHRINK_CENTER);
BIND_ENUM_CONSTANT(SIZE_SHRINK_END);
BIND_ENUM_CONSTANT(MOUSE_FILTER_STOP);
BIND_ENUM_CONSTANT(MOUSE_FILTER_PASS);
BIND_ENUM_CONSTANT(MOUSE_FILTER_IGNORE);
BIND_ENUM_CONSTANT(GROW_DIRECTION_BEGIN);
BIND_ENUM_CONSTANT(GROW_DIRECTION_END);
BIND_ENUM_CONSTANT(GROW_DIRECTION_BOTH);
BIND_ENUM_CONSTANT(ANCHOR_BEGIN);
BIND_ENUM_CONSTANT(ANCHOR_END);
ADD_SIGNAL(MethodInfo("resized"));
ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
ADD_SIGNAL(MethodInfo("focus_entered"));
ADD_SIGNAL(MethodInfo("focus_exited"));
ADD_SIGNAL(MethodInfo("size_flags_changed"));
ADD_SIGNAL(MethodInfo("minimum_size_changed"));
ADD_SIGNAL(MethodInfo("modal_closed"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_point", PropertyInfo(Variant::VECTOR2, "point")));
}
Control::Control() {
data.parent = NULL;
data.mouse_filter = MOUSE_FILTER_STOP;
data.pass_on_modal_close_click = true;
data.SI = NULL;
data.MI = NULL;
data.RI = NULL;
data.modal = false;
data.theme_owner = NULL;
data.modal_exclusive = false;
data.default_cursor = CURSOR_ARROW;
data.h_size_flags = SIZE_FILL;
data.v_size_flags = SIZE_FILL;
data.expand = 1;
data.rotation = 0;
data.parent_canvas_item = NULL;
data.scale = Vector2(1, 1);
data.drag_owner = 0;
data.modal_frame = 0;
data.block_minimum_size_adjust = false;
data.disable_visibility_clip = false;
data.h_grow = GROW_DIRECTION_END;
data.v_grow = GROW_DIRECTION_END;
data.minimum_size_valid = false;
data.updating_last_minimum_size = false;
data.clip_contents = false;
for (int i = 0; i < 4; i++) {
data.anchor[i] = ANCHOR_BEGIN;
data.margin[i] = 0;
}
data.focus_mode = FOCUS_NONE;
data.modal_prev_focus_owner = 0;
}
Control::~Control() {
}
|