X-Git-Url: https://git.openstreetmap.org/potlatch2.git/blobdiff_plain/41d852af78f1fefafe812c3c098427e82387412b..aec94286d17cabcd8016bb63ddb079fe4cbd334f:/net/systemeD/halcyon/NodeUI.as diff --git a/net/systemeD/halcyon/NodeUI.as b/net/systemeD/halcyon/NodeUI.as index b59c65ff..0467874c 100644 --- a/net/systemeD/halcyon/NodeUI.as +++ b/net/systemeD/halcyon/NodeUI.as @@ -13,29 +13,19 @@ package net.systemeD.halcyon { import net.systemeD.halcyon.styleparser.*; import net.systemeD.halcyon.Globals; - public class NodeUI extends Object { + public class NodeUI extends EntityUI { private var node:Node; - public var map:Map; // reference to parent map - public var icon:Sprite; // instance in display list - public var name:Sprite; // | + public var loaded:Boolean=false; private var iconname:String=''; // name of icon private var heading:Number=0; // heading within way private var rotation:Number=0; // rotation applied to this POI - public var loaded:Boolean=false; - - public static const DEFAULT_TEXTFIELD_PARAMS:Object = { -// embedFonts: true, - antiAliasType: AntiAliasType.ADVANCED, - gridFitType: GridFitType.NONE - }; -// [Embed(source="fonts/DejaVuSans.ttf", fontFamily="DejaVu", fontWeight="normal", mimeType="application/x-font-truetype")] -// public static var DejaVu:Class; - public function NodeUI(node:Node, map:Map, rotation:Number=0) { + public function NodeUI(node:Node, map:Map, heading:Number=0) { + super(); this.map = map; this.node = node; - this.rotation = rotation; + this.heading = heading; node.addEventListener(Connection.NODE_MOVED, nodeMoved); } @@ -44,67 +34,62 @@ package net.systemeD.halcyon { } public function redraw(sl:StyleList=null,forceDraw:Boolean=false):Boolean { + // *** forcedraw can be removed + var tags:Object = node.getTagsCopy(); - tags['_heading']=heading; - // ** apply :hover etc. + + // special tags + if (!node.hasParentWays) { tags[':poi']='yes'; } + for (var stateKey:String in stateClasses) { + tags[":"+stateKey] = 'yes'; + } + if (!sl) { sl=map.ruleset.getStyles(this.node,tags); } var inWay:Boolean=node.hasParentWays; var hasStyles:Boolean=sl.hasStyles(); - removePrevious(); - if (!hasStyles && !inWay) { - // No styles, not in way; usually return, but render as green circle if showall set - if (!map.showall) { return false; } - return renderAsCircle(); - } else if (!hasStyles && inWay) { - // No styles, in way; so render as highlight - // *** needs to be blue/red depending on mouse-over - if (forceDraw) { - return renderAsSquare(); - } else { - return false; - } - } else { - // Styled, so render properly - return renderFromStyle(sl,tags); - } + removeSprites(); iconname=''; + return renderFromStyle(sl,tags); } - private function renderAsSquare():Boolean { - createIcon(); - icon.graphics.beginFill(0xFF0000); - icon.graphics.drawRect(0,0,6,6); // ** NODESIZE - loaded=true; - updatePosition(); - iconname='_square'; - return true; - } - - private function renderAsCircle():Boolean { - createIcon(); - icon.graphics.lineStyle(1,0,1); - icon.graphics.beginFill(0x00FF00); - icon.graphics.drawCircle(4,4,4); // ** NODESIZE - loaded=true; - updatePosition(); - iconname='_circle'; - return true; - } - private function renderFromStyle(sl:StyleList,tags:Object):Boolean { var r:Boolean=false; // ** rendered - for (var sublayer:uint=0; sublayer<10; sublayer++) { + var w:Number; + var icon:Sprite; + layer=10; + for (var sublayer:int=10; sublayer>=0; sublayer--) { if (sl.pointStyles[sublayer]) { var s:PointStyle=sl.pointStyles[sublayer]; r=true; if (s.rotation) { rotation=s.rotation; } + if (s.icon_image!=iconname) { - // 'load' icon (actually just from library) - if (map.ruleset.images[s.icon_image]) { + if (s.icon_image=='square') { + // draw square + icon=new Sprite(); + addToLayer(icon,STROKESPRITE,sublayer); + w=styleIcon(icon,sl,sublayer); + icon.graphics.drawRect(0,0,w,w); + addHitSprite(w); + updatePosition(); + iconname='_square'; + + } else if (s.icon_image=='circle') { + // draw circle + icon=new Sprite(); + addToLayer(icon,STROKESPRITE,sublayer); + w=styleIcon(icon,sl,sublayer); + icon.graphics.drawCircle(w,w,w); + addHitSprite(w); + updatePosition(); + iconname='_circle'; + + } else if (map.ruleset.images[s.icon_image]) { + // 'load' icon (actually just from library) var loader:Loader = new Loader(); - loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedIcon); + loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void { loadedIcon(e,sublayer); } ); loader.loadBytes(map.ruleset.images[s.icon_image]); iconname=s.icon_image; } @@ -122,67 +107,73 @@ package net.systemeD.halcyon { } if (a) { - var l:DisplayObject=map.getChildAt(map.NAMESPRITE); - if (!name) { name=new Sprite(); Sprite(l).addChild(name); } + var name:Sprite=new Sprite(); + addToLayer(name,NAMESPRITE); t.writeNameLabel(name,a,map.lon2coord(node.lon),map.latp2coord(node.latp)); } } return r; } - private function removePrevious():void { - var l:DisplayObject; - - if (icon) { - l=map.getChildAt(map.POISPRITE); - Sprite(l).removeChild(icon); - icon=null; - iconname=''; - } - if (name) { - l=map.getChildAt(map.NAMESPRITE); - Sprite(l).removeChild(name); - name=null; + + private function styleIcon(icon:Sprite, sl:StyleList, sublayer:uint):Number { + loaded=true; + + // get colours + if (sl.shapeStyles[sublayer]) { + var s:ShapeStyle=sl.shapeStyles[sublayer]; + if (s.color) { icon.graphics.beginFill(s.color); } + if (s.casing_width || s.casing_color!=false) { + icon.graphics.lineStyle(s.casing_width ? s.casing_width : 1, + s.casing_color ? s.casing_color : 0, + s.casing_opacity ? s.casing_opacity : 1); + // ** this appears to give casing to things that shouldn't have it + // Globals.vars.root.addDebug("casing: "+(s.casing_width ? s.casing_width : 1)+","+(s.casing_color ? s.casing_color : 0)+","+(s.casing_opacity ? s.casing_opacity : 1)); + } } + + // return width + return sl.pointStyles[sublayer].icon_width ? sl.pointStyles[sublayer].icon_width : 4; } - private function loadedIcon(event:Event):void { - createIcon(); + private function addHitSprite(w:uint):void { + var hitzone:Sprite = new Sprite(); + hitzone.graphics.lineStyle(4, 0x000000, 1, false, "normal", CapsStyle.ROUND, JointStyle.ROUND); + hitzone.graphics.beginFill(0); + hitzone.graphics.drawRect(0,0,w,w); + addToLayer(hitzone, CLICKSPRITE); + hitzone.visible = false; + createListenSprite(hitzone); + } + + private function loadedIcon(event:Event,sublayer:uint):void { + var icon:Sprite=new Sprite(); + addToLayer(icon,STROKESPRITE,sublayer); icon.addChild(Bitmap(event.target.content)); + addHitSprite(icon.width); loaded=true; updatePosition(); } - private function createIcon():void { - icon = new Sprite(); - var l:DisplayObject=map.getChildAt(map.POISPRITE); - Sprite(l).addChild(icon); - icon.addEventListener(MouseEvent.CLICK, mouseEvent); - icon.addEventListener(MouseEvent.DOUBLE_CLICK, mouseEvent); - icon.addEventListener(MouseEvent.MOUSE_OVER, mouseEvent); - icon.addEventListener(MouseEvent.MOUSE_OUT, mouseEvent); - icon.addEventListener(MouseEvent.MOUSE_DOWN, mouseEvent); - icon.addEventListener(MouseEvent.MOUSE_UP, mouseEvent); - icon.addEventListener(MouseEvent.MOUSE_MOVE, mouseEvent); - icon.buttonMode = true; - icon.mouseEnabled = true; - } - - private function mouseEvent(event:MouseEvent):void { + override protected function mouseEvent(event:MouseEvent):void { map.entityMouseEvent(event, node); } private function updatePosition():void { - if (!loaded || !icon) { return; } - icon.x=0; icon.y=0; icon.rotation=0; - - var m:Matrix=new Matrix(); -// m.identity(); - m.translate(-icon.width/2,-icon.height/2); - m.rotate(rotation); - m.translate(map.lon2coord(node.lon),map.latp2coord(node.latp)); - icon.transform.matrix=m; - } + if (!loaded) { return; } + + // ** this won't work with text objects. They have a different .x and .y + // and (obviously) don't need to be rotated. Needs fixing + for (var i:uint=0; i