aboutsummaryrefslogtreecommitdiffstats
path: root/src/graphui/classes/com/jogamp/graph/ui/Shape.java
blob: 1811d2f6197679c7b6ec9fa372c7e5e8cce0969c (plain)
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
/**
 * Copyright 2010-2024 JogAmp Community. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are those of the
 * authors and should not be interpreted as representing official policies, either expressed
 * or implied, of JogAmp Community.
 */
package com.jogamp.graph.ui;

import java.util.ArrayList;
import java.util.Comparator;

import com.jogamp.nativewindow.NativeWindowException;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.ui.layout.Padding;
import com.jogamp.math.FloatUtil;
import com.jogamp.math.Matrix4f;
import com.jogamp.math.Quaternion;
import com.jogamp.math.Recti;
import com.jogamp.math.Vec2f;
import com.jogamp.math.Vec3f;
import com.jogamp.math.Vec4f;
import com.jogamp.math.geom.AABBox;
import com.jogamp.math.util.PMVMatrix4f;
import com.jogamp.newt.event.GestureHandler.GestureEvent;
import com.jogamp.newt.event.GestureHandler.GestureListener;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.KeyListener;
import com.jogamp.newt.event.MouseAdapter;
import com.jogamp.newt.event.NEWTEvent;
import com.jogamp.newt.event.PinchToZoomGesture;
import com.jogamp.newt.event.MouseEvent;
import com.jogamp.newt.event.MouseListener;

/**
 * Generic Shape, potentially using a Graph via {@link GraphShape} or other means of representing content.
 * <p>
 * A shape includes the following build-in user-interactions
 * - drag shape w/ 1-pointer click, see {@link #setDraggable(boolean)}
 * - resize shape w/ 1-pointer click and drag in 1/4th bottom-left and bottom-right corner, see {@link #setResizable(boolean)}.
 * </p>
 * <p>
 * A shape is expected to have its 0/0 origin in its bottom-left corner, otherwise the drag-zoom sticky-edge will not work as expected.
 * </p>
 * <p>
 * A shape's {@link #getBounds()} includes its optional {@link #getPadding()} and optional {@link #getBorderThickness()}.
 * </p>
 * <p>
 * GraphUI is GPU based and resolution independent.
 * </p>
 * <p>
 * GraphUI is intended to become an immediate- and retained-mode API.
 * </p>
 * <p>
 * Default colors (toggle-off is full color):
 * - non-toggle: 0.6 * color, static -> 0.6
 * - pressed: 0.8 * color, static -> 0.5
 * - toggle-off: 1.0 * color, static -> 0.6
 * - toggle-on: 0.8 * color
 * </p>
 * @see Scene
 */
public abstract class Shape {
    /**
     * General {@link Shape} visitor
     */
    public static interface Visitor1 {
        /**
         * Visitor method
         * @param s the {@link Shape} to process
         * @return true to signal operation complete and to stop traversal, otherwise false
         */
        boolean visit(Shape s);
    }

    /**
     * General {@link Shape} visitor
     */
    public static interface Visitor2 {
        /**
         * Visitor method
         * @param s the {@link Shape} to process
         * @param pmv the {@link PMVMatrix4f} setup from the {@link Scene} down to the {@link Shape}
         * @return true to signal operation complete and to stop traversal, otherwise false
         */
        boolean visit(Shape s, final PMVMatrix4f pmv);
    }

    /**
     * {@link Shape} move listener
     */
    public static interface MoveListener {
        /**
         * Move callback
         * @param s the moved shape
         * @param origin original position
         * @param dest new position
         */
        void run(Shape s, Vec3f origin, Vec3f dest);
    }

    /**
     * General {@link Shape} listener action
     */
    public static interface Listener {
        void run(final Shape shape);
    }
    /**
     * {@link Shape} listener action returning a boolean value
     */
    public static interface ListenerBool {
        boolean run(final Shape shape);
    }

    /**
     * Forward {@link KeyListener}, to be attached to a key event source forwarded to the receiver set at constructor.
     * <p>
     * This given receiver {@link Shape} must be {@link #setInteractive(boolean)} to have the events forwarded.
     * </p>
     * @see Shape#receiveKeyEvents(Shape)
     */
    public static class ForwardKeyListener implements KeyListener {
        public final Shape receiver;
        /**
         * {@link ForwardKeyListener} Constructor
         * @param receiver the {@link KeyListener} receiver
         */
        public ForwardKeyListener(final Shape receiver) {
            this.receiver = receiver;
        }

        private void dispatch(final KeyEvent e) {
            if( receiver.isInteractive() ) {
                receiver.dispatchKeyEvent(e);
            }
        }
        @Override
        public void keyPressed(final KeyEvent e) { dispatch(e); }
        @Override
        public void keyReleased(final KeyEvent e) { dispatch(e); }
    }

    /**
     * Forward {@link MouseGestureListener}, to be attached to a mouse event source forwarded to the receiver set at constructor.
     * <p>
     * This given receiver {@link Shape} must be {@link #setInteractive(boolean)} to have the events forwarded.
     * </p>
     * @see Shape#receiveMouseEvents(Shape)
     */
    public static class ForwardMouseListener implements MouseGestureListener {
        public final Shape receiver;
        /**
         * {@link ForwardMouseListener} Constructor
         * @param receiver the {@link MouseGestureListener} receiver
         */
        public ForwardMouseListener(final Shape receiver) {
            this.receiver = receiver;
        }
        private void dispatch(final MouseEvent e) {
            if( receiver.isInteractive() ) {
                receiver.dispatchMouseEvent(e);
            }
        }
        @Override
        public void mouseClicked(final MouseEvent e) { dispatch(e); }
        @Override
        public void mouseEntered(final MouseEvent e) { dispatch(e); }
        @Override
        public void mouseExited(final MouseEvent e) { dispatch(e); }
        @Override
        public void mousePressed(final MouseEvent e) { dispatch(e); }
        @Override
        public void mouseReleased(final MouseEvent e) { dispatch(e); }
        @Override
        public void mouseMoved(final MouseEvent e) { dispatch(e); }
        @Override
        public void mouseDragged(final MouseEvent e) { dispatch(e); }
        @Override
        public void mouseWheelMoved(final MouseEvent e) { dispatch(e); }
        @Override
        public void gestureDetected(final GestureEvent e) {
            if( receiver.isInteractive() ) {
                receiver.dispatchGestureEvent(e);
            }
        }
    };

    protected static final boolean DEBUG_DRAW = false;
    private static final boolean DEBUG = false;

    private static final int DIRTY_SHAPE    = 1 << 0 ;
    private static final int DIRTY_STATE    = 1 << 1 ;

    private volatile Group parent = null;
    protected final AABBox box = new AABBox();

    private final Vec3f position = new Vec3f();
    private float zOffset = 0;
    private final Quaternion rotation = new Quaternion();
    private Vec3f rotPivot = null;
    private final Vec3f scale = new Vec3f(1f, 1f, 1f);
    private final Matrix4f iMat = new Matrix4f();
    private final Matrix4f tmpMat = new Matrix4f();
    private boolean iMatIdent = true;

    private volatile int dirty = DIRTY_SHAPE | DIRTY_STATE;
    private final Object dirtySync = new Object();

    /** Default base-color w/o color channel, will be modulated w/ pressed- and toggle color */
    protected final Vec4f rgbaColor             = new Vec4f(0.60f, 0.60f, 0.60f, 1.0f);
    /** Default pressed color-factor (darker and slightly transparent), modulated base-color. ~0.65 (due to alpha) */
    protected final Vec4f pressedRGBAModulate   = new Vec4f(0.70f, 0.70f, 0.70f, 0.8f);
    /** Default toggle color-factor (darkest), modulated base-color.  0.60 * 0.83 ~= 0.50 */
    protected final Vec4f toggleOnRGBAModulate  = new Vec4f(0.83f, 0.83f, 0.83f, 1.0f);
    /** Default toggle color-factor, modulated base-color.  0.60 * 1.00 ~= 0.60 */
    protected final Vec4f toggleOffRGBAModulate = new Vec4f(1.00f, 1.00f, 1.00f, 1.0f);

    private final Vec4f rgba_tmp = new Vec4f(0, 0, 0, 1);
    private final Vec4f cWhite = new Vec4f(1, 1, 1, 1);

    private int id = -1;
    private String name = "noname";

    private static final int IO_VISIBLE            = 1 << 0;
    private static final int IO_INTERACTIVE        = 1 << 1;
    private static final int IO_ACTIVABLE          = 1 << 2;
    private static final int IO_TOGGLEABLE         = 1 << 3;
    private static final int IO_DRAGGABLE          = 1 << 4;
    private static final int IO_RESIZABLE          = 1 << 5;
    private static final int IO_RESIZE_FIXED_RATIO = 1 << 6;
    private static final int IO_ACTIVE             = 1 << 7;
    private static final int IO_DOWN               = 1 << 8;
    private static final int IO_TOGGLE             = 1 << 9;
    private static final int IO_DRAG_FIRST         = 1 << 10;
    private static final int IO_IN_MOVE            = 1 << 11;
    private static final int IO_IN_RESIZE_BR       = 1 << 12;
    private static final int IO_IN_RESIZE_BL       = 1 << 13;
    private volatile int ioState = IO_DRAGGABLE | IO_RESIZABLE | IO_INTERACTIVE | IO_ACTIVABLE | IO_VISIBLE;
    private final boolean isIO(final int mask) { return mask == ( ioState & mask ); }
    private final Shape setIO(final int mask, final boolean v) { if( v ) { ioState |= mask; } else { ioState &= ~mask; } return this; }

    private float borderThickness = 0f;
    private Padding padding = null;
    private final Vec4f borderColor = new Vec4f(0.0f, 0.0f, 0.0f, 1.0f);
    private ArrayList<MouseGestureListener> mouseListeners = new ArrayList<MouseGestureListener>();
    private ArrayList<KeyListener> keyListeners = new ArrayList<KeyListener>();

    private ListenerBool onInitListener = null;
    private MoveListener onMoveListener = null;
    private Listener onToggleListener = null;
    private ArrayList<Listener> activationListeners = new ArrayList<Listener>();
    private Listener onClickedListener = null;

