My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
/**
* @author Fabien BIZOT
* http://lafabrick.com/blog
* http://twitter.com/fabienbizot
*/
package com.lafabrick.uigfx.primitives
{
import flash.display.Graphics;

import spark.primitives.Line;
/**
* Draw an dashed line primitive
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*
* @mxml
* <p>
* <pre>
* &lt;uigfx:DashedLine
* dashes="[dash structure]"
* left="10" right="10"
* verticalCenter="0"&gt;
* ...
* </pre>
* </p>
* @example
* <p>The following code draws a dashed line primitive, with [20, 5, 30, 10] for dash definition</p>
* <listing version="3.0" >
* &lt;uigfx:DashedLine
* dashes="[20, 5, 30, 10]"
* left="10" right="10"
* verticalCenter="0"&gt;
*
* &lt;uigfx:stroke&gt;
* &lt;s:SolidColorStroke color="#222222" /&gt;
* &lt;/uigfx:stroke&gt;
*
* &lt;/uigfx:DashedLine&gt;
* </listing>
*
*/
public class DashedLine extends Line
{
/**
* Constructor
*/
public function DashedLine()
{
super();
}
/**
* defines the dashes construction
* The odd locations of the table defines the length of dashes.
* The pair locations of the table defines the length of spaces.
* By default [10, 10]
*/
private var _dashes : Array = [10, 10];

public function get dashes():Array
{
return _dashes;
}
/**
* @private
*/
public function set dashes(value:Array):void
{
_dashes = value;
invalidateSize();
invalidateDisplayList();
}

/**
* Draw the primitive
*/
override protected function draw(g:Graphics):void
{
if( dashes && dashes.length>0 ) {

var x1:Number = measuredX + drawX;
var y1:Number = measuredY + drawY;
var x2:Number = measuredX + drawX + width;
var y2:Number = measuredY + drawY + height;

var angle : Number = Math.atan( (x2-x1) / (y2-y1) );
var distance : Number = Math.sqrt( Math.pow( x2-x1, 2) + Math.pow(y2-y1, 2) );

var dashsCounter : Number = 0;
var sectionLength : Number = 0;

for(; dashsCounter<dashes.length; dashsCounter++) {
sectionLength += dashes[dashsCounter];
}

var numPasse : Number = Math.abs(distance/(sectionLength));

var startX : Number = 0;
var startY : Number = 0;

if ((xFrom <= xTo) == (yFrom <= yTo)) {
startX = x1,
startY = y1;
}
else {
startX = x1,
startY = y2;
}

var currentX : Number = startX;
var currentY : Number = startY;

g.moveTo( currentX, currentY );

var currentDistance : Number = 0;
var counter : Number = 0;

dashsCounter = 0;

for(; counter<numPasse; counter++) {
for(; dashsCounter<dashes.length; dashsCounter++) {

currentX+= Math.abs(dashes[dashsCounter]*Math.sin(angle));
currentY+= Math.abs(dashes[dashsCounter]*Math.cos(angle));

currentDistance = Math.sqrt( Math.pow(currentX-startX, 2) + Math.pow(currentY-startY, 2) );

if( currentDistance > distance ) {

if ((xFrom <= xTo) == (yFrom <= yTo)) {
currentX = x2,
currentY = y2;
}
else {
currentX = x2,
currentY = y1;
}
}

if( dashsCounter%2 == 0 ) {
g.lineTo( currentX, currentY );
}
else {
g.moveTo( currentX, currentY );
}

}
dashsCounter = 0;
}
}
}
}
}

Change log

r72 by fabien.bizot on Sep 28, 2010   Diff
1.2 version
SVG to UIGFX data path conversion
constraint's calculation improvement
Go to: 
Project members, sign in to write a code review

Older revisions

r66 by fabien.bizot on Jul 22, 2010   Diff
Update comment under DashedLine
primitive
r59 by fabien.bizot on Jul 21, 2010   Diff
Updating the DashedLine primitive :
just one property, 'dashes' for
definition of all part of the line
r58 by fabien.bizot on Jul 20, 2010   Diff
updating DashedLine (more complex
representation of dashed line are
possibile using 'dashsSize' property)
All revisions of this file

File info

Size: 3492 bytes, 155 lines
Powered by Google Project Hosting