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
|
/**
* @file llui.cpp
* @brief UI implementation
*
* $LicenseInfo:firstyear=2001&license=viewergpl$
*
* Copyright (c) 2001-2009, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
// Utilities functions the user interface needs
#include "linden_common.h"
#include <string>
#include <map>
// Linden library includes
#include "v2math.h"
#include "m3math.h"
#include "v4color.h"
#include "llrender.h"
#include "llrect.h"
#include "lldir.h"
#include "llgl.h"
// Project includes
#include "llcontrol.h"
#include "llui.h"
#include "lluicolortable.h"
#include "llview.h"
#include "lllineeditor.h"
#include "llfloater.h"
#include "llfloaterreg.h"
#include "llmenugl.h"
#include "llmenubutton.h"
#include "llwindow.h"
// for registration
#include "llfiltereditor.h"
#include "llflyoutbutton.h"
#include "llsearcheditor.h"
// for XUIParse
#include "llquaternion.h"
#include <boost/tokenizer.hpp>
//
// Globals
//
const LLColor4 UI_VERTEX_COLOR(1.f, 1.f, 1.f, 1.f);
// Language for UI construction
std::map<std::string, std::string> gTranslation;
std::list<std::string> gUntranslated;
/*static*/ LLUI::settings_map_t LLUI::sSettingGroups;
/*static*/ LLImageProviderInterface* LLUI::sImageProvider = NULL;
/*static*/ LLUIAudioCallback LLUI::sAudioCallback = NULL;
/*static*/ LLVector2 LLUI::sGLScaleFactor(1.f, 1.f);
/*static*/ LLWindow* LLUI::sWindow = NULL;
/*static*/ LLView* LLUI::sRootView = NULL;
/*static*/ BOOL LLUI::sDirty = FALSE;
/*static*/ LLRect LLUI::sDirtyRect;
/*static*/ LLHelp* LLUI::sHelpImpl = NULL;
/*static*/ std::vector<std::string> LLUI::sXUIPaths;
/*static*/ LLFrameTimer LLUI::sMouseIdleTimer;
/*static*/ LLUI::add_popup_t LLUI::sAddPopupFunc;
/*static*/ LLUI::remove_popup_t LLUI::sRemovePopupFunc;
/*static*/ LLUI::clear_popups_t LLUI::sClearPopupsFunc;
// register filtereditor here
static LLDefaultChildRegistry::Register<LLFilterEditor> register_filter_editor("filter_editor");
static LLDefaultChildRegistry::Register<LLFlyoutButton> register_flyout_button("flyout_button");
static LLDefaultChildRegistry::Register<LLSearchEditor> register_search_editor("search_editor");
static LLDefaultChildRegistry::Register<LLMenuButton> register_menu_button("menu_button");
//
// Functions
//
void make_ui_sound(const char* namep)
{
std::string name = ll_safe_string(namep);
if (!LLUI::sSettingGroups["config"]->controlExists(name))
{
llwarns << "tried to make ui sound for unknown sound name: " << name << llendl;
}
else
{
LLUUID uuid(LLUI::sSettingGroups["config"]->getString(name));
if (uuid.isNull())
{
if (LLUI::sSettingGroups["config"]->getString(name) == LLUUID::null.asString())
{
if (LLUI::sSettingGroups["config"]->getBOOL("UISndDebugSpamToggle"))
{
llinfos << "ui sound name: " << name << " triggered but silent (null uuid)" << llendl;
}
}
else
{
llwarns << "ui sound named: " << name << " does not translate to a valid uuid" << llendl;
}
}
else if (LLUI::sAudioCallback != NULL)
{
if (LLUI::sSettingGroups["config"]->getBOOL("UISndDebugSpamToggle"))
{
llinfos << "ui sound name: " << name << llendl;
}
LLUI::sAudioCallback(uuid);
}
}
}
BOOL ui_point_in_rect(S32 x, S32 y, S32 left, S32 top, S32 right, S32 bottom)
{
if (x < left || right < x) return FALSE;
if (y < bottom || top < y) return FALSE;
return TRUE;
}
// Puts GL into 2D drawing mode by turning off lighting, setting to an
// orthographic projection, etc.
void gl_state_for_2d(S32 width, S32 height)
{
stop_glerror();
F32 window_width = (F32) width;//gViewerWindow->getWindowWidth();
F32 window_height = (F32) height;//gViewerWindow->getWindowHeight();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, llmax(window_width, 1.f), 0.0f, llmax(window_height,1.f), -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
stop_glerror();
}
void gl_draw_x(const LLRect& rect, const LLColor4& color)
{
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.color4fv( color.mV );
gGL.begin( LLRender::LINES );
gGL.vertex2i( rect.mLeft, rect.mTop );
gGL.vertex2i( rect.mRight, rect.mBottom );
gGL.vertex2i( rect.mLeft, rect.mBottom );
gGL.vertex2i( rect.mRight, rect.mTop );
gGL.end();
}
void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, S32 pixel_offset, BOOL filled)
{
gGL.color4fv(color.mV);
gl_rect_2d_offset_local(left, top, right, bottom, pixel_offset, filled);
}
void gl_rect_2d_offset_local( S32 left, S32 top, S32 right, S32 bottom, S32 pixel_offset, BOOL filled)
{
gGL.pushUIMatrix();
left += LLFontGL::sCurOrigin.mX;
right += LLFontGL::sCurOrigin.mX;
bottom += LLFontGL::sCurOrigin.mY;
top += LLFontGL::sCurOrigin.mY;
gGL.loadUIIdentity();
gl_rect_2d(llfloor((F32)left * LLUI::sGLScaleFactor.mV[VX]) - pixel_offset,
llfloor((F32)top * LLUI::sGLScaleFactor.mV[VY]) + pixel_offset,
llfloor((F32)right * LLUI::sGLScaleFactor.mV[VX]) + pixel_offset,
llfloor((F32)bottom * LLUI::sGLScaleFactor.mV[VY]) - pixel_offset,
filled);
gGL.popUIMatrix();
}
void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, BOOL filled )
{
stop_glerror();
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
// Counterclockwise quad will face the viewer
if( filled )
{
gGL.begin( LLRender::QUADS );
gGL.vertex2i(left, top);
gGL.vertex2i(left, bottom);
gGL.vertex2i(right, bottom);
gGL.vertex2i(right, top);
gGL.end();
}
else
{
if( gGLManager.mATIOffsetVerticalLines )
{
// Work around bug in ATI driver: vertical lines are offset by (-1,-1)
gGL.begin( LLRender::LINES );
// Verticals
gGL.vertex2i(left + 1, top);
gGL.vertex2i(left + 1, bottom);
gGL.vertex2i(right, bottom);
gGL.vertex2i(right, top);
// Horizontals
top--;
right--;
gGL.vertex2i(left, bottom);
gGL.vertex2i(right, bottom);
gGL.vertex2i(left, top);
gGL.vertex2i(right, top);
gGL.end();
}
else
{
top--;
right--;
gGL.begin( LLRender::LINE_STRIP );
gGL.vertex2i(left, top);
gGL.vertex2i(left, bottom);
gGL.vertex2i(right, bottom);
gGL.vertex2i(right, top);
gGL.vertex2i(left, top);
gGL.end();
}
}
stop_glerror();
}
void gl_rect_2d(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &color, BOOL filled )
{
gGL.color4fv( color.mV );
gl_rect_2d( left, top, right, bottom, filled );
}
void gl_rect_2d( const LLRect& rect, const LLColor4& color, BOOL filled )
{
gGL.color4fv( color.mV );
gl_rect_2d( rect.mLeft, rect.mTop, rect.mRight, rect.mBottom, filled );
}
// Given a rectangle on the screen, draws a drop shadow _outside_
// the right and bottom edges of it. Along the right it has width "lines"
// and along the bottom it has height "lines".
void gl_drop_shadow(S32 left, S32 top, S32 right, S32 bottom, const LLColor4 &start_color, S32 lines)
{
stop_glerror();
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
// HACK: Overlap with the rectangle by a single pixel.
right--;
bottom++;
lines++;
LLColor4 end_color = start_color;
end_color.mV[VALPHA] = 0.f;
gGL.begin(LLRender::QUADS);
// Right edge, CCW faces screen
gGL.color4fv(start_color.mV);
gGL.vertex2i(right, top-lines);
gGL.vertex2i(right, bottom);
gGL.color4fv(end_color.mV);
gGL.vertex2i(right+lines, bottom);
gGL.vertex2i(right+lines, top-lines);
// Bottom edge, CCW faces screen
gGL.color4fv(start_color.mV);
gGL.vertex2i(right, bottom);
gGL.vertex2i(left+lines, bottom);
gGL.color4fv(end_color.mV);
gGL.vertex2i(left+lines, bottom-lines);
gGL.vertex2i(right, bottom-lines);
// bottom left Corner
gGL.color4fv(start_color.mV);
gGL.vertex2i(left+lines, bottom);
gGL.color4fv(end_color.mV);
gGL.vertex2i(left, bottom);
// make the bottom left corner not sharp
gGL.vertex2i(left+1, bottom-lines+1);
gGL.vertex2i(left+lines, bottom-lines);
// bottom right corner
gGL.color4fv(start_color.mV);
gGL.vertex2i(right, bottom);
gGL.color4fv(end_color.mV);
gGL.vertex2i(right, bottom-lines);
// make the rightmost corner not sharp
gGL.vertex2i(right+lines-1, bottom-lines+1);
gGL.vertex2i(right+lines, bottom);
// top right corner
gGL.color4fv(start_color.mV);
gGL.vertex2i( right, top-lines );
gGL.color4fv(end_color.mV);
gGL.vertex2i( right+lines, top-lines );
// make the corner not sharp
gGL.vertex2i( right+lines-1, top-1 );
gGL.vertex2i( right, top );
gGL.end();
stop_glerror();
}
void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2 )
{
// Work around bug in ATI driver: vertical lines are offset by (-1,-1)
if( (x1 == x2) && gGLManager.mATIOffsetVerticalLines )
{
x1++;
x2++;
y1++;
y2++;
}
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.begin(LLRender::LINES);
gGL.vertex2i(x1, y1);
gGL.vertex2i(x2, y2);
gGL.end();
}
void gl_line_2d(S32 x1, S32 y1, S32 x2, S32 y2, const LLColor4 &color )
{
// Work around bug in ATI driver: vertical lines are offset by (-1,-1)
if( (x1 == x2) && gGLManager.mATIOffsetVerticalLines )
{
x1++;
x2++;
y1++;
y2++;
}
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.color4fv( color.mV );
gGL.begin(LLRender::LINES);
gGL.vertex2i(x1, y1);
gGL.vertex2i(x2, y2);
gGL.end();
}
void gl_triangle_2d(S32 x1, S32 y1, S32 x2, S32 y2, S32 x3, S32 y3, const LLColor4& color, BOOL filled)
{
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.color4fv(color.mV);
if (filled)
{
gGL.begin(LLRender::TRIANGLES);
}
else
{
gGL.begin(LLRender::LINE_LOOP);
}
gGL.vertex2i(x1, y1);
gGL.vertex2i(x2, y2);
gGL.vertex2i(x3, y3);
gGL.end();
}
void gl_corners_2d(S32 left, S32 top, S32 right, S32 bottom, S32 length, F32 max_frac)
{
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
length = llmin((S32)(max_frac*(right - left)), length);
length = llmin((S32)(max_frac*(top - bottom)), length);
gGL.begin(LLRender::LINES);
gGL.vertex2i(left, top);
gGL.vertex2i(left + length, top);
gGL.vertex2i(left, top);
gGL.vertex2i(left, top - length);
gGL.vertex2i(left, bottom);
gGL.vertex2i(left + length, bottom);
gGL.vertex2i(left, bottom);
gGL.vertex2i(left, bottom + length);
gGL.vertex2i(right, top);
gGL.vertex2i(right - length, top);
gGL.vertex2i(right, top);
gGL.vertex2i(right, top - length);
gGL.vertex2i(right, bottom);
gGL.vertex2i(right - length, bottom);
gGL.vertex2i(right, bottom);
gGL.vertex2i(right, bottom + length);
gGL.end();
}
void gl_draw_image( S32 x, S32 y, LLTexture* image, const LLColor4& color, const LLRectf& uv_rect )
{
if (NULL == image)
{
llwarns << "image == NULL; aborting function" << llendl;
return;
}
gl_draw_scaled_rotated_image( x, y, image->getWidth(0), image->getHeight(0), 0.f, image, color, uv_rect );
}
void gl_draw_scaled_image(S32 x, S32 y, S32 width, S32 height, LLTexture* image, const LLColor4& color, const LLRectf& uv_rect)
{
if (NULL == image)
{
llwarns << "image == NULL; aborting function" << llendl;
return;
}
gl_draw_scaled_rotated_image( x, y, width, height, 0.f, image, color, uv_rect );
}
void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 border_width, S32 border_height, S32 width, S32 height, LLTexture* image, const LLColor4& color, BOOL solid_color, const LLRectf& uv_rect)
{
if (NULL == image)
{
llwarns << "image == NULL; aborting function" << llendl;
return;
}
// scale screen size of borders down
F32 border_width_fraction = (F32)border_width / (F32)image->getWidth(0);
F32 border_height_fraction = (F32)border_height / (F32)image->getHeight(0);
LLRectf scale_rect(border_width_fraction, 1.f - border_height_fraction, 1.f - border_width_fraction, border_height_fraction);
gl_draw_scaled_image_with_border(x, y, width, height, image, color, solid_color, uv_rect, scale_rect);
}
void gl_draw_scaled_image_with_border(S32 x, S32 y, S32 width, S32 height, LLTexture* image, const LLColor4& color, BOOL solid_color, const LLRectf& uv_rect, const LLRectf& scale_rect)
{
stop_glerror();
if (NULL == image)
{
llwarns << "image == NULL; aborting function" << llendl;
return;
}
// shrink scaling region to be proportional to clipped image region
LLRectf scale_rect_uv(
uv_rect.mLeft + (scale_rect.mLeft * uv_rect.getWidth()),
uv_rect.mBottom + (scale_rect.mTop * uv_rect.getHeight()),
uv_rect.mLeft + (scale_rect.mRight * uv_rect.getWidth()),
uv_rect.mBottom + (scale_rect.mBottom * uv_rect.getHeight()));
S32 image_natural_width = llround((F32)image->getWidth(0) * uv_rect.getWidth());
S32 image_natural_height = llround((F32)image->getHeight(0) * uv_rect.getHeight());
LLRect draw_rect(0, height, width, 0);
LLRect draw_scale_rect(llround(scale_rect_uv.mLeft * (F32)image->getWidth(0)),
llround(scale_rect_uv.mTop * (F32)image->getHeight(0)),
llround(scale_rect_uv.mRight * (F32)image->getWidth(0)),
llround(scale_rect_uv.mBottom * (F32)image->getHeight(0)));
// scale fixed region of image to drawn region
draw_scale_rect.mRight += width - image_natural_width;
draw_scale_rect.mTop += height - image_natural_height;
S32 border_shrink_width = llmax(0, draw_scale_rect.mLeft - draw_scale_rect.mRight);
S32 border_shrink_height = llmax(0, draw_scale_rect.mBottom - draw_scale_rect.mTop);
F32 shrink_width_ratio = scale_rect.getWidth() == 1.f ? 0.f : border_shrink_width / ((F32)image_natural_width * (1.f - scale_rect.getWidth()));
F32 shrink_height_ratio = scale_rect.getHeight() == 1.f ? 0.f : border_shrink_height / ((F32)image_natural_height * (1.f - scale_rect.getHeight()));
F32 shrink_scale = 1.f - llmax(shrink_width_ratio, shrink_height_ratio);
draw_scale_rect.mLeft = llround((F32)draw_scale_rect.mLeft * shrink_scale);
draw_scale_rect.mTop = llround(lerp((F32)height, (F32)draw_scale_rect.mTop, shrink_scale));
draw_scale_rect.mRight = llround(lerp((F32)width, (F32)draw_scale_rect.mRight, shrink_scale));
draw_scale_rect.mBottom = llround((F32)draw_scale_rect.mBottom * shrink_scale);
LLGLSUIDefault gls_ui;
if (solid_color)
{
gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR);
gGL.getTexUnit(0)->setTextureAlphaBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_ALPHA, LLTexUnit::TBS_VERT_ALPHA);
}
gGL.pushUIMatrix();
{
gGL.translateUI((F32)x, (F32)y, 0.f);
gGL.getTexUnit(0)->bind(image);
gGL.color4fv(color.mV);
gGL.begin(LLRender::QUADS);
{
// draw bottom left
gGL.texCoord2f(uv_rect.mLeft, uv_rect.mBottom);
gGL.vertex2i(0, 0);
gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mBottom);
gGL.vertex2i(draw_scale_rect.mLeft, 0);
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mBottom);
gGL.vertex2i(0, draw_scale_rect.mBottom);
// draw bottom middle
gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mBottom);
gGL.vertex2i(draw_scale_rect.mLeft, 0);
gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mBottom);
gGL.vertex2i(draw_scale_rect.mRight, 0);
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
// draw bottom right
gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mBottom);
gGL.vertex2i(draw_scale_rect.mRight, 0);
gGL.texCoord2f(uv_rect.mRight, uv_rect.mBottom);
gGL.vertex2i(width, 0);
gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mBottom);
gGL.vertex2i(width, draw_scale_rect.mBottom);
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
// draw left
gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mBottom);
gGL.vertex2i(0, draw_scale_rect.mBottom);
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mTop);
gGL.vertex2i(0, draw_scale_rect.mTop);
// draw middle
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mBottom);
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
// draw right
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mBottom);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mBottom);
gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mBottom);
gGL.vertex2i(width, draw_scale_rect.mBottom);
gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mTop);
gGL.vertex2i(width, draw_scale_rect.mTop);
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
// draw top left
gGL.texCoord2f(uv_rect.mLeft, scale_rect_uv.mTop);
gGL.vertex2i(0, draw_scale_rect.mTop);
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mTop);
gGL.vertex2i(draw_scale_rect.mLeft, height);
gGL.texCoord2f(uv_rect.mLeft, uv_rect.mTop);
gGL.vertex2i(0, height);
// draw top middle
gGL.texCoord2f(scale_rect_uv.mLeft, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mLeft, draw_scale_rect.mTop);
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mTop);
gGL.vertex2i(draw_scale_rect.mRight, height);
gGL.texCoord2f(scale_rect_uv.mLeft, uv_rect.mTop);
gGL.vertex2i(draw_scale_rect.mLeft, height);
// draw top right
gGL.texCoord2f(scale_rect_uv.mRight, scale_rect_uv.mTop);
gGL.vertex2i(draw_scale_rect.mRight, draw_scale_rect.mTop);
gGL.texCoord2f(uv_rect.mRight, scale_rect_uv.mTop);
gGL.vertex2i(width, draw_scale_rect.mTop);
gGL.texCoord2f(uv_rect.mRight, uv_rect.mTop);
gGL.vertex2i(width, height);
gGL.texCoord2f(scale_rect_uv.mRight, uv_rect.mTop);
gGL.vertex2i(draw_scale_rect.mRight, height);
}
gGL.end();
}
gGL.popUIMatrix();
if (solid_color)
{
gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT);
}
}
void gl_draw_rotated_image(S32 x, S32 y, F32 degrees, LLTexture* image, const LLColor4& color, const LLRectf& uv_rect)
{
gl_draw_scaled_rotated_image( x, y, image->getWidth(0), image->getHeight(0), degrees, image, color, uv_rect );
}
void gl_draw_scaled_rotated_image(S32 x, S32 y, S32 width, S32 height, F32 degrees, LLTexture* image, const LLColor4& color, const LLRectf& uv_rect)
{
if (NULL == image)
{
llwarns << "image == NULL; aborting function" << llendl;
return;
}
LLGLSUIDefault gls_ui;
gGL.getTexUnit(0)->bind(image);
gGL.color4fv(color.mV);
if (degrees == 0.f)
{
gGL.pushUIMatrix();
gGL.translateUI((F32)x, (F32)y, 0.f);
gGL.begin(LLRender::QUADS);
{
gGL.texCoord2f(uv_rect.mRight, uv_rect.mTop);
gGL.vertex2i(width, height );
gGL.texCoord2f(uv_rect.mLeft, uv_rect.mTop);
gGL.vertex2i(0, height );
gGL.texCoord2f(uv_rect.mLeft, uv_rect.mBottom);
gGL.vertex2i(0, 0);
gGL.texCoord2f(uv_rect.mRight, uv_rect.mBottom);
gGL.vertex2i(width, 0);
}
gGL.end();
gGL.popUIMatrix();
}
else
{
gGL.pushUIMatrix();
gGL.translateUI((F32)x, (F32)y, 0.f);
F32 offset_x = F32(width/2);
F32 offset_y = F32(height/2);
gGL.translateUI(offset_x, offset_y, 0.f);
LLMatrix3 quat(0.f, 0.f, degrees*DEG_TO_RAD);
gGL.getTexUnit(0)->bind(image);
gGL.color4fv(color.mV);
gGL.begin(LLRender::QUADS);
{
LLVector3 v;
v = LLVector3(offset_x, offset_y, 0.f) * quat;
gGL.texCoord2f(uv_rect.mRight, uv_rect.mTop);
gGL.vertex2f(v.mV[0], v.mV[1] );
v = LLVector3(-offset_x, offset_y, 0.f) * quat;
gGL.texCoord2f(uv_rect.mLeft, uv_rect.mTop);
gGL.vertex2f(v.mV[0], v.mV[1] );
v = LLVector3(-offset_x, -offset_y, 0.f) * quat;
gGL.texCoord2f(uv_rect.mLeft, uv_rect.mBottom);
gGL.vertex2f(v.mV[0], v.mV[1] );
v = LLVector3(offset_x, -offset_y, 0.f) * quat;
gGL.texCoord2f(uv_rect.mRight, uv_rect.mBottom);
gGL.vertex2f(v.mV[0], v.mV[1] );
}
gGL.end();
gGL.popUIMatrix();
}
}
void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LLColor4& color, F32 phase )
{
phase = fmod(phase, 1.f);
S32 shift = S32(phase * 4.f) % 4;
// Stippled line
LLGLEnable stipple(GL_LINE_STIPPLE);
gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], color.mV[VALPHA]);
gGL.flush();
glLineWidth(2.5f);
glLineStipple(2, 0x3333 << shift);
gGL.begin(LLRender::LINES);
{
gGL.vertex3fv( start.mV );
gGL.vertex3fv( end.mV );
}
gGL.end();
LLUI::setLineWidth(1.f);
}
void gl_rect_2d_xor(S32 left, S32 top, S32 right, S32 bottom)
{
gGL.color4fv( LLColor4::white.mV );
glLogicOp( GL_XOR );
stop_glerror();
gGL.begin(LLRender::QUADS);
gGL.vertex2i(left, top);
gGL.vertex2i(left, bottom);
gGL.vertex2i(right, bottom);
gGL.vertex2i(right, top);
gGL.end();
glLogicOp( GL_COPY );
stop_glerror();
}
void gl_arc_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled, F32 start_angle, F32 end_angle)
{
if (end_angle < start_angle)
{
end_angle += F_TWO_PI;
}
gGL.pushUIMatrix();
{
gGL.translateUI(center_x, center_y, 0.f);
// Inexact, but reasonably fast.
F32 delta = (end_angle - start_angle) / steps;
F32 sin_delta = sin( delta );
F32 cos_delta = cos( delta );
F32 x = cosf(start_angle) * radius;
F32 y = sinf(start_angle) * radius;
if (filled)
{
gGL.begin(LLRender::TRIANGLE_FAN);
gGL.vertex2f(0.f, 0.f);
// make sure circle is complete
steps += 1;
}
else
{
gGL.begin(LLRender::LINE_STRIP);
}
while( steps-- )
{
// Successive rotations
gGL.vertex2f( x, y );
F32 x_new = x * cos_delta - y * sin_delta;
y = x * sin_delta + y * cos_delta;
x = x_new;
}
gGL.end();
}
gGL.popUIMatrix();
}
void gl_circle_2d(F32 center_x, F32 center_y, F32 radius, S32 steps, BOOL filled)
{
gGL.pushUIMatrix();
{
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.translateUI(center_x, center_y, 0.f);
// Inexact, but reasonably fast.
F32 delta = F_TWO_PI / steps;
F32 sin_delta = sin( delta );
F32 cos_delta = cos( delta );
F32 x = radius;
F32 y = 0.f;
if (filled)
{
gGL.begin(LLRender::TRIANGLE_FAN);
gGL.vertex2f(0.f, 0.f);
// make sure circle is complete
steps += 1;
}
else
{
gGL.begin(LLRender::LINE_LOOP);
}
while( steps-- )
{
// Successive rotations
gGL.vertex2f( x, y );
F32 x_new = x * cos_delta - y * sin_delta;
y = x * sin_delta + y * cos_delta;
x = x_new;
}
gGL.end();
}
gGL.popUIMatrix();
}
// Renders a ring with sides (tube shape)
void gl_deep_circle( F32 radius, F32 depth, S32 steps )
{
F32 x = radius;
F32 y = 0.f;
F32 angle_delta = F_TWO_PI / (F32)steps;
gGL.begin( LLRender::TRIANGLE_STRIP );
{
S32 step = steps + 1; // An extra step to close the circle.
while( step-- )
{
gGL.vertex3f( x, y, depth );
gGL.vertex3f( x, y, 0.f );
F32 x_new = x * cosf(angle_delta) - y * sinf(angle_delta);
y = x * sinf(angle_delta) + y * cosf(angle_delta);
x = x_new;
}
}
gGL.end();
}
void gl_ring( F32 radius, F32 width, const LLColor4& center_color, const LLColor4& side_color, S32 steps, BOOL render_center )
{
gGL.pushUIMatrix();
{
gGL.translateUI(0.f, 0.f, -width / 2);
if( render_center )
{
gGL.color4fv(center_color.mV);
gl_deep_circle( radius, width, steps );
}
else
{
gl_washer_2d(radius, radius - width, steps, side_color, side_color);
gGL.translateUI(0.f, 0.f, width);
gl_washer_2d(radius - width, radius, steps, side_color, side_color);
}
}
gGL.popUIMatrix();
}
// Draw gray and white checkerboard with black border
void gl_rect_2d_checkerboard(const LLRect& rect)
{
// Initialize the first time this is called.
const S32 PIXELS = 32;
static GLubyte checkerboard[PIXELS * PIXELS];
static BOOL first = TRUE;
if( first )
{
for( S32 i = 0; i < PIXELS; i++ )
{
for( S32 j = 0; j < PIXELS; j++ )
{
checkerboard[i * PIXELS + j] = ((i & 1) ^ (j & 1)) * 0xFF;
}
}
first = FALSE;
}
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
// ...white squares
gGL.color3f( 1.f, 1.f, 1.f );
gl_rect_2d(rect);
// ...gray squares
gGL.color3f( .7f, .7f, .7f );
gGL.flush();
glPolygonStipple( checkerboard );
LLGLEnable polygon_stipple(GL_POLYGON_STIPPLE);
gl_rect_2d(rect);
gGL.flush();
}
// Draws the area between two concentric circles, like
// a doughnut or washer.
void gl_washer_2d(F32 outer_radius, F32 inner_radius, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color)
{
const F32 DELTA = F_TWO_PI / steps;
const F32 SIN_DELTA = sin( DELTA );
const F32 COS_DELTA = cos( DELTA );
F32 x1 = outer_radius;
F32 y1 = 0.f;
F32 x2 = inner_radius;
F32 y2 = 0.f;
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.begin( LLRender::TRIANGLE_STRIP );
{
steps += 1; // An extra step to close the circle.
while( steps-- )
{
gGL.color4fv(outer_color.mV);
gGL.vertex2f( x1, y1 );
gGL.color4fv(inner_color.mV);
gGL.vertex2f( x2, y2 );
F32 x1_new = x1 * COS_DELTA - y1 * SIN_DELTA;
y1 = x1 * SIN_DELTA + y1 * COS_DELTA;
x1 = x1_new;
F32 x2_new = x2 * COS_DELTA - y2 * SIN_DELTA;
y2 = x2 * SIN_DELTA + y2 * COS_DELTA;
x2 = x2_new;
}
}
gGL.end();
}
// Draws the area between two concentric circles, like
// a doughnut or washer.
void gl_washer_segment_2d(F32 outer_radius, F32 inner_radius, F32 start_radians, F32 end_radians, S32 steps, const LLColor4& inner_color, const LLColor4& outer_color)
{
const F32 DELTA = (end_radians - start_radians) / steps;
const F32 SIN_DELTA = sin( DELTA );
const F32 COS_DELTA = cos( DELTA );
F32 x1 = outer_radius * cos( start_radians );
F32 y1 = outer_radius * sin( start_radians );
F32 x2 = inner_radius * cos( start_radians );
F32 y2 = inner_radius * sin( start_radians );
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.begin( LLRender::TRIANGLE_STRIP );
{
steps += 1; // An extra step to close the circle.
while( steps-- )
{
gGL.color4fv(outer_color.mV);
gGL.vertex2f( x1, y1 );
gGL.color4fv(inner_color.mV);
gGL.vertex2f( x2, y2 );
F32 x1_new = x1 * COS_DELTA - y1 * SIN_DELTA;
y1 = x1 * SIN_DELTA + y1 * COS_DELTA;
x1 = x1_new;
F32 x2_new = x2 * COS_DELTA - y2 * SIN_DELTA;
y2 = x2 * SIN_DELTA + y2 * COS_DELTA;
x2 = x2_new;
}
}
gGL.end();
}
// Draws spokes around a circle.
void gl_washer_spokes_2d(F32 outer_radius, F32 inner_radius, S32 count, const LLColor4& inner_color, const LLColor4& outer_color)
{
const F32 DELTA = F_TWO_PI / count;
const F32 HALF_DELTA = DELTA * 0.5f;
const F32 SIN_DELTA = sin( DELTA );
const F32 COS_DELTA = cos( DELTA );
F32 x1 = outer_radius * cos( HALF_DELTA );
F32 y1 = outer_radius * sin( HALF_DELTA );
F32 x2 = inner_radius * cos( HALF_DELTA );
F32 y2 = inner_radius * sin( HALF_DELTA );
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.begin( LLRender::LINES );
{
while( count-- )
{
gGL.color4fv(outer_color.mV);
gGL.vertex2f( x1, y1 );
gGL.color4fv(inner_color.mV);
gGL.vertex2f( x2, y2 );
F32 x1_new = x1 * COS_DELTA - y1 * SIN_DELTA;
y1 = x1 * SIN_DELTA + y1 * COS_DELTA;
x1 = x1_new;
F32 x2_new = x2 * COS_DELTA - y2 * SIN_DELTA;
y2 = x2 * SIN_DELTA + y2 * COS_DELTA;
x2 = x2_new;
}
}
gGL.end();
}
void gl_rect_2d_simple_tex( S32 width, S32 height )
{
gGL.begin( LLRender::QUADS );
gGL.texCoord2f(1.f, 1.f);
gGL.vertex2i(width, height);
gGL.texCoord2f(0.f, 1.f);
gGL.vertex2i(0, height);
gGL.texCoord2f(0.f, 0.f);
gGL.vertex2i(0, 0);
gGL.texCoord2f(1.f, 0.f);
gGL.vertex2i(width, 0);
gGL.end();
}
void gl_rect_2d_simple( S32 width, S32 height )
{
gGL.begin( LLRender::QUADS );
gGL.vertex2i(width, height);
gGL.vertex2i(0, height);
gGL.vertex2i(0, 0);
gGL.vertex2i(width, 0);
gGL.end();
}
void gl_segmented_rect_2d_tex(const S32 left,
const S32 top,
const S32 right,
const S32 bottom,
const S32 texture_width,
const S32 texture_height,
const S32 border_size,
const U32 edges)
{
S32 width = llabs(right - left);
S32 height = llabs(top - bottom);
gGL.pushUIMatrix();
gGL.translateUI((F32)left, (F32)bottom, 0.f);
LLVector2 border_uv_scale((F32)border_size / (F32)texture_width, (F32)border_size / (F32)texture_height);
if (border_uv_scale.mV[VX] > 0.5f)
{
border_uv_scale *= 0.5f / border_uv_scale.mV[VX];
}
if (border_uv_scale.mV[VY] > 0.5f)
{
border_uv_scale *= 0.5f / border_uv_scale.mV[VY];
}
F32 border_scale = llmin((F32)border_size, (F32)width * 0.5f, (F32)height * 0.5f);
LLVector2 border_width_left = ((edges & (~(U32)ROUNDED_RECT_RIGHT)) != 0) ? LLVector2(border_scale, 0.f) : LLVector2::zero;
LLVector2 border_width_right = ((edges & (~(U32)ROUNDED_RECT_LEFT)) != 0) ? LLVector2(border_scale, 0.f) : LLVector2::zero;
LLVector2 border_height_bottom = ((edges & (~(U32)ROUNDED_RECT_TOP)) != 0) ? LLVector2(0.f, border_scale) : LLVector2::zero;
LLVector2 border_height_top = ((edges & (~(U32)ROUNDED_RECT_BOTTOM)) != 0) ? LLVector2(0.f, border_scale) : LLVector2::zero;
LLVector2 width_vec((F32)width, 0.f);
LLVector2 height_vec(0.f, (F32)height);
gGL.begin(LLRender::QUADS);
{
// draw bottom left
gGL.texCoord2f(0.f, 0.f);
gGL.vertex2f(0.f, 0.f);
gGL.texCoord2f(border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv(border_width_left.mV);
gGL.texCoord2f(border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + border_height_bottom).mV);
gGL.texCoord2f(0.f, border_uv_scale.mV[VY]);
gGL.vertex2fv(border_height_bottom.mV);
// draw bottom middle
gGL.texCoord2f(border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv(border_width_left.mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv((width_vec - border_width_right).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + border_height_bottom).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + border_height_bottom).mV);
// draw bottom right
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv((width_vec - border_width_right).mV);
gGL.texCoord2f(1.f, 0.f);
gGL.vertex2fv(width_vec.mV);
gGL.texCoord2f(1.f, border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec + border_height_bottom).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + border_height_bottom).mV);
// draw left
gGL.texCoord2f(0.f, border_uv_scale.mV[VY]);
gGL.vertex2fv(border_height_bottom.mV);
gGL.texCoord2f(border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + border_height_bottom).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + height_vec - border_height_top).mV);
gGL.texCoord2f(0.f, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((height_vec - border_height_top).mV);
// draw middle
gGL.texCoord2f(border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + border_height_bottom).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + border_height_bottom).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + height_vec - border_height_top).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + height_vec - border_height_top).mV);
// draw right
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + border_height_bottom).mV);
gGL.texCoord2f(1.f, border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec + border_height_bottom).mV);
gGL.texCoord2f(1.f, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + height_vec - border_height_top).mV);
// draw top left
gGL.texCoord2f(0.f, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((height_vec - border_height_top).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + height_vec - border_height_top).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f);
gGL.vertex2fv((border_width_left + height_vec).mV);
gGL.texCoord2f(0.f, 1.f);
gGL.vertex2fv((height_vec).mV);
// draw top middle
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((border_width_left + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f);
gGL.vertex2fv((width_vec - border_width_right + height_vec).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f);
gGL.vertex2fv((border_width_left + height_vec).mV);
// draw top right
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec - border_width_right + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((width_vec + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f, 1.f);
gGL.vertex2fv((width_vec + height_vec).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f);
gGL.vertex2fv((width_vec - border_width_right + height_vec).mV);
}
gGL.end();
gGL.popUIMatrix();
}
void gl_segmented_rect_2d_fragment_tex(const S32 left,
const S32 top,
const S32 right,
const S32 bottom,
const S32 texture_width,
const S32 texture_height,
const S32 border_size,
const F32 start_fragment,
const F32 end_fragment,
const U32 edges)
{
S32 width = llabs(right - left);
S32 height = llabs(top - bottom);
gGL.pushUIMatrix();
gGL.translateUI((F32)left, (F32)bottom, 0.f);
LLVector2 border_uv_scale((F32)border_size / (F32)texture_width, (F32)border_size / (F32)texture_height);
if (border_uv_scale.mV[VX] > 0.5f)
{
border_uv_scale *= 0.5f / border_uv_scale.mV[VX];
}
if (border_uv_scale.mV[VY] > 0.5f)
{
border_uv_scale *= 0.5f / border_uv_scale.mV[VY];
}
F32 border_scale = llmin((F32)border_size, (F32)width * 0.5f, (F32)height * 0.5f);
LLVector2 border_width_left = ((edges & (~(U32)ROUNDED_RECT_RIGHT)) != 0) ? LLVector2(border_scale, 0.f) : LLVector2::zero;
LLVector2 border_width_right = ((edges & (~(U32)ROUNDED_RECT_LEFT)) != 0) ? LLVector2(border_scale, 0.f) : LLVector2::zero;
LLVector2 border_height_bottom = ((edges & (~(U32)ROUNDED_RECT_TOP)) != 0) ? LLVector2(0.f, border_scale) : LLVector2::zero;
LLVector2 border_height_top = ((edges & (~(U32)ROUNDED_RECT_BOTTOM)) != 0) ? LLVector2(0.f, border_scale) : LLVector2::zero;
LLVector2 width_vec((F32)width, 0.f);
LLVector2 height_vec(0.f, (F32)height);
F32 middle_start = border_scale / (F32)width;
F32 middle_end = 1.f - middle_start;
F32 u_min;
F32 u_max;
LLVector2 x_min;
LLVector2 x_max;
gGL.begin(LLRender::QUADS);
{
if (start_fragment < middle_start)
{
u_min = (start_fragment / middle_start) * border_uv_scale.mV[VX];
u_max = llmin(end_fragment / middle_start, 1.f) * border_uv_scale.mV[VX];
x_min = (start_fragment / middle_start) * border_width_left;
x_max = llmin(end_fragment / middle_start, 1.f) * border_width_left;
// draw bottom left
gGL.texCoord2f(u_min, 0.f);
gGL.vertex2fv(x_min.mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv(x_max.mV);
gGL.texCoord2f(u_max, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + border_height_bottom).mV);
gGL.texCoord2f(u_min, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + border_height_bottom).mV);
// draw left
gGL.texCoord2f(u_min, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + border_height_bottom).mV);
gGL.texCoord2f(u_max, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + border_height_bottom).mV);
gGL.texCoord2f(u_max, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + height_vec - border_height_top).mV);
gGL.texCoord2f(u_min, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + height_vec - border_height_top).mV);
// draw top left
gGL.texCoord2f(u_min, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + height_vec - border_height_top).mV);
gGL.texCoord2f(u_max, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + height_vec - border_height_top).mV);
gGL.texCoord2f(u_max, 1.f);
gGL.vertex2fv((x_max + height_vec).mV);
gGL.texCoord2f(u_min, 1.f);
gGL.vertex2fv((x_min + height_vec).mV);
}
if (end_fragment > middle_start || start_fragment < middle_end)
{
x_min = border_width_left + ((llclamp(start_fragment, middle_start, middle_end) - middle_start)) * width_vec;
x_max = border_width_left + ((llclamp(end_fragment, middle_start, middle_end) - middle_start)) * width_vec;
// draw bottom middle
gGL.texCoord2f(border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv(x_min.mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 0.f);
gGL.vertex2fv((x_max).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + border_height_bottom).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + border_height_bottom).mV);
// draw middle
gGL.texCoord2f(border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + border_height_bottom).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + border_height_bottom).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + height_vec - border_height_top).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + height_vec - border_height_top).mV);
// draw top middle
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + height_vec - border_height_top).mV);
gGL.texCoord2f(1.f - border_uv_scale.mV[VX], 1.f);
gGL.vertex2fv((x_max + height_vec).mV);
gGL.texCoord2f(border_uv_scale.mV[VX], 1.f);
gGL.vertex2fv((x_min + height_vec).mV);
}
if (end_fragment > middle_end)
{
u_min = (1.f - llmax(0.f, ((start_fragment - middle_end) / middle_start))) * border_uv_scale.mV[VX];
u_max = (1.f - ((end_fragment - middle_end) / middle_start)) * border_uv_scale.mV[VX];
x_min = width_vec - ((1.f - llmax(0.f, ((start_fragment - middle_end) / middle_start))) * border_width_right);
x_max = width_vec - ((1.f - ((end_fragment - middle_end) / middle_start)) * border_width_right);
// draw bottom right
gGL.texCoord2f(u_min, 0.f);
gGL.vertex2fv((x_min).mV);
gGL.texCoord2f(u_max, 0.f);
gGL.vertex2fv(x_max.mV);
gGL.texCoord2f(u_max, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + border_height_bottom).mV);
gGL.texCoord2f(u_min, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + border_height_bottom).mV);
// draw right
gGL.texCoord2f(u_min, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + border_height_bottom).mV);
gGL.texCoord2f(u_max, border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + border_height_bottom).mV);
gGL.texCoord2f(u_max, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + height_vec - border_height_top).mV);
gGL.texCoord2f(u_min, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + height_vec - border_height_top).mV);
// draw top right
gGL.texCoord2f(u_min, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_min + height_vec - border_height_top).mV);
gGL.texCoord2f(u_max, 1.f - border_uv_scale.mV[VY]);
gGL.vertex2fv((x_max + height_vec - border_height_top).mV);
gGL.texCoord2f(u_max, 1.f);
gGL.vertex2fv((x_max + height_vec).mV);
gGL.texCoord2f(u_min, 1.f);
gGL.vertex2fv((x_min + height_vec).mV);
}
}
gGL.end();
gGL.popUIMatrix();
}
void gl_segmented_rect_3d_tex(const LLVector2& border_scale, const LLVector3& border_width,
const LLVector3& border_height, const LLVector3& width_vec, const LLVector3& height_vec,
const U32 edges)
{
LLVector3 left_border_width = ((edges & (~(U32)ROUNDED_RECT_RIGHT)) != 0) ? border_width : LLVector3::zero;
LLVector3 right_border_width = ((edges & (~(U32)ROUNDED_RECT_LEFT)) != 0) ? border_width : LLVector3::zero;
LLVector3 top_border_height = ((edges & (~(U32)ROUNDED_RECT_BOTTOM)) != 0) ? border_height : LLVector3::zero;
LLVector3 bottom_border_height = ((edges & (~(U32)ROUNDED_RECT_TOP)) != 0) ? border_height : LLVector3::zero;
gGL.begin(LLRender::QUADS);
{
// draw bottom left
gGL.texCoord2f(0.f, 0.f);
gGL.vertex3f(0.f, 0.f, 0.f);
gGL.texCoord2f(border_scale.mV[VX], 0.f);
gGL.vertex3fv(left_border_width.mV);
gGL.texCoord2f(border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + bottom_border_height).mV);
gGL.texCoord2f(0.f, border_scale.mV[VY]);
gGL.vertex3fv(bottom_border_height.mV);
// draw bottom middle
gGL.texCoord2f(border_scale.mV[VX], 0.f);
gGL.vertex3fv(left_border_width.mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], 0.f);
gGL.vertex3fv((width_vec - right_border_width).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + bottom_border_height).mV);
gGL.texCoord2f(border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + bottom_border_height).mV);
// draw bottom right
gGL.texCoord2f(1.f - border_scale.mV[VX], 0.f);
gGL.vertex3fv((width_vec - right_border_width).mV);
gGL.texCoord2f(1.f, 0.f);
gGL.vertex3fv(width_vec.mV);
gGL.texCoord2f(1.f, border_scale.mV[VY]);
gGL.vertex3fv((width_vec + bottom_border_height).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + bottom_border_height).mV);
// draw left
gGL.texCoord2f(0.f, border_scale.mV[VY]);
gGL.vertex3fv(bottom_border_height.mV);
gGL.texCoord2f(border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + bottom_border_height).mV);
gGL.texCoord2f(border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + height_vec - top_border_height).mV);
gGL.texCoord2f(0.f, 1.f - border_scale.mV[VY]);
gGL.vertex3fv((height_vec - top_border_height).mV);
// draw middle
gGL.texCoord2f(border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + bottom_border_height).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + bottom_border_height).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + height_vec - top_border_height).mV);
gGL.texCoord2f(border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + height_vec - top_border_height).mV);
// draw right
gGL.texCoord2f(1.f - border_scale.mV[VX], border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + bottom_border_height).mV);
gGL.texCoord2f(1.f, border_scale.mV[VY]);
gGL.vertex3fv((width_vec + bottom_border_height).mV);
gGL.texCoord2f(1.f, 1.f - border_scale.mV[VY]);
gGL.vertex3fv((width_vec + height_vec - top_border_height).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + height_vec - top_border_height).mV);
// draw top left
gGL.texCoord2f(0.f, 1.f - border_scale.mV[VY]);
gGL.vertex3fv((height_vec - top_border_height).mV);
gGL.texCoord2f(border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + height_vec - top_border_height).mV);
gGL.texCoord2f(border_scale.mV[VX], 1.f);
gGL.vertex3fv((left_border_width + height_vec).mV);
gGL.texCoord2f(0.f, 1.f);
gGL.vertex3fv((height_vec).mV);
// draw top middle
gGL.texCoord2f(border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((left_border_width + height_vec - top_border_height).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + height_vec - top_border_height).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], 1.f);
gGL.vertex3fv((width_vec - right_border_width + height_vec).mV);
gGL.texCoord2f(border_scale.mV[VX], 1.f);
gGL.vertex3fv((left_border_width + height_vec).mV);
// draw top right
gGL.texCoord2f(1.f - border_scale.mV[VX], 1.f - border_scale.mV[VY]);
gGL.vertex3fv((width_vec - right_border_width + height_vec - top_border_height).mV);
gGL.texCoord2f(1.f, 1.f - border_scale.mV[VY]);
gGL.vertex3fv((width_vec + height_vec - top_border_height).mV);
gGL.texCoord2f(1.f, 1.f);
gGL.vertex3fv((width_vec + height_vec).mV);
gGL.texCoord2f(1.f - border_scale.mV[VX], 1.f);
gGL.vertex3fv((width_vec - right_border_width + height_vec).mV);
}
gGL.end();
}
void gl_segmented_rect_3d_tex_top(const LLVector2& border_scale, const LLVector3& border_width, const LLVector3& border_height, const LLVector3& width_vec, const LLVector3& height_vec)
{
gl_segmented_rect_3d_tex(border_scale, border_width, border_height, width_vec, height_vec, ROUNDED_RECT_TOP);
}
void LLUI::initClass(const settings_map_t& settings,
LLImageProviderInterface* image_provider,
LLUIAudioCallback audio_callback,
const LLVector2* scale_factor,
const std::string& language)
{
sSettingGroups = settings;
if ((get_ptr_in_map(sSettingGroups, std::string("config")) == NULL) ||
(get_ptr_in_map(sSettingGroups, std::string("floater")) == NULL) ||
(get_ptr_in_map(sSettingGroups, std::string("ignores")) == NULL))
{
llerrs << "Failure to initialize configuration groups" << llendl;
}
sImageProvider = image_provider;
sAudioCallback = audio_callback;
sGLScaleFactor = (scale_factor == NULL) ? LLVector2(1.f, 1.f) : *scale_factor;
sWindow = NULL; // set later in startup
LLFontGL::sShadowColor = LLUIColorTable::instance().getColor("ColorDropShadow");
// Callbacks for associating controls with floater visibilty:
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.Toggle", boost::bind(&LLFloaterReg::toggleFloaterInstance, _2));
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.Show", boost::bind(&LLFloaterReg::showFloaterInstance, _2));
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.Hide", boost::bind(&LLFloaterReg::hideFloaterInstance, _2));
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Floater.InitToVisibilityControl", boost::bind(&LLFloaterReg::initUICtrlToFloaterVisibilityControl, _1, _2));
// Button initialization callback for toggle buttons
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Button.SetFloaterToggle", boost::bind(&LLButton::setFloaterToggle, _1, _2));
// Button initialization callback for toggle buttons on dockale floaters
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Button.SetDockableFloaterToggle", boost::bind(&LLButton::setDockableFloaterToggle, _1, _2));
// Display the help topic for the current context
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Button.ShowHelp", boost::bind(&LLButton::showHelp, _1, _2));
// Currently unused, but kept for reference:
LLUICtrl::CommitCallbackRegistry::defaultRegistrar().add("Button.ToggleFloater", boost::bind(&LLButton::toggleFloaterAndSetToggleState, _1, _2));
// Used by menus along with Floater.Toggle to display visibility as a checkmark
LLUICtrl::EnableCallbackRegistry::defaultRegistrar().add("Floater.Visible", boost::bind(&LLFloaterReg::floaterInstanceVisible, _2));
}
void LLUI::cleanupClass()
{
sImageProvider->cleanUp();
}
void LLUI::setPopupFuncs(const add_popup_t& add_popup, const remove_popup_t& remove_popup, const clear_popups_t& clear_popups)
{
sAddPopupFunc = add_popup;
sRemovePopupFunc = remove_popup;
sClearPopupsFunc = clear_popups;
}
//static
void LLUI::dirtyRect(LLRect rect)
{
if (!sDirty)
{
sDirtyRect = rect;
sDirty = TRUE;
}
else
{
sDirtyRect.unionWith(rect);
}
}
//static
void LLUI::translate(F32 x, F32 y, F32 z)
{
gGL.translateUI(x,y,z);
LLFontGL::sCurOrigin.mX += (S32) x;
LLFontGL::sCurOrigin.mY += (S32) y;
LLFontGL::sCurOrigin.mZ += z;
}
//static
void LLUI::pushMatrix()
{
gGL.pushUIMatrix();
LLFontGL::sOriginStack.push_back(LLFontGL::sCurOrigin);
}
//static
void LLUI::popMatrix()
{
gGL.popUIMatrix();
LLFontGL::sCurOrigin = *LLFontGL::sOriginStack.rbegin();
LLFontGL::sOriginStack.pop_back();
}
//static
void LLUI::loadIdentity()
{
gGL.loadUIIdentity();
LLFontGL::sCurOrigin.mX = 0;
LLFontGL::sCurOrigin.mY = 0;
LLFontGL::sCurOrigin.mZ = 0;
}
//static
void LLUI::setScaleFactor(const LLVector2 &scale_factor)
{
sGLScaleFactor = scale_factor;
}
//static
void LLUI::setLineWidth(F32 width)
{
gGL.flush();
glLineWidth(width * lerp(sGLScaleFactor.mV[VX], sGLScaleFactor.mV[VY], 0.5f));
}
//static
void LLUI::setMousePositionScreen(S32 x, S32 y)
{
S32 screen_x, screen_y;
screen_x = llround((F32)x * sGLScaleFactor.mV[VX]);
screen_y = llround((F32)y * sGLScaleFactor.mV[VY]);
LLCoordWindow window_point;
LLView::getWindow()->convertCoords(LLCoordGL(screen_x, screen_y), &window_point);
LLView::getWindow()->setCursorPosition(window_point);
}
//static
void LLUI::getMousePositionScreen(S32 *x, S32 *y)
{
LLCoordWindow cursor_pos_window;
getWindow()->getCursorPosition(&cursor_pos_window);
LLCoordGL cursor_pos_gl;
getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl);
*x = llround((F32)cursor_pos_gl.mX / sGLScaleFactor.mV[VX]);
*y = llround((F32)cursor_pos_gl.mY / sGLScaleFactor.mV[VX]);
}
//static
void LLUI::setMousePositionLocal(const LLView* viewp, S32 x, S32 y)
{
S32 screen_x, screen_y;
viewp->localPointToScreen(x, y, &screen_x, &screen_y);
setMousePositionScreen(screen_x, screen_y);
}
//static
void LLUI::getMousePositionLocal(const LLView* viewp, S32 *x, S32 *y)
{
S32 screen_x, screen_y;
getMousePositionScreen(&screen_x, &screen_y);
viewp->screenPointToLocal(screen_x, screen_y, x, y);
}
// On Windows, the user typically sets the language when they install the
// app (by running it with a shortcut that sets InstallLanguage). On Mac,
// or on Windows if the SecondLife.exe executable is run directly, the
// language follows the OS language. In all cases the user can override
// the language manually in preferences. JC
// static
std::string LLUI::getLanguage()
{
std::string language = "en";
if (sSettingGroups["config"])
{
language = sSettingGroups["config"]->getString("Language");
if (language.empty() || language == "default")
{
language = sSettingGroups["config"]->getString("InstallLanguage");
}
if (language.empty() || language == "default")
{
language = sSettingGroups["config"]->getString("SystemLanguage");
}
if (language.empty() || language == "default")
{
language = "en";
}
}
return language;
}
//static
void LLUI::setupPaths()
{
std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_SKINS, "paths.xml");
LLXMLNodePtr root;
BOOL success = LLXMLNode::parseFile(filename, root, NULL);
sXUIPaths.clear();
if (success)
{
LLStringUtil::format_map_t path_args;
path_args["[LANGUAGE]"] = LLUI::getLanguage();
for (LLXMLNodePtr path = root->getFirstChild(); path.notNull(); path = path->getNextSibling())
{
std::string path_val_ui(path->getValue());
LLStringUtil::format(path_val_ui, path_args);
if (std::find(sXUIPaths.begin(), sXUIPaths.end(), path_val_ui) == sXUIPaths.end())
{
sXUIPaths.push_back(path_val_ui);
}
}
}
else // parsing failed
{
std::string slash = gDirUtilp->getDirDelimiter();
std::string dir = "xui" + slash + "en";
llwarns << "XUI::config file unable to open: " << filename << llendl;
sXUIPaths.push_back(dir);
}
}
//static
std::string LLUI::locateSkin(const std::string& filename)
{
std::string slash = gDirUtilp->getDirDelimiter();
std::string found_file = filename;
if (!gDirUtilp->fileExists(found_file))
{
found_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, filename); // Should be CUSTOM_SKINS?
}
if (sSettingGroups["config"] && sSettingGroups["config"]->controlExists("Language"))
{
if (!gDirUtilp->fileExists(found_file))
{
std::string localization = getLanguage();
std::string local_skin = "xui" + slash + localization + slash + filename;
found_file = gDirUtilp->findSkinnedFilename(local_skin);
}
}
if (!gDirUtilp->fileExists(found_file))
{
std::string local_skin = "xui" + slash + "en" + slash + filename;
found_file = gDirUtilp->findSkinnedFilename(local_skin);
}
if (!gDirUtilp->fileExists(found_file))
{
found_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, filename);
}
return found_file;
}
//static
LLVector2 LLUI::getWindowSize()
{
LLCoordWindow window_rect;
sWindow->getSize(&window_rect);
return LLVector2(window_rect.mX / sGLScaleFactor.mV[VX], window_rect.mY / sGLScaleFactor.mV[VY]);
}
//static
void LLUI::screenPointToGL(S32 screen_x, S32 screen_y, S32 *gl_x, S32 *gl_y)
{
*gl_x = llround((F32)screen_x * sGLScaleFactor.mV[VX]);
*gl_y = llround((F32)screen_y * sGLScaleFactor.mV[VY]);
}
//static
void LLUI::glPointToScreen(S32 gl_x, S32 gl_y, S32 *screen_x, S32 *screen_y)
{
*screen_x = llround((F32)gl_x / sGLScaleFactor.mV[VX]);
*screen_y = llround((F32)gl_y / sGLScaleFactor.mV[VY]);
}
//static
void LLUI::screenRectToGL(const LLRect& screen, LLRect *gl)
{
screenPointToGL(screen.mLeft, screen.mTop, &gl->mLeft, &gl->mTop);
screenPointToGL(screen.mRight, screen.mBottom, &gl->mRight, &gl->mBottom);
}
//static
void LLUI::glRectToScreen(const LLRect& gl, LLRect *screen)
{
glPointToScreen(gl.mLeft, gl.mTop, &screen->mLeft, &screen->mTop);
glPointToScreen(gl.mRight, gl.mBottom, &screen->mRight, &screen->mBottom);
}
//static
LLPointer<LLUIImage> LLUI::getUIImageByID(const LLUUID& image_id, S32 priority)
{
if (sImageProvider)
{
return sImageProvider->getUIImageByID(image_id, priority);
}
else
{
return NULL;
}
}
//static
LLPointer<LLUIImage> LLUI::getUIImage(const std::string& name, S32 priority)
{
if (!name.empty() && sImageProvider)
return sImageProvider->getUIImage(name, priority);
else
return NULL;
}
LLControlGroup& LLUI::getControlControlGroup (const std::string& controlname)
{
for (settings_map_t::iterator itor = sSettingGroups.begin();
itor != sSettingGroups.end(); ++itor)
{
LLControlGroup* control_group = itor->second;
if(control_group != NULL)
{
if (control_group->controlExists(controlname))
return *control_group;
}
}
return *sSettingGroups["config"]; // default group
}
//static
void LLUI::addPopup(LLView* viewp)
{
if (sAddPopupFunc)
{
sAddPopupFunc(viewp);
}
}
//static
void LLUI::removePopup(LLView* viewp)
{
if (sRemovePopupFunc)
{
sRemovePopupFunc(viewp);
}
}
//static
// spawn_x and spawn_y are top left corner of view in screen GL coordinates
void LLUI::positionViewNearMouse(LLView* view, S32 spawn_x, S32 spawn_y)
{
const S32 CURSOR_HEIGHT = 16; // Approximate "normal" cursor size
const S32 CURSOR_WIDTH = 8;
LLView* parent = view->getParent();
S32 mouse_x;
S32 mouse_y;
LLUI::getMousePositionScreen(&mouse_x, &mouse_y);
// If no spawn location provided, use mouse position
if (spawn_x == S32_MAX || spawn_y == S32_MAX)
{
spawn_x = mouse_x + CURSOR_WIDTH;
spawn_y = mouse_y - CURSOR_HEIGHT;
}
LLRect virtual_window_rect = parent->getLocalRect();
LLRect mouse_rect;
const S32 MOUSE_CURSOR_PADDING = 1;
mouse_rect.setLeftTopAndSize(mouse_x - MOUSE_CURSOR_PADDING,
mouse_y + MOUSE_CURSOR_PADDING,
CURSOR_WIDTH + MOUSE_CURSOR_PADDING * 2,
CURSOR_HEIGHT + MOUSE_CURSOR_PADDING * 2);
S32 local_x, local_y;
// convert screen coordinates to tooltipview-local coordinates
parent->screenPointToLocal(spawn_x, spawn_y, &local_x, &local_y);
// Start at spawn position (using left/top)
view->setOrigin( local_x, local_y - view->getRect().getHeight());
// Make sure we're onscreen and not overlapping the mouse
view->translateIntoRectWithExclusion( virtual_window_rect, mouse_rect, FALSE );
}
// LLLocalClipRect and LLScreenClipRect moved to lllocalcliprect.h/cpp
namespace LLInitParam
{
TypedParam<LLUIColor >::TypedParam(BlockDescriptor& descriptor, const char* name, const LLUIColor& value, ParamDescriptor::validation_func_t func, S32 min_count, S32 max_count)
: super_t(descriptor, name, value, func, min_count, max_count),
red("red"),
green("green"),
blue("blue"),
alpha("alpha"),
control("")
{
setBlockFromValue();
}
void TypedParam<LLUIColor>::setValueFromBlock() const
{
if (control.isProvided())
{
mData.mValue = LLUIColorTable::instance().getColor(control);
}
else
{
mData.mValue = LLColor4(red, green, blue, alpha);
}
}
void TypedParam<LLUIColor>::setBlockFromValue()
{
LLColor4 color = mData.mValue.get();
red.set(color.mV[VRED], false);
green.set(color.mV[VGREEN], false);
blue.set(color.mV[VBLUE], false);
alpha.set(color.mV[VALPHA], false);
control.set("", false);
}
void TypeValues<LLUIColor>::declareValues()
{
declare("white", LLColor4::white);
declare("black", LLColor4::black);
declare("red", LLColor4::red);
declare("green", LLColor4::green);
declare("blue", LLColor4::blue);
}
bool ParamCompare<const LLFontGL*, false>::equals(const LLFontGL* a, const LLFontGL* b)
{
return !(a->getFontDesc() < b->getFontDesc())
&& !(b->getFontDesc() < a->getFontDesc());
}
TypedParam<const LLFontGL*>::TypedParam(BlockDescriptor& descriptor, const char* _name, const LLFontGL*const value, ParamDescriptor::validation_func_t func, S32 min_count, S32 max_count)
: super_t(descriptor, _name, value, func, min_count, max_count),
name("name"),
size("size"),
style("style")
{
setBlockFromValue();
addSynonym(name, "");
setBlockFromValue();
}
void TypedParam<const LLFontGL*>::setValueFromBlock() const
{
const LLFontGL* res_fontp = LLFontGL::getFontByName(name);
if (res_fontp)
{
mData.mValue = res_fontp;
return;
}
U8 fontstyle = 0;
fontstyle = LLFontGL::getStyleFromString(style());
LLFontDescriptor desc(name(), size(), fontstyle);
const LLFontGL* fontp = LLFontGL::getFont(desc);
if (fontp)
{
mData.mValue = fontp;
}
}
void TypedParam<const LLFontGL*>::setBlockFromValue()
{
if (mData.mValue)
{
name.set(LLFontGL::nameFromFont(mData.mValue), false);
size.set(LLFontGL::sizeFromFont(mData.mValue), false);
style.set(LLFontGL::getStringFromStyle(mData.mValue->getFontDesc().getStyle()), false);
}
}
TypedParam<LLRect>::TypedParam(BlockDescriptor& descriptor, const char* name, const LLRect& value, ParamDescriptor::validation_func_t func, S32 min_count, S32 max_count)
: super_t(descriptor, name, value, func, min_count, max_count),
left("left"),
top("top"),
right("right"),
bottom("bottom"),
width("width"),
height("height")
{
setBlockFromValue();
}
void TypedParam<LLRect>::setValueFromBlock() const
{
LLRect rect;
//calculate from params
// prefer explicit left and right
if (left.isProvided() && right.isProvided())
{
rect.mLeft = left;
rect.mRight = right;
}
// otherwise use width along with specified side, if any
else if (width.isProvided())
{
// only right + width provided
if (right.isProvided())
{
rect.mRight = right;
rect.mLeft = right - width;
}
else // left + width, or just width
{
rect.mLeft = left;
rect.mRight = left + width;
}
}
// just left, just right, or none
else
{
rect.mLeft = left;
rect.mRight = right;
}
// prefer explicit bottom and top
if (bottom.isProvided() && top.isProvided())
{
rect.mBottom = bottom;
rect.mTop = top;
}
// otherwise height along with specified side, if any
else if (height.isProvided())
{
// top + height provided
if (top.isProvided())
{
rect.mTop = top;
rect.mBottom = top - height;
}
// bottom + height or just height
else
{
rect.mBottom = bottom;
rect.mTop = bottom + height;
}
}
// just bottom, just top, or none
else
{
rect.mBottom = bottom;
rect.mTop = top;
}
mData.mValue = rect;
}
void TypedParam<LLRect>::setBlockFromValue()
{
// because of the ambiguity in specifying a rect by position and/or dimensions
// we clear the "provided" flag so that values from xui/etc have priority
// over those calculated from the rect object
left.set(mData.mValue.mLeft, false);
right.set(mData.mValue.mRight, false);
bottom.set(mData.mValue.mBottom, false);
top.set(mData.mValue.mTop, false);
width.set(mData.mValue.getWidth(), false);
height.set(mData.mValue.getHeight(), false);
}
TypedParam<LLCoordGL>::TypedParam(BlockDescriptor& descriptor, const char* name, LLCoordGL value, ParamDescriptor::validation_func_t func, S32 min_count, S32 max_count)
: super_t(descriptor, name, value, func, min_count, max_count),
x("x"),
y("y")
{
setBlockFromValue();
}
void TypedParam<LLCoordGL>::setValueFromBlock() const
{
mData.mValue.set(x, y);
}
void TypedParam<LLCoordGL>::setBlockFromValue()
{
x.set(mData.mValue.mX, false);
y.set(mData.mValue.mY, false);
}
void TypeValues<LLFontGL::HAlign>::declareValues()
{
declare("left", LLFontGL::LEFT);
declare("right", LLFontGL::RIGHT);
declare("center", LLFontGL::HCENTER);
}
void TypeValues<LLFontGL::VAlign>::declareValues()
{
declare("top", LLFontGL::TOP);
declare("center", LLFontGL::VCENTER);
declare("baseline", LLFontGL::BASELINE);
declare("bottom", LLFontGL::BOTTOM);
}
void TypeValues<LLFontGL::ShadowType>::declareValues()
{
declare("none", LLFontGL::NO_SHADOW);
declare("hard", LLFontGL::DROP_SHADOW);
declare("soft", LLFontGL::DROP_SHADOW_SOFT);
}
}
|