    private final Vec2f objDraggedFirst = new Vec2f(); // b/c its relative to Shape and we stick to it
    private final int[] winDraggedLast = { 0, 0 }; // b/c its absolute window pos
    private static final float resize_sxy_min = 1f/200f; // 1/2% - TODO: Maybe customizable?
    private static final float resize_section = 1f/5f; // resize action in a corner

    private volatile Tooltip tooltip = null;

    /**
     * Create a generic UI {@link Shape}
     */
    protected Shape() { }

    protected void setParent(final Group c) { parent = c; }

    /**
     * Returns the last parent container {@link Group} this shape has been added to or {@code null}.
     * <p>
     * Since a shape can be added to multiple container (DAG),
     * usability of this information depends on usage.
     * </p>
     */
    public Group getParent() { return parent; }

    /** Set a symbolic ID for this shape for identification. Default is -1 for noname. */
    public final Shape setID(final int id) { this.id = id; return this; }
    /** Return the optional symbolic ID for this shape. */
    public final int getID() { return this.id; }

    /** Set a symbolic name for this shape for identification. Default is `noname`. */
    public Shape setName(final String name) { this.name = name; return this; }
    /** Return the optional symbolic name for this shape, defaults to `noname`. */
    public final String getName() { return this.name; }

    /** Returns true if this shape denotes a {@link Group}, otherwise false. */
    public boolean isGroup() { return false; }

    /** Returns true if this shape is visible, otherwise false. */
    public final boolean isVisible() { return isIO(IO_VISIBLE); }
    /**
     * Enable or disable this shape's visibility.
     * <p>
     * Note that invisible shapes are still considered for picking/activation.
     * To completely mute the shape, issue {@link #setInteractive(boolean)} as well.
     * </p>
     */
    public final Shape setVisible(final boolean v) { return setIO(IO_VISIBLE, v); }

    /**
     * Sets the padding for this shape, which is included in {@link #getBounds()B} and also includes the border. Default is zero.
     *
     * Method issues {@link #markShapeDirty()}.
     *
     * @param padding distance of shape to the border, i.e. padding
     * @return this shape for chaining
     * @see #getPadding()
     * @see #hasPadding()
     */
    public final Shape setPaddding(final Padding padding) {
        this.padding = padding;
        markShapeDirty();
        return this;
    }

    /**
     * Returns {@link Padding} of this shape, which is included in {@link #getBounds()B} and also includes the border. Default is zero.
     * @see #setPaddding(Padding)
     * @see #hasPadding()
     */
    public Padding getPadding() { return padding; }

    /** Returns true if {@link #setPaddding(Padding)} added a non {@link Padding#zeroSize()} spacing to this shape. */
    public boolean hasPadding() { return null != padding && !padding.zeroSize(); }

    /**
     * Sets the thickness of the border, which is included in {@link #getBounds()} and is outside of {@link #getPadding()}. Default is zero for no border.
     *
     * Method issues {@link #markShapeDirty()}.
     *
     * @param thickness border thickness, zero for no border
     * @return this shape for chaining
     * @see #setBorderColor(Vec4f)
     */
    public final Shape setBorder(final float thickness) {
        borderThickness = Math.max(0f, thickness);
        markShapeDirty();
        return this;
    }
    /** Returns true if a border has been enabled via {@link #setBorder(float, Padding)}. */
    public final boolean hasBorder() { return !FloatUtil.isZero(borderThickness); }

    /** Returns the border thickness, see {@link #setBorder(float, Padding)}. */
    public final float getBorderThickness() { return borderThickness; }

    /** Perform given {@link Runnable} action synchronized */
    public final void runSynced(final Runnable action) {
        synchronized ( dirtySync ) {
            action.run();
        }
    }

    /**
     * Clears all data and reset all states as if this instance was newly created
     * @param gl current {@link GL2ES2} instance used to release GPU resources
     * @param renderer {@link RegionRenderer} used to release GPU resources
     */
    public final void clear(final GL2ES2 gl, final RegionRenderer renderer) {
        synchronized ( dirtySync ) {
            stopToolTip();
            clearImpl0(gl, renderer);
            resetState();
        }
    }
    private final void resetState() {
        position.set(0f, 0f, 0f);
        rotation.setIdentity();
        rotPivot = null;
        scale.set(1f, 1f, 1f);
        iMat.loadIdentity();
        iMatIdent = true;
        box.reset();
        mouseListeners.clear();
        keyListeners.clear();
        onInitListener = null;
        onMoveListener = null;
        onToggleListener = null;
        activationListeners.clear();
        onClickedListener = null;
        markShapeDirty();
    }

    /**
     * Destroys all data
     * @param gl current {@link GL2ES2} instance used to release GPU resources
     * @param renderer {@link RegionRenderer} used to release GPU resources
     */
    public final void destroy(final GL2ES2 gl, final RegionRenderer renderer) {
        removeToolTip();
        destroyImpl0(gl, renderer);
        resetState();
    }

    /**
     * Set a user one-shot initializer callback.
     * <p>
     * {@link ListenerBool#run(Shape)} will be called
     * after each {@link #draw(GL2ES2, RegionRenderer)}
     * until it returns true, signaling user initialization is completed.
     * </p>
     * @param l callback, which shall return true signaling user initialization is done
     */
    public final void onInit(final ListenerBool l) { onInitListener = l; }
    /**
     * Set user callback to be notified when shape is {@link #move(Vec3f)}'ed.
     */
    public final void onMove(final MoveListener l) { onMoveListener = l; }
    /**
     * Set user callback to be notified when shape {@link #toggle()}'ed.
     * <p>
     * This is usually the case when clicked, see {@link #onClicked(Listener)}.
     * </p>
     * <p>
     * Use {@link #isToggleOn()} to retrieve the state.
     * </p>
     */
    public final void onToggle(final Listener l) { onToggleListener = l; }

    /**
     * Add user callback to be notified when shape is activated (pointer-over and/or click) or de-activated (pointer left).
     * <p>
     * Use {@link #isActive()} to retrieve the state.
     * </p>
     */
    public final Shape addActivationListener(final Listener l) {
        if(l == null) {
            return this;
        }
        @SuppressWarnings("unchecked")
        final ArrayList<Listener> clonedListeners = (ArrayList<Listener>) activationListeners.clone();
        clonedListeners.add(l);
        activationListeners = clonedListeners;
        return this;
    }
    public final Shape removeActivationListener(final Listener l) {
        if (l == null) {
            return this;
        }
        @SuppressWarnings("unchecked")
        final ArrayList<Listener> clonedListeners = (ArrayList<Listener>) activationListeners.clone();
        clonedListeners.remove(l);
        activationListeners = clonedListeners;
        return this;
    }
    /**
     * Dispatch activation event event to this shape
     * @return true to signal operation complete and to stop traversal, otherwise false
     */
    private final void dispatchActivationEvent(final Shape s) {
        final int sz = activationListeners.size();
        for(int i = 0; i < sz; i++ ) {
            activationListeners.get(i).run(s);
        }
    }

    /**
     * Set user callback to be notified when shape is clicked.
     * <p>
     * Usually shape is {@link #toggle()}'ed when clicked, see {@link #onToggle(Listener)}.
     * However, in case shape is not {@link #isToggleable()} this is the last resort.
     * </p>
     */
    public final void onClicked(final Listener l) { onClickedListener = l; }

    /** Move to scaled position. Position ends up in PMVMatrix4f unmodified. No {@link MoveListener} notification will occur. */
    public final Shape moveTo(final float tx, final float ty, final float tz) {
        position.set(tx, ty, tz);
        updateMat();
        return this;
    }

    /** Move to scaled position. Position ends up in PMVMatrix4f unmodified. No {@link MoveListener} notification will occur. */
    public final Shape moveTo(final Vec3f t) {
        position.set(t);
        updateMat();
        return this;
    }

    /** Move about scaled distance. Position ends up in PMVMatrix4f unmodified. No {@link MoveListener} notification will occur. */
    public final Shape move(final float dtx, final float dty, final float dtz) {
        position.add(dtx, dty, dtz);
        updateMat();
        return this;
    }

    /** Move about scaled distance. Position ends up in PMVMatrix4f unmodified. No {@link MoveListener} notification will occur. */
    public final Shape move(final Vec3f dt) {
        position.add(dt);
        updateMat();
        return this;
    }

    private final Shape moveNotify(final float dtx, final float dty, final float dtz) {
        forwardMove(position.copy(), position.add(dtx, dty, dtz));
        return this;
    }

    private final void forwardMove(final Vec3f origin, final Vec3f dest) {
        if( !origin.isEqual(dest) ) {
            updateMat();
            if( null != onMoveListener ) {
                onMoveListener.run(this, origin, dest);
            }
        }
    }

    /**
     * Returns position {@link Vec3f} reference, i.e. scaled translation as set via {@link #moveTo(float, float, float) or {@link #move(float, float, float)}}.
     * @see #updateMat()
     */
    public final Vec3f getPosition() { return position; }

    /**
     * Returns {@link Quaternion} for rotation.
     * @see #updateMat()
     */
    public final Quaternion getRotation() { return rotation; }

    /**
     * Sets the rotation {@link Quaternion}.
     * @return this shape for chaining
     */
    public final Shape setRotation(final Quaternion q) {
        rotation.set(q);
        updateMat();
        return this;
    }

    /**
     * Return unscaled rotation origin {@link Vec3f} reference, aka pivot. Null if not set via {@link #setRotationPivot(float, float, float)}.
     * @see #updateMat()
     */
    public final Vec3f getRotationPivot() { return rotPivot; }

    /**
     * Set unscaled rotation origin, aka pivot. Usually the {@link #getBounds()} center and should be set while {@link #validateImpl(GL2ES2, GLProfile)}.
     * @return this shape for chaining
     */
    public final Shape setRotationPivot(final float px, final float py, final float pz) {
        rotPivot = new Vec3f(px, py, pz);
        updateMat();
        return this;
    }
    /**
     * Set unscaled rotation origin, aka pivot. Usually the {@link #getBounds()} center and should be set while {@link #validateImpl(GL2ES2, GLProfile)}.
     * @param pivot rotation origin
     * @return this shape for chaining
     */
    public final Shape setRotationPivot(final Vec3f pivot) {
        rotPivot = new Vec3f(pivot);
        updateMat();
        return this;
    }

