Mercurial > projects > dwt-addons
diff dwtx/draw2d/PolygonDecoration.d @ 103:2d6540440fe6
Replace static ctors with lazy init.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 17:01:51 +0200 |
parents | 95307ad235d9 |
children |
line wrap: on
line diff
--- a/dwtx/draw2d/PolygonDecoration.d Sun Aug 03 03:07:30 2008 +0200 +++ b/dwtx/draw2d/PolygonDecoration.d Sun Aug 03 17:01:51 2008 +0200 @@ -33,20 +33,36 @@ { /** Template for a triangle that points to the right when the rotation angle is 0 */ -public static const PointList TRIANGLE_TIP; +private static bool initStaticConsts_done = false; +private static PointList TRIANGLE_TIP_; /** Template for a triangle that points to the left when the rotation angle is 0 */ -public static const PointList INVERTED_TRIANGLE_TIP; +private static PointList INVERTED_TRIANGLE_TIP_; + +public static PointList TRIANGLE_TIP(){ + if( !initStaticConsts_done ) initStaticConsts(); + return TRIANGLE_TIP_; +} +public static PointList INVERTED_TRIANGLE_TIP(){ + if( !initStaticConsts_done ) initStaticConsts(); + return INVERTED_TRIANGLE_TIP_; +} -static this() { - TRIANGLE_TIP = new PointList(); - INVERTED_TRIANGLE_TIP = new PointList(); - TRIANGLE_TIP.addPoint(0, 0); - TRIANGLE_TIP.addPoint(-1, 1); - TRIANGLE_TIP.addPoint(-1, -1); +private static void initStaticConsts() { + synchronized( PolygonDecoration.classinfo ){ + if( !initStaticConsts_done ){ + TRIANGLE_TIP_ = new PointList(); + TRIANGLE_TIP_.addPoint(0, 0); + TRIANGLE_TIP_.addPoint(-1, 1); + TRIANGLE_TIP_.addPoint(-1, -1); - INVERTED_TRIANGLE_TIP.addPoint(0, 1); - INVERTED_TRIANGLE_TIP.addPoint(0, -1); - INVERTED_TRIANGLE_TIP.addPoint(-1, 0); + INVERTED_TRIANGLE_TIP_ = new PointList(); + INVERTED_TRIANGLE_TIP_.addPoint(0, 1); + INVERTED_TRIANGLE_TIP_.addPoint(0, -1); + INVERTED_TRIANGLE_TIP_.addPoint(-1, 0); + + initStaticConsts_done = true; + } + } } private Point location;