-
Notifications
You must be signed in to change notification settings - Fork 5
/
Slice.mxml
230 lines (203 loc) · 8.37 KB
/
Slice.mxml
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
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off"
backgroundColor="0xFFFFFF"
mouseDown="mouseDownHandler(event)"
mouseMove="mouseMoveHandler(event)"
mouseUp="mouseUpHandler(event)"
mouseOut="mouseOutHandler(event)"
resize="resizeHandler(event)" xmlns:ui="flex.utils.ui.*" xmlns:local="*">
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.events.FlexEvent;
import mx.events.ResizeEvent;
[Bindable] public var topText:String;
[Bindable] public var bottomText:String;
[Bindable] public var leftText:String;
[Bindable] public var rightText:String;
private var _volume:Volume; //??
public function set volume(v:Volume):void {
_volume=v;
}
public function get volume():Volume {
return _volume;
}
public var dataWidth:int;
public var dataHeight:int;
public var physWidth:Number;
public var physHeight:Number;
public var ready:Boolean=false;
protected function resizeHandler(event:ResizeEvent):void {
if(physWidth/physHeight<width/height) {
image.height=height;
image.y=0;
image.width=height*physWidth/physHeight;
image.x=(width-image.width)/2;
} else {
image.width=width;
image.x=0;
image.height=width*physHeight/physWidth;
image.y=(height-image.height)/2;
}
aligNavi();
const g:Graphics=clipmask.graphics;
g.clear();
g.beginFill(0xFFFFFF);
g.drawRect(0,0,width,height);
g.endFill();
}
override protected function commitProperties():void {
super.commitProperties();
DrawOverlay();
}
protected function image_resizeHandler(event:ResizeEvent):void {
DrawOverlay();
}
public var sliceDescriptor:SliceDescriptor;
[Bindable] public var plane:String;
protected var _midX:Number;
public function get midX():Number{return _midX;}
protected var _midY:Number;
public function get midY():Number{return _midY;}
public function DrawOverlay():void {
if(!ready)return;
// CheckPick();
const g:Graphics=marker.graphics;
g.clear();
const rate:Number=image.width/dataWidth;
_midX=image.width-sliceDescriptor.midpoint[plane.charAt(0)]*rate;
_midY=image.height-sliceDescriptor.midpoint[plane.charAt(1)]*rate;
CheckPick();
if(!dragPick) {
g.lineStyle(1,0xFF0000);
g.beginFill(0xFF0000);
g.drawCircle(midX,midY,4);
g.endFill();
}
const o:Vector3D=new Vector3D(QuickNII.diz.xdim,QuickNII.diz.ydim,QuickNII.diz.zdim).subtract(sliceDescriptor.o); // -1?
const ou:Vector3D=o.subtract(sliceDescriptor.u);
const ouv:Vector3D=ou.subtract(sliceDescriptor.v);
const ov:Vector3D=o.subtract(sliceDescriptor.v);
g.lineStyle(1,rotPick?0xFFFF00:0xFF0000);
g.beginFill(0xFF,0.2);
g.moveTo(o[plane.charAt(0)]*rate,o[plane.charAt(1)]*rate);
g.lineTo(ou[plane.charAt(0)]*rate,ou[plane.charAt(1)]*rate);
if(!rotPick)g.lineStyle(1,0xFF00);
g.lineTo(ouv[plane.charAt(0)]*rate,ouv[plane.charAt(1)]*rate);
if(!rotPick)g.lineStyle(1,0xFF);
g.lineTo(ov[plane.charAt(0)]*rate,ov[plane.charAt(1)]*rate);
if(!rotPick)g.lineStyle(1,0xFF00FF);
g.lineTo(o[plane.charAt(0)]*rate,o[plane.charAt(1)]*rate);
g.endFill();
if(dragPick) {
g.lineStyle(1,0xFFFF00);
g.beginFill(0xFFFF00);
g.drawCircle(midX,midY,4);
g.endFill();
}
}
public var pickLock:Boolean;
protected var _dragPick:Boolean;
public function get dragPick():Boolean{return _dragPick;}
protected var _rotPick:Boolean;
public function get rotPick():Boolean{return _rotPick;}
public function CheckPick():void {
if(pickLock)return;
_dragPick=false;
_rotPick=false;
const rate:Number=image.width/dataWidth;
if(RangeCheck(marker.mouseX,_midX,5) && RangeCheck(marker.mouseY,_midY,5))
_dragPick=true;
else if((image.mouseX>=0) && (image.mouseX<image.width) && (image.mouseY>=0) && (image.mouseY<image.height))
_rotPick=true;
}
public static function RangeCheck(val:Number,mid:Number,spread:Number):Boolean {
if(val<mid-spread)return false;
if(val>mid+spread)return false;
return true;
}
protected function mouseDownHandler(event:MouseEvent):void {
if(!QuickNII.navilock)
beginDrag();
}
protected function mouseOutHandler(event:MouseEvent):void {
if(mouseX<0 || mouseX>width || mouseY<0 || mouseY>height) { // ??
if(pickLock)
endDrag();
}
DrawOverlay();
}
protected function mouseUpHandler(event:MouseEvent):void {
endDrag();
}
protected function mouseMoveHandler(event:MouseEvent):void {
if(pickLock)
doDrag();
else
DrawOverlay();
}
public var downX:Number;
public var downY:Number;
private function beginDrag():void {
sliceDescriptor.CommitChanges();
downX=mouseX;
downY=mouseY;
pickLock=true;
}
private function endDrag():void {
sliceDescriptor.CommitChanges();
pickLock=false;
}
private function doDrag():void {
if(dragPick) {
const rate:Number=image.width/dataWidth;
sliceDescriptor.BaseShift(plane,(downX-mouseX)/rate,(downY-mouseY)/rate);
} else if(rotPick) {
const v1:Vector3D=new Vector3D(midX-downX+image.x,midY-downY+image.y);
const v2:Vector3D=new Vector3D(midX-mouseX+image.x,midY-mouseY+image.y);
const cross:Vector3D=v1.crossProduct(v2);
var angle:Number=Vector3D.angleBetween(v1,v2)*180/Math.PI;
if(cross.z<0)angle=360-angle;
sliceDescriptor.BaseRotate(plane,plane!="xzy"?angle:-angle);
}
}
public function onLeft(event:MouseEvent):void{sliceDescriptor.Shift(plane,-1,0);sliceDescriptor.StopRedo();}
public function onRight(event:MouseEvent):void{sliceDescriptor.Shift(plane,1,0);sliceDescriptor.StopRedo();}
public function onUp(event:MouseEvent):void{sliceDescriptor.Shift(plane,0,-1);sliceDescriptor.StopRedo();}
public function onDown(event:MouseEvent):void{sliceDescriptor.Shift(plane,0,1);sliceDescriptor.StopRedo();}
public function onCCW(event:MouseEvent):void{sliceDescriptor.Rotate(plane,plane!="xzy"?-1:1);sliceDescriptor.StopRedo();}
public function onCW(event:MouseEvent):void{sliceDescriptor.Rotate(plane,plane!="xzy"?1:-1);sliceDescriptor.StopRedo();}
private function aligNavi():void {
topLabel.x=(width-topLabel.width)/2;
bottomLabel.x=(width-bottomLabel.width)/2;
topLabel.y=image.y;//0;
bottomLabel.y=image.y+image.height-bottomLabel.height;//height-bottomLabel.height;
leftLabel.y=(height-leftLabel.height)/2;
rightLabel.y=(height-rightLabel.height)/2;
leftLabel.x=image.x;//0;
rightLabel.x=image.x+image.width-rightLabel.width;//width-rightLabel.width;
axes.x=-0.5;
axes.y=height-0.3-axes.height;
}
]]>
</mx:Script>
<mx:Image id="image" maintainAspectRatio="false" focusEnabled="false"
resize="image_resizeHandler(event)"/>
<local:Axes id="axes"
labels="{plane}"
focusEnabled="false"/>
<mx:Image id="topLabel" source="{topText}" focusEnabled="false"/>
<mx:Image id="bottomLabel" source="{bottomText}" focusEnabled="false"/>
<mx:Image id="leftLabel" source="{leftText}" focusEnabled="false"/>
<mx:Image id="rightLabel" source="{rightText}" focusEnabled="false"/>
<mx:Canvas id="marker" x="{image.x}" y="{image.y}" focusEnabled="false" mask="{clipmask}"/>
<mx:UIComponent id="clipmask"/>
<mx:Button icon="@Embed(source='icons/LeftArrow.png')" x="0" y="0" width="22" height="22" click="onLeft(event)" visible="{!QuickNII.navilock}" enabled="{!QuickNII.navilock}"/>
<mx:Button icon="@Embed(source='icons/RightArrow.png')" x="22" y="0" width="22" height="22" click="onRight(event)" visible="{!QuickNII.navilock}" enabled="{!QuickNII.navilock}"/>
<mx:Button icon="@Embed(source='icons/UpArrow.png')" x="46" y="0" width="22" height="22" click="onUp(event)" visible="{!QuickNII.navilock}" enabled="{!QuickNII.navilock}"/>
<mx:Button icon="@Embed(source='icons/DownArrow.png')" x="68" y="0" width="22" height="22" click="onDown(event)" visible="{!QuickNII.navilock}" enabled="{!QuickNII.navilock}"/>
<mx:Button icon="@Embed(source='icons/RotCCW.png')" x="92" y="0" width="22" height="22" click="onCCW(event)" visible="{!QuickNII.navilock}" enabled="{!QuickNII.navilock}"/>
<mx:Button icon="@Embed(source='icons/RotCW.png')" x="114" y="0" width="22" height="22" click="onCW(event)" visible="{!QuickNII.navilock}" enabled="{!QuickNII.navilock}"/>
</mx:Canvas>