    /**
     * Set scale factor to given scale.
     * @see #scale(Vec3f)
     * @see #getScale()
     */
    public final Shape setScale(final Vec3f s) {
        scale.set(s);
        updateMat();
        return this;
    }
    /**
     * Set scale factor to given scale.
     * @see #scale(float, float, float)
     * @see #getScale()
     */
    public final Shape setScale(final float sx, final float sy, final float sz) {
        scale.set(sx, sy, sz);
        updateMat();
        return this;
    }
    /**
     * Multiply current scale factor by given scale.
     * @see #setScale(Vec3f)
     * @see #getScale()
     */
    public final Shape scale(final Vec3f s) {
        scale.scale(s);
        updateMat();
        return this;
    }
    /**
     * Multiply current scale factor by given scale.
     * @see #setScale(float, float, float)
     * @see #getScale()
     */
    public final Shape scale(final float sx, final float sy, final float sz) {
        scale.scale(sx, sy, sz);
        updateMat();
        return this;
    }
    /**
     * Returns scale {@link Vec3f} reference.
     * @see #setScale(float, float, float)
     * @see #scale(float, float, float)
     * @see #updateMat()
     */
    public final Vec3f getScale() { return scale; }

    /**
     * Marks the shape dirty, causing next {@link #draw(GL2ES2, RegionRenderer) draw()}
     * to recreate the Graph shape and reset the region.
     */
    public final void markShapeDirty() {
        synchronized ( dirtySync ) {
            dirty |= DIRTY_SHAPE;
        }
    }

    /**
     * Marks the rendering state dirty, causing next {@link #draw(GL2ES2, RegionRenderer) draw()}
     * to notify the Graph region to reselect shader and repaint potentially used FBOs.
     */
    public final void markStateDirty() {
        synchronized ( dirtySync ) {
            dirty |= DIRTY_STATE;
        }
    }

    /** Returns the shape's dirty state, see {@link #markShapeDirty()}. */
    protected boolean isShapeDirty() {
        return 0 != ( dirty & DIRTY_SHAPE ) ;
    }
    /** Returns the rendering dirty state, see {@link #markStateDirty()}. */
    protected final boolean isStateDirty() {
        return 0 != ( dirty & DIRTY_STATE ) ;
    }

    protected final String getDirtyString() {
        if( isShapeDirty() && isShapeDirty() ) {
            return "dirty[shape, state]";
        } else if( isShapeDirty() ) {
            return "dirty[shape]";
        } else if( isStateDirty() ) {
            return "dirty[state]";
        } else {
            return "clean";
        }
    }

    /**
     * Returns the unscaled bounding {@link AABBox} for this shape, borrowing internal instance.
     *
     * The returned {@link AABBox} will cover the unscaled shape
     * as well as its optional {@link #getPadding()} and optional {@link #getBorderThickness()}.
     *
     * The returned {@link AABBox} is only valid after an initial call to {@link #draw(GL2ES2, RegionRenderer) draw(..)}
     * or {@link #validate(GL2ES2)}.
     *
     * @see #getBounds(GLProfile)
     */
    public final AABBox getBounds() { return box; }

    /**
     * Returns the scaled width of the bounding {@link AABBox} for this shape.
     *
     * The returned width will cover the scaled shape
     * as well as its optional scaled {@link #getPadding()} and optional scaled {@link #getBorderThickness()}.
     *
     * The returned width is only valid after an initial call to {@link #draw(GL2ES2, RegionRenderer) draw(..)}
     * or {@link #validate(GL2ES2)}.
     *
     * @see #getBounds()
     */
    public final float getScaledWidth() {
        return box.getWidth() * getScale().x();
    }

    /**
     * Returns the scaled height of the bounding {@link AABBox} for this shape.
     *
     * The returned height will cover the scaled shape
     * as well as its optional scaled {@link #getPadding()} and optional scaled {@link #getBorderThickness()}.
     *
     * The returned height is only valid after an initial call to {@link #draw(GL2ES2, RegionRenderer) draw(..)}
     * or {@link #validate(GL2ES2)}.
     *
     * @see #getBounds()
     */
    public final float getScaledHeight() {
        return box.getHeight() * getScale().y();
    }

    public final float getScaledDepth() {
        return box.getDepth() * getScale().z();
    }

    /**
     * Returns the unscaled bounding {@link AABBox} for this shape.
     *
     * This variant differs from {@link #getBounds()} as it
     * returns a valid {@link AABBox} even before {@link #draw(GL2ES2, RegionRenderer) draw(..)}
     * and having an OpenGL instance available.
     *
     * @see #getBounds()
     */
    public final AABBox getBounds(final GLProfile glp) {
        validate(glp);
        return box;
    }

    /** Experimental selection draw command used by {@link Scene}. */
    public void drawToSelect(final GL2ES2 gl, final RegionRenderer renderer) {
        synchronized ( dirtySync ) {
            validate(gl);
            drawToSelectImpl0(gl, renderer);
        }
    }

    /**
     * Renders the shape.
     * <p>
     * {@link #transformMvTo(PMVMatrix4f)} is expected to be completed beforehand.
     * </p>
     * @param gl the current GL object
     * @param renderer {@link RegionRenderer} which might be used for Graph Curve Rendering, also source of {@link RegionRenderer#getMatrix()} and {@link RegionRenderer#getViewport()}.
     */
    public void draw(final GL2ES2 gl, final RegionRenderer renderer) {
        final boolean isPressed = isPressed(), isToggleOn = isToggleOn();
        final Vec4f rgba;
        if( hasColorChannel() ) {
            if( isPressed ) {
                rgba = pressedRGBAModulate;
            } else if( isToggleable() ) {
                if( isToggleOn ) {
                    rgba = toggleOnRGBAModulate;
                } else {
                    rgba = toggleOffRGBAModulate;
                }
            } else {
                rgba = cWhite;
            }
        } else {
            rgba = rgba_tmp;
            if( isPressed ) {
                rgba.mul(rgbaColor, pressedRGBAModulate);
            } else if( isToggleable() ) {
                if( isToggleOn ) {
                    rgba.mul(rgbaColor, toggleOnRGBAModulate);
                } else {
                    rgba.mul(rgbaColor, toggleOffRGBAModulate);
                }
            } else {
                rgba.set(rgbaColor);
            }
        }
        synchronized ( dirtySync ) {
            validate(gl);
            drawImpl0(gl, renderer, rgba);
        }
        if( null != onInitListener ) {
            if( onInitListener.run(this) ) {
                onInitListener = null;
            }
        }
    }

    /**
     * Validates the shape's underlying {@link GLRegion}.
     * <p>
     * If the region is dirty, it gets {@link GLRegion#clear(GL2ES2) cleared} and is reused.
     * </p>
     * @param gl current {@link GL2ES2} object
     * @see #validate(GLProfile)
     */
    public final Shape validate(final GL2ES2 gl) {
        synchronized ( dirtySync ) {
            if( isShapeDirty() ) {
                box.reset();
            }
            validateImpl(gl, gl.getGLProfile());
            dirty = 0;
        }
        return this;
    }

    /**
     * Validates the shape's underlying {@link GLRegion} w/o a current {@link GL2ES2} object
     * <p>
     * If the region is dirty a new region is created
     * and the old one gets pushed to a dirty-list to get disposed when a GL context is available.
     * </p>
     * @see #validate(GL2ES2)
     */
    public final Shape validate(final GLProfile glp) {
        synchronized ( dirtySync ) {
            if( isShapeDirty() ) {
                box.reset();
            }
            validateImpl(null, glp);
            dirty = 0;
        }
        return this;
    }

    /**
     * Validate the shape via {@link #validate(GL2ES2)} if {@code gl} is not null,
     * otherwise uses {@link #validate(GLProfile)}.
     * @see #validate(GL2ES2)
     * @see #validate(GLProfile)
     */
    public final Shape validate(final GL2ES2 gl, final GLProfile glp) {
        if( null != gl ) {
            return validate(gl);
        } else {
            return validate(glp);
        }
    }

    /**
     * Applies the internal {@link Matrix4f} to the given {@link PMVMatrix4f#getMv() modelview matrix},
     * i.e. {@code pmv.mulMv( getMat() )}.
     * <p>
     * In case {@link #isMatIdentity()} is {@code true}, implementation is a no-operation.
     * </p>
     * @param pmv the matrix
     * @see #isMatIdentity()
     * @see #updateMat()
     * @see #getMat()
     * @see PMVMatrix4f#mulMv(Matrix4f)
     */
    public final void transformMvTo(final PMVMatrix4f pmv) {
        if( !iMatIdent ) {
            pmv.mulMv(iMat);
        }
    }

    /**
     * Returns the internal {@link Matrix4f} reference, see {@link #updateMat()}.
     * <p>
     * Using this method renders {@link #isMatIdentity()} {@code false},
     * since its content is mutable. Use {@link #getMat(Matrix4f) instead if suitable.
     * </p>
     * @see #getMat(Matrix4f)
     * @see #isMatIdentity()
     * @see #transformMvTo(PMVMatrix4f)
     * @see #updateMat()
     */
    public final Matrix4f getMat() { iMatIdent = false; return iMat; }

    /**
     * Returns a copy of the internal {@link Matrix4f} to {@code out} see {@link #updateMat()}.
     * @see #getMat()
     * @see #isMatIdentity()
     * @see #transformMvTo(PMVMatrix4f)
     * @see #updateMat()
     */
    public final Matrix4f getMat(final Matrix4f out) { out.load(iMat); return out; }

    /**
     * Returns true if {@link #getMat()} has not been mutated, i.e. contains identity.
     * @see #getMat()
     * @see #updateMat()
     */
    public final boolean isMatIdentity() { return iMatIdent; }

