Various rendering/CSS parsing improvements. Tagged-nodes-in-ways still needs looking...
authorRichard Fairhurst <richard@systemed.net>
Fri, 9 Oct 2009 12:24:01 +0000 (12:24 +0000)
committerRichard Fairhurst <richard@systemed.net>
Fri, 9 Oct 2009 12:24:01 +0000 (12:24 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/POI.as
net/systemeD/halcyon/WayUI.as
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/styleparser/MapCSS.as
net/systemeD/halcyon/styleparser/ShapeStyle.as
net/systemeD/halcyon/styleparser/Style.as
net/systemeD/halcyon/styleparser/TextStyle.as

index 4e3004f37fa3b5f9b6829942be61f907fa749be4..ac886f1ef7be3952b4713fd926d3879b86c07fa7 100755 (executable)
@@ -75,9 +75,10 @@ package net.systemeD.halcyon {
                public var connection:Connection;                               // server connection
 
                public const TILESPRITE:uint=0;
-               public const WAYSPRITE:uint=1;
-               public const POISPRITE:uint=12;
-               public const NAMESPRITE:uint=13;
+               public const GPSSPRITE:uint=1;
+               public const WAYSPRITE:uint=2;
+               public const POISPRITE:uint=13;
+               public const NAMESPRITE:uint=14;
 
                // ------------------------------------------------------------------------------------------
                // Map constructor function
@@ -104,7 +105,8 @@ package net.systemeD.halcyon {
                                }                                                                               //  |  |  |
                                s.addChild(t);                                                  //  |  |
                                s.addChild(getPaintSprite());                   //      | 3 names
-                               s.addChild(getHitSprite());                         //  | 4 entity hit tests
+                               s.addChild(getPaintSprite());                   //      | 4 nodes
+                               s.addChild(getHitSprite());                         //  | 5 entity hit tests
                                addChild(s);                                                    //  |
                        }
                        addChild(getPaintSprite());                             // 12 - POIs
index 73e10b2652e2adecb71e06f036fa14e78a114b4b..be01436da347c94906441268cba396f6229fd256 100644 (file)
@@ -41,13 +41,10 @@ package net.systemeD.halcyon {
 
                                if (sl.pointStyles[sublayer]) {
                                        var s:PointStyle=sl.pointStyles[sublayer];
-//                                     if ((s is PointStyle) && s.icon && s.icon!="") 
                                        r=true;
                                        if (s.icon_image!=iconname) {
                                                // 'load' icon (actually just from library)
                                                if (map.ruleset.images[s.icon_image]) {
-//                                                     l=map.getChildAt(map.POISPRITE);
-//                                                     Sprite(l).addChild(map.ruleset.images[s.icon_image]);
                                                        var loader:Loader = new Loader();
                                                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon);
                                                        loader.loadBytes(map.ruleset.images[s.icon_image]);
@@ -62,7 +59,6 @@ package net.systemeD.halcyon {
 
                                if (sl.textStyles[sublayer]) {
                                        var t:TextStyle=sl.textStyles[sublayer];
-//                                     if ((s is TextStyle) && s.tag && tags[s.tag])
                                        // create name sprite
                                        if (!name) {
                                                name=new Sprite();
index abad93afc02eb8941f87ebe4b9655b3efa70e7db..8ca965cd4766b652dcc8054f1c4aeddc6c4640fe 100755 (executable)
@@ -32,6 +32,13 @@ package net.systemeD.halcyon {
                        gridFitType: GridFitType.NONE
                };
                public var nameformat:TextFormat;
+               
+               private const FILLSPRITE:uint=0;
+               private const CASINGSPRITE:uint=1;
+               private const STROKESPRITE:uint=2;
+               private const NAMESPRITE:uint=3;
+               private const NODESPRITE:uint=4;
+               private const CLICKSPRITE:uint=5;
 
 
                public function WayUI(way:Way, map:Map) {
@@ -119,6 +126,7 @@ package net.systemeD.halcyon {
             for (var stateKey:String in stateClasses) {
                 tags[":"+stateKey] = stateKey;
             }
+                       if (way.isArea()) { tags[':area']='yes'; }
 
                        // Remove all currently existing sprites
                        while (sprites.length>0) {
@@ -142,7 +150,7 @@ package net.systemeD.halcyon {
 
                                        // Stroke
                                        if (s.width)  {
-                                               stroke=new Shape(); addToLayer(stroke,2,sublayer);
+                                               stroke=new Shape(); addToLayer(stroke,STROKESPRITE,sublayer);
                                                stroke.graphics.moveTo(x0,y0);
                                                s.applyStrokeStyle(stroke.graphics);
                                                if (s.dashes && s.dashes.length>0) { dashedLine(stroke.graphics,s.dashes); }
@@ -152,7 +160,7 @@ package net.systemeD.halcyon {
 
                                        // Fill
                                        if (s.fill_color || s.fill_image) {
-                                               fill=new Shape(); addToLayer(fill,0);
+                                               fill=new Shape(); addToLayer(fill,FILLSPRITE);
                                                fill.graphics.moveTo(x0,y0);
                                                if (s.fill_image) { new WayBitmapFiller(this,fill.graphics,s); }
                                                                         else { s.applyFill(fill.graphics); }
@@ -163,7 +171,7 @@ package net.systemeD.halcyon {
 
                                        // Casing
                                        if (s.casing_width) { 
-                                               casing=new Shape(); addToLayer(casing,1);
+                                               casing=new Shape(); addToLayer(casing,CASINGSPRITE);
                                                casing.graphics.moveTo(x0,y0);
                                                s.applyCasingStyle(casing.graphics);
                                                if (s.casing_dashes && s.casing_dashes.length>0) { dashedLine(casing.graphics,s.casing_dashes); }
@@ -174,7 +182,7 @@ package net.systemeD.halcyon {
                                
                                if (sl.textStyles[sublayer]) {
                                        var t:TextStyle=sl.textStyles[sublayer];
-                                       roadname=new Sprite(); addToLayer(roadname,3);
+                                       roadname=new Sprite(); addToLayer(roadname,NAMESPRITE);
                                        nameformat = t.getTextFormat();
                                        var a:String=tags[t.text];
                                        if (a) {
@@ -188,6 +196,15 @@ package net.systemeD.halcyon {
                                        }
                                }
                                
+                               // ** draw icons
+                               for (var i:uint = 0; i < way.length; i++) {
+                       var node:Node = way.getNode(i);
+                                       if (node.hasTags()) {
+                                               map.connection.registerPOI(node);
+                                       }
+                               }
+                               
+                               
                                // ** ShieldStyle to do
                        }
 
@@ -196,14 +213,14 @@ package net.systemeD.halcyon {
                 var def:Sprite = new Sprite();
                 def.graphics.lineStyle(0.5, 0x808080, 1, false, "normal");
                 solidLine(def.graphics);
-                addToLayer(def, 2);
+                addToLayer(def, STROKESPRITE);         // ** this probably needs a sublayer
                                drawn=true;
             }
             
             if ( stateClasses["showNodes"] != null ) {
                 var nodes:Sprite = new Sprite();
                 drawNodes(nodes.graphics);
-                addToLayer(nodes, 3);
+                addToLayer(nodes, NODESPRITE);
             }
 
                        if (!drawn) { return; }
@@ -212,7 +229,7 @@ package net.systemeD.halcyon {
             hitzone = new Sprite();
             hitzone.graphics.lineStyle(4, 0x000000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND);
             solidLine(hitzone.graphics);
-            addToLayer(hitzone, 4);
+            addToLayer(hitzone, CLICKSPRITE);
             hitzone.visible = false;
 
             if ( listenSprite == null ) {
@@ -226,7 +243,7 @@ package net.systemeD.halcyon {
                 listenSprite.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent);
             }
             listenSprite.hitArea = hitzone;
-            addToLayer(listenSprite, 4);
+            addToLayer(listenSprite, CLICKSPRITE);
             listenSprite.buttonMode = true;
             listenSprite.mouseEnabled = true;
 
@@ -333,7 +350,6 @@ package net.systemeD.halcyon {
 
                // Draw name along path
                // based on code by Tom Carden
-               // ** needs styling
                
                private function writeNameOnPath(s:Sprite,a:String,textOffset:Number=0):void {
 
index f7d48d5d1dbf25a42e94eb9f839b495ab5d22a4b..384afebe6b37ab36e1044c60d598075c8ea83ed5 100755 (executable)
@@ -110,7 +110,7 @@ package net.systemeD.halcyon.connection {
                        dispatchEvent(e);
                }
 
-        protected function registerPOI(node:Node):void {
+        public function registerPOI(node:Node):void {
             if ( pois.indexOf(node) < 0 ) {
                 pois.push(node);
                 sendEvent(new EntityEvent(NEW_POI, node));
index bd6bf122876b260e7d4f1895f5c2d0dbdd6a95dd..60bcfea15846d40a2d55284f2697fa0a8b141df0 100755 (executable)
@@ -61,6 +61,7 @@ package net.systemeD.halcyon.styleparser {
                private static const COLOR:RegExp=/color$/;
                private static const BOLD:RegExp=/^bold$/i;
                private static const ITALIC:RegExp=/^italic|oblique$/i;
+               private static const UNDERLINE:RegExp=/^underline$/i;
                private static const CAPS:RegExp=/^uppercase$/i;
                private static const CENTER:RegExp=/^center$/i;
 
@@ -324,9 +325,10 @@ package net.systemeD.halcyon.styleparser {
                        xs.sublayer=10;
 
                        // Munge special values
-                       if (t['font_weight']   ) { t['font_bold'  ] = t['font_weight'  ].match(BOLD  ) ? true : false; }
-                       if (t['font_style']    ) { t['font_italic'] = t['font_style'   ].match(ITALIC) ? true : false; }
-                       if (t['text_position'] ) { t['text_center'] = t['text_position'].match(CENTER) ? true : false; }
+                       if (t['font_weight']    ) { t['font_bold'  ]    = t['font_weight'    ].match(BOLD  )    ? true : false; }
+                       if (t['font_style']     ) { t['font_italic']    = t['font_style'     ].match(ITALIC)    ? true : false; }
+                       if (t['text_decoration']) { t['font_underline'] = t['text_decoration'].match(UNDERLINE) ? true : false; }
+                       if (t['text_position']  ) { t['text_center']    = t['text_position'  ].match(CENTER)    ? true : false; }
                        if (t['text_transform']) {
                                // ** needs other transformations, e.g. lower-case, sentence-case
                                if (t['text_transform'].match(CAPS)) { t['font_caps']=true; } else { t['font_caps']=false; }
index 5efa7077bc0277ac564c452c5a40ea774d6d1377..d440a361c54562fd581da2e0d3f43af13bc255b3 100644 (file)
@@ -7,7 +7,7 @@ package net.systemeD.halcyon.styleparser {
                public var width:Number;
                public var color:Number;
                public var opacity:Number;
-               public var dashes:Array;
+               public var dashes:Array=[];
                public var linecap:String;
                public var linejoin:String;
                
@@ -18,7 +18,7 @@ package net.systemeD.halcyon.styleparser {
                public var casing_width:Number;
                public var casing_color:Number;
                public var casing_opacity:Number;
-               public var casing_dashes:Array;
+               public var casing_dashes:Array=[];
                
                override public function get properties():Array {
                        return [
index 0e6c7f3310739a8947bff02deaaa1a3e9bfa7571..d0708239805c84f102d0c130252911c8471eecf6 100755 (executable)
@@ -2,6 +2,7 @@ package net.systemeD.halcyon.styleparser {
 
        import flash.utils.ByteArray;
        import flash.net.*;
+       import net.systemeD.halcyon.Globals;
 
        public class Style {
 
@@ -62,9 +63,20 @@ package net.systemeD.halcyon.styleparser {
                public function setPropertyFromString(k:String,v:*):Boolean {
                        if (!this.hasOwnProperty(k)) { return false; }
                        if (v is Eval) { evals[k]=v; v=1; }
+
+                       // Arrays don't return a proper typeof, so check manually
+                       // Note that undefined class variables always have typeof=object,
+                       // so we need to declare them as empty arrays (cf ShapeStyle)
+                       if (this[k] is Array) {
+                               // Split comma-separated array and coerce as numbers
+                               this[k]=v.split(',').map(function(el:Object,index:int,array:Array):Number { return Number(el); });
+                               edited=true; return true;
+                       }
+
+                       // Check for other object types
                        switch (typeof(this[k])) {
                                case "number":  this[k]=Number(v) ; edited=true; return true;
-                               case "object":  // **for some reason, typeof(string class variables) returns "object".
+                               case "object":  // **for now, just assume objects are undefined strings
                                                                // We'll probably need to fix this in future if we have more complex
                                                                // properties
                                case "string":  this[k]=String(v) ; edited=true; return true;
index ba772b4cd452f5f03e08e21d066274476cb8d029..bf3d4f1000a0661e8dd6e07d71ec12134e6c38ad 100644 (file)
@@ -11,6 +11,7 @@ package net.systemeD.halcyon.styleparser {
                public var font_family:String;
                public var font_bold:Boolean;
                public var font_italic:Boolean;
+               public var font_underline:Boolean;
                public var font_caps:Boolean;
                public var font_size:uint;
                public var text_color:uint;
@@ -20,22 +21,27 @@ package net.systemeD.halcyon.styleparser {
                public var text_halo_color:uint;
                public var text_halo_radius:uint=0;
                public var text_center:Boolean;
+               public var letter_spacing:uint;
 
                override public function get properties():Array {
                        return [
                                'font_family','font_bold','font_italic','font_caps','font_size',
                                'text_color','text_offset','max_width',
-                               'text','text_halo_color','text_halo_radius','text_center'
+                               'text','text_halo_color','text_halo_radius','text_center',
+                               'letter_spacing'
                        ];
                }
 
                
                public function getTextFormat():TextFormat {
-                       return new TextFormat(font_family ? font_family: "DejaVu",
-                                                                 font_size   ? font_size  : 8,
-                                                                 text_color  ? text_color : 0,
-                                                                 font_bold   ? font_bold  : false,
-                                                                 font_italic ? font_italic: false);
+                       var tf:TextFormat=new TextFormat(font_family    ? font_family   : "DejaVu",
+                                                        font_size      ? font_size     : 8,
+                                                        text_color     ? text_color    : 0,
+                                                        font_bold      ? font_bold     : false,
+                                                        font_italic    ? font_italic   : false,
+                                                        font_underline ? font_underline: false);
+                       tf.letterSpacing=(letter_spacing ? letter_spacing : 0);
+                       return tf;
                }
        
                public function getHaloFilter():Array {