[go: up one dir, main page]

Menu

[r52]: / lpi_gui.cpp  Maximize  Restore  History

Download this file

6147 lines (5114 with data), 179.9 kB

   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
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
/*
Copyright (c) 2005-2007 Lode Vandevenne
All rights reserved.
This file is part of Lode's Programming Interface.
Lode's Programming Interface is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Lode's Programming Interface is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Lode's Programming Interface. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lpi_gui.h"
#include "lodepng.h"
#include "lpi_general.h"
#include "lpi_screen.h"
#include "lpi_draw2dgl.h"
#include "lpi_draw2d.h"
#include <SDL/SDL.h>
namespace lpi
{
namespace gui
{
Texture builtInTexture[128];
BackPanel builtInPanel[4];
BackRule builtInRule[2];
GuiSet builtInGuiSet;
MouseState::MouseState()
{
justdown_prev = 0;
justdownhere_prev = 0;
grabbed_grabbed = 0;
grabbed_prev = 0;
downhere_bool1 = 0;
downhere_bool2 = 0;
justuphere_bool1 = 0;
justuphere_bool2 = 0;
}
////////////////////////////////////////////////////////////////////////////////
//TEXTURESET////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
A PNG image, encoded in base64, containing all the GUI images
First use the function decodeBase64
Then use the function LodePNG::Decoder::decode
And you get the pixels in a buffer
*/
const std::string builtInTextureData = "\
iVBORw0KGgoAAAANSUhEUgAAAFAAAABgCAIAAAAFCWJXAAAAK3RFWHRDcmVhdGlvbiBUaW1lAG1h\n\
IDEwIGphbiAyMDA1IDIxOjE0OjA5ICswMTAwDaUqSAAAAAd0SU1FB9UFBgAdIz6n6v4AAAAJcEhZ\n\
cwAATiAAAE4gARZ9md4AAAAEZ0FNQQAAsY8L/GEFAAAI70lEQVR42u2cXWgUVxTH7ySbTYxaNWr8\n\
AIPfBlQQRJ9asy15iWDEolB98CG0hhZBUkFpkzYbyGqF2iAESoKI5EELSiG1xD4swdgnReqLb0at\n\
MajU7xiTTZrs9D9zNrOTmZ2Ze2dm43aS0+0yc+fMved3z7nn3rszUZJlmelEwn+2IrO0flNTU7Qx\n\
aq8fbUorNDY2OtZvuMWxfjKJp1qSEP7v6emhk4qKCp57NH1OiUQi/MpKhzamjnl7p9FRazJwTgm/\n\
r9xJ3vsGnGpRPMwZySQYt0INYNxmm0EoKCQm8ysHQaZdSM8AB11mgIMuM8BBlxngoMu0A1Z3S/xL\n\
UVqH5pq+GLDErl279q9JxsbGzIVRKYp7cktfkDnn9sPuxT4uJvolKMAS6+rqsomIY9IxYg5U0tq9\n\
e7e5sK6uTn/63oBramo4Nffv38+p2dnZuXfvXn3J4cOHW1panIEPHjyYVVrR+vn1L1++rHVQbW1t\n\
a2urQSHDGKYb4IG2tjb72jOGkKFHreoXFR57SC5evEhNQB+j13DV6GF9SKCH7KtGCBlKzD1qU7+o\n\
ONrDI5OAzR7DGLC/HyGkHfN4QK8vKpwehns7OjrOnTuXsYMmhTQ8ljGt2zdAIYQGHDX1+qK0nPUj\n\
glA/aaKDwMyVtEQFPZoL+ohQQwRhiOXKtASPcWrCY5ya5pzCTEk0KCstme2UdtorBAuY8e6c1CcP\n\
ubbdy+b2UPAe2ZW+6ROLxawuudEXsSe1H+bUj0gRxgT1TQbFTsTq6+tjLFb/bT1PJQ76gvv51Bje\n\
sWOHrIrSCxYHN2/e1FoR1TdYDxMjkQgPs6i+o7iflkKhUEFBgbl81qxZxcXF9tZXVFTgW/HbiRgP\n\
Lac+l9ke7wfz6OionpbHeqY+lLb3m15fkiSEjC9+dg+MQQIn4yAcDo+MjOCgqKiILg0NDRnelTHQ\n\
ktgwG2hR4hezJw8jDVBUFxYWaoXDw8M8tDbMZloSX5i9hrTGrNEaFGxoMzJb0frFnPWVlsLAYrDP\n\
irmnp0exPpayXq8PNgMzSgz6Uw1sSNRIWmYn2zBntN6K2TutV2CNlpIWjWQwI2nxMNtYb2b2hZZ5\n\
nIfpQJuWEokEHWSchxWGmMJAL/I5Wq/X94uW+ZK09DkZ8WwzFev9xmO9qH52gTEPG6YfjVlbY9ow\n\
cFovqs8LfP36daHbRPXNDPzWi+rby5Tsh7MtIvZI/Hs9kkhFxK4xM6FkfckFj3Ul9CK343uXHpIW\n\
1dzdxoqLlE9RWPmWqsxmUcpx3UR7e3toQg5IBzz1nXtgmPLLSYUwmUwXJmX2T5wVFTLpIx+CWWJn\n\
zpzRJj+SS5cuoWSPtMd1/a7mYdCe/U5Bra5jlV+ysXHlA9qynay0EumbDfzp9TVviZ0+fdrq4pUr\n\
V7T6Ecn0QTDjo536CsxUZx6oZ7/+yP5oZR/WKJDln7LeTtbXxUo+ZqNcjyBsaE+dOmWvcvXqVXd9\n\
Kg6MZn76WnHp+aaUb+M/K99/XVA48fn7d5YYYf1pg/SbR9+FHKv5Vju10nc1hoH31UkHnd70QwDt\n\
hwFOgubmZh7FeDxeKVVOyUstAFb3Lmxig5oydeJY2d8MJVwCZ1ncAzuIDthmde2jcP7lg6ukxZOT\n\
ctXD4sCI2eaz7PsvzL+/kCjlv7WwT2q10SUGLLOGhgYexcpK4QHsCpgETs7ErJRciOndKwycZXEF\n\
jH794TwxEySJcqm9QaH97Bt93wtPSzI7fvy4vUpVVZW7xZbbpaWyxzqvHDR8zsIFLJSf+hxqTl31\n\
KDI7Kh3F0jLjxV27drluwsPmIbVVPJuh0BeR2RHpCFM3D1rZvn37PLbi+Wdajrat0htn5YekQ0LN\n\
ORhjsAySl5dHB8lkEgsJ+s5qj/gK4WBM2sPgLCgoQIIJh8P5+flM/dVqVBX6pc4em9zoqWvc0vI3\n\
CiNTwCDE5DF37twPVKGJJJFIvHnzZmBgYHBwcGhoSL+K1AihDAUcz5kzB2qpfsxoAd/7zO71+SRE\n\
pmP1N3/+/KVLl65YsWL58uUgRzlIHj9+3N/f//TpU6Y+EzTcXFZWtnr1akQEQuDVq1eoAdh37tx5\n\
9uyZBq9Zz/k+s0t9IWCEMQwFbXl5+aZNm9asWbNw4UKUv3jx4t69ewBganiPj4+PjIxo3gPqypUr\n\
N2/ejOZxF9TmzZuHvlu0aFF3d/e7d+/eQ3jzAGPoAhiRCd/C7u3bt4MEpzD37du3RA53IbaHh4fB\n\
BmyUIATg3q1bt27btg03QhM6GzdufPjwIXXN7Nmzc5M5D6MXuQqEy5Ytg29XrVq1ZMkS+ArxiQPA\n\
oxBBjpJQKKQ9mx5UhZDQEcjkiA5UAvciwtevX49LPlrp4/vbCgNIkKVgLvyJb1hMYDjAaUlJCaUx\n\
9AvCgW6jYQ+F0tJSuHft2rVI5rdu3dqwYcPz588p/yEFGBrz8n41//vS9jJpLZ3xeax52YBC+B+h\n\
C+De3l4wg7avr2/Lli24ijyHqEEvmBvz+H61P+9LIxoxMjEDwSEvX77EN6ynWRcHOEXqwjcUtIdJ\n\
6ALk5HXr1uESQv3169e4EdjwLXkViZ1ZLLCE3q928f62o4TAABLkJHgGOZmyFAIS5sL6Bw8eoPDJ\n\
kyc41jIWBJy3b9+urq7GSKakBYVHjx7R6Fi8ePGCBQvQCxmb5H+/2t372w7A8DAmG1gMt9AMBL8Z\n\
piWQgAdqSfVnd/QROghpCVcRBUhad+/exVAvLi6G2o0bN3BqRUvS0dEBAI++cu9hAqbVBTyG0Ygs\n\
hWMUwu2gxSWU02N+EtwFpHg8jtkbORxXQUsrk/v371NVuSmpaYapj+2x/AAqwlVbWg6oAnIca/Gc\n\
vnlilsKNlKUQGogLpl9dyvqmrMX10lJwLS2ljyQJE09YFXqiA0JELByLYZPUP0PKhG3ZaraXHu6A\n\
tXPaG+KbEjXtDYO0PZz5p2mCLjPA1iIHIvp5gUEr+i9p5apw/I0FsnQ0GhX6s4zc/UwvWkdgPa1M\n\
r0783z/8tAHx8/SitQIOLG1GYCvaYI5hG9qA+Hl60eqBpwXtNNwe/geKSkSJyAJVpgAAAABJRU5E\n\
rkJggg==\
";
void initBuiltInGuiTextures()
{
LodePNG::Decoder pngdec;
std::vector<unsigned char> decoded64;
const int GDW = 80; //width of the gui data
const int GDH = 96; //height of the gui data
//read the data string into buffer
std::vector<unsigned char> dataBuffer;
dataBuffer.resize(GDH * GDW * 4);
decodeBase64(decoded64, builtInTextureData);
pngdec.decode(dataBuffer, decoded64);
/*
Below the built in gui textures are loaded from the buffer.
Coordinates gotten by looking at the texture that's encoded here, in a painting program.
*/
//panel
builtInTexture[0].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 0, 2, 2);
builtInTexture[1].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 2, 0, 3, 2);
builtInTexture[2].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 3, 0, 5, 2);
builtInTexture[3].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 2, 2, 3);
builtInTexture[4].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 2, 2, 3, 3);
builtInTexture[5].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 3, 2, 5, 3);
builtInTexture[6].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 3, 2, 5);
builtInTexture[7].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 2, 3, 3, 5);
builtInTexture[8].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 3, 3, 5, 5);
for(size_t i = 0; i < 9; i++) builtInGuiSet.windowTextures[i] = &builtInTexture[i];
//button normal
builtInTexture[9].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 16, 0, 18, 2);
builtInTexture[10].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 18, 0, 19, 2);
builtInTexture[11].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 19, 0, 21, 2);
builtInTexture[12].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 16, 2, 18, 3);
builtInTexture[13].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 18, 2, 19, 3);
builtInTexture[14].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 19, 2, 21, 3);
builtInTexture[15].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 16, 3, 18, 5);
builtInTexture[16].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 18, 3, 19, 5);
builtInTexture[17].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 19, 3, 21, 5);
for(size_t i = 0; i < 9; i++) builtInGuiSet.buttonTextures[i] = &builtInTexture[i + 9];
for(size_t i = 0; i < 9; i++) builtInGuiSet.buttonOverTextures[i] = &builtInTexture[i + 9];
//button pressed
builtInTexture[18].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 32, 0, 34, 2);
builtInTexture[19].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 34, 0, 35, 2);
builtInTexture[20].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 35, 0, 37, 2);
builtInTexture[21].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 32, 2, 34, 3);
builtInTexture[22].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 34, 2, 35, 3);
builtInTexture[23].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 35, 2, 37, 3);
builtInTexture[24].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 32, 3, 34, 5);
builtInTexture[25].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 34, 3, 35, 5);
builtInTexture[26].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 35, 3, 37, 5);
for(size_t i = 0; i < 9; i++) builtInGuiSet.buttonDownTextures[i] = &builtInTexture[i + 18];
//button arrow up
builtInTexture[27].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 16, 16, 32);
builtInGuiSet.arrowN = &builtInTexture[27];
//button arrow down
builtInTexture[28].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 16, 16, 32, 32);
builtInGuiSet.arrowS = &builtInTexture[28];
//button arrow left
builtInTexture[29].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 32, 16, 48, 32);
builtInGuiSet.arrowW = &builtInTexture[29];
//button arrow right
builtInTexture[30].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 48, 16, 64, 32);
builtInGuiSet.arrowE = &builtInTexture[30];
//empty button & scroller
builtInTexture[31].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 64, 32, 80, 48);
builtInGuiSet.emptyButton = &builtInTexture[31];
builtInGuiSet.scroller = &builtInTexture[31];
//scrollbar background
builtInTexture[32].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 48, 16, 64);
builtInGuiSet.scrollbarBackground = &builtInTexture[32];
builtInGuiSet.scrollBarPairCorner = &builtInTexture[32];
//check box unchecked
builtInTexture[33].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 32, 16, 48);
builtInGuiSet.checkBox[0] = &builtInTexture[33];
//check box checked
builtInTexture[34].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 16, 32, 32, 48);
builtInGuiSet.checkBox[1] = &builtInTexture[34];
//bullet unchecked
builtInTexture[35].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 32, 32, 48, 48);
builtInGuiSet.bullet[0] = &builtInTexture[35];
//bullet checked
builtInTexture[36].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 48, 32, 64, 48);
builtInGuiSet.bullet[1] = &builtInTexture[36];
//image (smiley :D)
builtInTexture[37].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 16, 48, 32, 64);
builtInGuiSet.smiley = &builtInTexture[37];
//horizontal line
builtInTexture[41].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 48, 0, 50, 2);
builtInTexture[42].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 50, 0, 51, 2);
builtInTexture[43].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 51, 0, 53, 2);
for(size_t i = 0; i < 3; i++) builtInGuiSet.hline[i] = &builtInTexture[i + 41];
//vertical line
builtInTexture[44].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 64, 0, 66, 2);
builtInTexture[45].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 64, 2, 66, 3);
builtInTexture[46].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 64, 3, 66, 5);
for(size_t i = 0; i < 3; i++) builtInGuiSet.vline[i] = &builtInTexture[i + 44];
//window top bar (also a horizontal line)
builtInTexture[47].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 32, 48, 33, 64);
builtInTexture[48].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 33, 48, 34, 64);
builtInTexture[49].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 34, 48, 35, 64);
for(size_t i = 0; i < 3; i++) builtInGuiSet.windowTop[i] = &builtInTexture[i + 47];
//crosshair
builtInTexture[50].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 64, 48, 72, 56);
builtInGuiSet.crossHair = &builtInTexture[50];
//round button
builtInTexture[51].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 48, 48, 64, 64);
builtInGuiSet.roundButton = &builtInTexture[51];
builtInGuiSet.slider = &builtInTexture[51];
//particle 1
builtInTexture[52].create(&dataBuffer[0], GDW, GDH, AE_Particle, 0, 64, 16, 80);
//particle 2
builtInTexture[53].create(&dataBuffer[0], GDW, GDH, AE_Particle, 16, 64, 32, 80);
//close button
builtInTexture[54].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 64, 16, 80, 32);
builtInGuiSet.closeButton = &builtInTexture[54];
//minimize button
//55
//maximize button
//56
//white button
//57
//resizer of window (corner at bottom right)
builtInTexture[58].create(&dataBuffer[0], GDW, GDH, AE_GreenKey, 0, 80, 16, 96);
builtInGuiSet.resizer = &builtInTexture[58];
//panels
builtInPanel[0].makeTextured(builtInGuiSet.windowTextures[0], RGB_White);
builtInGuiSet.windowPanel = &builtInPanel[0];
builtInPanel[1].makeTextured(builtInGuiSet.buttonTextures[0], RGB_White);
builtInGuiSet.buttonPanel = &builtInPanel[1];
builtInPanel[2].makeTextured(builtInGuiSet.buttonOverTextures[0], RGB_Grey);
builtInGuiSet.buttonOverPanel = &builtInPanel[2];
builtInPanel[3].makeTextured(builtInGuiSet.buttonDownTextures[0], RGB_Grey);
builtInGuiSet.buttonDownPanel = &builtInPanel[3];
//rules (= 1D versions of panels)
builtInRule[0] = BackRule(1);
builtInGuiSet.sliderHRule = &builtInRule[0];
builtInRule[1] = BackRule(2);
builtInGuiSet.sliderVRule = &builtInRule[1];
//colors
builtInGuiSet.mainColor = RGB_White;
builtInGuiSet.mouseOverColor = RGB_Brightred;
builtInGuiSet.mouseDownColor = RGB_Grey;
//markup
builtInGuiSet.panelButtonMarkup[0] = TS_B;
builtInGuiSet.panelButtonMarkup[1] = TS_B;
builtInGuiSet.panelButtonMarkup[2] = TS_B;
builtInGuiSet.textButtonMarkup[0] = TS_Shadow;
builtInGuiSet.textButtonMarkup[1] = TS_RShadow;
builtInGuiSet.textButtonMarkup[2] = TS_RShadow;
}
Texture& TextureSet::operator[](int index)
{
return texture[index];
}
////////////////////////////////////////////////////////////////////////////////
//BACKPANEL/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The BackPanel functions.
BackPanel is a class containing 9 textures, being able to draw textured panels of any size with those.
See the .h file for meaning of vareous variables of the classes
*/
//Constructors
BackPanel::BackPanel()
{
this->colorMod = RGB_White;
this->fillColor = RGB_White;
this->enableSides = 0;
this->enableCenter = 0;
this->t00 = &emptyTexture;
this->t01 = &emptyTexture;
this->t02 = &emptyTexture;
this->t10 = &emptyTexture;
this->t11 = &emptyTexture;
this->t12 = &emptyTexture;
this->t20 = &emptyTexture;
this->t21 = &emptyTexture;
this->t22 = &emptyTexture;
}
BackPanel::BackPanel(int style)
{
switch(style)
{
case 1:
this->colorMod = RGB_White;
this->fillColor = RGB_White;
this->enableSides = 1;
this->enableCenter = 1;
this->t00 = &builtInTexture[0];
this->t01 = &builtInTexture[1];
this->t02 = &builtInTexture[2];
this->t10 = &builtInTexture[3];
this->t11 = &builtInTexture[4];
this->t12 = &builtInTexture[5];
this->t20 = &builtInTexture[6];
this->t21 = &builtInTexture[7];
this->t22 = &builtInTexture[8];
break;
default: break;
}
}
BackPanel::BackPanel(const ColorRGB& color)
{
makeUntextured(color);
}
void BackPanel::makeUntextured(const ColorRGB& fillColor)
{
this->colorMod = RGB_White;
this->fillColor = fillColor;
this->enableSides = 0;
this->enableCenter = 0;
this->t00 = &emptyTexture;
this->t01 = &emptyTexture;
this->t02 = &emptyTexture;
this->t10 = &emptyTexture;
this->t11 = &emptyTexture;
this->t12 = &emptyTexture;
this->t20 = &emptyTexture;
this->t21 = &emptyTexture;
this->t22 = &emptyTexture;
}
void BackPanel::makeTextured9(const Texture* t00, const Texture* t01, const Texture* t02, const Texture* t10, const Texture* t11, const Texture* t12, const Texture* t20, const Texture* t21, const Texture* t22,
const ColorRGB& colorMod)
{
this->colorMod = colorMod;
this->enableSides = 1;
this->enableCenter = 1;
this->t00 = t00;
this->t01 = t01;
this->t02 = t02;
this->t10 = t10;
this->t11 = t11;
this->t12 = t12;
this->t20 = t20;
this->t21 = t21;
this->t22 = t22;
}
void BackPanel::makeTextured(const Texture* t00, const ColorRGB& colorMod)
{
this->colorMod = colorMod;
this->enableSides = 1;
this->enableCenter = 1;
this->t00 = &t00[0];
this->t01 = &t00[1];
this->t02 = &t00[2];
this->t10 = &t00[3];
this->t11 = &t00[4];
this->t12 = &t00[5];
this->t20 = &t00[6];
this->t21 = &t00[7];
this->t22 = &t00[8];
}
/*The draw function of the BackPanel: draws the 9 different textures tiled or
non-tiled at the positions needed to get a window at the correct position
with the correct size*/
void BackPanel::draw(int x, int y, int width, int height) const
{
//draw rectangle
if(!enableCenter)
{
drawRectangle(x, y, x + width, y + height, fillColor);
}
//if center texture enabled, draw center texture instead, as repeated texture. MUST HAVE POWER OF TWO SIDES TO LOOK AS SUPPOSED!
else
{
if(t11 != 0) t11->drawRepeated(x + t00->getU(), y + t00->getV(), x + width - t02->getU(), y + height - t20->getV(), 1.0, 1.0, colorMod);
}
//draw sides
if(enableSides)
{
t01->drawRepeated(x + t00->getU(), y , x + width - t02->getU(), y + t00->getV() , 1.0, 1.0, colorMod);
t21->drawRepeated(x + t00->getU(), y + height - t20->getV(), x + width - t02->getU(), y + height , 1.0, 1.0, colorMod);
t10->drawRepeated(x, y + t00->getV() , x + t00->getU() , y + height - t20->getV(), 1.0, 1.0, colorMod);
t12->drawRepeated(x + width - t02->getU(), y + t00->getV() , x + width , y + height - t20->getV(), 1.0, 1.0, colorMod);
}
//draw corners
if(enableSides)
{
t00->draw(x , y , colorMod); //top left
t02->draw(x + width - t02->getU(), y , colorMod); //top right
t20->draw(x , y + height - t20->getV(), colorMod); //bottom left
t22->draw(x + width - t02->getU(), y + height - t20->getV(), colorMod); //bottom right
}
}
////////////////////////////////////////////////////////////////////////////////
//BACKRULE//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
a BackRule is a collection of 3 textures (2 corners and 1 tileable center) that
can form a horizontal or vertical line
*/
//Constructors
BackRule::BackRule()
{
this->colorMod = RGB_White;
this->enableSides = 0;
this->t0 = &emptyTexture;
this->t1 = &emptyTexture;
this->t2 = &emptyTexture;
}
BackRule::BackRule(int style)
{
switch(style)
{
case 1: //a default horizontal BackRule
this->direction = H;
this->colorMod = RGB_White;
this->enableSides = 1;
this->t0 = &builtInTexture[41];
this->t1 = &builtInTexture[42];
this->t2 = &builtInTexture[43];
break;
case 2: //a default vertical BackRule
this->direction = V;
this->colorMod = RGB_White;
this->enableSides = 1;
this->t0 = &builtInTexture[44];
this->t1 = &builtInTexture[45];
this->t2 = &builtInTexture[46];
break;
default: break;
}
}
void BackRule::makeHorizontal(const Texture* t0, Texture* t1, Texture* t2,
const ColorRGB& colorMod)
{
this->direction = H;
this->colorMod = colorMod;
this->enableSides = 1;
this->t0 = t0;
this->t1 = t1;
this->t2 = t2;
}
void BackRule::makeHorizontal1(const Texture* t0, const ColorRGB& colorMod)
{
this->direction = H;
this->colorMod = colorMod;
this->enableSides = 1;
this->t0 = &t0[0];
this->t1 = &t0[1];
this->t2 = &t0[2];
}
void BackRule::makeVertical(const Texture* t0, Texture* t1, Texture* t2,
const ColorRGB& colorMod)
{
this->direction = V;
this->colorMod = colorMod;
this->enableSides = 1;
this->t0 = t0;
this->t1 = t1;
this->t2 = t2;
}
void BackRule::makeVertical1(const Texture* t0, const ColorRGB& colorMod)
{
this->direction = V;
this->colorMod = colorMod;
this->enableSides = 1;
this->t0 = &t0[0];
this->t1 = &t0[1];
this->t2 = &t0[2];
}
void BackRule::draw(int x, int y, int length) const
{
if(direction == H)
{
//draw center texture tiled, as repeated texture. MUST HAVE POWER OF TWO SIDES TO LOOK AS SUPPOSED!
t1->drawRepeated(x + t0->getU(), y, x + length - t2->getU(), y + t0->getV(), 1.0, 1.0, colorMod);
//draw endpoints
if(enableSides)
{
t0->draw(x, y, colorMod); //left
t2->draw(x + length - t2->getU(), y, colorMod); //right
}
}
else
{
//draw center texture tiled, as repeated texture. MUST HAVE POWER OF TWO SIDES TO LOOK AS SUPPOSED!
t1->drawRepeated(x, y + t0->getV(), x + t0->getU(), y + length - t2->getV(), 1.0, 1.0, colorMod);
//draw endpoints
if(enableSides)
{
t0->draw(x, y, colorMod); //left
t2->draw(x, y + length - t2->getV(), colorMod); //right
}
}
}
////////////////////////////////////////////////////////////////////////////////
//BASICELEMENT
////////////////////////////////////////////////////////////////////////////////
int BasicElement::mouseGetRelPosX() const
{
return globalMouseX - x0;
}
int BasicElement::mouseGetRelPosY() const
{
return globalMouseY - y0;
}
bool BasicElement::mouseOver() const
{
bool over = 0;
//some variables used during case calculations
int relX, relY, symX, symY;
//only if the mouse is in the rectangle, and the current object is on top, the other shapes should be tested
if(globalMouseX >= x0 && globalMouseX < x1 && globalMouseY >= y0 && globalMouseY < y1)
switch(shape)
{
case 0: //rectangle
over = 1;
break;
case 1: //triangle pointing up
relX = globalMouseX - x0;
relY = globalMouseY - y0;
symX = std::abs(getSizex() / 2 - relX); //it's symmetrical
if(relY >= (2 * symX * getSizey()) / getSizex()) over = 1;
break;
case 2: //triangle pointing right
relX = globalMouseX - x0;
relY = globalMouseY - y0;
symY = std::abs(getSizey() / 2 - relY); //it's symmetrical
if(getSizex() - relX >= (2 * symY * getSizex()) / getSizey()) over = 1;
break;
case 3: //triangle pointing down
relX = globalMouseX - x0;
relY = globalMouseY - y0;
symX = std::abs(getSizex() / 2 - relX); //it's symmetrical
if(getSizey() - relY >= (2 * symX * getSizey()) / getSizex()) over = 1;
case 4: //triangle pointing left
relX = globalMouseX - x0;
relY = globalMouseY - y0;
symY = std::abs(getSizey() / 2 - relY); //it's symmetrical
if(relX >= (2 * symY * getSizey()) / getSizey()) over = 1;
break;
default: //rectangle
over = 1;
break;
}
return over;
}
bool BasicElement::mouseDown(MouseButton button) const
{
return mouseOver() && getGlobalMouseButton(button);
}
bool BasicElement::mouseDownHere(MouseState& state, MouseButton button) const
{
bool down = getGlobalMouseButton(button);//mouseDown(button);
bool over = mouseOver();
if(!down)
{
state.downhere_bool1 = false;
state.downhere_bool2 = false;
}
if(down && state.downhere_bool2 == false) //state.downhere_bool2 means justOver (it's the prevstate)
{
state.downhere_bool2 = true;
state.downhere_bool1 = over; //true means it was inside when just clicked, false that it was not
}
return state.downhere_bool1 && over;
}
bool BasicElement::mouseDownHere(MouseButton button)
{
return mouseDownHere(_mouseState[button], button);
}
bool BasicElement::mouseGrabbed(MouseState& state, MouseButton button) const
{
if(!mouseGrabbable()) return false;
//grab
if(mouseJustDownHere(state.grabbed_prev, button))
{
state.grabbed_grabbed = true;
state.grabx = globalMouseX;
state.graby = globalMouseY;
state.grabrelx = mouseGetRelPosX();
state.grabrely = mouseGetRelPosY();
}
//ungrab
if(!getGlobalMouseButton(button))
{
state.grabbed_grabbed = false;
state.grabbed_prev = false;
}
return state.grabbed_grabbed;
}
bool BasicElement::mouseGrabbed(MouseButton button)
{
return mouseGrabbed(_mouseState[button], button);
}
void BasicElement::mouseGrab(MouseState& state) const
{
state.grabbed_grabbed = true;
state.grabx = globalMouseX;
state.graby = globalMouseY;
state.grabrelx = mouseGetRelPosX();
state.grabrely = mouseGetRelPosY();
}
void BasicElement::mouseGrab(MouseButton button)
{
mouseGrab(_mouseState[button]);
}
void BasicElement::mouseUngrab(MouseState& state) const
{
state.grabbed_grabbed = false;
state.grabbed_prev = false;
}
void BasicElement::mouseUngrab(MouseButton button)
{
mouseUngrab(_mouseState[button]);
}
bool BasicElement::mouseJustDown(bool& prevstate, MouseButton button) const
{
bool nowDown = mouseOver() && getGlobalMouseButton(button);
if(nowDown)
{
if(!prevstate)
{
prevstate = true;
return true;
}
else return false;
}
else
{
prevstate = false;
return false;
}
}
bool BasicElement::mouseJustDown(MouseState& state, MouseButton button) const
{
return mouseJustDown(state.justdown_prev, button);
}
bool BasicElement::mouseJustDown(MouseButton button)
{
return mouseJustDown(_mouseState[button], button);
}
bool BasicElement::mouseJustDownHere(bool& prevstate, MouseButton button) const
{
bool nowDown = mouseOver() && getGlobalMouseButton(button);
if(nowDown)
{
if(!prevstate)
{
prevstate = true;
return true;
}
else return false;
}
else
{
prevstate = false;
}
if(!mouseOver()) prevstate = true; //so that it can't return true anymore after mouse was not on this
return false;
}
bool BasicElement::mouseJustDownHere(MouseState& state, MouseButton button) const
{
return mouseJustDownHere(state.justdownhere_prev, button);
}
bool BasicElement::mouseJustDownHere(MouseButton button)
{
return mouseJustDownHere(_mouseState[button], button);
}
bool BasicElement::mouseJustUpHere(MouseState& state, MouseButton button) const
{
if(mouseJustDownHere(state.justuphere_bool1, button))
{
state.justuphere_bool2 = true;
}
if(state.justuphere_bool2 && !getGlobalMouseButton(button))
{
state.justuphere_bool2 = false;
if(mouseOver()) return true;
else return false;
}
return false;
}
bool BasicElement::mouseJustUpHere(MouseButton button)
{
return mouseJustUpHere(_mouseState[button], button);
}
bool BasicElement::pressed(MouseButton button)
{
return mouseActive() && mouseJustDownHere(button);
}
bool BasicElement::clicked(MouseButton button)
{
return mouseActive() && mouseJustUpHere(button);
}
bool BasicElement::mouseScrollUp() const
{
return mouseActive() && mouseOver() && globalMouseWheelUp;
}
bool BasicElement::mouseScrollDown() const
{
return mouseActive() && mouseOver() && globalMouseWheelDown;
}
bool BasicElement::mouseDoubleClicked(MouseState& state, MouseButton button) const
{
bool dclick = 0;
bool down = mouseOver() && getGlobalMouseButton(button); //is the button down
switch(state.doubleClickState)
{
case 0:
if(down)
{
state.doubleClickTime = getTicks() / 1000.0;
state.doubleClickState = 1;
}
break;
case 1:
if(!down)
{
state.doubleClickState = 2;
}
break;
case 2:
if(down)
{
state.doubleClickState = 3;
}
break;
case 3:
if(!down)
{
state.doubleClickState = 0;
if(getTicks() / 1000.0 - state.doubleClickTime < doubleClickTime) dclick = 1;
}
break;
}
if
(
(state.doubleClickState > 0 && (getTicks() / 1000.0) - state.doubleClickTime > doubleClickTime)
|| (!mouseOver())
)
{
state.doubleClickState = 0;
state.doubleClickTime = 0;
}
return dclick;
}
bool BasicElement::mouseDoubleClicked(MouseButton button)
{
return mouseDoubleClicked(_mouseState[button], button);
}
BasicElement::BasicElement() : x0(0),
y0(0),
x1(0),
y1(0),
shape(0),
doubleClickTime(500)
{}
////////////////////////////////////////////////////////////////////////////////
//GUIELEMENT////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
GuiElement is the mother class of all the other GUI classes below.
*/
Element::Element() : selfActivate(false),
minSizex(0),
minSizey(0),
labelX(0),
labelY(0),
tooltipenabled(false),
hasBackgroundRectangle(false),
elementOver(false),
notDrawnByContainer(false)
{
totallyEnable();
}
void Element::drawBorder(const ColorRGB& color)
{
drawLine(x0 , y0 , x0 , y1 - 1, color);
drawLine(x1 - 1, y0 , x1 - 1, y1 - 1, color);
drawLine(x0 , y0 , x1 - 1, y0 , color);
drawLine(x0 , y1 - 1, x1 - 1, y1 - 1, color);
}
void Element::drawLabel() const
{
if(label.length() > 0)
print(label, x0 + labelX, y0 + labelY, labelMarkup);
}
void Element::drawToolTip() const
{
if(tooltipenabled && mouseOver())
{
int x = globalMouseX;
int y = globalMouseY - 6;
int sizex = tooltip.size() * 6 + 4;
int sizey = 8;
drawRectangle(x, y, x + sizex, y + sizey, RGBA_Lightyellow(224));
print(tooltip, x + 2, y + 2, TS_Black6);
}
}
void Element::makeLabel(const std::string& label, int labelX, int labelY, const Markup& labelMarkup)
{
this->label = label;
this->labelX = labelX;
this->labelY = labelY;
this->labelMarkup = labelMarkup;
}
bool Element::mouseOver() const
{
if(!present) return false;
if(elementOver) return false; //there is another element over this element, so says the container containing this element
return BasicElement::mouseOver();
}
bool Element::mouseGrabbable() const
{
return present;
}
void Element::draw() const
{
if(!visible) return;
if(hasBackgroundRectangle) drawRectangle(x0, y0, x1, y1, backgroundRectangleColor);
drawWidget();
drawLabel();
}
/*void Element::drawWidget() const
{
//this function is pure virtual
}*/
void Element::move(int x, int y)
{
this->x0 += x;
this->y0 += y;
this->x1 += x;
this->y1 += y;
moveWidget(x, y);
}
void Element::moveWidget(int /*x*/, int /*y*/)
{
//this function is virtual
}
void Element::moveTo(int x, int y)
{
this->move(x - this->x0, y - this->y0);
}
void Element::moveCenterTo(int x, int y)
{
this->moveTo(x - this->getSizex() / 2, y - this->getSizey() / 2);
}
void Element::autoActivate()
{
if(selfActivate)
{
if(mouseDownHere(auto_activate_mouse_state)) active = 1;
else
{
if(!mouseOver() && globalLMB && !mouseGrabbed(auto_activate_mouse_state)) active = 0; //"forceActive" enabled so that this disactivating also works if mouseActive is false!
//without the mouseGrabbed() test, it'll become inactive when you grab the scrollbar scroller and go outside with the mouse = annoying
}
}
}
void Element::handle()
{
autoActivate();
if(!active) return;
handleWidget();
//no stuff needed for most elements
}
void Element::handleWidget()
{
//no stuff needed for most elements
}
void Element::setElementOver(bool state)
{
elementOver = state;
}
bool Element::hasElementOver() const
{
return elementOver;
}
bool Element::isContainer() const
{
return 0;
}
//I have serious doubts if this function shouldn't be made obsolete: use a container the size of the screen instead and use it's function to keep elements inside...
//no wait the function is still handy here and there if you want to compare something to the screen, not it's container, or if there is no container at all
void Element::putInScreen()
{
int newx = x0, newy = y0;
if(x0 < 0) newx = 0;
if(y0 < 0) newy = 0;
if(x1 >= screenWidth()) newx = screenWidth() - getSizex();
if(y1 >= screenHeight()) newy = screenWidth() - getSizey();
moveTo(newx, newy);
}
void Element::resize(int x0, int y0, int x1, int y1)
{
if(x1 - x0 < minSizex) x1 = x0 + minSizex;
if(y1 - y0 < minSizey) y1 = y0 + minSizey;
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
resizeWidget();
}
void Element::resizeWidget()
{
//nothing to do. Overload this for guielements that need to do something to sub elements if they resize.
}
//this function uses ix0, iy0, ix1 and iy1 so only use if those values are properly set!
void Element::resizeSticky(int x0, int y0, int x1, int y1)
{
int newMasterSizex = x1 - x0;
int newMasterSizey = y1 - y0;
int ex0, ey0, ex1, ey1; //the new positions for this element that have to be calculated now
ex0 = int(x0 + ix0 + (leftSticky * newMasterSizex) - (leftSticky * iMasterSizex));
ey0 = int(y0 + iy0 + (topSticky * newMasterSizey) - (topSticky * iMasterSizey));
ex1 = int(x0 + ix1 + (rightSticky * newMasterSizex) - (rightSticky * iMasterSizex));
ey1 = int(y0 + iy1 + (bottomSticky * newMasterSizey) - (bottomSticky * iMasterSizey));
if(leftSticky == -2.0) ex0 = this->x0;
else if(leftSticky == -3.0) {ex0 = this->x0; if(ex0 < x0) ex1 = ex1 + (x0 - ex0), ex0 = x0;}
if(topSticky == -2.0) ey0 = this->y0;
else if(topSticky == -3.0) {ey0 = this->y0; if(ey0 < y0) ey1 = ey1 + (y0 - ey0), ey0 = y0;}
if(rightSticky == -2.0) ex1 = this->x1;
else if(rightSticky == -3.0) {ex1 = this->x1; if(ex1 > x1) ex0 = ex0 - (ex1 - x1), ex1 = x1;}
if(bottomSticky == -2.0) ey1 = this->y1;
else if(bottomSticky == -3.0) {ey1 = this->y1; if(ey1 > y1) ey0 = ey0 - (ey1 - y1), ey1 = y1;}
resize(ex0, ey0, ex1, ey1);
}
////////////////////////////////////////////////////////////////////////////////
//GUICONTAINER//////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Contains many elements in it and draws them and handles them, and even makes
sure you can't press the mouse "through" elements on top of other elements.
Also can have scrollbars.
*/
void Container::setScrollSizeToElements()
{
int newx0 = x0, newy0 = y0, newx1 = x1, newy1 = y1;
if(size() > 0)
{
newx0 = element[0]->getX0();
newy0 = element[0]->getY0();
newx1 = element[0]->getX1();
newy1 = element[0]->getY1();
}
for(unsigned i = 1; i < size(); i++)
{
if(element[i]->getX0() < newx0) newx0 = element[i]->getX0();
if(element[i]->getY0() < newy0) newy0 = element[i]->getY0();
if(element[i]->getX1() > newx1) newx1 = element[i]->getX1();
if(element[i]->getY1() > newy1) newy1 = element[i]->getY1();
}
area.resizeSticky(newx0, newy0, newx1, newy1);
}
Container::Container() : keepElementsInside(false), enableTooltips(true)
{
clear(); //clear the element list
totallyEnable();
//the default container is as big as the screen (note: don't forget to resize it if you resize the resolution of the screen!)
x0 = 0;
y0 = 0;
x1 = screenWidth();
y1 = screenHeight();
}
void Container::make(int x, int y, int sizex, int sizey,
int areax, int areay, int areasizex, int areasizey, //areax and areay are relative to the container!
double areaLeftSticky, double areaTopSticky, double areaRightSticky, double areaBottomSticky)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
bars.make(x, y, sizex, sizey);
bars.disableV();
bars.disableH();
bars.setSticky(0, 0, 1, 1);
bars.saveInitialPosition(this->x0, this->y0, this->x1, this->y1);
if(areasizex == -1)
{
areax = 0;
areasizex = sizex;
}
if(areasizey == -1)
{
areay = 0;
areasizey = sizey;
}
area.make(this->x0 + areax, this->y0 + areay, this->x0 + areax + areasizex, this->y0 + areay + areasizey);
area.setSticky(areaLeftSticky, areaTopSticky, areaRightSticky, areaBottomSticky);
area.saveInitialPosition(this->x0, this->y0, this->x1, this->y1);
initBars();
}
void Container::setElementOver(bool state)
{
Element::setElementOver(state);
bars.setElementOver(state);
for(size_t i = 0; i < size(); i++) element[i]->setElementOver(state);
}
void Container::toggleBars() //turns bars on or of if they're needed or not (depending on visible size and scroll area size) (different than MS Windows where scrollbars become inactive grey when not needed)
{
if(area.getSizex() <= getVisibleSizex() && area.getSizey() <= getVisibleSizey())
{
bars.disableH();
bars.disableV();
}
else if(area.getSizex() > getVisibleSizex() && area.getSizey() <= getVisibleSizey())
{
bars.enableH();
bars.disableV();
}
else if(area.getSizex() <= getVisibleSizex() && area.getSizey() > getVisibleSizey())
{
bars.disableH();
bars.enableV();
}
else if(area.getSizex() > getVisibleSizex() && area.getSizey() > getVisibleSizey())
{
bars.enableH();
bars.enableV();
}
}
void Container::initBars()
{
toggleBars();
bars.vbar.scrollSize = area.getSizey() - getVisibleSizey();
bars.hbar.scrollSize = area.getSizex() - getVisibleSizex();
bars.vbar.scrollPos = y0 - area.getY0();
bars.hbar.scrollPos = x0 - area.getX0();
}
void Container::updateBars()
{
toggleBars();
bars.hbar.scrollSize = area.getSizex() - getVisibleSizex();
bars.vbar.scrollSize = area.getSizey() - getVisibleSizey();
if(bars.hbar.scrollSize < 0) bars.hbar.scrollSize = 0;
if(bars.vbar.scrollSize < 0) bars.vbar.scrollSize = 0;
if(bars.hbar.scrollPos > bars.hbar.scrollSize) bars.hbar.scrollPos = bars.hbar.scrollSize;
if(bars.vbar.scrollPos > bars.vbar.scrollSize) bars.vbar.scrollPos = bars.vbar.scrollSize;
}
int Container::getVisibleX0() const
{
return x0;
}
int Container::getVisibleY0() const
{
return y0;
}
int Container::getVisibleX1() const
{
if(bars.venabled) return x1 - bars.vbar.getSizex();
else return x1;
}
int Container::getVisibleY1() const
{
if(bars.henabled) return y1 - bars.hbar.getSizey();
else return y1;
}
int Container::getVisibleSizex() const
{
return getVisibleX1() - getVisibleX0();
}
int Container::getVisibleSizey() const
{
return getVisibleY1() - getVisibleY0();
}
void Container::handleWidget()
{
//if(mouseOver())
if(!elementOver)
{
int topElement = -1;
//priority to mouseGrabbed over mouseOver
//for(size_t i = 0; i < size(); i++)
for(int i = size() - 1; i >= 0; i--)
{
element[i]->setElementOver(0);
if(element[i]->mouseGrabbed(element[i]->getMouseStateForContainer()))
{
if(topElement < 0) topElement = i;
//break;
}
element[i]->setElementOver(1);
}
//only now test mouseOver
if(topElement == -1)
for(int i = size() - 1; i >= 0; i--)
{
element[i]->setElementOver(0);
if(element[i]->mouseOver())
{
topElement = i;
break;
}
element[i]->setElementOver(1);
}
//if(topElement >= 0) std::cout << size() << " " << topElement << "\n";
//for(int j = 0; j < int(size()); j++)
for(int j = size() - 1; j >= 0; j--)
if(j != topElement)
{
element[j]->setElementOver(1);
//element[j]->unGrab(mouse_state_for_containers);
}
else
{
element[j]->setElementOver(0);
if(element[j]->isContainer() && element[j]->mouseDownHere(element[j]->getMouseStateForContainer())) pushTop(element[j]);
}
}
//else setElementOver(true); //some elements may be left without element over status...
/*if(mouseOver())
for(int i = size() - 1; i >= 0; i--)
{
element[i]->setElementOver(0);
//element[i]->autoActivate(); //let the self activate system of the element work now, otherwise the element will never get selfactivated because the mouseover test below returns false if the element is not active
if(element[i]->mouseOver() || element[i]->mouseGrabbed(mouse_state_for_containers)) //forceActive of mouseOver is enabled, so that this test also works if the element isn't active (mouseActive should be handled even if the element is inactive). Note that the container itself must be mouseActive too; the mouseOver test is because I don't want elements outside the container to react to the mouse (but they should be able to react to the keyboard if they're an active textinput box)
{
topElement = i;
for(int j = topElement - 1; j >= 0; j--) element[j]->setElementOver(1); //make elements below top NOT mouseactive. After all, the topElement is on top of those.
break; //it's very important to stop the loop now, so that this is the ONLY top element under mouse pointer with mouseActive = true!
}
else
{
element[i]->setElementOver(1); //this element isn't under the mouse, so may not react on mouse (during this frame)
}
}
else for(int j = size() - 1; j >= 0; j--) element[j]->setElementOver(1); //if this container isn't mouseActive, none of its elements should be.
if(topElement >= 0 && topElement < int(element.size()) && element[topElement]->isContainer() && (element[topElement]->mouseDownHere(mouse_state_for_containers))))
{
pushTop(element[topElement]); //bring window on which you clicked to the top
}*/
if(keepElementsInside)
for(unsigned long i = 0; i < size(); i++)
{
if(element[i]->mouseGrabbed(element[i]->getMouseStateForContainer())) putInside(i);
}
for(unsigned long i = 0; i < size(); i++)
{
element[i]->handle();
}
bars.handle();
int scrollx = x0 - int(bars.hbar.scrollPos); //the scrollpos is 0 if a bar is not enabled
int scrolly = y0 - int(bars.vbar.scrollPos);
moveAreaTo(scrollx, scrolly);
}
void Container::moveAreaTo(int x, int y)
{
for(unsigned long i = 0; i < size(); i++) element[i]->move(x - area.getX0(), y - area.getY0());
area.moveTo(x, y);
}
void Container::drawWidget() const
{
setSmallestScissor(getVisibleX0(), getVisibleY0(), getVisibleX1(), getVisibleY1()); //currently does same as setScissor (because otherwise there's weird bug, to reproduce: resize the red window and look at smiley in the small grey window), so elements from container in container are still drawn outside container. DEBUG THIS ASAP!!!
Element* tooltipelement = 0;
for(unsigned long i = 0; i < size(); i++)
{
if(!element[i]->isNotDrawnByContainer())
{
element[i]->draw();
if(enableTooltips && element[i]->tooltipenabled && element[i]->mouseOver()) tooltipelement = element[i];
}
}
resetScissor();
//tooltip (only 1 can be active at the same time)
if(enableTooltips && tooltipelement) tooltipelement->drawToolTip();
bars.draw();
}
unsigned long Container::size() const
{
return element.size();
}
void Container::remove(Element* element)
{
for(unsigned long i = 0; i < size(); i++)
{
if(element == this->element[i])
{
this->element.erase(this->element.begin() + i);
}
}
}
void Container::pushTop(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
pushTopAt(element, element->getX0() - x0, element->getY0() - y0, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::pushBottom(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
pushBottomAt(element, element->getX0() - x0, element->getY0() - y0, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::insert(size_t pos, Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
insertAt(pos, element, element->getX0() - x0, element->getY0() - y0, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::pushTopRelative(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
pushTopAt(element, element->getX0(), element->getY0(), leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::pushBottomRelative(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
pushBottomAt(element, element->getX0(), element->getY0(), leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::insertRelative(size_t pos, Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
insertAt(pos, element, element->getX0(), element->getY0(), leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::pushTopAt(Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
remove(element); //prevent duplicates
this->element.push_back(element);
initElement(element, x, y, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::pushBottomAt(Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
remove(element); //prevent duplicates
this->element.insert(this->element.begin(), element);
initElement(element, x, y, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::insertAt(size_t pos, Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
remove(element); //prevent duplicates
this->element.insert(this->element.begin() + pos, element);
initElement(element, x, y, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Container::initElement(Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
element->moveTo(x0 + x, y0 + y);
//sticky factors for resizing
element->setSticky(leftSticky, topSticky, rightSticky, bottomSticky);
//remembering coordinates for proper resizing
element->saveInitialPosition(area.getX0(), area.getY0(), area.getX1(), area.getY1());
}
bool Container::isContainer() const
{
return 1;
}
void Container::clear()
{
element.clear();
}
void Container::putInside(unsigned long i)
{
if(/*i >= 0 &&*/ i < size())
{
int ex0 = element[i]->getX0();
int ey0 = element[i]->getY0();
int ex1 = element[i]->getX1();
int ey1 = element[i]->getY1();
int esx = ex1 - ex0;
int esy = ey1 - ey0;
int newx = ex0, newy = ey0;
if(ex0 < area.getX0()) newx = area.getX0();
if(ey0 < area.getY0()) newy = area.getY0();
if(ex1 > area.getX1()) newx = area.getX1() - esx;
if(ey1 > area.getY1()) newy = area.getY1() - esy;
//if the size of the element is too large to fit in the window, there's no reason to move it (or it'll warp all the time)
if(element[i]->getSizex() > area.getSizex()) newx = element[i]->getX0();
if(element[i]->getSizey() > area.getSizey()) newy = element[i]->getY0();
element[i]->moveTo(newx, newy);
}
}
void Container::moveWidget(int x, int y)
{
for(unsigned long i = 0; i < size(); i++) element[i]->move(x, y);
bars.move(x, y);
area.move(x, y);
}
void Container::getRelativeElementPos(Element& element, int& ex, int& ey) const
{
ex = element.getX0() - x0;
ey = element.getY0() - y0;
}
void Container::resizeWidget()
{
bars.resizeSticky(x0, y0, x1, y1);
area.resizeSticky(x0, y0, x1, y1);
updateBars(); //if this is done at the wrong moment, the bars may appear after resizing the container at times where it isn't desired
for(unsigned long i = 0; i < size(); i++)
{
element[i]->resizeSticky(area.getX0(), area.getY0(), area.getX1(), area.getY1());
}
}
void Container::saveInitialPositions()
{
for(unsigned long i = 0; i < size(); i++)
{
element[i]->saveInitialPosition(area.getX0(), area.getY0(), area.getX1(), area.getY1());
}
}
////////////////////////////////////////////////////////////////////////////////
//GUIGROUP//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
bool Group::mouseOver() const
{
if(!present) return false;
if(elementOver) return false; //there is another element over this element, so says the container containing this element
for(int i = size() - 1; i >= 0; i--)
{
element[i]->setElementOver(0);
if(element[i]->mouseOver()) return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
//GUIPANEL//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The Panel functions.
Panel is a class containing a backpanel, but it also shares the Element functions
*/
Panel::Panel()
{
this->panel.colorMod = RGB_White;
this->panel.fillColor = RGB_White;
this->panel.enableSides = 0;
this->panel.enableCenter = 0;
this->panel.t00 = &emptyTexture;
this->panel.t01 = &emptyTexture;
this->panel.t02 = &emptyTexture;
this->panel.t10 = &emptyTexture;
this->panel.t11 = &emptyTexture;
this->panel.t12 = &emptyTexture;
this->panel.t20 = &emptyTexture;
this->panel.t21 = &emptyTexture;
this->panel.t22 = &emptyTexture;
}
void Panel::makeUntextured(int x, int y, int sizex, int sizey, const ColorRGB& fillColor)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->totallyEnable();
this->panel.makeUntextured(fillColor);
}
void Panel::makeTextured(int x, int y, int sizex, int sizey,
const Texture* t00, const ColorRGB& colorMod, int shape)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->totallyEnable();
this->shape = shape;
this->panel.makeTextured(t00, colorMod);
}
void Panel::make(int x, int y, int sizex, int sizey,
const GuiSet* set, int shape)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->totallyEnable();
this->shape = shape;
this->panel = *set->windowPanel;
}
//this function should become obsolete after there is a general "moveTo, resize" combo function which is planned to be made
void Panel::setSize(int x, int y, int sizex, int sizey)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
}
void Panel::drawWidget() const
{
panel.draw(x0, y0, getSizex(), getSizey());
}
////////////////////////////////////////////////////////////////////////////////
//GUILINE//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Rule is a class containing a BackLine, but it also shares the Element functions
*/
Rule::Rule()
{
this->line.colorMod = RGB_White;
this->line.enableSides = 0;
this->line.t0 = &emptyTexture;
this->line.t1 = &emptyTexture;
this->line.t2 = &emptyTexture;
}
void Rule::makeHorizontal(int x, int y, int length, const GuiSet* set)
{
this->x0 = x;
this->y0 = y;
this->setSizex(length);
this->setSizey(set->hline[0]->getV());
this->totallyEnable();
this->shape = 0;
this->line.makeHorizontal1(set->hline[0], set->mainColor);
}
void Rule::makeHorizontal1(int x, int y, int length, Texture* t0, const ColorRGB& colorMod)
{
this->x0 = x;
this->y0 = y;
this->setSizex(length);
this->setSizey(t0->getV());
this->totallyEnable();
this->shape = 0;
this->line.makeHorizontal1(t0, colorMod);
}
void Rule::makeVertical(int x, int y, int length, const GuiSet* set)
{
this->x0 = x;
this->y0 = y;
this->setSizey(length);
this->setSizex(set->vline[0]->getU());
this->totallyEnable();
this->shape = 0;
this->line.makeVertical1(set->vline[0], set->mainColor);
}
void Rule::makeVertical1(int x, int y, int length, Texture* t0, const ColorRGB& colorMod)
{
this->x0 = x;
this->y0 = y;
this->setSizey(length);
this->setSizex(t0->getU());
this->totallyEnable();
this->shape = 0;
this->line.makeVertical1(t0, colorMod);
}
void Rule::setSize(int x, int y, int length)
{
this->x0 = x;
this->y0 = y;
if(line.direction == H) this->setSizex(length);
else this->setSizey(length);
}
void Rule::drawWidget() const
{
if(line.direction == H) line.draw(x0, y0, getSizex());
else line.draw(x0, y0, getSizey());
}
////////////////////////////////////////////////////////////////////////////////
//GUIWINDOW/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Window is a window that contains pointers to any kind of other Elements.
When the window gets drawn, all Elements get drawn as well.
When the window moves, all Elements are moved as well.
You can still operate the Elements like you normally do.
The window also contains a Panel for it's own background, and will have a bar
at the top that allows you to drag the window if you click it with the mouse.
Things like the drawing order of the window, or detecting if you click on the
window and not something behind it, you'll have to do yourself...
*/
Window::Window()
{
this->active = 0;
this->visible = 0;
this->enableResizer = 0;
this->closed = 0;
this->resizerOverContainer = 0;
}
int Window::getRelContentStart() const
{
int result = 0;
if(enableTop) result = top.getY1() - y0;
return result;
}
void Window::addCloseButton(int offsetX, int offsetY, const GuiSet* set)
{
int closeX = x1 + offsetX - set->closeButton->getU();
int closeY = y0 + offsetY;
closeButton.makeImage(closeX, closeY, set->closeButton, set->closeButton, set->closeButton, set->mainColor, set->mouseOverColor, set->mouseDownColor);
closed = 0;
closeEnabled = 1;
closeButton.setSticky(1.0, 0.0, 1.0, 0.0);
closeButton.saveInitialPosition(x0, y0, x1, y1);
}
void Window::addResizer(const GuiSet* set, bool overContainer, int offsetX, int offsetY)
{
int resizerX = x1 - offsetX - set->resizer->getU();
int resizerY = y1 - offsetY - set->resizer->getV();
resizer.makeImage(resizerX, resizerY, set->resizer, set->resizer, set->resizer, set->mainColor, set->mouseOverColor, set->mouseDownColor);
enableResizer = true;
resizer.setSticky(1.0, 1.0, 1.0, 1.0);
resizer.saveInitialPosition(x0, y0, x1, y1);
if(!overContainer)
{
container.resize(container.getX0(), container.getY0(), container.getX1(), container.getY1() - (y1 - resizer.getY0()));
container.saveInitialPosition(x0, y0, x1, y1);
}
resizerOverContainer = overContainer;
}
//returns the lowest position the container bottom side is allowed to have (for example not over resizer if resizerOverContainer is false
int Window::getContainerLowest() const
{
int pos = y1;
if(enableResizer && !resizerOverContainer) pos = resizer.getY0();
return pos;
}
//returns the highest position the container top side is allowed to have
int Window::getContainerHighest() const
{
int pos = y0;
if(enableTop) pos = top.getY1();
return pos;
}
//returns the leftmost position the container left side is allowed to have
int Window::getContainerLeftmost() const
{
return x0;
}
//returns the rightmost position the container right side is allowed to have
int Window::getContainerRightmost() const
{
return x1;
}
void Window::setContainerBorders(int left, int up, int right, int down)
{
if(up < 0) up = left;
if(right < 0) right = left;
if(down < 0) down = left;
container.resize(getContainerLeftmost() + left, getContainerHighest() + up, getContainerRightmost() - right, getContainerLowest() - down);
container.saveInitialPosition(x0, y0, x1, y1);
}
bool Window::isContainer() const
{
return 1;
}
void Window::makeUntextured(int x, int y, int sizex, int sizey, const ColorRGB& fillColor)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->totallyEnable();
this->enableTop = 0;
this->panel.makeUntextured(fillColor);
initContainer();
}
void Window::makeTextured(int x, int y, int sizex, int sizey,
const Texture* t00, const ColorRGB& colorMod, int shape)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->totallyEnable();
this->shape = shape;
this->enableTop = 0;
this->panel.makeTextured(t00, colorMod);
initContainer();
}
void Window::make(int x, int y, int sizex, int sizey,
const GuiSet* set, int shape)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->totallyEnable();
this->shape = shape;
this->enableTop = 0;
this->panel = *set->windowPanel;
initContainer();
}
void Window::addTop(Texture* t0, int offsetLeft, int offsetRight, int offsetTop, const ColorRGB& colorMod)
{
top.makeHorizontal1(x0 + offsetLeft, y0 + offsetTop, getSizex() - offsetLeft - offsetRight, t0, colorMod);
this->enableTop = 1;
top.setSticky(0.0, 0.0, 1.0, 0.0);
top.saveInitialPosition(x0, y0, x1, y1);
container.resize(container.getX0(), container.getY0() + (top.getY1() - y0), container.getX1(), container.getY1());
container.saveInitialPosition(x0, y0, x1, y1);
}
void Window::initContainer()
{
container.make(x0, y0, getSizex(), getSizey());
container.setSticky(0.0, 0.0, 1.0, 1.0);
container.saveInitialPosition(x0, y0, x1, y1);
container.setKeepElementsInside(true);
}
//to let the scrollbars work properly, call this AFTER using setContainerBorders, addTop, addResizer and such of the window
void Window::addScrollbars(int areax, int areay, int areasizex, int areasizey, double areaStickyLeft, double areaStickyTop, double areaStickyRight, double areaStickyBottom)
{
container.make(container.getX0(), container.getY0(), container.getSizex(), container.getSizey(), areax, areay, areasizex, areasizey, areaStickyLeft, areaStickyTop, areaStickyRight, areaStickyBottom);
}
//this function could be obsolete once there's the resize function
void Window::setSize(int x, int y, int sizex, int sizey)
{
x0 = x;
y0 = y;
setSizex(sizex);
setSizey(sizey);
}
void Window::putInside(int i)
{
container.putInside(i);
}
void Window::handleWidget()
{
//the close button
if(closeEnabled && closeButton.clicked()) closed = 1;
container.handle();
//resize window
if(enableResizer && resizer.mouseGrabbed()) resize(x0, y0, globalMouseX - resizer.mouseGetRelGrabX() + (x1 - resizer.getX0()), globalMouseY - resizer.mouseGetRelGrabY() + (y1 - resizer.getY0()));
//drag window
if(!enableTop && mouseGrabbed()) moveTo(globalMouseX - mouseGetRelGrabX(), globalMouseY - mouseGetRelGrabY()); //um this means a window without top can always be dragged?? maybe I should turn this off? in case you want a non moveable window...
if(enableTop && top.mouseGrabbed())
{
moveTo(globalMouseX - top.mouseGetRelGrabX(), globalMouseY - top.mouseGetRelGrabY());
}
//the scrollbar's conserveCorner should be the same as this window's resizerOverContainer
container.bars.conserveCorner = resizerOverContainer;
}
void Window::drawWidget() const
{
panel.draw(x0, y0, getSizex(), getSizey());
if(enableTop)
{
top.draw(); //draw top bar before the elements, or it'll appear above windows relative to the current window
print(title, top.getX0() + titleX, top.getY0() + titleY, titleMarkup);
}
if(closeEnabled) closeButton.draw();
container.draw();
if(enableResizer) resizer.draw(); //draw this after the container so the resizer is drawn over scrollbars if that is needed
}
void Window::addTitle(const std::string& title, int titleX, int titleY, const Markup& titleMarkup)
{
this->title = title;
this->titleX = titleX;
this->titleY = titleY;
this->titleMarkup = titleMarkup;
}
void Window::setTitle(const std::string& title)
{
this->title = title;
}
void Window::moveWidget(int x, int y)
{
container.move(x, y);
top.move(x, y);
closeButton.move(x, y);
resizer.move(x, y);
}
void Window::resizeWidget()
{
container.resizeSticky(x0, y0, x1, y1);
top.resizeSticky(x0, y0, x1, y1);
closeButton.resizeSticky(x0, y0, x1, y1);
resizer.resizeSticky(x0, y0, x1, y1);
}
int Window::size()
{
return container.size();
}
void Window::remove(Element* element)
{
container.remove(element);
}
void Window::pushTopAt(Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.pushTopAt(element, x, y, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::pushBottomAt(Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.pushBottomAt(element, x, y, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::insertAt(size_t pos, Element* element, int x, int y, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.insertAt(pos, element, x, y, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::pushTop(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.pushTop(element, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::pushBottom(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.pushBottom(element, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::insert(size_t pos, Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.insert(pos, element, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::pushTopRelative(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.pushTopRelative(element, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::pushBottomRelative(Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.pushBottomRelative(element, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::insertRelative(size_t pos, Element* element, double leftSticky, double topSticky, double rightSticky, double bottomSticky)
{
container.insertRelative(pos, element, leftSticky, topSticky, rightSticky, bottomSticky);
}
void Window::setElementOver(bool state)
{
Element::setElementOver(state);
top.setElementOver(state);
resizer.setElementOver(state);
container.setElementOver(state); //this has to be done too, otherwise the container of this window (and thus all elements inside) will be accessible to the mouse through other windows that are on top of it
closeButton.setElementOver(state);
}
////////////////////////////////////////////////////////////////////////////////
//GUIBUTTON/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The Button functions.
Button is a class for a button supporting different graphics on mouseover,
and that can return if the mouse is over the button, the mouse is down, or the
mouse was down and is released again.
*/
//Empty Constructor
Button::Button()
{
this->enableImage = 0;
this->enableImage2 = 0;
this->enableText = 0;
this->enablePanel = 0;
this->image[0] = 0;
this->image[1] = 0;
this->image[2] = 0;
this->imageOffsetx = 0;
this->imageOffsety = 0;
this->imageColor[0] = RGB_Black;
this->imageColor[1] = RGB_Black;
this->imageColor[2] = RGB_Black;
this->text = "";
this->textOffsetx = 0;
this->textOffsety = 0;
this->markup[0] = TS_Black;
this->markup[1] = TS_Black;
this->markup[2] = TS_Black;
/*this->panel1.t00 = &emptyTexture;
this->panel1.t01 = &emptyTexture;
this->panel1.t02 = &emptyTexture;
this->panel1.t10 = &emptyTexture;
this->panel1.t11 = &emptyTexture;
this->panel1.t12 = &emptyTexture;
this->panel1.t20 = &emptyTexture;
this->panel1.t21 = &emptyTexture;
this->panel1.t22 = &emptyTexture;
this->panel2.t00 = &emptyTexture;
this->panel2.t01 = &emptyTexture;
this->panel2.t02 = &emptyTexture;
this->panel2.t10 = &emptyTexture;
this->panel2.t11 = &emptyTexture;
this->panel2.t12 = &emptyTexture;
this->panel2.t20 = &emptyTexture;
this->panel2.t21 = &emptyTexture;
this->panel2.t22 = &emptyTexture;
this->panelOffsetx = 0;
this->panelOffsety = 0;
this->panel1.colorMod = RGB_Black;
this->panel2.colorMod = RGB_Black;
this->panel1.enableSides = 0;
this->panel2.enableSides = 0;
this->panel1.enableCenter = 0;
this->panel2.enableCenter = 0;*/
this->active = 0;
this->visible = 0;
this->doubleClickTime = 500;
this->shape = 0;
this->mouseDownVisualStyle = 0;
}
//Full Constructor
void Button::make
(
int x, int y, int sizex, int sizey, //basic properties
bool enableImage, Texture* texture1, Texture* texture2, Texture* texture3, int imageOffsetx, int imageOffsety, const ColorRGB& imageColor1, const ColorRGB& imageColor2, const ColorRGB& imageColor3, //image
bool enableText, const std::string& text, int textOffsetx, int textOffsety, const Markup& markup1, const Markup& markup2, const Markup& markup3, //text
bool enablePanel, const BackPanel* panel1, const BackPanel* panel2, const BackPanel* panel3, int panelOffsetx, int panelOffsety, //panel
int shape //special options
)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->enableImage = enableImage;
this->enableText = enableText;
this->enablePanel = enablePanel;
this->image[0] = texture1;
this->image[1] = texture2;
this->image[2] = texture3;
this->imageOffsetx = imageOffsetx;
this->imageOffsety = imageOffsety;
this->imageColor[0] = imageColor1;
this->imageColor[1] = imageColor2;
this->imageColor[2] = imageColor3;
this->text = text;
this->textOffsetx = textOffsetx;
this->textOffsety = textOffsety;
this->markup[0] = markup1;
this->markup[1] = markup2;
this->markup[2] = markup3;
this->panel[0] = panel1;
this->panel[1] = panel2;
this->panel[2] = panel3;
this->panelOffsetx = panelOffsetx;
this->panelOffsety = panelOffsety;
/*if(panelTexture1 != &emptyTexture)
{
this->panel1.t00 = &panelTexture1[0]; //+ 0*sizeof(Texture);
this->panel1.t01 = &panelTexture1[1]; //+ 1*sizeof(Texture);
this->panel1.t02 = &panelTexture1[2]; //+ 2*sizeof(Texture);
this->panel1.t10 = &panelTexture1[3]; //+ 3*sizeof(Texture);
this->panel1.t11 = &panelTexture1[4]; //+ 4*sizeof(Texture);
this->panel1.t12 = &panelTexture1[5]; //+ 5*sizeof(Texture);
this->panel1.t20 = &panelTexture1[6]; //+ 6*sizeof(Texture);
this->panel1.t21 = &panelTexture1[7]; //+ 7*sizeof(Texture);
this->panel1.t22 = &panelTexture1[8]; //+ 8*sizeof(Texture);
}
if(panelTexture2 != &emptyTexture)
{
this->panel2.t00 = &panelTexture2[0]; //+ 0*sizeof(Texture);
this->panel2.t01 = &panelTexture2[1]; //+ 1*sizeof(Texture);
this->panel2.t02 = &panelTexture2[2]; //+ 2*sizeof(Texture);
this->panel2.t10 = &panelTexture2[3]; //+ 3*sizeof(Texture);
this->panel2.t11 = &panelTexture2[4]; //+ 4*sizeof(Texture);
this->panel2.t12 = &panelTexture2[5]; //+ 5*sizeof(Texture);
this->panel2.t20 = &panelTexture2[6]; //+ 6*sizeof(Texture);
this->panel2.t21 = &panelTexture2[7]; //+ 7*sizeof(Texture);
this->panel2.t22 = &panelTexture2[8]; //+ 8*sizeof(Texture);
}
this->panelOffsetx = panelOffsetx;
this->panelOffsety = panelOffsety;
this->panel1.colorMod = panelColor1;
this->panel2.colorMod = panelColor2;
this->panel1.enableSides = 1;
this->panel2.enableSides = 1;
this->panel1.enableCenter = 1;
this->panel2.enableCenter = 1;*/
this->totallyEnable();
this->doubleClickTime = 500;
this->shape = shape;
this->mouseDownVisualStyle = 0;
}
void Button::addFrontImage
(
const Texture* texture1, const Texture* texture2, const Texture* texture3, const ColorRGB& imageColor1, const ColorRGB& imageColor2, const ColorRGB& imageColor3
)
{
this->enableImage2 = 1;
this->image2[0] = texture1;
this->image2[1] = texture2;
this->image2[2] = texture3;
this->imageOffsetx2 = 0;
this->imageOffsety2 = 0;
this->imageColor2[0] = imageColor1;
this->imageColor2[1] = imageColor2;
this->imageColor2[2] = imageColor3;
}
void Button::addFrontImage(const Texture* texture)
{
addFrontImage(texture, texture, texture, imageColor[0], imageColor[1], imageColor[2]);
}
//Constructor to make a button with only images, no text
void Button::makeImage
(
int x, int y, //basic properties
const Texture* texture1, const Texture* texture2, const Texture* texture3, const ColorRGB& imageColor1, const ColorRGB& imageColor2, const ColorRGB& imageColor3, //image
int shape //special options
)
{
this->x0 = x;
this->y0 = y;
this->setSizex(texture1->getU());
this->setSizey(texture1->getV());
this->enableImage = 1;
this->enableText = 0;
this->enablePanel = 0;
this->image[0] = texture1;
this->image[1] = texture2;
this->image[2] = texture3;
this->imageOffsetx = 0;
this->imageOffsety = 0;
this->imageColor[0] = imageColor1;
this->imageColor[1] = imageColor2;
this->imageColor[2] = imageColor3;
this->text = "";
this->textOffsetx = 0;
this->textOffsety = 0;
this->markup[0] = TS_Black;
this->markup[1] = TS_Black;
this->markup[2] = TS_Black;
/*this->panel1.t00 = &emptyTexture;
this->panel1.t01 = &emptyTexture;
this->panel1.t02 = &emptyTexture;
this->panel1.t10 = &emptyTexture;
this->panel1.t11 = &emptyTexture;
this->panel1.t12 = &emptyTexture;
this->panel1.t20 = &emptyTexture;
this->panel1.t21 = &emptyTexture;
this->panel1.t22 = &emptyTexture;
this->panel2.t00 = &emptyTexture;
this->panel2.t01 = &emptyTexture;
this->panel2.t02 = &emptyTexture;
this->panel2.t10 = &emptyTexture;
this->panel2.t11 = &emptyTexture;
this->panel2.t12 = &emptyTexture;
this->panel2.t20 = &emptyTexture;
this->panel2.t21 = &emptyTexture;
this->panel2.t22 = &emptyTexture;
this->panelOffsetx = 0;
this->panelOffsety = 0;
this->panel1.colorMod = RGB_Black;
this->panel2.colorMod = RGB_Black;
this->panel1.enableSides = 0;
this->panel2.enableSides = 0;
this->panel1.enableCenter = 0;
this->panel2.enableCenter = 0;*/
this->totallyEnable();
this->doubleClickTime = 500;
this->shape = shape;
this->mouseDownVisualStyle = 0;
}
//Constructor to make a button with only text, no images
void Button::makeText
(
int x, int y, //basic properties
const std::string& text, //text
const GuiSet* set,
int shape //special options
)
{
this->x0 = x;
this->y0 = y;
this->setSizex(0);
this->setSizey(0);
this->enableImage = 0;
this->enableText = 1;
this->enablePanel = 0;
this->image[0] = 0;
this->image[1] = 0;
this->image[2] = 0;
this->imageOffsetx = 0;
this->imageOffsety = 0;
this->imageColor[0] = RGB_Black;
this->imageColor[1] = RGB_Black;
this->imageColor[2] = RGB_Black;
this->text = text;
this->textOffsetx = 0;
this->textOffsety = 0;
this->markup[0] = set->textButtonMarkup[0];
this->markup[1] = set->textButtonMarkup[1];
this->markup[2] = set->textButtonMarkup[2];
this->totallyEnable();
this->doubleClickTime = 500;
this->shape = shape;
this->mouseDownVisualStyle = 0;
autoTextSize();
}
//constructor for button with panel and text, auto generated text offset
void Button::makeTextPanel
(
int x, int y, const std::string& text, int sizex, int sizey, //basic properties + text
const GuiSet* set, //panel
int shape //special options
)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->enableImage = 0;
this->enableText = 1;
this->enablePanel = 1;
this->image[0] = 0;
this->image[1] = 0;
this->image[2] = 0;
this->imageOffsetx = 0;
this->imageOffsety = 0;
this->imageColor[0] = RGB_Black;
this->imageColor[1] = RGB_Black;
this->imageColor[2] = RGB_Black;
this->text = text;
this->textOffsetx = 0;
this->textOffsety = 0;
this->markup[0] = set->panelButtonMarkup[0];
this->markup[1] = set->panelButtonMarkup[0];
this->markup[2] = set->panelButtonMarkup[0];
this->panel[0] = set->buttonPanel;
this->panel[1] = set->buttonOverPanel;
this->panel[2] = set->buttonDownPanel;
this->panelOffsetx = 0;
this->panelOffsety = 0;
this->totallyEnable();
this->doubleClickTime = 500;
this->shape = shape;
this->mouseDownVisualStyle = 1;
//put text in the center
centerText();
}
//Draws the button, also checks for mouseover and mousedown to draw mouseover graphic
void Button::drawWidget() const
{
int i = 0; //0 = normal, 1 = mouseOver, 2 = mouseDown
if((mouseDownVisualStyle == 0 && mouseDown(LMB/*, 15*/))
|| (mouseDownVisualStyle == 1 && mouseDownHere(mutable_button_drawing_mouse_test))
|| (mouseDownVisualStyle == 2 && mouseGrabbed(mutable_button_drawing_mouse_test)))
i = 2;
else if(mouseOver()) i = 1;
int textDownOffset = 0;
if(i == 2) textDownOffset = 1; //on mouseDown, the text goes down a bit too
if(enablePanel) panel[i]->draw(x0 + panelOffsetx, y0 + panelOffsety, getSizex(), getSizey());
if(enableImage) image[i]->draw(x0 + imageOffsetx, y0 + imageOffsety, imageColor[i]);
if(enableImage2) image2[i]->draw(x0 + imageOffsetx2, y0 + imageOffsety2, imageColor2[i]);
if(enableText) printFormatted(text, x0 + textOffsetx + textDownOffset, y0 + textOffsety + textDownOffset, markup[i]);
//NOTE: ik heb de print functies nu veranderd naar printFormatted! Zo kan je gekleurde texten enzo printen met # codes
}
/*This function automaticly changes sizex and sizey of the button so that the
size of the button matches the size of the text, so that it detects the mouse
as being in the button when the mouse is over the text*/
void Button::autoTextSize(int extrasize)
{
setSizex(text.length() * markup[0].getWidth());
setSizey(markup[0].getHeight());
x1 += 2 * extrasize;
y1 += 2 * extrasize;
x0 -= extrasize;
y0 -= extrasize;
textOffsetx += extrasize;
textOffsety += extrasize;
}
/*Place the text in the center of the button without having to calculate
these positions by hand*/
void Button::centerText()
{
textOffsetx = (getSizex() / 2) - text.length() * (markup[0].getWidth() / 2); //4 = fontwidth / 2
textOffsety = (getSizey() / 2) - (markup[0].getHeight() / 2);
}
void Button::makeImage(int x, int y, const Texture* texture123, const ColorRGB& imageColor1, const ColorRGB& imageColor2, const ColorRGB& imageColor3, int shape)
{
makeImage(x, y, texture123, texture123, texture123, imageColor1, imageColor2, imageColor3, shape);
}
////////////////////////////////////////////////////////////////////////////////
//GUISCROLLBAR//////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The Scrollbar Class Functions
Scrollbar is a scrollbar that can be used for lists of things that are too
large to fit on screen so you have to scroll through them, for example useful
for Console.
It has a length on screen (sizey) and a length of the scroller (scrollSize), in
pixels, and you can scroll up or down with the mouse.
See gui.h for meanings of all the members of ScrollBar
*/
int Scrollbar::getSliderSize() const
{
if(direction == V)
{
return getSizey() - txUp->getV() - txDown->getV() - txScroller->getV(); //scroller length also subtracted from it: the scroller can only move over this distance since it's full width must always be inside the slider length
}
else
{
return getSizex() - txUp->getU() - txDown->getU() - txScroller->getU();
}
}
int Scrollbar::getSliderStart() const
{
if(direction == V)
{
return txUp->getV();
}
else
{
return txUp->getU();
}
}
int Scrollbar::getSliderEnd() const
{
if(direction == V)
{
return getSizey() - txDown->getV();
}
else
{
return getSizex() - txDown->getU();
}
}
void Scrollbar::init()
{
if(scrollSize == 0) scrollSize = 1;
if(direction == V)
{
buttonUp.makeImage(x0, y0, txUp, txUpOver, txUpOver, colorMod, colorModOver, colorModDown);
buttonDown.makeImage(x0, y1 - txDown->getV(), txDown, txDownOver, txDownOver, colorMod, colorModOver, colorModDown);
scroller.makeImage(x0, int(y0 + getSliderStart() + (getSliderSize() * scrollPos) / scrollSize), txScroller, txScrollerOver, txScrollerOver, colorMod, colorModOver, colorModDown);
buttonUp.setSticky(0, 0, 0, 0);
buttonDown.setSticky(0, 1, 0, 1);
scroller.setSticky(0, -2, 0, -2);
buttonDown.saveInitialPosition(x0, y0, x1, y1);
buttonUp.saveInitialPosition(x0, y0, x1, y1);
scroller.saveInitialPosition(x0, y0, x1, y1);
}
else
{
buttonUp.makeImage(x0, y0, txUp, txUpOver, txUpOver, colorMod, colorModOver, colorModDown);
buttonDown.makeImage(x1 - txDown->getU(), y0, txDown, txDownOver, txDownOver, colorMod, colorModOver, colorModDown);
scroller.makeImage(int(x0 + getSliderStart() + (getSliderSize() * scrollPos) / scrollSize), y0, txScroller, txScrollerOver, txScrollerOver, colorMod, colorModOver, colorModDown);
buttonUp.setSticky(0, 0, 0, 0);
buttonDown.setSticky(1, 0, 1, 0);
scroller.setSticky(-2, 0, -2, 0);
buttonDown.saveInitialPosition(x0, y0, x1, y1);
buttonUp.saveInitialPosition(x0, y0, x1, y1);
scroller.saveInitialPosition(x0, y0, x1, y1);
}
buttonUp.mouseDownVisualStyle = 1;
buttonDown.mouseDownVisualStyle = 1;
scroller.mouseDownVisualStyle = 2;
}
Scrollbar::Scrollbar()
{
this->scrollSize = 0;
this->scrollPos = 0;
this->scrollSpeed = 0;
this->txUp = &emptyTexture;
this->txDown = &emptyTexture;
this->txScroller = &emptyTexture;
this->txBack = &emptyTexture;
this->txUpOver = &emptyTexture;
this->txDownOver = &emptyTexture;
this->txScrollerOver = &emptyTexture;
this->colorMod = RGB_White;
this->colorModOver = RGB_White;
this->colorModDown = RGB_White;
this->absoluteSpeed = 0;
this->speedMode = 0;
this->enableValue = 0;
}
void Scrollbar::showValue(int x, int y, const Markup& valueMarkup, int type)
{
this->valueMarkup = valueMarkup;
this->valueX = x;
this->valueY = y;
this->enableValue = type;
}
void Scrollbar::makeVertical(int x, int y, int length,
double scrollSize, double scrollPos, double offset, double scrollSpeed,
const GuiSet* set, int speedMode)
{
this->x0 = x;
this->y0 = y;
this->direction = V;
this->setSizex(set->scroller->getU());
this->setSizey(length);
this->scrollSize = scrollSize;
this->scrollPos = scrollPos;
this->scrollSpeed = scrollSpeed;
this->offset = offset;
this->txUp = set->arrowN;
this->txDown = set->arrowS;
this->txScroller = set->scroller;
this->txBack = set->scrollbarBackground;
this->txUpOver = set->arrowN;
this->txDownOver = set->arrowS;
this->txScrollerOver = set->scroller;
this->colorMod = set->mainColor;
this->colorModOver = set->mouseOverColor;
this->colorModDown = set->mouseDownColor;
this->absoluteSpeed = scrollSpeed;
this->speedMode = speedMode;
this->totallyEnable();
init();
if(speedMode == 1) setRelativeScrollSpeed();
}
void Scrollbar::makeHorizontal(int x, int y, int length,
double scrollSize, double scrollPos, double offset, double scrollSpeed,
const GuiSet* set, int speedMode)
{
this->x0 = x;
this->y0 = y;
this->direction = H;
this->setSizex(length);
this->setSizey(set->scroller->getV());
this->scrollSize = scrollSize;
this->scrollPos = scrollPos;
this->scrollSpeed = scrollSpeed;
this->offset = offset;
this->txUp = set->arrowE;
this->txDown = set->arrowW;
this->txScroller = set->scroller;;
this->txBack = set->scrollbarBackground;
this->txUpOver = set->arrowE;
this->txDownOver = set->arrowW;
this->txScrollerOver = set->scroller;;
this->colorMod = set->mainColor;
this->colorModOver = set->mouseOverColor;
this->colorModDown = set->mouseDownColor;
this->absoluteSpeed = scrollSpeed;
this->speedMode = speedMode;
this->totallyEnable();
init();
if(speedMode == 1) setRelativeScrollSpeed();
}
double Scrollbar::getValue() const
{
return offset + scrollPos;
}
void Scrollbar::setValue(double value)
{
scrollPos = value - offset;
}
void Scrollbar::randomize()
{
double r = getRandom();
scrollPos = r * scrollSize;
}
void Scrollbar::handleWidget()
{
int scrollDir = 0;
if(buttonUp.mouseDownHere()) scrollDir = -1;
if(buttonDown.mouseDownHere()) scrollDir = 1;
if(direction == V)
{
if(scroller.mouseGrabbed())
scrollPos = (scrollSize * (globalMouseY - y0 - getSliderStart() - txScroller->getV() / 2)) / getSliderSize();
else if(mouseDownHere() && !scroller.mouseGrabbed() && !buttonUp.mouseGrabbed() && !buttonDown.mouseGrabbed())
{
scrollPos = (scrollSize * (globalMouseY - y0 - getSliderStart() - txScroller->getV() / 2)) / getSliderSize();
scroller.mouseGrab();
}
if(mouseScrollUp()) scrollDir = -2;
if(mouseScrollDown()) scrollDir = 2;
}
else
{
if(scroller.mouseGrabbed())
scrollPos = (scrollSize * (globalMouseX - x0 - getSliderStart() - txScroller->getU() / 2)) / getSliderSize();
else if(mouseDownHere() && !scroller.mouseGrabbed() && !buttonUp.mouseGrabbed() && !buttonDown.mouseGrabbed())
{
scrollPos = (scrollSize * (globalMouseX - x0 - getSliderStart() - txScroller->getU() / 2)) / getSliderSize();
scroller.mouseGrab();
}
}
if(scrollDir != 0)
{
scrollPos += scrollDir * absoluteSpeed * ((getTicks() - oldTime) / 1000.0);
}
oldTime = getTicks();
if(scrollPos < 0) scrollPos = 0;
if(scrollPos > scrollSize) scrollPos = scrollSize;
if(speedMode == 1) setRelativeScrollSpeed();
if(direction == V) scroller.moveTo(scroller.getX0(), int(y0 + getSliderStart() + (getSliderSize() * scrollPos) / scrollSize));
else scroller.moveTo(int(x0 + getSliderStart() + (getSliderSize() * scrollPos) / scrollSize), scroller.getY0());
}
void Scrollbar::resizeWidget()
{
scroller.resizeSticky(x0, y0, x1, y1);
buttonUp.resizeSticky(x0, y0, x1, y1);
buttonDown.resizeSticky(x0, y0, x1, y1);
}
//from an external source, use this function only BEFORE using the handle() function or getTicks() - oldTime will be zero
void Scrollbar::scroll(int dir)
{
scrollPos += dir * absoluteSpeed * (getTicks() - oldTime) / 1000.0;
}
void Scrollbar::drawWidget() const
{
//in the drawRepeated functions, sizeButton is divided through two, so if the arrow buttons have a few transparent pixels, in one half of the button you see the background through, in the other half not
if(direction == V)
{
txBack->drawRepeated(x0, y0 + getSliderStart(), x1, y0 + getSliderEnd(), 1.0, 1.0, colorMod);
}
else
{
txBack->drawRepeated(x0 + getSliderStart(), y0, x0 + getSliderEnd(), y1, 1.0, 1.0, colorMod);
}
buttonUp.draw();
buttonDown.draw();
if(scrollSize > 0) scroller.draw();
if(enableValue == 1)
{
print(getValue(), x0 + valueX, y0 + valueY, valueMarkup);
}
else if(enableValue == 2)
{
print(int(getValue()), x0 + valueX, y0 + valueY, valueMarkup);
}
}
void Scrollbar::setRelativePosition(float position)
{
scrollPos = int(position * getSliderSize());
}
void Scrollbar::setRelativeScrollSpeed()
{
absoluteSpeed = scrollSize / (scrollSpeed);
}
void Scrollbar::moveWidget(int x, int y)
{
scroller.move(x, y);
buttonUp.move(x, y);
buttonDown.move(x, y);
}
void Scrollbar::setElementOver(bool state)
{
Element::setElementOver(state);
scroller.setElementOver(state);
buttonUp.setElementOver(state);
buttonDown.setElementOver(state);
}
////////////////////////////////////////////////////////////////////////////////
//GUISCROLLBARPAIR//////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
a horizontal and vertical scrollbar in one, for use for areas that can be scrolled in two directions
*/
ScrollbarPair::ScrollbarPair() : venabled(false), henabled(false)
{
this->conserveCorner = 0;
scrollbarGuiSet = &builtInGuiSet;
}
int ScrollbarPair::getVisiblex() const
{
if(venabled) return x1 - x0 - vbar.getSizex();
else return x1 - x0;
}
int ScrollbarPair::getVisibley() const
{
if(venabled) return y1 - y0 - hbar.getSizey();
else return y1 - y0;
}
void ScrollbarPair::moveWidget(int x, int y)
{
vbar.move(x, y);
hbar.move(x, y);
}
void ScrollbarPair::make(int x, int y, int sizex, int sizey, double scrollSizeH, double scrollSizeV,
const GuiSet* set)
{
scrollbarGuiSet = set;
this->totallyEnable();
this->x0 = x;
this->y0 = y;
this->x1 = x + sizex;
this->y1 = y + sizey;
this->txCorner = set->scrollBarPairCorner;
vbar.makeVertical(x1 - set->arrowN->getU(), y0, sizey - set->arrowE->getV(),
scrollSizeV, 0, 0, 1,
set, 1);
hbar.makeHorizontal(x0, y1 - set->arrowW->getU(), sizex - set->arrowS->getU(),
scrollSizeH, 0, 0, 1,
set, 1);
vbar.setSticky(1, 0, 1, 1);
hbar.setSticky(0, 1, 1, 1);
vbar.saveInitialPosition(x0, y0, x1, y1);
hbar.saveInitialPosition(x0, y0, x1, y1);
this->venabled = 1;
this->henabled = 1;
}
void ScrollbarPair::disableV()
{
venabled = 0;
if(henabled)
hbar.makeHorizontal(hbar.getX0(), hbar.getY0(), getSizex() - vbar.getSizex() * conserveCorner,
hbar.scrollSize, hbar.scrollPos, hbar.offset, hbar.scrollSpeed,
scrollbarGuiSet, hbar.speedMode);
}
void ScrollbarPair::disableH()
{
henabled = 0;
if(venabled)
vbar.makeVertical(vbar.getX0(), vbar.getY0(), getSizey() - hbar.getSizey() * conserveCorner,
vbar.scrollSize, vbar.scrollPos, vbar.offset, vbar.scrollSpeed,
scrollbarGuiSet, vbar.speedMode);
}
void ScrollbarPair::enableV()
{
venabled = 1;
if(henabled)
{
vbar.makeVertical(vbar.getX0(), vbar.getY0(), getSizey() - hbar.getSizey(),
vbar.scrollSize, vbar.scrollPos, vbar.offset, vbar.scrollSpeed,
scrollbarGuiSet, vbar.speedMode);
hbar.makeHorizontal(hbar.getX0(), hbar.getY0(), getSizex() - vbar.getSizex(),
hbar.scrollSize, hbar.scrollPos, hbar.offset, hbar.scrollSpeed,
scrollbarGuiSet, hbar.speedMode);
}
else
{
vbar.makeVertical(vbar.getX0(), vbar.getY0(), getSizey() - hbar.getSizey() * conserveCorner,
vbar.scrollSize, vbar.scrollPos, vbar.offset, vbar.scrollSpeed,
scrollbarGuiSet, vbar.speedMode);
}
}
void ScrollbarPair::enableH()
{
henabled = 1;
if(venabled)
{
hbar.makeHorizontal(hbar.getX0(), hbar.getY0(), getSizex() - vbar.getSizex(),
hbar.scrollSize, hbar.scrollPos, hbar.offset, hbar.scrollSpeed,
scrollbarGuiSet, hbar.speedMode);
vbar.makeVertical(vbar.getX0(), vbar.getY0(), getSizey() - hbar.getSizey(),
vbar.scrollSize, vbar.scrollPos, vbar.offset, vbar.scrollSpeed,
scrollbarGuiSet, vbar.speedMode);
}
else
{
hbar.makeHorizontal(hbar.getX0(), hbar.getY0(), getSizex() - vbar.getSizex() * conserveCorner,
hbar.scrollSize, hbar.scrollPos, hbar.offset, hbar.scrollSpeed,
scrollbarGuiSet, hbar.speedMode);
}
}
void ScrollbarPair::handleWidget()
{
if(venabled) vbar.handle();
if(henabled) hbar.handle();
}
void ScrollbarPair::drawWidget() const
{
if(venabled) vbar.draw();
if(henabled) hbar.draw();
if((venabled && henabled && !conserveCorner) || ((venabled || henabled) && conserveCorner)) txCorner->draw(x1 - txCorner->getU(), y1 - txCorner->getV());
}
void ScrollbarPair::resizeWidget()
{
vbar.resizeSticky(x0, y0, x1, y1);
hbar.resizeSticky(x0, y0, x1, y1);
}
void ScrollbarPair::setElementOver(bool state)
{
Element::setElementOver(state);
vbar.setElementOver(state);
hbar.setElementOver(state);
}
////////////////////////////////////////////////////////////////////////////////
//GUISLIDER/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
A simplified version of the scrollbar
*/
Slider::Slider()
{
this->visible = 0;
this->active = 0;
}
void Slider::resizeWidget()
{
slider.resizeSticky(x0, y0, x1, y1);
}
void Slider::makeHorizontal(int x, int y, int length, double scrollSize, const GuiSet* set)
{
this->totallyEnable();
int sliderCenter = set->slider->getV() / 2;
int rulerCenter = set->sliderHRule->t0->getV() / 2;
int centerPos = sliderCenter;
if(rulerCenter > sliderCenter) centerPos = rulerCenter;
this->direction = H;
this->scrollPos = 0;
this->scrollSize = scrollSize;
this->x0 = x;
this->y0 = y;
this->setSizex(length);
this->setSizey(set->slider->getV());
this->ruler = set->sliderHRule;
this->slider.makeImage(x0, y0 + centerPos - sliderCenter, set->slider, set->slider, set->slider, set->mainColor, set->mouseOverColor, set->mouseDownColor);
slider.setSticky(-2, 0, -2, 0);
slider.saveInitialPosition(x0, y0, x1, y1);
slider.mouseDownVisualStyle = 2;
}
void Slider::makeVertical(int x, int y, int length, double scrollSize, const GuiSet* set)
{
this->totallyEnable();
int sliderCenter = set->slider->getU() / 2;
int rulerCenter = set->sliderVRule->t0->getU() / 2;
int centerPos = sliderCenter;
if(rulerCenter > sliderCenter) centerPos = rulerCenter;
this->direction = V;
this->scrollPos = 0;
this->scrollSize = scrollSize;
this->x0 = x;
this->y0 = y;
this->setSizey(length);
this->setSizex(set->slider->getU());
this->ruler = set->sliderVRule;
this->slider.makeImage(x + centerPos - sliderCenter, y, set->slider, set->slider, set->slider, set->mainColor, set->mouseOverColor, set->mouseDownColor);
slider.setSticky(0, -2, 0, -2);
slider.saveInitialPosition(x0, y0, x1, y1);
slider.mouseDownVisualStyle = 2;
}
//screenPos must be relative to the x or y position of the gui element!!!
double Slider::screenPosToScrollPos(int screenPos)
{
if(direction == H)
{
int sliderSize = slider.image[0]->getU();
return (scrollSize * (screenPos - sliderSize / 2)) / (getSizex() - sliderSize);
}
else //if(direction == V)
{
int sliderSize = slider.image[0]->getV();
return (scrollSize * (screenPos - sliderSize / 2)) / (getSizey() - sliderSize);
}
}
//screenPos is relative to the x or y position of the gui element!!!
int Slider::scrollPosToScreenPos(double scrollPos)
{
if(direction == H)
{
int sliderSize = slider.image[0]->getU();
return int(((getSizex() - sliderSize) * scrollPos) / scrollSize);
}
else //if(direction == V)
{
int sliderSize = slider.image[0]->getV();
return int(((getSizey() - sliderSize) * scrollPos) / scrollSize);
}
}
void Slider::drawWidget() const
{
if(direction == H)
{
int rulerCenter = ruler->t0->getV() / 2;
int centerPos = slider.getRelCentery();
if(rulerCenter > centerPos) centerPos = rulerCenter;
ruler->draw(x0, y0 + centerPos - rulerCenter, getSizex());
slider.draw();
}
else //if(direction == V)
{
int rulerCenter = ruler->t0->getU() / 2;
int centerPos = slider.getRelCenterx();
if(rulerCenter > centerPos) centerPos = rulerCenter;
ruler->draw(x0 + centerPos - rulerCenter, y0, getSizey());
slider.draw();
}
}
void Slider::handleWidget()
{
if(direction == H)
{
int rulerCenter = ruler->t0->getV() / 2;
int centerPos = slider.getRelCentery();
if(rulerCenter > centerPos) centerPos = rulerCenter;
//int sliderSize = slider.texture1->getU();
if(slider.mouseGrabbed()) scrollPos = screenPosToScrollPos(mouseGetRelPosX());
else if(mouseDownHere() && !slider.mouseOver())
{
scrollPos = screenPosToScrollPos(mouseGetRelPosX());
slider.mouseGrab();
}
if(scrollPos < 0) scrollPos = 0;
if(scrollPos > scrollSize) scrollPos = scrollSize;
slider.moveTo(x0 + scrollPosToScreenPos(scrollPos), slider.getY0());
}
else //if(direction == V)
{
int rulerCenter = ruler->t0->getV() / 2;
int centerPos = slider.getRelCenterx();
if(rulerCenter > centerPos) centerPos = rulerCenter;
//int sliderSize = slider.texture1->getV();
if(slider.mouseGrabbed()) scrollPos = screenPosToScrollPos(mouseGetRelPosY());
else if(mouseDownHere() && !slider.mouseOver())
{
scrollPos = screenPosToScrollPos(mouseGetRelPosY());
slider.mouseGrab();
}
if(scrollPos < 0) scrollPos = 0;
if(scrollPos > scrollSize) scrollPos = scrollSize;
slider.moveTo(slider.getX0(), y0 + scrollPosToScreenPos(scrollPos));
}
}
void Slider::moveWidget(int x, int y)
{
slider.move(x, y);
}
void Slider::setElementOver(bool state)
{
Element::setElementOver(state);
slider.setElementOver(state);
}
double Slider::getValue() const
{
return scrollPos;
}
void Slider::setValue(double value)
{
scrollPos = value;
}
double Slider::getRelValue() const
{
return scrollPos / scrollSize;
}
void Slider::setRelValue(double value)
{
scrollPos = scrollSize * value;
}
////////////////////////////////////////////////////////////////////////////////
//DropMenu/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The DropMenu class.
DropMenu is a list of text buttons, each having their own text.
The DropMenu can have a panel or rectangle behind the text buttons as background.
How to use the DropMenu class:
- x and y define the position of the top left corner of the menu
- text contains the text of all buttons, separated by '|' chars.
- put two '|' chars in a row to get a separator in the menu
- draw the menu on screen with it's draw() function
- It can be used perfectly for both right click menus of in game objects,
as for menus at the top of the program window
*/
//Constructor to make an empty menu
DropMenu::DropMenu()
{
this->markup1 = TS_White;
this->markup2 = TS_White;
setOptions("");
autoDisable = true;
}
//Constructor to make the menu
void DropMenu::makeColored(int x, int y, const std::string& text,
const Markup& markup1, const Markup& markup2,
const ColorRGB& menuColor, BackRule hrule)
{
this->x0 = x;
this->y0 = y;
this->totallyEnable();
this->markup1 = markup1;
this->markup2 = markup2;
this->panel.makeUntextured(menuColor);
this->hrule = hrule;
setOptions(text);
putInScreen(); //reposition then does setOptions a second time to fix changed positions
}
//Constructor to make the menu
void DropMenu::make(int x, int y, const std::string& text,
const Markup& markup1, const Markup& markup2,
BackPanel panel, BackRule hrule)
{
this->x0 = x;
this->y0 = y;
this->totallyEnable();
this->markup1 = markup1;
this->markup2 = markup2;
this->panel = panel;
this->hrule = hrule;
setOptions(text);
putInScreen(); //reposition then does setOptions a second time to fix changed positions
}
void DropMenu::clearOptions()
{
menuButton.clear();
separator.clear();
identity.clear();
}
/*Initialize the menu, calculate all positions, make the buttons, ...
This function is called automaticly by the constructors*/
void DropMenu::setOptions(const std::string& text)
{
clearOptions();
unsigned long maxTextSize = 0; //the size of the largest text
//calculate n, the number of elements
unsigned long pos = 0;
unsigned long n = 0;
while(pos < text.length())
{
if(text[pos] == '|') n++;
pos++;
}
n++;
unsigned long i = 0;
unsigned long t = 0;
while(i < n)
{
std::string buttonText = "";
while(text[t] != '|' && t < text.length())
{
buttonText += text[t];
t++;
if(text[t] == 0) break;
}
separator.push_back(false);
if(buttonText.length() == 0) separator[i] = true;
t++;
Button b;
b.makeText(x0 + 2, y0 + 2 + (markup1.getHeight() + 2) * i, buttonText);
menuButton.push_back(b);
identity.push_back(0); //no useful identity added, but it has to be increased in size to match menuButton size
if(buttonText.length() > maxTextSize) maxTextSize = buttonText.length();
i++;
}
setSizex(maxTextSize * markup1.getWidth() + markup1.getWidth() / 2);
setSizey(n * (markup1.getHeight() + 2) + markup1.getHeight() / 2);
}
void DropMenu::addOption(const std::string& text, int id)
{
Button b;
b.makeText(x0 + 2, y0 + 2 + (markup1.getHeight() + 2) * menuButton.size(), text);
menuButton.push_back(b);
separator.push_back(false);
int separatorsize = 0;
for(unsigned long i = 0; i < separator.size(); i++) if(separator[i]) separatorsize++;
setSizey((menuButton.size() + separatorsize) * (markup1.getHeight() + 2) + markup1.getHeight() / 2);
//int newSizex = text.length() * markup1.getWidth() + markup1.getWidth() / 2;
int newSizex;// = text.length();
int textheight;
getFormattedTextSize(text, newSizex, textheight, markup1);
newSizex += markup1.getWidth() / 2;
if(newSizex > getSizex()) setSizex(newSizex);
identity.push_back(id);
}
void DropMenu::drawWidget() const
{
panel.draw(x0, y0, getSizex(), getSizey());
for(unsigned long i = 0; i < menuButton.size(); i++)
{
if(!separator[i]) menuButton[i].draw();
else hrule.draw(x0 + markup1.getWidth() / 2, y0 + 2 + (markup1.getHeight() + 2) * i + markup1.getHeight() / 2, getSizex() - markup1.getWidth());
}
}
void DropMenu::handleWidget()
{
if(autoDisable && globalLMB && !mouseDown()) totallyDisable();
}
/*
Returns which of the options was pressed
Note: separaters take up a number spot too
It returns:
-1 if nothing clicked
i (= 0 or a positive integer) if option i was clicked
*/
int DropMenu::check()
{
for(unsigned long i = 0; i < menuButton.size(); i++)
{
if(!separator[i])
{
if(menuButton[i].clicked()) return i;
}
}
return -1;
}
Button* DropMenu::getButton(int i)
{
return &menuButton[i];
}
Button* DropMenu::getButton(const std::string& name)
{
int i = 0;
for(int j = 0; j < getNumButtons(); j++) if(menuButton[j].text == name) i = j;
return &menuButton[i];
}
std::string DropMenu::checkText()
{
for(unsigned long i = 0; i < menuButton.size(); i++)
{
if(!separator[i])
{
if(menuButton[i].clicked()) return menuButton[i].text;
}
}
return "";
}
int DropMenu::checkIdentity()
{
for(unsigned long i = 0; i < menuButton.size(); i++)
{
if(!separator[i])
{
if(menuButton[i].clicked()) return identity[i];
}
}
return 0;
}
void DropMenu::moveWidget(int x, int y)
{
for(unsigned long i = 0; i < menuButton.size(); i++) menuButton[i].move(x, y);
}
void DropMenu::setElementOver(bool state)
{
Element::setElementOver(state);
for(unsigned long i = 0; i < menuButton.size(); i++) menuButton[i].setElementOver(state);
}
////////////////////////////////////////////////////////////////////////////////
//GUIDROPLIST///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The DropList class
this class contains a list of options that can be opened or closed with a button,
the list will have a scrollbar and allow you to choose an option with the mouse
*/
//Constructor to make an empty droplist
Droplist::Droplist()
{
this->x0 = 0;
this->y0 = 0;
this->markup1 = TS_White;
this->markup2 = TS_White;
init("", -1);
}
void Droplist::make(int x, int y, const std::string& text, int numVisibleOptions,
const Markup& markup1, const Markup& markup2, const Markup& markup3,
BackPanel topPanel, BackPanel listPanel,
Texture* buttonTexture)
{
this->topPanel = topPanel;
this->listPanel = listPanel;
this->markup1 = markup1;
this->markup2 = markup2;
this->markup3 = markup3;
this->opened = 0;
this->selected = 0;
this->x0 = x;
this->y0 = y;
this->totallyEnable();
int buttonWidth = buttonTexture->getU();
int buttonHeight = buttonTexture->getV();
sizeyc = buttonHeight;
init(text, numVisibleOptions);
sizexo += buttonWidth;
sizexc = sizexo;
this->setSizex(sizexc);
this->setSizey(sizeyc);
listButton.makeImage(x1 - buttonWidth, y0, buttonTexture, buttonTexture, buttonTexture, RGB_White, RGB_Grey, RGB_Grey, 0);
bar.makeVertical(x1 - buttonWidth, y0 + sizeyc, sizeyo - sizeyc,
100, 0, 0, 1,
&builtInGuiSet, 1);
}
void Droplist::makeScrollbar(const GuiSet* set)
{
bar.makeVertical(x1 - set->arrowN->getU(), y0 + sizeyc, sizeyo - sizeyc,
100, 0, 0, 1,
set, 1);
}
void Droplist::init(const std::string& text, int numVisibleOptions)
{
textButton.clear();
unsigned long maxTextSize = 0; //the size of the largest text
//calculate n, the number of elements
unsigned long pos = 0;
unsigned long n = 0;
while(pos < text.length())
{
if(text[pos] == '|') n++;
pos++;
}
n++;
unsigned long i = 0;
unsigned long t = 0;
while(i < n)
{
std::string buttonText = "";
while(text[t] != '|' && t < text.length())
{
buttonText += text[t];
t++;
}
t++;
Button b;
b.makeText(x0 + 2, y0 + sizeyc + 2 + (markup1.getHeight() + 2) * i, buttonText);
textButton.push_back(b);
if(buttonText.length() > maxTextSize) maxTextSize = buttonText.length();
i++;
}
if(numVisibleOptions == -1) this->numVisibleOptions = numVisibleOptions = n;
else this->numVisibleOptions = numVisibleOptions;
sizexo = maxTextSize * markup1.getWidth() + markup1.getWidth() / 2 + bar.getSizex();
sizeyo = sizeyc + numVisibleOptions * (markup1.getHeight() + 2) + markup1.getHeight() / 2;
int buttonWidth = maxTextSize * markup1.getWidth();
for(unsigned long i = 0; i < textButton.size(); i++)
{
textButton[i].setSizex(buttonWidth);
}
}
void Droplist::addOption(const std::string& text)
{
Button b;
b.makeText(x0 + 2, y0 + sizeyc + 2 + (markup1.getHeight() + 2) * textButton.size(), text);
textButton.push_back(b);
unsigned long maxTextSize = b.getSizex() / markup1.getWidth();
if(text.length() > maxTextSize) maxTextSize = text.length();
int buttonWidth = maxTextSize * markup1.getWidth();
for(unsigned long i = 0; i < textButton.size(); i++)
{
textButton[i].setSizex(buttonWidth);
}
setSizex(maxTextSize * markup1.getWidth() + markup1.getWidth() / 2 + bar.getSizex());
sizexo = sizexc = getSizex();
bar.moveTo(x0 + sizexo - bar.getSizex(), bar.getY0());
listButton.moveTo(x0 + sizexc - listButton.getSizex(), listButton.getY0());
}
void Droplist::drawWidget() const
{
topPanel.draw(x0, y0, sizexc, sizeyc);
listButton.draw();
print(textButton[selected].text, x0, y0 + sizeyc / 2 - markup3.getHeight() / 2, markup3);
if(opened)
{
listPanel.draw(x0, y0 + sizeyc, sizexo, sizeyo - sizeyc);
for(unsigned long i = 0; i < textButton.size(); i++) textButton[i].draw();
bar.draw();
}
}
int Droplist::check()
{
return selected;
}
std::string Droplist::checkText()
{
return textButton[selected].text;
}
void Droplist::handleWidget()
{
if(listButton.clicked() || (clicked() && mouseGetRelPosY() < sizeyc && !listButton.mouseOver())) //behind the or is to open it also if you press the thing itself but not the button, the getMouseY() < sizeyc is necessary, without it, the code after this will not work anymore (starting from if(openen)
{
if(!opened)
{
open();
}
else
{
close();
}
}
if(opened)
{
for(unsigned long i = 0; i < textButton.size(); i++)
{
if(textButton[i].clicked())
{
close();
selected = i;
}
}
if(mouseScrollUp() && !bar.mouseOver()) bar.scroll(-2);
if(mouseScrollDown() && !bar.mouseOver()) bar.scroll(2);
bar.handle();
scroll();
}
}
void Droplist::scroll()
{
int v = numVisibleOptions;
int n = textButton.size();
if(n <= v); //dan moet er ni gescrolld worden
else
{
int s = int(((n - v) * bar.scrollPos) / bar.scrollSize);
for(int i = 0; i < n; i++)
{
textButton[i].moveTo(textButton[i].getX0(), y0 + sizeyc + 2 + (markup1.getHeight() + 2) * (i - s));
if(i >= s && i < s + v)
{
textButton[i].setVisible(1);
textButton[i].setActive(1);
}
else
{
textButton[i].setVisible(0);
textButton[i].setActive(0);
}
}
}
}
void Droplist::open()
{
opened = 1;
setSizex(sizexo);
setSizey(sizeyo);
}
void Droplist::close()
{
opened = 0;
setSizex(sizexc);
setSizey(sizeyc);
}
void Droplist::moveWidget(int x, int y)
{
for(unsigned long i = 0; i < textButton.size(); i++) textButton[i].move(x, y);
listButton.move(x, y);
bar.move(x, y);
}
void Droplist::setElementOver(bool state)
{
Element::setElementOver(state);
for(unsigned long i = 0; i < textButton.size(); i++) textButton[i].setElementOver(state);
listButton.setElementOver(state);
bar.setElementOver(state);
}
////////////////////////////////////////////////////////////////////////////////
//GUIINPUTLINE//////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The InputLine Class Functions
InputLine allows the user to enter a single line of text.
How to use it:
You can give text color styles with color1, color2, style
When the draw() function is called, it is drawn and handled, i.e. user unicode key presses are detected, ...
It is only handled if "active" is true, otherwise it's only drawn and it ignores user input
Fetch the text with getText or by simply using inputLine.text
Check if the user pressed enter, clicked on it with mouse, .... with the check() function
*/
//the default constructor
InputLine::InputLine()
{
this->x0 = 0;
this->y0 = 0;
this->l = 0;
this->markup = TS_White;
this->type = 0;
this->allowedChars = 0;
this->title = "";
this->selfActivate = 0;
this->text = "";
cursor = 0;
entered = 0;
this->keyCheckIndex = 0;
}
void InputLine::make(int x, int y, unsigned long l, const Markup& markup, int type, int allowedChars, const std::string& title, const Markup& titleMarkup, const ColorRGB& cursorColor)
{
this->x0 = x;
this->y0 = y;
this->l = l;
this->markup = markup;
this->titleMarkup = titleMarkup;
this->cursorColor = cursorColor;
this->type = type;
this->allowedChars = allowedChars;
this->title = title;
this->text = "";
cursor = 0;
entered = 0;
if(type == 2) //if the type is "integer"
{
allowedChars |= 3; //set "disable text" and "disable special symbols" to true
}
this->setSizey( markup.getHeight()); //font height
this->setSizex((title.length() + l) * markup.getWidth());
this->active = 0;
this->visible = 1;
this->present = 1;
this->selfActivate = 1; //with this true, it'll disable itself if you click outside of it, and turn on again if you click inside
}
//this function draws the line, and makes sure it gets handled too (calls handle())
void InputLine::drawWidget() const
{
print(title, x0, y0, titleMarkup);
int inputX = x0 + title.length() * markup.getWidth()/*(inputPos / h) % w*/;
int inputY = y0/*inputPos % h*/;
if(type == 0) print(text, inputX, inputY, markup);
else if(type == 1) //password
{
unsigned long p = 0;
while(p < text.length() && p < l)
{
drawLetter('*', inputX + p * 8, inputY, markup);
p++;
}
}
else if(type == 2) print(getInteger(), inputX, inputY, markup);
//draw the cursor if active
if(active && int((getTicks() / 1000.0) * 2) % 2 == 0)
{
int cursorXDraw = inputX + cursor * markup.getWidth();
drawLine(cursorXDraw, inputY, cursorXDraw, inputY + markup.getHeight(), cursorColor);
}
}
//return values of check():
/*
0: the text string is empty, and the rest of the things below aren't true either
&1: the text string is not empty
&2: you pressed ENTER (to enter the text string!)
normally you'll want to check if the return value is 3: then you entered a non-empty string
*/
int InputLine::check() //both check if you pressed enter, and also check letter keys pressed, backspace, etc...
{
int returnValue = 0;
if(text.length() > 0) returnValue |= 1;
if(entered) returnValue |= 2;
entered = 0;
return returnValue;
}
//returns true if the user entered text, i.e. if there's text in it, and the user presses enter, and it's active
int InputLine::enter()
{
if((check() & 2) && (check() & 1) && active) return 1;
else return 0;
}
void InputLine::handleWidget() //both check if you pressed enter, and also check letter keys pressed, backspace, etc...
{
if(cursor >= text.length()) cursor = text.length();
int ascii = unicodeKey(allowedChars, 500, 25, keyCheckIndex);
if(ascii)
{
switch(ascii)
{
case 8: //backspace
if(cursor > 0)
{
cursor--;
text.erase(cursor, 1);
}
break;
case 13:
entered = 1;
break;
//a few certainly not meant to be printed ones
case 0:
break;
case 10: break;
default:
if(text.length() < l) text.insert(cursor, 1, ascii);
if(text.length() < l || cursor == l - 1) cursor++;
break;
}
}
if(keyPressed(SDLK_DELETE)) text.erase(cursor, 1);
if(keyPressed(SDLK_HOME)) cursor = 0;
if(keyPressed(SDLK_END))
{
unsigned long pos = 0;
while(text[pos] != 0 && pos < text.length()) pos++;
cursor = pos;
}
if(keyPressed(SDLK_LEFT)) if(cursor > 0) cursor--;
if(keyPressed(SDLK_RIGHT)) if(cursor < text.length()) cursor++;
if(mouseDown())
{
int relMouse = globalMouseX - x0;
relMouse -= title.length() * markup.getWidth();
if(relMouse / markup.getWidth() < int(text.length())) cursor = relMouse / markup.getWidth();
else cursor = text.length();
}
}
void InputLine::clear()
{
setText("");
cursor = 0;
}
void InputLine::setText(const std::string& i_text)
{
this->text = i_text;
}
const std::string& InputLine::getText() const
{
return text;
}
void InputLine::setTitle(const std::string& i_title)
{
int size_diff = i_title.size() - title.size();
this->title = i_title;
growX1(size_diff * titleMarkup.getWidth());
}
const std::string& InputLine::getTitle() const
{
return title;
}
int InputLine::getInteger() const
{
return std::atoi(text.c_str());
}
////////////////////////////////////////////////////////////////////////////////
//GUIINPUTBOX///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The InputBox Class Functions
InputBox allows the user to enter a multi line text.
*/
InputBox::InputBox()
{
this->visible = 0;
this->active = 0;
}
void InputBox::make(int x, int y, int sizex, int sizey, int maxLines, int border, const Markup& markup, BackPanel panel, const ColorRGB& cursorColor)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->maxLines = maxLines;
this->markup = markup;
this->multiText.markup = markup;
this->panel = panel;
this->cursorColor = cursorColor;
this->active = 0;
this->visible = 1;
this->present = 1;
this->cursor = 0;
this->selfActivate = 0;
this->border = border;
this->selfActivate = 1;
init();
}
void InputBox::makeScrollbar(const GuiSet* set)
{
bar.makeVertical(x1 - set->arrowN->getU(), y0, getSizey(),
100, 0, 0, 1,
set, 1);
}
void InputBox::init()
{
bar.makeVertical(x1 - builtInGuiSet.arrowN->getU(), y0, getSizey(), 100, 0, 0, 1);
bar.scrollSize = 1;
bar.scrollPos = 0;
}
int InputBox::getLeftText() const
{
return border;
}
int InputBox::getRightText() const
{
return getSizex() - border - bar.getSizex();
}
int InputBox::getTopText() const
{
return border;
}
int InputBox::getBottomText() const
{
return getSizey() - border;
}
int InputBox::getTextAreaHeight() const
{
return getBottomText() - getTopText();
}
int InputBox::getTextAreaWidth() const
{
return getRightText() - getLeftText();
}
int InputBox::getLinesVisible() const
{
return getTextAreaHeight() / markup.getHeight();
}
void InputBox::drawWidget() const
{
panel.draw(x0, y0, getSizex(), getSizey());
bar.draw();
//draw the cursor if active
if(active && int((getTicks() / 1000.0) * 2) % 2 == 0)
{
unsigned long cursorLine;
unsigned long cursorColumn;
multiText.cursorAtCharPos(cursor, cursorLine, cursorColumn);
int cursorXDraw = x0 + getLeftText() + cursorColumn * markup.getWidth();
int cursorYDraw = y0 + getTopText() + (cursorLine - firstVisibleLine) * markup.getHeight();
if(cursorYDraw >= y0 + getTopText() && cursorYDraw < y0 + getBottomText() - markup.getHeight()) drawLine(cursorXDraw, cursorYDraw, cursorXDraw, cursorYDraw + markup.getHeight(), cursorColor);
}
multiText.draw(x0 + getLeftText(), y0 + getTopText(), firstVisibleLine, firstVisibleLine + getLinesVisible());
}
void InputBox::handleWidget()
{
bool scrollerMayJump = 0;
if(keyPressed(SDLK_RIGHT)) if(cursor < text.length()) cursor++, scrollerMayJump = 1;
if(keyPressed(SDLK_LEFT)) if(cursor > 0) cursor--, scrollerMayJump = 1;
if(keyPressed(SDLK_UP))
{
unsigned long cursorLine;
unsigned long cursorColumn;
multiText.cursorAtCharPos(cursor, cursorLine, cursorColumn);
if(cursorLine > 0) cursor = multiText.charAtCursorPos(cursorLine - 1, cursorColumn);
scrollerMayJump = 1;
}
if(keyPressed(SDLK_DOWN))
{
unsigned long cursorLine;
unsigned long cursorColumn;
multiText.cursorAtCharPos(cursor, cursorLine, cursorColumn);
cursor = multiText.charAtCursorPos(cursorLine + 1, cursorColumn);
scrollerMayJump = 1;
}
if(keyPressed(SDLK_HOME))
{
if(keyDown(SDLK_LCTRL)) cursor = 0;
else
{
unsigned long cursorLine;
unsigned long cursorColumn;
multiText.cursorAtCharPos(cursor, cursorLine, cursorColumn);
cursor = multiText.charAtCursorPos(cursorLine, 0);
}
scrollerMayJump = 1;
}
if(keyPressed(SDLK_END))
{
if(keyDown(SDLK_LCTRL)) cursor = text.length();
else
{
unsigned long cursorLine;
unsigned long cursorColumn;
multiText.cursorAtCharPos(cursor, cursorLine, cursorColumn);
cursor = multiText.charAtCursorPos(cursorLine, int(getSizex() / markup.getWidth()));
}
scrollerMayJump = 1;
}
int ascii = unicodeKey(0, 500, 25);
if(ascii)
{
switch(ascii)
{
case 8: //backspace
if(cursor > 0)
{
cursor--;
text.erase(cursor, 1);
}
break;
//a few certainly not meant to be printed ones
case 0:
break;
case 10:
break;
case 13:
text.insert(cursor, 1, 10);
cursor++;
break;
default:
text.insert(cursor, 1, ascii);
cursor++;
break;
}
multiText.text = text;
multiText.splitWords(getTextAreaWidth());
scrollerMayJump = 1;
}
if(mouseDownHere() && !bar.mouseOver())
{
unsigned long mouseColumn = (mouseGetRelPosX() - getLeftText()) / markup.getWidth();
unsigned long mouseLine = (mouseGetRelPosY() - getTopText()) / markup.getHeight() + firstVisibleLine;
cursor = multiText.charAtCursorPos(mouseLine, mouseColumn);
}
int scrollSize = multiText.getNumLines() - getLinesVisible();
if(scrollSize < 1) scrollSize = 1;
bar.scrollSize = scrollSize;
if(mouseScrollUp() && !bar.mouseOver())
{
bar.scroll(-2);
}
if(mouseScrollDown() && !bar.mouseOver())
{
bar.scroll(2);
}
bar.handle();
firstVisibleLine = int(bar.scrollPos);
if(scrollerMayJump)
{
unsigned long cursorLine;
unsigned long cursorColumn;
multiText.cursorAtCharPos(cursor, cursorLine, cursorColumn);
//int lineDifference = multiText.getNumLines() - getLinesVisible();
//if(lineDifference < 1) lineDifference = 1;
int cursorRelative = cursorLine - firstVisibleLine; //relative to the first visible line
if(cursorRelative >= getLinesVisible()) bar.scrollPos = cursorLine - getLinesVisible() + 1;
if(cursorRelative < 0) bar.scrollPos = cursorLine;
//if(cursorRelative < 0) bar.scrollPos = cursorRelative + 1;
//if((cursorRelative + 1) * markup.getHeight()
//if(-getTopText() + (cursorRelative + 1) * markup.getHeight() >= 0) bar.scrollPos = cursorRelative + 1;
//if(getBottomText() + cursorRelative * markup.getHeight() < (getBottomText() - getTopText())) bar.scrollPos = cursorLine;
}
}
void InputBox::moveWidget(int x, int y)
{
bar.move(x, y);
}
void InputBox::setElementOver(bool state)
{
Element::setElementOver(state);
bar.setElementOver(state);
}
////////////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void Invisible::make(int x0, int y0, int x1, int y1)
{
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
this->active = true;
this->visible = true;
}
void Invisible::drawWidget() const
{
//intentionally do nothing, because this is invisible
}
////////////////////////////////////////////////////////////////////////////////
//GUIMATRIX/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void Matrix::make(int x0, int y0, int x1, int y1, int numx, int numy)
{
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
this->active = true;
this->visible = true;
this->numx = numx;
this->numy = numy;
}
unsigned long Matrix::getTileX() const
{
return mouseGetRelPosX() / (getSizex() / numx);
}
unsigned long Matrix::getTileY() const
{
return mouseGetRelPosY() / (getSizey() / numy);
}
int Matrix::getScreenX(int tilex) const
{
return (tilex * getSizex()) / numx + x0;
}
int Matrix::getScreenY(int tiley) const
{
return (tiley * getSizey()) / numy + y0;
}
////////////////////////////////////////////////////////////////////////////////
//GUIGRID///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void Grid::make(int x0, int y0, int x1, int y1, int tileSizeX, int tileSizeY)
{
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
this->active = true;
this->visible = true;
this->tileSizeX = tileSizeX;
this->tileSizeY = tileSizeY;
}
void Grid::setNumTiles(int amount) //real amount can be larger, as the width of rows will stay the same, it'll add rows at the bottom or remove rows
{
int newsize = 0;
if(amount > 0) newsize = tileSizeY * (((amount - 1) / getNumx()) + 1);
growSizeY1(newsize);
}
Grid::Grid()
{
showGrid = false;
}
//returns x position on screen of center of given tile
int Grid::getTileCenterx(int index) const //index = index of the tile
{
if(getNumx() == 0) return x0;
int x = (index % getNumx());
x = x * tileSizeX;
x += tileSizeX / 2;
return x0 + x;
}
//returns y position on screen of center of given tile
int Grid::getTileCentery(int index) const //index = index of the tile
{
if(getNumy() == 0) return y0;
int y = (index / getNumx());
y = y * tileSizeY;
y += tileSizeY / 2;
return y0 + y;
}
unsigned long Grid::getNumx() const
{
if(tileSizeX == 0) return 0;
else return getSizex() / tileSizeX;
}
unsigned long Grid::getNumy() const
{
if(tileSizeY == 0) return 0;
else return getSizey() / tileSizeY;
}
unsigned long Grid::getNumElements() const
{
return getNumx() * getNumy();
}
int Grid::getTileX() const
{
return mouseGetRelPosX() / tileSizeX;
}
int Grid::getTileY() const
{
return mouseGetRelPosY() / tileSizeY;
}
int Grid::getTile() const //returns index of the tile
{
return getTileX() + getNumx() * getTileY();
}
int Grid::getScreenX(int tilex) const
{
return tilex * tileSizeX + x0;
}
int Grid::getScreenY(int tiley) const
{
return tiley * tileSizeY + y0;
}
void Grid::drawWidget() const
{
if(showGrid)
{
for(int y = y0; y < y1; y += tileSizeY)
for(int x = x0; x < x1; x += tileSizeX)
{
drawLine(x, y0, x, y1, gridColor);
drawLine(x0, y, x1, y, gridColor);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//GUICHECKBOX///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The Checkbox Class Functions
CheckBox is a simple box that can have a different texture if "on" or "off",
and toggles if you press or release the mouse button on it.
How to use:
Give it two textures, texture1 one that looks like an unchecked checkbox,
texture two like a checked checkbox.
Optionally, give it a title that'll be drawn next to the textbox
Choose if you want it to toggle on mousedown, or on mouseup with the
toggleOnMouseUp boolean.
*/
Checkbox::Checkbox()
{
this->enableImage2 = 0;
//bad old code, must be fixed!
this->active = 0;
this->checked = 0;
this->texture[0] = &emptyTexture;
this->texture[1] = &emptyTexture;
this->texture[2] = &emptyTexture;
this->texture[3] = &emptyTexture;
this->colorMod[0] = RGB_White;
this->colorMod[1] = RGB_White;
this->colorMod[2] = RGB_White;
this->colorMod[3] = RGB_White;
this->toggleOnMouseUp = 0;
this->enableText = 0;
}
void Checkbox::addFrontImage
(
const Texture* texture1, const Texture* texture2, const Texture* texture3, const Texture* texture4,
const ColorRGB& imageColor1, const ColorRGB& imageColor2, const ColorRGB& imageColor3, const ColorRGB& imageColor4
)
{
this->enableImage2 = 1;
this->texture2[0] = texture1;
this->texture2[1] = texture2;
this->texture2[2] = texture3;
this->texture2[3] = texture4;
this->colorMod2[0] = imageColor1;
this->colorMod2[1] = imageColor2;
this->colorMod2[2] = imageColor3;
this->colorMod2[3] = imageColor4;
}
void Checkbox::addFrontImage(const Texture* texture)
{
addFrontImage(texture, texture, texture, texture, colorMod[0], colorMod[1], colorMod[2], colorMod[3]);
}
//constructor for checkbox with text title
void Checkbox::make(int x, int y, bool checked, const GuiSet* set, int toggleOnMouseUp)
{
this->x0 = x;
this->y0 = y;
this->checked = checked;
this->texture[0] = set->checkBox[0];
this->texture[1] = set->checkBox[0];
this->texture[2] = set->checkBox[1];
this->texture[3] = set->checkBox[1];
this->colorMod[0] = set->mainColor;
this->colorMod[1] = set->mouseOverColor;
this->colorMod[2] = set->mainColor;
this->colorMod[3] = set->mouseOverColor;
this->setSizex(set->checkBox[0]->getU());
this->setSizey(set->checkBox[0]->getV());
this->toggleOnMouseUp = toggleOnMouseUp;
this->totallyEnable();
positionText();
}
void Checkbox::setTexturesAndColors(const Texture* texture1, const Texture* texture2, const Texture* texture3, const Texture* texture4, const ColorRGB& color1, const ColorRGB& color2, const ColorRGB& color3, const ColorRGB& color4)
{
this->texture[0] = texture1;
this->texture[1] = texture2;
this->texture[2] = texture3;
this->texture[3] = texture4;
this->colorMod[0] = color1;
this->colorMod[1] = color2;
this->colorMod[2] = color3;
this->colorMod[3] = color4;
this->setSizex(texture[0]->getU());
this->setSizey(texture[0]->getV());
positionText();
}
void Checkbox::setTexturesAndColors(const Texture* texture1, const Texture* texture2, const ColorRGB& color1, const ColorRGB& color2)
{
setTexturesAndColors(texture1, texture1, texture2, texture2, color1, color1, color2, color2);
}
void Checkbox::addText(const std::string& text, const Markup& markup)
{
this->text = text;
this->markup = markup;
this->enableText = 1;
positionText();
}
//place the text next to the checkbox
void Checkbox::positionText()
{
textOffsetX = getSizex() + 2; //need some number of pixels that text is away from the texture, eg 2
textOffsetY = getSizey() / 2 - markup.getHeight() / 2;
}
//toggle "checked" or "unchecked" state
void Checkbox::toggle()
{
if(checked) uncheck();
else check();
}
//see how you click with the mouse and toggle on click
void Checkbox::handleWidget()
{
//make sure never both pressed() and clicked() are checked, because one test screws up the other, hence the order of the tests in the if conditions
if(toggleOnMouseUp == 0 && pressed()) toggle();
if(toggleOnMouseUp == 1 && clicked()) toggle();
}
//draw the checkbox with a texture depending on it's state
void Checkbox::drawWidget() const
{
/*if(checked) texture2->draw(x0, y0, colorMod2);
else texture1->draw(x0, y0, colorMod1);*/
int i = 0;
if(mouseOver()) i++;
if(checked) i += 2;
texture[i]->draw(x0, y0, colorMod[i]);
if(enableImage2)
texture2[i]->draw(x0, y0, colorMod2[i]);
if(enableText)
print(text, x0 + textOffsetX, y0 + textOffsetY, markup);
}
////////////////////////////////////////////////////////////////////////////////
//GUINSTATESTATE////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
This class is used by NState
*/
NStateState::NStateState()
{
this->texture = &emptyTexture;
this->colorMod = RGB_White;
this->enableText = 0;
this->text = "";
}
//constructor for checkbox with text title
void NStateState::make(Texture* texture, const ColorRGB& colorMod, const std::string& text, const Markup& markup)
{
this->texture = texture;
this->colorMod = colorMod;
this->text = text;
this->markup = markup;
if(text != "") enableText = 1;
positionText();
}
//place the text next to the checkbox
void NStateState::positionText()
{
textOffsetX = texture->getU() + 2; //need some number of pixels that text is away from the texture, eg 2
textOffsetY = texture->getV() / 2 - markup.getHeight() / 2;
}
////////////////////////////////////////////////////////////////////////////////
//GUINSTATE/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
This is a sort of advanced checkbox, it can go through multiple states and you can add more states.
*/
NState::NState()
{
//bad old code, must be fixed!
this->active = 0;
this->states.clear();
this->toggleOnMouseUp = 0;
}
//constructor for checkbox with text title
void NState::make(int x, int y, int toggleOnMouseUp)
{
states.clear();
this->x0 = x;
this->y0 = y;
this->toggleOnMouseUp = toggleOnMouseUp;
this->totallyEnable();
this->setSizex(0); //no states yet, size 0
this->setSizey(0);
}
void NState::addState(Texture* texture, const ColorRGB& colorMod, const std::string& text, const Markup& markup)
{
this->setSizex(texture->getU()); //set the size of the NState to that of the last added texture
this->setSizey(texture->getV());
NStateState s;
s.make(texture, colorMod, text, markup);
states.push_back(s);
}
//see how you click with the mouse and toggle on click
void NState::handleWidget()
{
//make sure never both pressed() and clicked() are checked, because one test screws up the other, hence the order of the tests in the if conditions
if(states.size() == 0) return;
if((toggleOnMouseUp == 0 && pressed()) || (toggleOnMouseUp == 1 && clicked()))
{
if(state >= states.size() - 1) state = 0;
else state++;
}
if((toggleOnMouseUp == 0 && pressed(RMB)) || (toggleOnMouseUp == 1 && clicked(RMB)))
{
if(state == 0) state = states.size() - 1;
else state--;
}
}
//draw the checkbox with a texture depending on it's state
void NState::drawWidget() const
{
if(states.size() == 0) return;
NStateState s = states[state];
s.texture->draw(x0, y0, s.colorMod);
if(s.enableText) print(s.text, x0 + s.textOffsetX, y0 + s.textOffsetY, s.markup);
}
////////////////////////////////////////////////////////////////////////////////
//GUIBULLETLIST/////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The BulletList
it's a list of checkboxes, where only one can be selected at the time
you first make() the prototype, and make() the bulletlist. Then all checkboxes have the
style you want!
*/
void BulletList::setElementOver(bool state)
{
Element::setElementOver(state);
for(unsigned long i = 0; i < bullet.size(); i++) bullet[i].setElementOver(state);
}
BulletList::BulletList()
{
this->active = 0;
this->visible = 0;
this->lastChecked = -1;
this->prototype.make(0, 0, 0, &builtInGuiSet, 1);
this->prototype.setTexturesAndColors(builtInGuiSet.bullet[0], builtInGuiSet.bullet[1], builtInGuiSet.mainColor, builtInGuiSet.mainColor);
}
void BulletList::make(int x, int y, unsigned long amount, int xDiff, int yDiff, const GuiSet* set)
{
this->prototype.make(0, 0, 0, set, 1);
this->prototype.setTexturesAndColors(set->bullet[0], set->bullet[1], set->mainColor, set->mainColor);
this->x0 = x;
this->y0 = y;
this->xDiff = xDiff;
this->yDiff = yDiff;
this->totallyEnable();
bullet.clear();
for(unsigned long i = 0; i < amount; i++)
{
bullet.push_back(prototype);
bullet[i].moveTo(x + xDiff * i, y + yDiff * i);
}
//NOTE: DIT IS NIET CORRECT, DEZE FORMULES
this->setSizex(amount * xDiff + prototype.getSizex());
this->setSizey(amount * yDiff + prototype.getSizey());
}
void BulletList::make(int x, int y, unsigned long amount, int xDiff, int yDiff, unsigned long amountx, const GuiSet* set)
{
if(amountx < 1) amountx = 1;
this->prototype.make(0, 0, 0, set, 1);
this->prototype.setTexturesAndColors(set->bullet[0], set->bullet[1], set->mainColor, set->mainColor);
this->x0 = x;
this->y0 = y;
this->xDiff = xDiff;
this->yDiff = yDiff;
this->totallyEnable();
bullet.clear();
int xPos = x, yPos = y;
for(unsigned long i = 0; i < amount; i++)
{
xPos = x + xDiff * (i % amountx);
yPos = y + yDiff * (i / amountx);
bullet.push_back(prototype);
bullet[i].moveTo(xPos, yPos);
}
setCorrectSize();
}
void BulletList::setCorrectSize()
{
if(bullet.size() == 0) return;
int minx = bullet[0].getX0();
int miny = bullet[0].getY0();
int maxx = bullet[0].getX1();
int maxy = bullet[0].getY1();
for(size_t i = 1; i < bullet.size(); i++)
{
minx = std::min(minx, bullet[i].getX0());
miny = std::min(miny, bullet[i].getY0());
maxx = std::max(maxx, bullet[i].getX1());
maxy = std::max(maxy, bullet[i].getY1());
}
this->x0 = minx;
this->y0 = miny;
this->setSizex(maxx - minx);
this->setSizey(maxy - miny);
}
void BulletList::handleWidget()
{
if(!mouseOver()) return; //some speed gain, don't do all those loops if the mouse isn't over this widget
for(unsigned long i = 0; i < bullet.size(); i++)
{
bullet[i].handle();
}
int newChecked = -1;
for(size_t i = 0; i < bullet.size(); i++)
{
if(bullet[i].checked && int(i) != lastChecked) newChecked = i;
bullet[i].checked = false;
}
if(newChecked >= 0)
{
bullet[newChecked].checked = true;
lastChecked = newChecked;
}
else if(lastChecked >= 0 && lastChecked < int(bullet.size()))
bullet[lastChecked].checked = true;
}
void BulletList::drawWidget() const
{
for(unsigned long i = 0; i < bullet.size(); i++)
{
bullet[i].draw();
}
}
void BulletList::moveWidget(int x, int y)
{
for(unsigned long i = 0; i < bullet.size(); i++)
{
bullet[i].move(x, y);
}
}
int BulletList::check()
{
return lastChecked;
}
void BulletList::addText(const std::string& text, unsigned long i)
{
if(i < bullet.size()) bullet[i].addText(text);
}
std::string BulletList::getText(unsigned long i) const
{
std::string result;
if(i < bullet.size()) result = bullet[i].getText();
return result;
}
const std::string& BulletList::getCurrentText() const
{
return bullet[lastChecked].getText();
}
void BulletList::set(unsigned long i)
{
/*if(i >= 0 && i < bullet.size()) bullet[i].checked = true;
if(!active) lastChecked = i;*/
for(unsigned long j = 0; j < bullet.size(); j++)
{
if(i != j) bullet[j].checked = false;
else bullet[j].checked = true;
}
lastChecked = i;
handle();
}
////////////////////////////////////////////////////////////////////////////////
//STRINGSTACK///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
The String Stack is a rotating stack of strings, that is very helpful for the
Console.
It's actually not a real stack: you don't have to pop() to get values out of it,
you only have to push values into it, it rotates, and you can access any value.
You can access values relative to the newest, or relative to the oldest value.
The StringStack has a finite number of positions, when it's full, it'll overwrite
the oldest value. It can however use indexes as if the newely added text has always
the highest index when the stack is full.
First it must allocate memory for the wanted number of strings, and it must
destroy it again when it's no longer used.
num = max number of strings
*/
StringStack::StringStack()
{
this->num = 0;
this->oldest = 0;
this->next = 0;
this->numFilled = 0;
}
void StringStack::make(int num)
{
if(num < 1) num = 1;
this->num = num;
this->oldest = 0;
this->next = 0;
this->numFilled = 0;
for(int i = 0; i < num; i++) text.push_back("");
}
void StringStack::push(const std::string& text)
{
this->text[next] = text;
if(next == oldest && numFilled > 0) oldest = increase(oldest);
next = increase(next);
if(numFilled < num) numFilled++;
}
//returns the text that is position positions away from the oldest text
const std::string& StringStack::getOldest(int offset)
{
int pointer = increase(oldest, offset);
return text[pointer];
}
const std::string& StringStack::getNewest(int offset)
{
int pointer = decrease(next);
pointer = decrease(pointer, offset);
return text[pointer];
}
//returns how full the memory is
int StringStack::getNumText() const
{
return numFilled;
}
//increase the position of a pointer (like oldest or next), if it reaches the edge it goes back to 0
int StringStack::increase(int pointer, int amount)
{
pointer += amount;
if(pointer >= num) pointer %= num;
return pointer;
}
int StringStack::decrease(int pointer, int amount)
{
pointer -= amount;
while(pointer < 0) pointer += num;
if(pointer >= num) pointer %= num;
return pointer;
}
////////////////////////////////////////////////////////////////////////////////
//GUICONSOLE////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Console is a text window that contains different texts and can display
some of them like a console.
It's supposed to be used together with a scrollbar to be able to scroll it.
*/
Console::Console()
{
this->num = 0;
this->active = 0;
this->visible = 0;
this->scroll = 0;
}
void Console::make(int x, int y, int sizex, int sizey, int num, const Markup& markup)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->num = num;
this->markup = markup;
this->totallyEnable();
this->scroll = 0;
this->stack.make(num);
calcNumLines();
}
void Console::push(const std::string& text/*, int length*/)
{
stack.push(text);
calcNumLines();
}
void Console::calcNumLines()
{
int line = 0;
MultiLineText t;
t.markup = markup;
for(int i = 0; i < num; i++)
{
t.setText(stack.getOldest(i));
t.splitWords(getSizex());
line += t.getNumLines();
}
numLines = line;
}
int Console::getNumLines() const
{
return numLines;
}
int Console::getNumMessages() const
{
return stack.getNumText();
}
int Console::getVisibleLines(const Markup& markup)
{
return getSizey() / markup.getHeight();
}
void Console::drawWidget() const
{
int line = 0;
int message = 0;
int maxScreenLines = getSizey() / markup.getHeight();
int messageLines = 0;
int messageStartLine = 0;
int messageEndLine = 0;
int messageStartLineScreen = 0;
int messageEndLineScreen = 0;
int drawMessageStartLine = -1;
int drawMessageEndLine = -1;
int yDraw = 0;
MultiLineText t;
t.markup = markup;
while(line - scroll < maxScreenLines && message < stack.getNumText())
{
messageStartLine = line; //first line of the message in all messages
t.setText(stack.getOldest(message));
t.splitWords(getSizex());
messageLines = t.getNumLines();
//messageLines = calcTextLines(text[message], sizex, markup); //number of lines of the message
messageEndLine = messageStartLine + messageLines - 1; //last line of the message
messageStartLineScreen = messageStartLine - scroll;
messageEndLineScreen = messageEndLine - scroll;
line += messageLines;
if(line >= scroll)
{
yDraw = y0 + (messageStartLine - scroll) * markup.getHeight();
if(messageStartLineScreen < 0)
{
drawMessageStartLine = -messageStartLineScreen;
yDraw = y0;
}
else drawMessageStartLine = -1;
if(messageEndLineScreen >= maxScreenLines) drawMessageEndLine = messageLines - (messageEndLineScreen - maxScreenLines + 1);
else drawMessageEndLine = -1;
t.draw(x0, yDraw, drawMessageStartLine, drawMessageEndLine);
}
message++;
}
}
////////////////////////////////////////////////////////////////////////////////
//GUITEXTAREA///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
hmm I forgot what a guitextarea is for...
*/
TextArea::TextArea()
{
this->active = 0;
this->visible = 0;
this->scroll = 0;
this->scrollEnabled = 0;
}
void TextArea::make(int x, int y, int sizex, int sizey, const std::string& text, const Markup& markup)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->markup = markup;
this->text.markup = markup;
this->text.setText(text);
this->text.splitWords(getSizex());
this->totallyEnable();
this->scroll = 0;
}
void TextArea::setText(const std::string& text, const Markup& markup)
{
this->markup = markup;
this->text.markup = markup;
this->text.setText(text);
int width = getSizex();
if(scrollEnabled) width -= scrollbar.getSizex();
this->text.splitWords(width);
this->scroll = 0;
if(scrollEnabled) setScrollbarSize();
}
int TextArea::getNumLines() const
{
return text.getNumLines();
}
void TextArea::resizeWidget()
{
this->text.splitWords(getSizex());
if(scrollEnabled)
{
scrollbar.resizeSticky(x0, y0, x1, y1);
setScrollbarSize();
}
}
void TextArea::moveWidget(int x, int y)
{
if(scrollEnabled) scrollbar.move(x, y);
}
void TextArea::setElementOver(bool state)
{
Element::setElementOver(state);
scrollbar.setElementOver(state);
}
void TextArea::handleWidget()
{
if(scrollEnabled)
{
scrollbar.handle();
scroll = int(scrollbar.scrollPos);
}
}
int TextArea::getVisibleLines(const Markup& markup) const
{
return getSizey() / markup.getHeight();
}
void TextArea::drawWidget() const
{
int visible = getVisibleLines(markup);
//scroll is the startline, scroll + visible is the end line
int startLine = scroll;
int endLine = scroll + visible;
text.draw(x0, y0, startLine, endLine);
if(scrollEnabled) scrollbar.draw();
}
void TextArea::setScrollbarSize()
{
int size = text.getNumLines() - (getSizey() / markup.getHeight());
if(size < 0) size = 0;
scrollbar.scrollSize = size;
}
void TextArea::addScrollbar()
{
scrollEnabled = true;
scrollbar.makeVertical(x1 - 16, 0, getSizey());
this->text.splitWords(getSizex() - scrollbar.getSizex());
setScrollbarSize();
}
////////////////////////////////////////////////////////////////////////////////
//GUIIMAGE//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Image is a simple texture but as child class of Element
*/
Image::Image()
{
this->visible = 0;
this->active = 0;
this->image = &emptyTexture;
}
void Image::make(int x, int y, Texture* image, const ColorRGB& colorMod)
{
this->x0 = x;
this->y0 = y;
this->setSizex(image->getU());
this->setSizey(image->getV());
this->image = image;
this->colorMod = colorMod;
this->totallyEnable();
}
void Image::make(int x, int y, int sizex, int sizey, Texture* image, const ColorRGB& colorMod)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->image = image;
this->colorMod = colorMod;
this->totallyEnable();
}
void Image::drawWidget() const
{
image->draw(x0, y0, colorMod, getSizex(), getSizey());
}
////////////////////////////////////////////////////////////////////////////////
//GUIRECTANGLE//////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Rectangle is a simple rectangle but as child class of Element
*/
Rectangle::Rectangle()
{
this->visible = 0;
this->active = 0;
this->color = RGB_Black;
}
void Rectangle::make(int x, int y, int sizex, int sizey, const ColorRGB& color)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->color = color;
this->totallyEnable();
}
void Rectangle::drawWidget() const
{
drawRectangle(x0, y0, x1, y1, color);
}
////////////////////////////////////////////////////////////////////////////////
//GUIPAINTER////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
You give Painter drawing commands (lines, pictures, points, ...) that are queued, and then
all drawn when you call draw(). The queues are then cleared, to be filled again the next frame.
There's also by default a rectangle behind it, if you don't want it, set alpha channel of rectangle color to 0
*/
Painter::Painter()
{
this->visible = 0;
this->active = 0;
this->stack.clear();
}
void Painter::make(int x, int y, int sizex, int sizey, const ColorRGB& color)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->color = color;
this->stack.clear();
this->totallyEnable();
}
void Painter::drawWidget() const
{
//first draw the rectangle if the alpha channel of color is > 0
if(color.a > 0) drawRectangle(x0, y0, x1, y1, color);
//then draw the queued elements, in order
for(unsigned long i = 0; i < stack.size(); i++)
{
switch(stack[i].type)
{
case 0:
drawPoint(stack[i].x0 + x0, stack[i].y0 + y0, stack[i].color);
break;
case 1:
drawLine(stack[i].x0 + x0, stack[i].y0 + y0, stack[i].x1 + x0, stack[i].y1 + y0, stack[i].color);
break;
case 2:
stack[i].texture->draw(stack[i].x0 + x0, stack[i].y0 + y0, stack[i].color);
break;
case 3:
stack[i].texture->drawCentered(stack[i].x0 + x0, stack[i].y0 + y0, stack[i].color);
break;
case 4:
drawRectangle(stack[i].x0 + x0, stack[i].y0 + y0, stack[i].x1 + x0, stack[i].y1 + y0, stack[i].color);
break;
default: break;
}
}
stack.clear();
}
void Painter::queuePoint(int x, int y, const ColorRGB& color)
{
int i = stack.size();
stack.resize(stack.size() + 1);
stack[i].x0 = x;
stack[i].y0 = y;
stack[i].color = color;
stack[i].type = 0;
}
void Painter::queueLine(int x0, int y0, int x1, int y1, const ColorRGB& color)
{
int i = stack.size();
stack.resize(stack.size() + 1);
stack[i].x0 = x0;
stack[i].y0 = y0;
stack[i].x1 = x1;
stack[i].y1 = y1;
stack[i].color = color;
stack[i].type = 1;
}
void Painter::queueTexture(int x, int y, Texture* texture, const ColorRGB& colorMod)
{
int i = stack.size();
stack.resize(stack.size() + 1);
stack[i].x0 = x;
stack[i].y0 = y;
stack[i].color = colorMod;
stack[i].texture = texture;
stack[i].type = 2;
}
void Painter::queueTextureCentered(int x, int y, Texture* texture, const ColorRGB& colorMod)
{
int i = stack.size();
stack.resize(stack.size() + 1);
stack[i].x0 = x;
stack[i].y0 = y;
stack[i].color = colorMod;
stack[i].texture = texture;
stack[i].type = 3;
}
void Painter::queueRectangle(int x0, int y0, int x1, int y1, const ColorRGB& color)
{
int i = stack.size();
stack.resize(stack.size() + 1);
stack[i].x0 = x0;
stack[i].y0 = y0;
stack[i].x1 = x1;
stack[i].y1 = y1;
stack[i].color = color;
stack[i].type = 4;
}
////////////////////////////////////////////////////////////////////////////////
//GUILINE///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Line is a simple line but as child class of Element
*/
Line::Line()
{
this->visible = 0;
this->active = 0;
this->color = RGB_Black;
this->lx0 = 0;
this->ly0 = 0;
this->lx1 = 0;
this->ly1 = 0;
}
void Line::make(int x, int y, int sizex, int sizey, const ColorRGB& color)
{
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->color = color;
this->totallyEnable();
this->lx0 = x;
this->ly0 = y;
this->lx1 = x + sizex;
this->ly1 = y + sizey;
}
void Line::setEndpoints(int x0, int y0, int x1, int y1)
{
this->lx0 = x0;
this->ly0 = y0;
this->lx1 = x1;
this->ly1 = y1;
}
void Line::drawWidget() const
{
drawLine(lx0, ly0, lx1, ly1, color);
}
////////////////////////////////////////////////////////////////////////////////
//GUITEXT///////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Text is just some text as child of Element
*/
Text::Text()
{
this->visible = 0;
this->active = 0;
this->useNewLine = true;
}
void Text::make(int x, int y, const std::string& text, const Markup& markup)
{
this->x0 = x;
this->y0 = y;
this->setSizex(text.length() * markup.getWidth());
this->setSizey(markup.getHeight());
this->text = text;
this->markup = markup;
this->totallyEnable();
}
void Text::drawWidget() const
{
print(text, x0, y0, markup, useNewLine);
}
void Text::setText(const std::string& text)
{
this->text = text;
}
////////////////////////////////////////////////////////////////////////////////
//GUIFORMATTEDTEXT//////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
FormattedText is just some formatted text as child of Element
*/
FormattedText::FormattedText()
{
this->visible = 0;
this->active = 0;
}
void FormattedText::make(int x, int y, const std::string& text, const Markup& markup)
{
this->x0 = x;
this->y0 = y;
this->setSizex(text.length() * markup.getWidth());
this->setSizey(markup.getHeight());
this->text = text;
this->markup = markup;
this->totallyEnable();
}
void FormattedText::drawWidget() const
{
printFormatted(text, x0, y0, markup);
}
void FormattedText::setText(const std::string& text)
{
this->text = text;
}
////////////////////////////////////////////////////////////////////////////////
//YESNOWINDOW///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
YesNoWindow::YesNoWindow()
{
this->active = 0;
this->visible = 0;
}
void YesNoWindow::make(int x, int y, int sizex, int sizey, const std::string& text)
{
Window::make(x, y , sizex, sizey);
addTop();
yes.makeTextPanel(0, 0, "Yes");
no.makeTextPanel(0, 0, "No");
//yes.autoTextSize();
//no.autoTextSize();
message.make(0, 0, text);
pushTop(&message, 16, 16);
int centerx = getSizex() / 2;
pushTop(&yes, centerx - yes.getSizex() - 16, getSizey() - yes.getSizey() - 8 - 16);
pushTop(&no, centerx + 16, getSizey() - no.getSizey() - 8 - 16);
this->active = 1;
this->visible = 1;
}
////////////////////////////////////////////////////////////////////////////////
//OKWINDOW//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
OkWindow::OkWindow()
{
this->active = 0;
this->visible = 0;
}
void OkWindow::make(int x, int y, int sizex, int sizey, const std::string& text)
{
Window::make(x, y , sizex, sizey);
addTop();
ok.makeTextPanel(0, 0, "Ok");
//ok.autoTextSize();
message.make(0, 0, text);
pushTop(&message, 16, 16);
int centerx = getSizex() / 2;
pushTop(&ok, centerx - ok.getSizex() / 2, getSizey() - ok.getSizey() - 8 - 16);
this->active = 1;
this->visible = 1;
}
////////////////////////////////////////////////////////////////////////////////
//GUICANVAS/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/*
Canvas: allows you to draw on it with the mouse
*/
Canvas::Canvas()
{
this->visible = 0;
this->active = 0;
}
void Canvas::make(int x, int y, int sizex, int sizey, const ColorRGB& backColor, int border, const ColorRGB& leftColor, const ColorRGB& rightColor, double size, double hardness, double opacity)
{
this->visible = true;
this->active = true;
this->x0 = x;
this->y0 = y;
this->setSizex(sizex);
this->setSizey(sizey);
this->leftColor = leftColor;
this->rightColor = rightColor;
this->backColor = backColor;
this->border = border;
this->size = size;
this->opacity = opacity;
this->hardness = hardness;
this->oldMouseX = -1;
this->oldMouseY = -1;
init();
}
void Canvas::init()
{
canvas.create(backColor, getSizex(), getSizey());
}
void Canvas::handleWidget()
{
if(mouseGrabbed(LMB) || mouseGrabbed(RMB))
{
ColorRGB drawColor;
if(globalLMB) drawColor = leftColor;
else drawColor = rightColor;
int drawx = mouseGetRelPosX();
int drawy = mouseGetRelPosY();
if(validOldMousePos == true)
{
drawLine(&canvas.getOpenGLBuffer()[0], canvas.getU2(), canvas.getV2(), oldMouseX, oldMouseY, drawx, drawy, drawColor, border, border, getSizex() - border, getSizey() - border);
canvas.upload();
}
oldMouseX = drawx;
oldMouseY = drawy;
validOldMousePos = true;
}
else validOldMousePos = false;
}
void Canvas::drawWidget() const
{
canvas.draw(x0, y0);
}
void Canvas::clear()
{
canvas.create(backColor, getSizex(), getSizey());
}
////////////////////////////////////////////////////////////////////////////////
//OTHER FUNCTIONS///////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//MultiLineText class
////////////////////////////////////////////////////////////////////////////////
MultiLineText::MultiLineText()
{
this->text = "";
resetLines();
char10 = 1;
useFormatting = 1;
markup = TS_W;
}
void MultiLineText::resetLines()
{
line.clear(); //reset lines
line.push_back(0); //character 0 is always a new line since it's the beginning of the text
}
void MultiLineText::generateLineMarkup()
{
lineMarkup.clear();
lineMarkup.push_back(markup);
Markup markup_ = markup;
for(unsigned long i = 0; i < getNumLines(); i++)
{
std::string s = getLine(i);
getFormattedMarkup(s, markup_, markup);
lineMarkup.push_back(markup_);
}
}
//from now on, this will also split words that are too long into multiple parts
void MultiLineText::splitWords(int width)
{
resetLines();
unsigned long charsPerLine = width / markup.getWidth();
unsigned long pos = 0; //current position in the string
unsigned long cline = 1; //current line
unsigned long linepos = 0; //*printable* character position on current line, becomes 0 at every "newline"
while(pos < text.length())
{
//get length of next word
unsigned long wordpos = pos;
unsigned long wordlength = 0;
unsigned long steplength = 0; //word length + length of possible format symbols
bool formattedEnd = false;
while(!formattedEnd && !(text[wordpos] == ' ' || text[wordpos] == 0 || (char10 && (text[wordpos] == 10 || text[wordpos] == 13)) || wordlength >= charsPerLine))
{
if(!useFormatting || text[wordpos] != '#')
{
wordpos++;
wordlength++;
steplength++;
}
else
{
wordpos++;
steplength++;
if(wordpos < text.size())
{
char c = text[wordpos];
switch(c)
{
case 'n':
formattedEnd = true; //it breaks out of this loop, and the next part of the function will then detect the 'n' and treat it as newline
break;
default:
wordpos += getFormattedTextAttrSize(c) + 1;
wordlength += getFormattedTextSymbolPrintSize(c);
steplength += getFormattedTextAttrSize(c) + 1;
break;
}
}
}
}
//for now, words longer than width aren't split in two parts
//see if word can be drawn on current line
if(linepos + wordlength > charsPerLine)
{
line.push_back(pos); //the word is split by inserting newline in front of the word
cline++;
linepos = 0; //you're at a new line, so you're at the first char of the new line again
}
//pos pointer now goes to behind the following word
pos += steplength;
linepos += wordlength; //since you go to behind the word drawn on the current line
//now check what is there behind the word: is it a newline? a space? or a null-termination char?
switch(text[pos])
{
case ' ': //space
pos++;
linepos++;
break;
case 10: //newline
if(char10)
{
line.push_back(pos);
cline++;
linepos = 0;
pos++;
}
break;
case 13: //ms windows newline, ignore
if(char10)
{
pos++;
//linepos++;
}
break;
case 'n': //it's the newline, there's a # in front of it for sure because that was already checked higher
if(useFormatting)
{
line.push_back(pos - 1);
cline++;
linepos = 0;
pos++;
}
break;
/*case 0: //null termination char
break;*/
default: //not supposed to happen
//dprint("WTF? Error in MultiLineText::splitWords");
break;
}
}
line.push_back(text.length());
if(useFormatting) generateLineMarkup();
}
void MultiLineText::splitLetters(int width)
{
resetLines();
unsigned long charsPerLine = width / markup.getWidth();
unsigned long pos = 0; //current position in the string
unsigned long cline = 1; //current line
unsigned long linepos = 0; //character position on current line, becomes 0 at every "newline"
while(/*text[pos] != 0*/pos < text.length())
{
switch(text[pos])
{
/*case 0: //termination char
break;*/
case 10: //newline char
if(char10)
{
line[cline] = pos;
cline++;
linepos = 0;
pos++;
}
break;
default:
if(linepos >= charsPerLine)
{
line.push_back(pos);
cline++;
linepos = 0;
}
pos++;
linepos++;
break;
}
}
line.push_back(text.length());
if(useFormatting) generateLineMarkup();
}
void MultiLineText::splitChar10()
{
resetLines();
unsigned long pos = 0; //current position in the string
unsigned long cline = 1; //current line
while(/*text[pos] != 0*/pos < text.length())
{
switch(text[pos])
{
/*case 0: //termination char
break;*/
case 10: //newline char
line.push_back(pos);
cline++;
pos++;
break;
default:
pos++;
break;
}
}
line.push_back(text.length());
if(useFormatting) generateLineMarkup();
}
void MultiLineText::setText(const std::string& text)
{
this->text = text;
}
void MultiLineText::addText(const std::string& text)
{
this->text += text;
}
void MultiLineText::draw(int x, int y, unsigned long startLine, unsigned long endLine) const
{
Markup markup_ = markup;
if(startLine == endLine) return;
unsigned long cline = startLine;
while(cline < endLine)
{
int printy = y + markup.getHeight() * (cline - startLine); //y coordinate to draw the text
std::string sub = getLine(cline); //string containing the current line
if(useFormatting)
{
if(cline < lineMarkup.size()) markup_ = lineMarkup[cline];
printFormattedM(sub, x, printy, markup_, markup);
}
else print(sub, x, printy, markup);
cline++;
}
}
void MultiLineText::draw(int x, int y) const
{
draw(x, y, 0, getNumLines());
}
unsigned long MultiLineText::getNumLines() const
{
if(text.length() == 0) return 0; //no text!
return line.size() - 1; //the size of the std::vector is also the number of lines, minus one because the last value denotes the position of the final character of the text, which is no new line
}
std::string MultiLineText::getLine(unsigned long i) const
{
if(i >= getNumLines()/* || i < 0*/) return "";
int length = line[i + 1] - line[i];
int start = line[i]; //the first character of the substring
if(char10 && text[line[i]] == 10) //do NOT draw newline chars if it's used as newline (i.e. when char10 is true)
{
start++;
length--;
}
if(length < 0) length = 0;
//std::string sub = text.substr(start, length);
std::string sub;
for(int j = start; j < start + length; j++)
{
if(!(char10 && text[j] == 13)) sub += text[j];
}
return sub;
}
//returns line and column of character at pos (handy for cursors)
void MultiLineText::cursorAtCharPos(unsigned long pos, unsigned long& cline, unsigned long& column) const
{
cline = 0;
column = 0;
int extraPos = 0;
if(text[pos] == 10) {pos--; extraPos++;}
if(text.length() == 0)
{
cline = 0;
column = 0;
}
else if(getNumLines() == 1)
{
cline = 0;
column = pos;
}
else if(pos < line[1])
{
cline = 0;
column = pos;
}
else
{
if(pos >= text.length())
{
extraPos = pos - text.length() + 1;
pos = text.length() - 1;
}
while(line[cline] <= pos)
{
cline++;
}
cline--;
column = pos - line[cline];
if(text[line[cline]] == 10) {column--; } //lines start with a 10 char if you pressed enter but this char isn't drawn. If the line does not start with a 10 char, column must be done + 1
}
column += extraPos;
}
//returns position of letter at given line and column
int MultiLineText::charAtCursorPos(unsigned long cline, unsigned long column) const
{
if(getNumLines() <= cline) return text.length();
unsigned long lineLength;
if(cline == getNumLines() - 1) lineLength = text.length() - line[cline];
else if(cline == 0)
{
lineLength = line[1];
if(text[line[1]] != 10) lineLength--;
}
else lineLength = line[cline + 1] - line[cline] - 1;
unsigned long pos = line[cline];
if(column > lineLength) column = lineLength;
if(text[line[cline]] == 10) pos += 1;
pos += column;
if(pos > text.length()) pos = text.length();
/*if(cline == 0)
{
pos = column;
}*/
return pos;
}
#include "lpi_unittest.h"
#define LUT_MY_RESET \
{\
debugSetLMB(0);\
debugSetRMB(0);\
debugSetMousePos(0, 0);\
}
void unitTest()
{
screen(1024, 768, 0, "Unit Testing...");
LUT_START_UNIT_TEST
//I had a bug where when making a new BulletList and using "set" to give it a value, "check" wasn't returning the correct value until mouseOver
LUT_CASE("set bulletlist")
BulletList test1;
test1.make(0, 0, 5, 0, 0);
test1.set(3);
LUT_SUB_ASSERT_FALSE(test1.check() != 3)
test1.set(1);
LUT_SUB_ASSERT_FALSE(test1.check() != 1)
LUT_CASE_END
LUT_CASE("mouseOver and mouseDown on Dummy")
Dummy dummy;
dummy.resize(0, 0, 50, 50);
debugSetMousePos(100, 100);
LUT_SUB_ASSERT_TRUE(!dummy.mouseOver())
debugSetMousePos(1, 1);
LUT_SUB_ASSERT_TRUE(dummy.mouseOver())
LUT_SUB_ASSERT_TRUE(!dummy.mouseDown())
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(dummy.mouseDown())
debugSetMousePos(100, 100);
LUT_SUB_ASSERT_TRUE(!dummy.mouseDown())
LUT_CASE_END
LUT_CASE("mouseJustDown")
Dummy dummy;
dummy.resize(0, 0, 50, 50);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown())
debugSetMousePos(100, 100);
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown())
debugSetMousePos(20, 20);
LUT_SUB_ASSERT_TRUE(dummy.mouseJustDown()) //the mouse moved over the element, the mouse button was already down since being outside the element, so it's now down over the element for the first time
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown()) //now it may not return true anymore!
debugSetLMB(0);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown())
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(dummy.mouseJustDown())
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown()) //now it may not return true anymore!
LUT_CASE_END
LUT_CASE("mouseJustDownHere")
Dummy dummy;
dummy.resize(0, 0, 50, 50);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere())
debugSetMousePos(100, 100);
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere())
debugSetMousePos(20, 20);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere())
debugSetLMB(0);
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere())
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(dummy.mouseJustDownHere())
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere()) //now it may not return true anymore!
LUT_CASE_END
LUT_CASE("mouseJustDownHere on top of window")
Container c;
Window w;
w.make(0, 0, 100, 100);
c.pushTop(&w, 0, 0);
w.addTop();
c.handle();c.handle();
int mx = w.top.getCenterx();
int my = w.top.getCentery();
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(!w.top.mouseJustDownHere())
debugSetMousePos(100, 100);
debugSetLMB(1);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(!w.top.mouseJustDownHere())
debugSetMousePos(mx, my);
LUT_SUB_ASSERT_TRUE(!w.top.mouseJustDownHere())
debugSetLMB(0);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(!w.top.mouseJustDownHere())
debugSetLMB(1);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(w.top.mouseJustDownHere())
LUT_SUB_ASSERT_TRUE(!w.top.mouseJustDownHere()) //now it may not return true anymore!
LUT_CASE_END
LUT_CASE("mouseGrabbed")
Dummy dummy;
dummy.resize(0, 0, 50, 50);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse not down yet
debugSetMousePos(10, 10);
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(dummy.mouseGrabbed()) //mouse down on element so it's grabbed
debugSetMousePos(100, 100);
LUT_SUB_ASSERT_TRUE(dummy.mouseGrabbed()) //mouse moved away but still down ==> still grabbed
LUT_SUB_ASSERT_TRUE(dummy.mouseGetGrabX() == 10 && dummy.mouseGetGrabY() == 10)
debugSetLMB(0);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse button up ==> not grabbed anymore
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse down somewhere else not on element ==> not grabbed
debugSetMousePos(15, 15);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse still down and moving over element, but it wasn't down HERE, so not grabbed
/*//now repeat the test to see if states can properly be reused
debugSetLMB(0);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed())
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(dummy.mouseGrabbed()) //mouse down on element so it's grabbed
debugSetMousePos(100, 100);
LUT_SUB_ASSERT_TRUE(dummy.mouseGrabbed()) //mouse moved away but still down ==> still grabbed
LUT_SUB_ASSERT_TRUE(dummy.mouseGetGrabX() == 15 && dummy.mouseGetGrabY() == 15)
debugSetLMB(0);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse button up ==> not grabbed anymore
debugSetLMB(1);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse down somewhere else not on element ==> not grabbed
debugSetMousePos(11, 11);
LUT_SUB_ASSERT_TRUE(!dummy.mouseGrabbed()) //mouse still down and moving over element, but it wasn't down HERE, so not grabbed*/
LUT_CASE_END
//the fact that the container and the window handles the elements, influences the result
LUT_CASE("mouseGrabbed on top of window")
Container c;
Window w;
w.make(0, 0, 100, 100);
c.pushTop(&w, 0, 0);
w.addTop();
c.handle();c.handle();
int mx = w.top.getCenterx();
int my = w.top.getCentery();
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(!w.top.mouseGrabbed()) //mouse not down yet
debugSetMousePos(mx, my);
debugSetLMB(1);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(w.top.mouseGrabbed()) //mouse down on element so it's grabbed
debugSetMousePos(200, 200);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(w.top.mouseGrabbed()) //mouse moved away but still down ==> still grabbed
LUT_SUB_ASSERT_TRUE(w.top.mouseGetGrabX() == mx && w.top.mouseGetGrabY() == my)
debugSetLMB(0);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(!w.top.mouseGrabbed()) //mouse button up ==> not grabbed anymore
debugSetLMB(1);
c.handle();c.handle();
LUT_SUB_ASSERT_TRUE(w.top.mouseGrabbed()) //mouse down somewhere else not on element ==> normally not grabbed, BUT, the window moves!! ==> under mouse and grabbed again
LUT_CASE_END
LUT_CASE("dragging a window")
Container c;
Window w;
w.make(0, 0, 100, 100);
c.pushTop(&w, 0, 0);
w.addTop();
c.handle();c.handle();
int mx = w.top.getCenterx();
int my = w.top.getCentery();
int wx1 = w.getX0();
int wy1 = w.getY0();
debugSetMousePos(mx, my); //mouse above top bar of the window
debugSetLMB(1);
c.handle();c.handle();
int wx2 = w.getX0();
int wy2 = w.getY0();
LUT_SUB_ASSERT_TRUE(wx1 == wx2 && wy1 == wy2)
debugSetMousePos(mx + 100, my + 50);
c.handle();c.handle();
int wx3 = w.getX0();
int wy3 = w.getY0();
LUT_SUB_ASSERT_FALSE(wx3 == wx1 && wy3 == wy1)
LUT_SUB_ASSERT_TRUE(wx3 == wx1 + 100 && wy3 == wy1 + 50)
LUT_APPEND_MSG << "wx1: " << wx1 << "wy1: " << wy1 << "wx2: " << wx2 << "wy2: " << wy2 << "wx3: " << wx3 << "wy3: " << wy3;
LUT_CASE_END
//functions like mouseJustDown and mouseJustDownHere may not influence each other's result, so both can return true once
LUT_CASE("mouse independence")
Dummy dummy;
dummy.resize(0, 0, 50, 50);
debugSetMousePos(10, 10); //mouse above
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown())
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere())
debugSetLMB(1); //press button
//now both must return true
LUT_SUB_ASSERT_TRUE(dummy.mouseJustDown())
LUT_SUB_ASSERT_TRUE(dummy.mouseJustDownHere())
//but of course now both must return false
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDown())
LUT_SUB_ASSERT_TRUE(!dummy.mouseJustDownHere())
LUT_CASE_END
//when boolean mouseActive is true, mouseOver should work, when it's false, mouseOver shout NOT work
LUT_CASE("mouseOver when active and not active")
Dummy dummy;
dummy.resize(0, 0, 50, 50);
debugSetMousePos(1, 1);
LUT_SUB_ASSERT_TRUE(dummy.mouseOver())
dummy.setElementOver(true);
LUT_SUB_ASSERT_TRUE(!dummy.mouseOver())
//note: containers like a gui::Window have to take control of the mouseActive boolean of the elements in it
LUT_CASE_END
//the selfActivate system (used by text input boxes) didn't work anymore, so I added this test to make sure it won't break anymore
LUT_CASE("selfActivate of InputLine")
InputLine line;
line.make(0, 0, 10);
//initially it's not active
line.handle(); //handle line all the time to let the selfActivate system work
LUT_SUB_ASSERT_TRUE(!line.isActive())
//move mouse above it and click
debugSetMousePos(1, 1);
debugSetLMB(1);
line.handle();
//it must be active now!
LUT_SUB_ASSERT_TRUE(line.isActive())
//now release the mouse button
debugSetLMB(0);
line.handle();
//it should still be active!
LUT_SUB_ASSERT_TRUE(line.isActive())
//move mouse away
debugSetMousePos(100, 100);
line.handle();
//it should still be active!
LUT_SUB_ASSERT_TRUE(line.isActive())
//move mouse away from it and click
debugSetMousePos(100, 100);
debugSetLMB(1);
line.handle();
//it may not be active anymore after clicking on a location outside (???????)
LUT_SUB_ASSERT_TRUE(!line.isActive())
LUT_CASE_END
LUT_CASE("selfActivate of InputLine in Window")
Container c;
Window w;
w.make(0, 0, 100, 100);
c.pushTop(&w, 0, 0);
InputLine line;
line.make(0, 0, 10);
w.pushTop(&line, 0, 0);
//initially it's not active
c.handle(); //handle line all the time to let the selfActivate system work
LUT_SUB_ASSERT_TRUE(!line.isActive())
//now a little test to see if it's at the correct position for these tests below
debugSetMousePos(line.getCenterx(), line.getCentery());
line.setActive(true);
line.setElementOver(false);
LUT_SUB_ASSERT_TRUE(line.mouseOver())
line.setElementOver(true);
line.setActive(false);
//move mouse above it and click
debugSetMousePos(line.getCenterx(), line.getCentery());
debugSetLMB(1);
c.handle();
//it must be active now!
LUT_SUB_ASSERT_TRUE(line.isActive())
//now release the mouse button
debugSetLMB(0);
c.handle();
//it should still be active!
LUT_SUB_ASSERT_TRUE(line.isActive())
//move mouse away
debugSetMousePos(100, 100);
c.handle();
//it should still be active!
LUT_SUB_ASSERT_TRUE(line.isActive())
//move mouse away from it and click
debugSetMousePos(100, 100);
debugSetLMB(1);
c.handle();
//it may not be active anymore after clicking on a location outside (???????)
LUT_SUB_ASSERT_TRUE(!line.isActive())
LUT_CASE_END
//two things on a container, both at the same location, first the one is totallyEnabled and the other totallyDisabled, then vica versa, then each time only the enabled one may return true to mouseOver
LUT_CASE("enabled and disabled on each other")
Container c;
Window w;
w.make(0, 0, 100, 100);
c.pushTop(&w, 0, 0);
Dummy dummy1;
dummy1.resize(0, 0, 50, 50);
w.pushTop(&dummy1, 0, 0);
Dummy dummy2;
dummy2.resize(0, 0, 50, 50);
w.pushTop(&dummy2, 0, 0);
debugSetMousePos(dummy1.getCenterx(), dummy1.getCentery()); //doesn't matter if you take center of dummy1 or dummy2, both are exactly at same position
dummy1.totallyEnable();
dummy2.totallyDisable();
LUT_SUB_ASSERT_TRUE(dummy1.mouseOver())
LUT_SUB_ASSERT_TRUE(!dummy2.mouseOver())
dummy1.totallyDisable();
dummy2.totallyEnable();
LUT_SUB_ASSERT_TRUE(!dummy1.mouseOver())
LUT_SUB_ASSERT_TRUE(dummy2.mouseOver())
LUT_CASE_END
//dragging a window that has a top
LUT_CASE("dragging of a window")
Container c;
Window w;
w.make(0, 0, 100, 100);
w.addTop();
c.pushTop(&w, 0, 0);
int mx = w.top.getCenterx();
int my = w.top.getCentery();
//grab the window
debugSetMousePos(mx, my);
debugSetLMB(1);
c.handle();
//move
debugSetMousePos(200, 200);
c.handle();
//now the window must still be below the mouse
LUT_SUB_ASSERT_TRUE(w.mouseOver())
LUT_CASE_END
//when there are two windows, A and B, and you're dragging one over the other, but you drag the mouse fast and the mousepointer goes to a location not over the dragged window (the dragged window will be under the mouse again soon), then the other window may not swap to top
LUT_CASE("fast dragging of one window over another")
Container c;
Window A;
A.make(0, 0, 100, 100);
A.addTop();
c.pushTopAt(&A, 0, 0);
Window B;
B.make(0, 0, 100, 100);
B.addTop();
c.pushTopAt(&B, 200, 0);
int ax = A.top.getCenterx();
int ay = A.top.getCentery();
int bx = B.top.getCenterx();
int by = B.top.getCentery();
//grab the window A
debugSetMousePos(ax, ay);
debugSetLMB(1);
c.handle();
//move it over window B
debugSetMousePos(bx, by);
c.handle();
//now window A must be over window B, so window A must have mouseOver, window B not
LUT_SUB_ASSERT_TRUE(A.mouseOver())
LUT_SUB_ASSERT_TRUE(!B.mouseOver())
LUT_CASE_END
LUT_END_UNIT_TEST
}
} //namespace gui
} //namespace lpi
////////////////////////////////////////////////////////////////////////////////