    /**
     * Updates the internal {@link Matrix4f} with local position, rotation and scale.
     * <ul>
     * <li>Scale shape from its center position</li>
     * <li>Rotate shape around optional scaled pivot, see {@link #setRotationPivot(float[])}), otherwise rotate around its scaled center (default)</li>
     * </ul>
     * <p>
     * Shape's origin should be bottom-left @ 0/0 to have build-in drag-zoom work properly.
     * </p>
     * <p>
     * Usually only used internally after modifying position, scale or rotation.
     * </p>
     * <p>
     * However, after modifying borrowed values via {@link #getPosition()}, {@link #getScale()}, {@link #getRotation()} or {@link #getRotationPivot()}
     * without any other change thereafter, e.g. {@link #move(Vec3f)}, this method must be called!
     * </p>
     * @see #isMatIdentity()
     * @see #getMat()
     * @see #getPosition()
     * @see #getScale()
     * @see #getRotation()
     * @see #getRotationPivot()
     * @see #transformMvTo(PMVMatrix4f)
     */
    public final void updateMat() {
        final boolean hasScale = !scale.isEqual(Vec3f.ONE);
        final boolean hasRotate = !rotation.isIdentity();
        final boolean hasRotPivot = null != rotPivot;
        final Vec3f ctr = box.getCenter();
        final boolean sameScaleRotatePivot = hasScale && hasRotate && ( !hasRotPivot || rotPivot.isEqual(ctr) );

        iMatIdent = false;

        iMat.setToTranslation(position); // identify + translate, scaled

        if( sameScaleRotatePivot ) {
            // Scale shape from its center position and rotate around its center
            iMat.translate(ctr.x()*scale.x(), ctr.y()*scale.y(), ctr.z()*scale.z(), tmpMat); // add-back center, scaled
            iMat.rotate(rotation, tmpMat);
            iMat.scale(scale.x(), scale.y(), scale.z(), tmpMat);
            iMat.translate(-ctr.x(), -ctr.y(), -ctr.z(), tmpMat); // move to center
        } else if( hasRotate || hasScale ) {
            if( hasRotate ) {
                if( hasRotPivot ) {
                    // Rotate shape around its scaled pivot
                    iMat.translate(rotPivot.x()*scale.x(), rotPivot.y()*scale.y(), rotPivot.z()*scale.z(), tmpMat); // pivot back from rot-pivot, scaled
                    iMat.rotate(rotation, tmpMat);
                    iMat.translate(-rotPivot.x()*scale.x(), -rotPivot.y()*scale.y(), -rotPivot.z()*scale.z(), tmpMat); // pivot to rot-pivot, scaled
                } else {
                    // Rotate shape around its scaled center
                    iMat.translate(ctr.x()*scale.x(), ctr.y()*scale.y(), ctr.z()*scale.z(), tmpMat); // pivot back from center-pivot, scaled
                    iMat.rotate(rotation, tmpMat);
                    iMat.translate(-ctr.x()*scale.x(), -ctr.y()*scale.y(), -ctr.z()*scale.z(), tmpMat); // pivot to center-pivot, scaled
                }
            }
            if( hasScale ) {
                // Scale shape from its center position
                iMat.translate(ctr.x()*scale.x(), ctr.y()*scale.y(), ctr.z()*scale.z(), tmpMat); // add-back center, scaled
                iMat.scale(scale.x(), scale.y(), scale.z(), tmpMat);
                iMat.translate(-ctr.x(), -ctr.y(), -ctr.z(), tmpMat); // move to center
            }
        }
    }

    /**
     * {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) Setup} the given {@link PMVMatrix4f}
     * and apply this shape's {@link #transformMvTo(PMVMatrix4f) transformation}.
     * </p>
     * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} given {@link PMVMatrix4f} {@code pmv}.
     * @param viewport used viewport for {@link PMVMatrix4f#mapObjToWin(Vec3f, Recti, Vec3f)}
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @return the given {@link PMVMatrix4f} for chaining
     * @see Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti)
     * @see #transformMvTo(PMVMatrix4f)
     * @see #setPMVMatrix(Scene, PMVMatrix4f)
     */
    public final PMVMatrix4f setPMVMatrix(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final PMVMatrix4f pmv) {
        pmvMatrixSetup.set(pmv, viewport);
        transformMvTo(pmv);
        return pmv;
    }

    /**
     * {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) Setup} the given {@link PMVMatrix4f}
     * and apply this shape's {@link #transformMvTo(PMVMatrix4f) transformation}.
     * </p>
     * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport.
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @return the given {@link PMVMatrix4f} for chaining
     * @see Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti)
     * @see #transformMvTo(PMVMatrix4f)
     * @see #setPMVMatrix(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix4f)
     */
    public final PMVMatrix4f setPMVMatrix(final Scene scene, final PMVMatrix4f pmv) {
        return setPMVMatrix(scene.getPMVMatrixSetup(), scene.getViewport(), pmv);
    }

    /**
     * Retrieve surface (view) port of this shape, i.e. lower x/y position and size.
     * <p>
     * The given {@link PMVMatrix4f} has to be setup properly for this object,
     * i.e. its {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} for the surrounding scene
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}. See {@link #setPMVMatrix(Scene, PMVMatrix4f)}.
     * </p>
     * @param pmv well formed {@link PMVMatrix4f}, e.g. could have been setup via {@link Shape#setPMVMatrix(Scene, PMVMatrix4f)}.
     * @param viewport the int[4] viewport
     * @param surfacePort Recti target surface port
     * @return given Recti {@code surfacePort} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     */
    public final Recti getSurfacePort(final PMVMatrix4f pmv, final Recti viewport, final Recti surfacePort) {
        final Vec3f winCoordHigh = new Vec3f();
        final Vec3f winCoordLow = new Vec3f();
        final Vec3f high = box.getHigh();
        final Vec3f low = box.getLow();

        final Matrix4f matPMv = pmv.getPMv();
        if( Matrix4f.mapObjToWin(high, matPMv, viewport, winCoordHigh) ) {
            if( Matrix4f.mapObjToWin(low, matPMv, viewport, winCoordLow) ) {
                surfacePort.setX( (int)Math.abs( winCoordLow.x() ) );
                surfacePort.setY( (int)Math.abs( winCoordLow.y() ) );
                surfacePort.setWidth( (int)Math.abs( winCoordHigh.x() - winCoordLow.x() ) );
                surfacePort.setHeight( (int)Math.abs( winCoordHigh.y() - winCoordLow.y() ) );
                return surfacePort;
            }
        }
        return null;
    }

    /**
     * Retrieve surface (view) size in pixels of this shape.
     * <p>
     * The given {@link PMVMatrix4f} has to be setup properly for this object,
     * i.e. its {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} for the surrounding scene
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}. See {@link #setPMVMatrix(Scene, PMVMatrix4f)}.
     * </p>
     * @param pmv well formed {@link PMVMatrix4f}, e.g. could have been setup via {@link Shape#setPMVMatrix(Scene, PMVMatrix4f)}.
     * @param viewport the int[4] viewport
     * @param surfaceSize int[2] target surface size
     * @return given int[2] {@code surfaceSize} in pixels for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix4f, int[])
     * @see #getSurfaceSize(Scene, PMVMatrix4f, int[])
     */
    public final int[/*2*/] getSurfaceSize(final PMVMatrix4f pmv, final Recti viewport, final int[/*2*/] surfaceSize) {
        // System.err.println("Shape::getSurfaceSize.VP "+viewport[0]+"/"+viewport[1]+" "+viewport[2]+"x"+viewport[3]);
        final Vec3f winCoordHigh = new Vec3f();
        final Vec3f winCoordLow = new Vec3f();
        final Vec3f high = box.getHigh();
        final Vec3f low = box.getLow();

        final Matrix4f matPMv = pmv.getPMv();
        if( Matrix4f.mapObjToWin(high, matPMv, viewport, winCoordHigh) ) {
            if( Matrix4f.mapObjToWin(low, matPMv, viewport, winCoordLow) ) {
                surfaceSize[0] = (int)Math.abs(winCoordHigh.x() - winCoordLow.x());
                surfaceSize[1] = (int)Math.abs(winCoordHigh.y() - winCoordLow.y());
                return surfaceSize;
            }
        }
        return null;
    }

    /**
     * Retrieve surface (view) size in pixels of this shape.
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} given {@link PMVMatrix4f} {@code pmv}.
     * @param viewport used viewport for {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)}
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param surfaceSize int[2] target surface size
     * @return given int[2] {@code surfaceSize} in pixels for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #getSurfaceSize(PMVMatrix4f, Recti, int[])
     * @see #getSurfaceSize(Scene, PMVMatrix4f, int[])
     */
    public final int[/*2*/] getSurfaceSize(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final PMVMatrix4f pmv, final int[/*2*/] surfaceSize) {
        return getSurfaceSize(setPMVMatrix(pmvMatrixSetup, viewport, pmv), viewport, surfaceSize);
    }

    /**
     * Retrieve surface (view) size in pixels of this shape.
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport.
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param surfaceSize int[2] target surface size
     * @return given int[2] {@code surfaceSize} in pixels for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #getSurfaceSize(PMVMatrix4f, Recti, int[])
     * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix4f, int[])
     */
    public final int[/*2*/] getSurfaceSize(final Scene scene, final PMVMatrix4f pmv, final int[/*2*/] surfaceSize) {
        return getSurfaceSize(scene.getPMVMatrixSetup(), scene.getViewport(), pmv, surfaceSize);
    }

    /**
     * Retrieve pixel per scaled shape-coordinate unit, i.e. [px]/[obj].
     * @param shapeSizePx int[2] shape size in pixel as retrieved via e.g. {@link #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix4f, int[])}
     * @param pixPerShape float[2] pixel scaled per shape-coordinate unit result storage
     * @return given float[2] {@code pixPerShape}
     * @see #getPixelPerShapeUnit(Scene, PMVMatrix4f, float[])
     * @see #getSurfaceSize(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, PMVMatrix4f, int[])
     * @see #getScaledWidth()
     * @see #getScaledHeight()
     */
    public final float[] getPixelPerShapeUnit(final int[] shapeSizePx, final float[] pixPerShape) {
        pixPerShape[0] = shapeSizePx[0] / getScaledWidth();
        pixPerShape[0] = shapeSizePx[1] / getScaledHeight();
        return pixPerShape;
    }

    /**
     * Retrieve pixel per scaled shape-coordinate unit, i.e. [px]/[obj].
     * <p>
     * The given {@link PMVMatrix4f} has to be setup properly for this object,
     * i.e. its {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} for the surrounding scene
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}. See {@link #setPMVMatrix(Scene, PMVMatrix4f)}.
     * </p>
     * @param pmv well formed {@link PMVMatrix4f}, e.g. could have been setup via {@link Shape#setPMVMatrix(Scene, PMVMatrix4f)}.
     * @param viewport the int[4] viewport
     * @param pixPerShape float[2] pixel per scaled shape-coordinate unit result storage
     * @return given float[2] {@code pixPerShape} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #getPixelPerShapeUnit(int[], float[])
     * @see #getSurfaceSize(Scene, PMVMatrix4f, int[])
     * @see #getScaledWidth()
     * @see #getScaledHeight()
     */
    public final float[] getPixelPerShapeUnit(final PMVMatrix4f pmv, final Recti viewport, final float[] pixPerShape) {
        final int[] shapeSizePx = new int[2];
        if( null != getSurfaceSize(pmv, viewport, shapeSizePx) ) {
            return getPixelPerShapeUnit(shapeSizePx, pixPerShape);
        } else {
            return null;
        }
    }

    /**
     * Retrieve pixel per scaled shape-coordinate unit, i.e. [px]/[obj].
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport.
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param pixPerShape float[2] pixel per scaled shape-coordinate unit result storage
     * @return given float[2] {@code pixPerShape} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #getPixelPerShapeUnit(int[], float[])
     * @see #getSurfaceSize(Scene, PMVMatrix4f, int[])
     * @see #getScaledWidth()
     * @see #getScaledHeight()
     */
    public final float[] getPixelPerShapeUnit(final Scene scene, final PMVMatrix4f pmv, final float[] pixPerShape) {
        final int[] shapeSizePx = new int[2];
        if( null != getSurfaceSize(scene, pmv, shapeSizePx) ) {
            return getPixelPerShapeUnit(shapeSizePx, pixPerShape);
        } else {
            return null;
        }
    }

    /**
     * Map given object coordinate relative to this shape to window coordinates.
     * <p>
     * The given {@link PMVMatrix4f} has to be setup properly for this object,
     * i.e. its {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} for the surrounding scene
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}. See {@link #setPMVMatrix(Scene, PMVMatrix4f)}.
     * </p>
     * @param pmv well formed {@link PMVMatrix4f}, e.g. could have been setup via {@link Shape#setPMVMatrix(Scene, PMVMatrix4f)}.
     * @param viewport the viewport
     * @param objPos object position relative to this shape's center
     * @param glWinPos int[2] target window position of objPos relative to this shape
     * @return given int[2] {@code glWinPos} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix4f, int[])
     * @see #shapeToWinCoord(Scene, float[], PMVMatrix4f, int[])
     */
    public final int[/*2*/] shapeToWinCoord(final PMVMatrix4f pmv, final Recti viewport, final Vec3f objPos, final int[/*2*/] glWinPos) {
        // System.err.println("Shape::objToWinCoordgetSurfaceSize.VP "+viewport[0]+"/"+viewport[1]+" "+viewport[2]+"x"+viewport[3]);
        final Vec3f winCoord = new Vec3f();

        if( pmv.mapObjToWin(objPos, viewport, winCoord) ) {
            glWinPos[0] = (int)(winCoord.x());
            glWinPos[1] = (int)(winCoord.y());
            return glWinPos;
        }
        return null;
    }

    /**
     * Map given object coordinate relative to this shape to window coordinates.
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} given {@link PMVMatrix4f} {@code pmv}.
     * @param viewport used viewport for {@link PMVMatrix4f#mapObjToWin(Vec3f, Recti, Vec3f)}
     * @param objPos object position relative to this shape's center
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param glWinPos int[2] target window position of objPos relative to this shape
     * @return given int[2] {@code glWinPos} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #shapeToWinCoord(PMVMatrix4f, Recti, float[], int[])
     * @see #shapeToWinCoord(Scene, float[], PMVMatrix4f, int[])
     */
    public final int[/*2*/] shapeToWinCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final Vec3f objPos, final PMVMatrix4f pmv, final int[/*2*/] glWinPos) {
        return this.shapeToWinCoord(setPMVMatrix(pmvMatrixSetup, viewport, pmv), viewport, objPos, glWinPos);
    }

    /**
     * Map given object coordinate relative to this shape to window coordinates.
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport.
     * @param objPos object position relative to this shape's center
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param glWinPos int[2] target window position of objPos relative to this shape
     * @return given int[2] {@code glWinPos} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)} operation, otherwise {@code null}
     * @see #shapeToWinCoord(PMVMatrix4f, Recti, float[], int[])
     * @see #shapeToWinCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, float[], PMVMatrix4f, int[])
     */
    public final int[/*2*/] shapeToWinCoord(final Scene scene, final Vec3f objPos, final PMVMatrix4f pmv, final int[/*2*/] glWinPos) {
        return this.shapeToWinCoord(scene.getPMVMatrixSetup(), scene.getViewport(), objPos, pmv, glWinPos);
    }

    /**
     * Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
     * <p>
     * The given {@link PMVMatrix4f} has to be setup properly for this object,
     * i.e. its {@link GLMatrixFunc#GL_PROJECTION} and {@link GLMatrixFunc#GL_MODELVIEW} for the surrounding scene
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}. See {@link #setPMVMatrix(Scene, PMVMatrix4f)}.
     * </p>
     * @param pmv well formed {@link PMVMatrix4f}, e.g. could have been setup via {@link Shape#setPMVMatrix(Scene, PMVMatrix4f)}.
     * @param viewport the Rect4i viewport
     * @param glWinX in GL window coordinates, origin bottom-left
     * @param glWinY in GL window coordinates, origin bottom-left
     * @param objPos target object position of glWinX/glWinY relative to this shape
     * @return given {@code objPos} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)}
     *         and {@link Matrix4f#mapWinToObj(float, float, float, float, Matrix4f, Recti, Vec3f, Vec3f) gluUnProject(..)}
     *         operation, otherwise {@code null}
     * @see #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix4f, float[])
     * @see #winToShapeCoord(Scene, int, int, PMVMatrix4f, float[])
     */
    public final Vec3f winToShapeCoord(final PMVMatrix4f pmv, final Recti viewport, final int glWinX, final int glWinY, final Vec3f objPos) {
        final Vec3f ctr = box.getCenter();

        if( Matrix4f.mapObjToWin(ctr, pmv.getPMv(), viewport, objPos) ) {
            final float winZ = objPos.z();
            if( Matrix4f.mapWinToObj(glWinX, glWinY, winZ, pmv.getPMvi(), viewport, objPos) ) {
                return objPos;
            }
        }
        return null;
    }

    /**
     * Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param pmvMatrixSetup {@link Scene.PMVMatrixSetup} to {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} given {@link PMVMatrix4f} {@code pmv}.
     * @param viewport used viewport for {@link PMVMatrix4f#mapWinToObj(float, float, float, Recti, Vec3f)}
     * @param glWinX in GL window coordinates, origin bottom-left
     * @param glWinY in GL window coordinates, origin bottom-left
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param objPos target object position of glWinX/glWinY relative to this shape
     * @return given {@code objPos} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)}
     *         and {@link Matrix4f#mapWinToObj(float, float, float, float, Matrix4f, Recti, Vec3f, Vec3f) gluUnProject(..)}
     *         operation, otherwise {@code null}
     * @see #winToShapeCoord(PMVMatrix4f, Recti, int, int, float[])
     * @see #winToShapeCoord(Scene, int, int, PMVMatrix4f, float[])
     */
    public final Vec3f winToShapeCoord(final Scene.PMVMatrixSetup pmvMatrixSetup, final Recti viewport, final int glWinX, final int glWinY, final PMVMatrix4f pmv, final Vec3f objPos) {
        return this.winToShapeCoord(setPMVMatrix(pmvMatrixSetup, viewport, pmv), viewport, glWinX, glWinY, objPos);
    }

    /**
     * Map given gl-window-coordinates to object coordinates relative to this shape and its z-coordinate.
     * <p>
     * The given {@link PMVMatrix4f} will be {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) setup} properly for this shape
     * including this shape's {@link #transformMvTo(PMVMatrix4f)}.
     * </p>
     * @param scene {@link Scene} to retrieve {@link Scene.PMVMatrixSetup} and the viewport.
     * @param glWinX in GL window coordinates, origin bottom-left
     * @param glWinY in GL window coordinates, origin bottom-left
     * @param pmv a new {@link PMVMatrix4f} which will {@link Scene.PMVMatrixSetup#set(PMVMatrix4f, Recti) be setup},
     *            {@link #transformMvTo(PMVMatrix4f) shape-transformed} and can be reused by the caller.
     * @param objPos target object position of glWinX/glWinY relative to this shape
     * @return given {@code objPos} for successful {@link Matrix4f#mapObjToWin(Vec3f, Matrix4f, Recti, Vec3f) gluProject(..)}
     *         and {@link Matrix4f#mapWinToObj(float, float, float, float, Matrix4f, Recti, Vec3f, Vec3f) gluUnProject(..)}
     *         operation, otherwise {@code null}
     * @see #winToShapeCoord(PMVMatrix4f, Recti, int, int, float[])
     * @see #winToShapeCoord(com.jogamp.graph.ui.Scene.PMVMatrixSetup, Recti, int, int, PMVMatrix4f, float[])
     */
    public final Vec3f winToShapeCoord(final Scene scene, final int glWinX, final int glWinY, final PMVMatrix4f pmv, final Vec3f objPos) {
        return this.winToShapeCoord(scene.getPMVMatrixSetup(), scene.getViewport(), glWinX, glWinY, pmv, objPos);
    }

    public final Vec4f getColor() { return rgbaColor; }

    /**
     * Set base color.
     * <p>
     * Base color w/o color channel, will be modulated w/ pressed- and toggle color
     * </p>
     * <p>
     * Default RGBA value is 0.60f, 0.60f, 0.60f, 1.0f
     * </p>
     */
    public Shape setColor(final float r, final float g, final float b, final float a) {
        this.rgbaColor.set(r, g, b, a);
        return this;
    }

    /**
     * Set base color.
     * <p>
     * Default base-color w/o color channel, will be modulated w/ pressed- and toggle color
     * </p>
     * <p>
     * Default RGBA value is 0.60f, 0.60f, 0.60f, 1.0f
     * </p>
     */
    public Shape setColor(final Vec4f c) {
        this.rgbaColor.set(c);
        return this;
    }

    /**
     * Set pressed color.
     * <p>
     * Default pressed color-factor w/o color channel, modulated base-color. ~0.65 (due to alpha)
     * </p>
     * <p>
     * Default RGBA value is 0.70f, 0.70f, 0.70f, 0.8f
     * </p>
     */
    public Shape setPressedColorMod(final float r, final float g, final float b, final float a) {
        this.pressedRGBAModulate.set(r, g, b, a);
        return this;
    }

    /**
     * Set toggle-on color.
     * <p>
     * Default toggle-on color-factor w/o color channel, modulated base-color.  0.60 * 0.83 ~= 0.50
     * </p>
     * <p>
     * Default RGBA value is 0.83f, 0.83f, 0.83f, 1.0f
     * </p>
     */
    public final Shape setToggleOnColorMod(final float r, final float g, final float b, final float a) {
        this.toggleOnRGBAModulate.set(r, g, b, a);
        return this;
    }

    /**
     * Set toggle-off color.
     * <p>
     * Default toggle-off color-factor w/o color channel, modulated base-color.  0.60 * 1.00 ~= 0.60
     * </p>
     * <p>
     * Default RGBA value is 1.00f, 1.00f, 1.00f, 1.0f
     * </p>
     */
    public final Shape setToggleOffColorMod(final float r, final float g, final float b, final float a) {
        this.toggleOffRGBAModulate.set(r, g, b, a);
        return this;
    }

    public final Vec4f getBorderColor() { return borderColor; }

    /**
     * Set border color.
     * <p>
     * Default RGBA value is 0.00f, 0.00f, 0.00f, 1.0f
     * </p>
     * @see #setBorder(float)
     */
    public final Shape setBorderColor(final float r, final float g, final float b, final float a) {
        this.borderColor.set(r, g, b, a);
        markShapeDirty();
        return this;
    }

    /**
     * Set border color.
     * <p>
     * Default RGBA value is 0.00f, 0.00f, 0.00f, 1.0f
     * </p>
     * @see #setBorder(float)
     */
    public final Shape setBorderColor(final Vec4f c) {
        this.borderColor.set(c);
        markShapeDirty();
        return this;
    }

    @Override
    public final String toString() {
        return getClass().getSimpleName()+"["+getSubString()+"]";
    }

    public String getSubString() {
        final String pivotS;
        if( null != rotPivot ) {
            pivotS = "pivot["+rotPivot+"], ";
        } else {
            pivotS = "";
        }
        final String scaleS;
        if( !scale.isEqual( Vec3f.ONE ) ) {
            scaleS = "scale["+scale+"], ";
        } else {
            scaleS = "scale 1, ";
        }
        final String rotateS;
        if( !rotation.isIdentity() ) {
            final Vec3f euler = rotation.toEuler(new Vec3f());
            rotateS = "rot["+euler+"], ";
        } else {
            rotateS = "";
        }
        final String activeS = isIO(IO_ACTIVE) ? ", active" : "";
        final String ps = hasPadding() ? padding.toString()+", " : "";
        final String bs = hasBorder() ? "border[l "+getBorderThickness()+", c "+getBorderColor()+"], " : "";
        final String idS = -1 != id ? ", id "+id : "";
        final String nameS = "noname" != name ? ", '"+name+"'" : "";
        return getDirtyString()+idS+nameS+", visible "+isIO(IO_VISIBLE)+activeS+", toggle "+isIO(IO_TOGGLE)+
               ", able[toggle "+isIO(IO_TOGGLEABLE)+", iactive "+isInteractive()+", resize "+isResizable()+", move "+this.isDraggable()+
               "], pos["+position+"], "+pivotS+scaleS+rotateS+
                ps+bs+"box"+box;
    }

    //
    // Input
    //

    public final Shape setPressed(final boolean b) {
        setIO(IO_DOWN, b);
        markStateDirty();
        return this;
    }
    public final boolean isPressed() { return isIO(IO_DOWN); }

    /**
     * Set this shape toggleable, default is off.
     * @param toggleable
     * @see #isInteractive()
     */
    public final Shape setToggleable(final boolean toggleable) { return setIO(IO_TOGGLEABLE, toggleable); }

    /**
     * Returns true if this shape is toggable,
     * i.e. rendered w/ {@link #setToggleOnColorMod(float, float, float, float)} or {@link #setToggleOffColorMod(float, float, float, float)}.
     * @see #isInteractive()
     */
    public boolean isToggleable() { return isIO(IO_TOGGLEABLE); }

    /**
     * Set this shape's toggle state, default is off.
     * @param v
     * @return
     */
    public final Shape setToggle(final boolean v) {
        setIO(IO_TOGGLE, v);
        toggleNotify(v);
        if( null != onToggleListener ) {
            onToggleListener.run(this);
        }
        markStateDirty();
        return this;
    }
    public final Shape toggle() {
        if( isToggleable() ) {
            setIO(IO_TOGGLE, !isToggleOn());
            toggleNotify(isToggleOn());
            if( null != onToggleListener ) {
                onToggleListener.run(this);
            }
            markStateDirty();
        }
        return this;
    }
    protected void toggleNotify(final boolean on) {}

    /** Returns true this shape's toggle state. */
    public final boolean isToggleOn() { return isIO(IO_TOGGLE); }

    protected final boolean setActive(final boolean v, final float zOffset) {
        if( isActivable() ) {
            this.zOffset = zOffset;
            setIO(IO_ACTIVE, v);
            if( !v ) {
                releaseInteraction();
                final Tooltip tt = tooltip;
                if( null != tt ) {
                    tt.stop(false);
                }
            }
            if( DEBUG ) {
                System.err.println("XXX "+(v?"  Active":"DeActive")+" "+this);
            }
            dispatchActivationEvent(this);
            return true;
        } else {
            return false;
        }
    }
    /** Returns true of this shape is active */
    public boolean isActive() { return isIO(IO_ACTIVE); }

    protected final Listener forwardActivation = new Listener() {
        @Override
        public void run(final Shape shape) {
            dispatchActivationEvent(shape);
        }
    };

    public float getAdjustedZ() {
        return getAdjustedZImpl();
    }
    protected final float getAdjustedZImpl() {
        return position.z() * getScale().z() + zOffset;
    }

    /**
     * Set's a new {@link Tooltip} for this shape.
     * <p>
     * The {@link Shape} must be set {@link #setInteractive(boolean) interactive}
     * to receive the mouse-over signal, i.e. being picked.
     * </p>
     */
    public Tooltip setToolTip(final Tooltip newTooltip) {
        final Tooltip oldTT = this.tooltip;
        this.tooltip = null;
        if( null != oldTT ) {
            oldTT.stop(true);
        }
        newTooltip.setTool(this);
        this.tooltip = newTooltip;
        return newTooltip;
    }
    public void removeToolTip() {
        final Tooltip tt = tooltip;
        tooltip = null;
        if( null != tt ) {
            tt.stop(true);
            tt.setTool(null);
        }
    }
    private void stopToolTip() {
        final Tooltip tt = tooltip;
        if( null != tt ) {
            tt.stop(true);
        }
    }
    /* pp */ Tooltip startToolTip(final boolean lookupParents) {
        Tooltip tt = tooltip;
        if( null != tt ) {
            tt.start();
            return tt;
        } else if( lookupParents ) {
            Shape p = getParent();
            while( null != p ) {
                tt = p.startToolTip(false);
                if( null != tt ) {
                    return tt;
                } else {
                    p = p.getParent();
                }
            }
        }
        return null;
    }
    public Tooltip getTooltip() { return tooltip; }

    /**
     * Set whether this shape is interactive,
     * i.e. any user interaction like
     * - {@link #isToggleable()}
     * - {@link #isDraggable()}
     * - {@link #isResizable()}
     * but excluding programmatic changes.
     * @param v new value for {@link #isInteractive()}
     * @see #isInteractive()
     * @see #setDraggable(boolean)
     * @see #setResizable(boolean)
     * @see #setDragAndResizeable(boolean)
     */
    public final Shape setInteractive(final boolean v) { return setIO(IO_INTERACTIVE, v); }
    /**
     * Returns if this shape allows user interaction, see {@link #setInteractive(boolean)}
     * @see #setInteractive(boolean)
     */
    public final boolean isInteractive() { return isIO(IO_INTERACTIVE); }

    /**
     * Set whether this shape is allowed to be activated, i.e become {@link #isActive()}.
     * <p>
     * A non activable shape still allows a shape to be dragged or resized,
     * it just can't gain the main focus.
     * </p>
     */
    public final Shape setActivable(final boolean v) { return setIO(IO_ACTIVABLE, v); }

    /** Returns if this shape is allowed to be activated, i.e become {@link #isActive()}. */
    public final boolean isActivable() { return isIO(IO_ACTIVABLE); }

    /**
     * Set whether this shape is draggable,
     * i.e. translated by 1-pointer-click and drag.
     * <p>
     * Default draggable is true.
     * </p>
     * @see #isDraggable()
     * @see #setInteractive(boolean)
     * @see #setResizable(boolean)
     * @see #setDragAndResizeable(boolean)
     */
    public final Shape setDraggable(final boolean draggable) { return setIO(IO_DRAGGABLE, draggable); }
    /**
     * Returns if this shape is draggable, a user interaction.
     * @see #setDraggable(boolean)
     */
    public final boolean isDraggable() { return isIO(IO_DRAGGABLE); }

    /**
     * Set whether this shape is resizable,
     * i.e. zoomed by 1-pointer-click and drag in 1/4th bottom-left and bottom-right corner.
     * <p>
     * Default resizable is true.
     * </p>
     * @see #isResizable()
     * @see #setInteractive(boolean)
     * @see #setDraggable(boolean)
     * @see #setDragAndResizeable(boolean)
     */
    public final Shape setResizable(final boolean resizable) { return setIO(IO_RESIZABLE, resizable); }

    /**
     * Returns if this shape is resiable, a user interaction.
     * @see #setResizable(boolean)
     */
    public final boolean isResizable() { return isIO(IO_RESIZABLE); }

    /**
     * Returns if aspect-ratio shall be kept at resize, if {@link #isResizable()}.
     * @see #setFixedARatioResize(boolean)
     */
    public final boolean isFixedARatioResize() { return isIO(IO_RESIZE_FIXED_RATIO); }

    /**
     * Sets whether aspect-ratio shall be kept at resize, if {@link #isResizable()}.
     * @see #isResizable()
     * @see #isFixedARatioResize()
     */
    public final Shape setFixedARatioResize(final boolean v) { return setIO(IO_RESIZE_FIXED_RATIO, v); }

    /**
     * Set whether this shape is draggable and resizable.
     * <p>
     * Default draggable and resizable is true.
     * </p>
     * @see #isDraggable()
     * @see #isResizable()
     * @see #setInteractive(boolean)
     * @see #setDraggable(boolean)
     * @see #setResizable(boolean)
     */
    public final Shape setDragAndResizeable(final boolean v) {
        setDraggable(v);
        setResizable(v);
        return this;
    }

    public final Shape addMouseListener(final MouseGestureListener l) {
        if(l == null) {
            return this;
        }
        @SuppressWarnings("unchecked")
        final ArrayList<MouseGestureListener> clonedListeners = (ArrayList<MouseGestureListener>) mouseListeners.clone();
        clonedListeners.add(l);
        mouseListeners = clonedListeners;
        return this;
    }
    public final Shape removeMouseListener(final MouseGestureListener l) {
        if (l == null) {
            return this;
        }
        @SuppressWarnings("unchecked")
        final ArrayList<MouseGestureListener> clonedListeners = (ArrayList<MouseGestureListener>) mouseListeners.clone();
        clonedListeners.remove(l);
        mouseListeners = clonedListeners;
        return this;
    }
    /**
     * Forward {@link MouseGestureListener} events to this {@link Shape} from {@code source} using a {@link ForwardMouseListener}.
     * <p>
     * This source {@link Shape} must be {@link #setInteractive(boolean)} to receive and forward the events.
     * </p>
     * <p>
     * This receiver {@link Shape} must be {@link #setInteractive(boolean)} to have the events forwarded.
     * </p>
     * @see #receiveKeyEvents(Shape)
     */
    public void receiveMouseEvents(final Shape source) {
        source.addMouseListener(new Shape.ForwardMouseListener(this));
    }

    public final Shape addKeyListener(final KeyListener l) {
        if(l == null) {
            return this;
        }
        @SuppressWarnings("unchecked")
        final ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
        clonedListeners.add(l);
        keyListeners = clonedListeners;
        return this;
    }
    public final Shape removeKeyListener(final KeyListener l) {
        if (l == null) {
            return this;
        }
        @SuppressWarnings("unchecked")
        final ArrayList<KeyListener> clonedListeners = (ArrayList<KeyListener>) keyListeners.clone();
        clonedListeners.remove(l);
        keyListeners = clonedListeners;
        return this;
    }
    /**
     * Forward {@link KeyListener} events to this {@link Shape} from {@code source} using a {@link ForwardKeyListener}.
     * <p>
     * This source {@link Shape} must be {@link #setInteractive(boolean)} to receive and forward the events.
     * </p>
     * <p>
     * This receiver {@link Shape} must be {@link #setInteractive(boolean)} to have the events forwarded.
     * </p>
     * @see #receiveMouseEvents(Shape)
     */
    public void receiveKeyEvents(final Shape source) {
        source.addKeyListener(new Shape.ForwardKeyListener(this));
    }

    /**
     * Combining {@link MouseListener} and {@link GestureListener}
     */
    public static interface MouseGestureListener extends MouseListener, GestureListener {
    }

    /**
     * Convenient adapter combining dummy implementation for {@link MouseListener} and {@link GestureListener}
     */
    public static abstract class MouseGestureAdapter extends MouseAdapter implements MouseGestureListener {
        @Override
        public void gestureDetected(final GestureEvent gh) {
        }
    }

    /**
     * {@link Shape} event info for propagated {@link NEWTEvent}s
     * containing reference of {@link #shape the intended shape} as well as
     * the {@link #objPos rotated relative position} to this shape.
     * The latter is normalized to bottom-left zero origin, allowing easier usage.
     */
    public static class EventInfo {
        /** The associated {@link Shape} for this event */
        public final Shape shape;
        /** The relative object coordinate of glWinX/glWinY to the associated {@link Shape}. */
        public final Vec3f objPos;
        /** The GL window coordinates, origin bottom-left */
        public final int[] winPos;
        /** The drag delta of the relative object coordinate of glWinX/glWinY to the associated {@link Shape}. */
        public final Vec2f objDrag = new Vec2f();
        /** The drag delta of GL window coordinates, origin bottom-left */
        public final int[] winDrag = { 0, 0 };

        /**
         * Ctor
         * @param glWinX in GL window coordinates, origin bottom-left
         * @param glWinY in GL window coordinates, origin bottom-left
         * @param shape associated shape
         * @param objPos relative object coordinate of glWinX/glWinY to the associated shape.
         */
        EventInfo(final int glWinX, final int glWinY, final Shape shape, final Vec3f objPos) {
            this.winPos = new int[] { glWinX, glWinY };
            this.shape = shape;
            this.objPos = objPos;
        }

        @Override
        public String toString() {
            return "EventInfo[winPos ["+winPos[0]+", "+winPos[1]+"], objPos ["+objPos+"], "+shape+"]";
        }
    }

    private final void releaseInteraction() {
        setPressed(false);
        setIO(IO_IN_MOVE, false);
        setIO(IO_IN_RESIZE_BR, false);
        setIO(IO_IN_RESIZE_BL, false);
    }

    /**
     * Dispatch given NEWT mouse event to this shape
     * @param e original Newt {@link MouseEvent}
     * @param glWinX in GL window coordinates, origin bottom-left
     * @param glWinY in GL window coordinates, origin bottom-left
     * @param objPos object position of mouse event relative to this shape
     * @return true to signal operation complete and to stop traversal, otherwise false
     */
    /* pp */ final boolean dispatchMouseEvent(final MouseEvent e, final int glWinX, final int glWinY, final Vec3f objPos) {
        /**
         * Checked at caller!
        if( !isInteractive() ) {
            return false;
        } */
        final boolean resizableOrDraggable = isResizable() || isDraggable();
        final Shape.EventInfo shapeEvent = new EventInfo(glWinX, glWinY, this, objPos);

        final short eventType = e.getEventType();
        if( 1 == e.getPointerCount() ) {
            switch( eventType ) {
                case MouseEvent.EVENT_MOUSE_CLICKED:
                    toggle();
                    if( null != onClickedListener ) {
                        onClickedListener.run(this);
                    }
                    break;
                case MouseEvent.EVENT_MOUSE_PRESSED:
                    if( resizableOrDraggable ) {
                        setIO(IO_DRAG_FIRST, true);
                    }
                    setPressed(true);
                    break;
                case MouseEvent.EVENT_MOUSE_RELEASED:
                    // Release active shape: last pointer has been lifted!
                    releaseInteraction();
                    break;
            }
        }
        if( resizableOrDraggable && MouseEvent.EVENT_MOUSE_DRAGGED == eventType ) {
            // adjust for rotation
            final Vec3f euler = rotation.toEuler(new Vec3f());
            final boolean x_flip, y_flip;
            {
                final float x_rot = Math.abs(euler.x());
                final float y_rot = Math.abs(euler.y());
                x_flip = 1f*FloatUtil.HALF_PI <= y_rot && y_rot <= 3f*FloatUtil.HALF_PI;
                y_flip = 1f*FloatUtil.HALF_PI <= x_rot && x_rot <= 3f*FloatUtil.HALF_PI;
            }
            // 1 pointer drag and potential drag-resize
            if( isIO(IO_DRAG_FIRST) ) {
                objDraggedFirst.set(objPos);
                winDraggedLast[0] = glWinX;
                winDraggedLast[1] = glWinY;
                setIO(IO_DRAG_FIRST, false);

                final float ix = x_flip ? box.getWidth()  - objPos.x() : objPos.x();
                final float iy = y_flip ? box.getHeight() - objPos.y() : objPos.y();
                final float minx_br = box.getMaxX() - box.getWidth() * resize_section;
                final float miny_br = box.getMinY();
                final float maxx_br = box.getMaxX();
                final float maxy_br = box.getMinY() + box.getHeight() * resize_section;
                if( minx_br <= ix && ix <= maxx_br &&
                    miny_br <= iy && iy <= maxy_br ) {
                    if( isResizable() ) {
                        setIO(IO_IN_RESIZE_BR, true);
                    }
                } else {
                    final float minx_bl = box.getMinX();
                    final float miny_bl = box.getMinY();
                    final float maxx_bl = box.getMinX() + box.getWidth() * resize_section;
                    final float maxy_bl = box.getMinY() + box.getHeight() * resize_section;
                    if( minx_bl <= ix && ix <= maxx_bl &&
                        miny_bl <= iy && iy <= maxy_bl ) {
                        if( isResizable() ) {
                            setIO(IO_IN_RESIZE_BL, true);
                        }
                    } else {
                        setIO(IO_IN_MOVE, isDraggable());
                    }
                }
                if( DEBUG ) {
                    System.err.printf("DragFirst: drag %b, resize[br %b, bl %b], obj[%s], flip[x %b, y %b]%n",
                            isIO(IO_IN_MOVE), isIO(IO_IN_RESIZE_BR), isIO(IO_IN_RESIZE_BL), objPos, x_flip, y_flip);
                    System.err.printf("DragFirst: %s%n", this);
                }
                return true; // end signal traversal at 1st drag
            }
            shapeEvent.objDrag.set( objPos.x() - objDraggedFirst.x(),
                                    objPos.y() - objDraggedFirst.y() );
            shapeEvent.objDrag.scale(x_flip ? -1f : 1f, y_flip ? -1f : 1f);

            shapeEvent.winDrag[0] = glWinX - winDraggedLast[0];
            shapeEvent.winDrag[1] = glWinY - winDraggedLast[1];
            winDraggedLast[0] = glWinX;
            winDraggedLast[1] = glWinY;
            if( 1 == e.getPointerCount() ) {
                final float sdx = shapeEvent.objDrag.x() * scale.x(); // apply scale, since operation
                final float sdy = shapeEvent.objDrag.y() * scale.y(); // is from a scaled-model-viewpoint
                if( isIO(IO_IN_RESIZE_BR) || isIO(IO_IN_RESIZE_BL) ) {
                    final float bw = box.getWidth();
                    final float bh = box.getHeight();
                    final float sdy2, sx, sy;
                    if( isIO(IO_IN_RESIZE_BR) ) {
                        sx = scale.x() + sdx/bw; // bottom-right
                    } else {
                        sx = scale.x() - sdx/bw; // bottom-left
                    }
                    if( isFixedARatioResize() ) {
                        sy = sx;
                        sdy2  = bh * ( scale.y() - sy );
                    } else {
                        sdy2 = sdy;
                        sy = scale.y() - sdy2/bh;
                    }
                    if( resize_sxy_min <= sx && resize_sxy_min <= sy ) { // avoid scale flip
                        if( DEBUG ) {
                            System.err.printf("DragZoom: resize[br %b, bl %b], win[%4d, %4d], , flip[x %b, y %b], obj[%s], dxy +[%s], sdxy +[%.4f, %.4f], sdxy2 +[%.4f, %.4f], scale [%s] -> [%.4f, %.4f]%n",
                                    isIO(IO_IN_RESIZE_BR), isIO(IO_IN_RESIZE_BL), glWinX, glWinY, x_flip, y_flip, objPos,
                                    shapeEvent.objDrag, sdx, sdy, sdx, sdy2,
                                    scale, sx, sy);
                        }
                        if( isIO(IO_IN_RESIZE_BR) ) {
                            moveNotify(   0, sdy2, 0f); // bottom-right, sticky left- and top-edge
                        } else {
                            moveNotify( sdx, sdy2, 0f); // bottom-left, sticky right- and top-edge
                        }
                        setScale(sx, sy, scale.z());
                    }
                    return true; // end signal traversal with completed drag
                } else if( isIO(IO_IN_MOVE) ) {
                    if( DEBUG ) {
                        System.err.printf("DragMove: win[%4d, %4d] +[%2d, %2d], , flip[x %b, y %b], obj[%s] +[%s], rot %s%n",
                                glWinX, glWinY, shapeEvent.winDrag[0], shapeEvent.winDrag[1],
                                x_flip, y_flip, objPos, shapeEvent.objDrag, euler);
                    }
                    moveNotify( sdx, sdy, 0f);
                    return true; // end signal traversal with completed move
                }
            }
        } // resizableOrDraggable && EVENT_MOUSE_DRAGGED
        e.setAttachment(shapeEvent);

        return dispatchMouseEvent(e);
    }

    /**
     * Dispatch given NEWT mouse event to this shape
     * @param e original Newt {@link MouseEvent}
     * @return true to signal operation complete and to stop traversal, otherwise false
     */
    /* pp */ final boolean dispatchMouseEvent(final MouseEvent e) {
        final short eventType = e.getEventType();
        for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
            final MouseGestureListener l = mouseListeners.get(i);
            switch( eventType ) {
                case MouseEvent.EVENT_MOUSE_CLICKED:
                    l.mouseClicked(e);
                    break;
                case MouseEvent.EVENT_MOUSE_ENTERED:
                    l.mouseEntered(e);
                    break;
                case MouseEvent.EVENT_MOUSE_EXITED:
                    l.mouseExited(e);
                    break;
                case MouseEvent.EVENT_MOUSE_PRESSED:
                    l.mousePressed(e);
                    break;
                case MouseEvent.EVENT_MOUSE_RELEASED:
                    l.mouseReleased(e);
                    break;
                case MouseEvent.EVENT_MOUSE_MOVED:
                    l.mouseMoved(e);
                    break;
                case MouseEvent.EVENT_MOUSE_DRAGGED:
                    l.mouseDragged(e);
                    break;
                case MouseEvent.EVENT_MOUSE_WHEEL_MOVED:
                    l.mouseWheelMoved(e);
                    break;
                default:
                    throw new NativeWindowException("Unexpected mouse event type " + e.getEventType());
            }
        }
        return e.isConsumed(); // end signal traversal if consumed
    }

    /**
     * @param e original Newt {@link GestureEvent}
     * @param glWinX x-position in OpenGL model space
     * @param glWinY y-position in OpenGL model space
     * @param pmv well formed PMVMatrix4f for this shape
     * @param viewport the viewport
     * @param objPos object position of mouse event relative to this shape
     */
    /* pp */ final void dispatchGestureEvent(final GestureEvent e, final int glWinX, final int glWinY, final PMVMatrix4f pmv, final Recti viewport, final Vec3f objPos) {
        if( isInteractive() && isResizable() && e instanceof PinchToZoomGesture.ZoomEvent ) {
            final PinchToZoomGesture.ZoomEvent ze = (PinchToZoomGesture.ZoomEvent) e;
            final float pixels = ze.getDelta() * ze.getScale(); //
            final int winX2 = glWinX + Math.round(pixels);
            final Vec3f objPos2 = winToShapeCoord(pmv, viewport, winX2, glWinY, new Vec3f());
            if( null == objPos2 ) {
                return;
            }
            final float dx = objPos2.x();
            final float dy = objPos2.y();
            final float sx = scale.x() + ( dx/box.getWidth() ); // bottom-right
            final float sy = scale.y() + ( dy/box.getHeight() );
            if( DEBUG ) {
                System.err.printf("DragZoom: resize[br %b, bl %b], win %4d/%4d, obj %s, %s + %.3f/%.3f -> %.3f/%.3f%n",
                        isIO(IO_IN_RESIZE_BR), isIO(IO_IN_RESIZE_BL), glWinX, glWinY, objPos, position, dx, dy, sx, sy);
            }
            if( resize_sxy_min <= sx && resize_sxy_min <= sy ) { // avoid scale flip
                if( DEBUG ) {
                    System.err.printf("PinchZoom: pixels %f, win %4d/%4d, obj %s, %s + %.3f/%.3f -> %.3f/%.3f%n",
                            pixels, glWinX, glWinY, objPos, position, dx, dy, sx, sy);
                }
                // moveNotify(dx, dy, 0f);
                setScale(sx, sy, scale.z());
            }
            return; // FIXME: pass through event? Issue zoom event?
        }
        final Shape.EventInfo shapeEvent = new EventInfo(glWinX, glWinY, this, objPos);
        e.setAttachment(shapeEvent);

        dispatchGestureEvent(e);
    }

    /**
     * Dispatch given NEWT mouse event to this shape
     * @param e original Newt {@link MouseEvent}
     * @return true to signal operation complete and to stop traversal, otherwise false
     */
    /* pp */ final boolean dispatchGestureEvent(final GestureEvent e) {
        for(int i = 0; !e.isConsumed() && i < mouseListeners.size(); i++ ) {
            mouseListeners.get(i).gestureDetected(e);
        }
        return e.isConsumed(); // end signal traversal if consumed
    }

    /**
     * Dispatch given NEWT key event to this shape
     * @param e original Newt {@link KeyEvent}
     * @return true to signal operation complete and to stop traversal, otherwise false
     */
    /* pp */ final boolean dispatchKeyEvent(final KeyEvent e) {
        /**
         * Checked at caller!
        if( !isInteractive() ) {
            return false;
        } */
        final short eventType = e.getEventType();
        for(int i = 0; !e.isConsumed() && i < keyListeners.size(); i++ ) {
            final KeyListener l = keyListeners.get(i);
            switch( eventType ) {
                case KeyEvent.EVENT_KEY_PRESSED:
                    l.keyPressed(e);
                    break;
                case KeyEvent.EVENT_KEY_RELEASED:
                    l.keyReleased(e);
                    break;
                default:
                    throw new NativeWindowException("Unexpected key event type " + e.getEventType());
            }
        }
        return e.isConsumed(); // end signal traversal if consumed
    }

    //
    //
    //

    protected abstract void validateImpl(final GL2ES2 gl, final GLProfile glp);

    /**
     * Actual draw implementation, called by {@link #draw(GL2ES2, RegionRenderer)}
     * @param gl
     * @param renderer
     * @param rgba
     */
    protected abstract void drawImpl0(final GL2ES2 gl, final RegionRenderer renderer, final Vec4f rgba);

    /**
     * Actual draw implementation, called by {@link #drawToSelect(GL2ES2, RegionRenderer)}
     * @param gl
     * @param renderer
     */
    protected abstract void drawToSelectImpl0(final GL2ES2 gl, final RegionRenderer renderer);

    /** Custom {@link #clear(GL2ES2, RegionRenderer)} task, called 1st. */
    protected abstract void clearImpl0(final GL2ES2 gl, final RegionRenderer renderer);

    /** Custom {@link #destroy(GL2ES2, RegionRenderer)} task, called 1st. */
    protected abstract void destroyImpl0(final GL2ES2 gl, final RegionRenderer renderer);

    /**
     * Returns true if implementation uses an extra color channel or texture
     * which will be modulated with the passed rgba color {@link #drawImpl0(GL2ES2, RegionRenderer, float[])}.
     *
     * Otherwise the base color will be modulated and passed to {@link #drawImpl0(GL2ES2, RegionRenderer, float[])}.
     */
    public abstract boolean hasColorChannel();

    @SuppressWarnings("unused")
    private static int compareAsc0(final float a, final float b) {
        if( FloatUtil.isEqual2(a, b) ) {
            return 0;
        } else if( a < b ){
            return -1;
        } else {
            return 1;
        }
    }
    private static int compareAsc1(final float a, final float b) {
        if (a < b) {
            return -1; // Neither is NaN, a is smaller
        }
        if (a > b) {
            return 1;  // Neither is NaN, a is larger
        }
        return 0;
    }
    @SuppressWarnings("unused")
    private static int compareDesc0(final float a, final float b) {
        if( FloatUtil.isEqual2(a, b) ) {
            return 0;
        } else if( a < b ){
            return 1;
        } else {
            return -1;
        }
    }
    private static int compareDesc1(final float a, final float b) {
        if (a < b) {
            return 1; // Neither is NaN, a is smaller
        }
        if (a > b) {
            return -1;  // Neither is NaN, a is larger
        }
        return 0;
    }

    public static Comparator<Shape> ZAscendingComparator = new Comparator<Shape>() {
        @Override
        public int compare(final Shape s1, final Shape s2) {
            return compareAsc1( s1.getAdjustedZ(), s2.getAdjustedZ() );
        } };

    public static Comparator<Shape> ZDescendingComparator = new Comparator<Shape>() {
        @Override
        public int compare(final Shape s1, final Shape s2) {
            return compareDesc1( s2.getAdjustedZ(), s1.getAdjustedZ() );
        } };

    //
    //
    //
}