| 1 |
<?xml version="1.0" encoding="utf-8"?> |
|---|
| 2 |
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" |
|---|
| 3 |
width="144" height="360" |
|---|
| 4 |
implements="org.libspark.gunyarapaint.ui.v1.IController" |
|---|
| 5 |
xmlns:ui="org.libspark.gunyarapaint.ui.v1.*"> |
|---|
| 6 |
<mx:Script> |
|---|
| 7 |
<![CDATA[ |
|---|
| 8 |
import mx.collections.ArrayCollection; |
|---|
| 9 |
import mx.controls.Alert; |
|---|
| 10 |
import mx.core.Application; |
|---|
| 11 |
import mx.events.DragEvent; |
|---|
| 12 |
import mx.events.FlexEvent; |
|---|
| 13 |
import mx.events.ListEvent; |
|---|
| 14 |
import mx.events.SliderEvent; |
|---|
| 15 |
|
|---|
| 16 |
import org.libspark.gunyarapaint.framework.LayerBitmap; |
|---|
| 17 |
import org.libspark.gunyarapaint.framework.LayerBitmapCollection; |
|---|
| 18 |
import org.libspark.gunyarapaint.framework.Painter; |
|---|
| 19 |
import org.libspark.gunyarapaint.framework.UndoStack; |
|---|
| 20 |
import org.libspark.gunyarapaint.framework.events.UndoEvent; |
|---|
| 21 |
import org.libspark.gunyarapaint.framework.ui.IApplication; |
|---|
| 22 |
import org.libspark.gunyarapaint.ui.utils.ComponentResizer; |
|---|
| 23 |
|
|---|
| 24 |
public function init(app:IApplication):void |
|---|
| 25 |
{ |
|---|
| 26 |
var layers:LayerBitmapCollection = app.layers; |
|---|
| 27 |
var currentLayerIndex:uint = layers.currentIndex; |
|---|
| 28 |
var currentLayerBlendMode:String = layers.at(currentLayerIndex).blendMode; |
|---|
| 29 |
var blendModes:Object = blendModeComboBox.dataProvider; |
|---|
| 30 |
var blendModeLength:uint = blendModes.length; |
|---|
| 31 |
var undo:UndoStack = app.undoStack; |
|---|
| 32 |
undo.addEventListener(UndoEvent.UNDO, onChangeUndo); |
|---|
| 33 |
undo.addEventListener(UndoEvent.REDO, onChangeUndo); |
|---|
| 34 |
blendModeComboBox.dataProvider = app.supportedBlendModes; |
|---|
| 35 |
layerDataGrid.selectedIndex = getSelectedIndex(layers); |
|---|
| 36 |
alphaSlider.value = layers.at(currentLayerIndex).alpha; |
|---|
| 37 |
for (var i:uint = 0; i < blendModeLength; i++) { |
|---|
| 38 |
if (blendModes[i].data == currentLayerBlendMode) |
|---|
| 39 |
blendModeComboBox.selectedIndex = i; |
|---|
| 40 |
} |
|---|
| 41 |
layerDataGrid.addEventListener("describeChange", itemCheckChangeHandler); |
|---|
| 42 |
ComponentResizer.addResize(this, new Point(144, 230)); |
|---|
| 43 |
m_initPosition = new Point(x, y); |
|---|
| 44 |
update(); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
public function load(data:Object):void |
|---|
| 48 |
{ |
|---|
| 49 |
var point:Object = data.point; |
|---|
| 50 |
move(point.x, point.y); |
|---|
| 51 |
update(); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
public function save(data:Object):void |
|---|
| 55 |
{ |
|---|
| 56 |
data.point = new Point(x, y); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
public function resetWindow():void |
|---|
| 60 |
{ |
|---|
| 61 |
move(m_initPosition.x, m_initPosition.y); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
public function update():void |
|---|
| 65 |
{ |
|---|
| 66 |
var layers:LayerBitmapCollection = IApplication(Application.application).layers; |
|---|
| 67 |
var layer:LayerBitmap = layers.at(layers.currentIndex); |
|---|
| 68 |
var currentLayerBlendMode:String = layer.blendMode; |
|---|
| 69 |
layerDataGrid.dataProvider = layers.toDataProvider(); |
|---|
| 70 |
layerDataGrid.selectedIndex = getSelectedIndex(layers); |
|---|
| 71 |
alphaSlider.value = layer.alpha; |
|---|
| 72 |
var ac:ArrayCollection = blendModeComboBox.dataProvider as ArrayCollection; |
|---|
| 73 |
var length:uint = ac.length; |
|---|
| 74 |
for (var i:uint = 0; i < length; i++) { |
|---|
| 75 |
if (ac.getItemAt(i).data == currentLayerBlendMode) { |
|---|
| 76 |
blendModeComboBox.selectedIndex = i; |
|---|
| 77 |
return; |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
private function onClickLayer(event:ListEvent):void |
|---|
| 83 |
{ |
|---|
| 84 |
var app:IApplication = IApplication(Application.application); |
|---|
| 85 |
var layer:LayerBitmap = LayerBitmap(event.currentTarget.selectedItem); |
|---|
| 86 |
if (app.layers.currentIndex != layer.index) |
|---|
| 87 |
app.canvasModule.layerIndex = layer.index; |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
private function onCreateLayer(event:Event):void |
|---|
| 91 |
{ |
|---|
| 92 |
try { |
|---|
| 93 |
// should catch AddLayerError here |
|---|
| 94 |
var app:IApplication = IApplication(Application.application); |
|---|
| 95 |
app.canvasModule.createLayer(); |
|---|
| 96 |
update(); |
|---|
| 97 |
} catch (e:Error) { |
|---|
| 98 |
Alert.show(e.message, title); |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
private function onCopyLayer(event:Event):void |
|---|
| 103 |
{ |
|---|
| 104 |
try { |
|---|
| 105 |
// should catch AddLayerError here |
|---|
| 106 |
var app:IApplication = IApplication(Application.application); |
|---|
| 107 |
app.canvasModule.copyLayer(); |
|---|
| 108 |
update(); |
|---|
| 109 |
} catch (e:Error) { |
|---|
| 110 |
Alert.show(e.message, title); |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
private function onRemoveLayer(event:Event):void |
|---|
| 115 |
{ |
|---|
| 116 |
try { |
|---|
| 117 |
// should catch RemoveLayerError here |
|---|
| 118 |
var app:IApplication = IApplication(Application.application); |
|---|
| 119 |
app.canvasModule.removeLayer(); |
|---|
| 120 |
update(); |
|---|
| 121 |
} catch (e:Error) { |
|---|
| 122 |
Alert.show(e.message, title); |
|---|
| 123 |
} |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
private function onMergeLayers(event:Event):void |
|---|
| 127 |
{ |
|---|
| 128 |
try { |
|---|
| 129 |
// should catch MergeLayersError here |
|---|
| 130 |
var app:IApplication = IApplication(Application.application); |
|---|
| 131 |
app.canvasModule.mergeLayers(); |
|---|
| 132 |
update(); |
|---|
| 133 |
} catch (e:Error) { |
|---|
| 134 |
Alert.show(e.message, title); |
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
private function itemCheckChangeHandler(event:Event):void |
|---|
| 139 |
{ |
|---|
| 140 |
// do nothing... |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
private function onChangeAlphaSlider(event:SliderEvent):void |
|---|
| 144 |
{ |
|---|
| 145 |
var app:IApplication = IApplication(Application.application); |
|---|
| 146 |
app.canvasModule.layerAlpha = event.value; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
private function onSelectBlendMode(event:ListEvent):void |
|---|
| 150 |
{ |
|---|
| 151 |
var app:IApplication = IApplication(Application.application); |
|---|
| 152 |
app.canvasModule.layerBlendMode = String(event.currentTarget.value); |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
private function onChangeUndo(event:UndoEvent):void |
|---|
| 156 |
{ |
|---|
| 157 |
update(); |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
private function onDragStart(event:DragEvent):void |
|---|
| 161 |
{ |
|---|
| 162 |
var app:IApplication = IApplication(Application.application); |
|---|
| 163 |
m_selectedIndex = getSelectedIndex(app.layers); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
private function onDragComplete(event:DragEvent):void |
|---|
| 167 |
{ |
|---|
| 168 |
var app:IApplication = IApplication(Application.application); |
|---|
| 169 |
var a:Array = ArrayCollection(layerDataGrid.dataProvider).toArray().reverse(); |
|---|
| 170 |
var length:uint = a.length; |
|---|
| 171 |
var layers:LayerBitmapCollection = app.layers; |
|---|
| 172 |
for (var i:uint = 0; i < length; i++) { |
|---|
| 173 |
var from:uint = a[i].index; |
|---|
| 174 |
var to:uint = layers.at(i).index; |
|---|
| 175 |
if (a[i].index != to) { |
|---|
| 176 |
app.canvasModule.swapLayers(from, to); |
|---|
| 177 |
return; |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
// レイヤーの入れ替え処理がなかった場合はレイヤーの選択位置に戻すように |
|---|
| 181 |
// (例えばレイヤーウィンドウ外にレイヤーをドラッグした時とか) |
|---|
| 182 |
layerDataGrid.selectedIndex = m_selectedIndex; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
private function getSelectedIndex(layers:LayerBitmapCollection):uint |
|---|
| 186 |
{ |
|---|
| 187 |
return layers.count - layers.currentIndex - 1; |
|---|
| 188 |
} |
|---|
| 189 |
|
|---|
| 190 |
private var m_initPosition:Point; |
|---|
| 191 |
private var m_selectedIndex:uint; |
|---|
| 192 |
]]> |
|---|
| 193 |
</mx:Script> |
|---|
| 194 |
<ui:ExtendedDataGrid id="layerDataGrid" x="0" y="43" width="124" height="200" editable="true" sortableColumns="false" dragMoveEnabled="true" dragEnabled="true" dropEnabled="true" |
|---|
| 195 |
itemClick="onClickLayer(event)" dragStart="onDragStart(event)" dragComplete="onDragComplete(event)"> |
|---|
| 196 |
<ui:columns> |
|---|
| 197 |
<mx:DataGridColumn editable="false" headerText="目" dataField="visible" itemRenderer="org.libspark.gunyarapaint.ui.v1.CheckBoxEditor" rendererIsEditor="true" width="20"/> |
|---|
| 198 |
<mx:DataGridColumn editable="false" headerText="ロ" dataField="locked" itemRenderer="org.libspark.gunyarapaint.ui.v1.CheckBoxEditor" rendererIsEditor="true" width="20"/> |
|---|
| 199 |
<!--mx:DataGridColumn headerText="マ" dataField="maskCheck" itemRenderer="org.libspark.gunyarapaint.controls.CheckBoxEditor" rendererIsEditor="true" width="20"/--> |
|---|
| 200 |
<mx:DataGridColumn editable="true" headerText="レイヤ名" dataField="name"/> |
|---|
| 201 |
</ui:columns> |
|---|
| 202 |
</ui:ExtendedDataGrid> |
|---|
| 203 |
<mx:Button x="6" y="246" id="newLayerButton" label="新" width="22" paddingLeft="0" paddingRight="0" buttonDown="onCreateLayer(event)"/> |
|---|
| 204 |
<mx:Button x="36" y="246" id="copyLayerButton" label="複" width="22" paddingLeft="0" paddingRight="0" buttonDown="onCopyLayer(event)"/> |
|---|
| 205 |
<mx:Button x="66" y="246" id="deleteLayerButton" label="削" width="22" paddingLeft="0" paddingRight="0" buttonDown="onRemoveLayer(event)"/> |
|---|
| 206 |
<mx:Button x="96" y="246" id="mergeLayerButton" label="統" width="22" paddingLeft="0" paddingRight="0" buttonDown="onMergeLayers(event)"/> |
|---|
| 207 |
<mx:ComboBox id="blendModeComboBox" x="0" y="0" width="124" change="onSelectBlendMode(event)"></mx:ComboBox> |
|---|
| 208 |
<mx:Label x="5" y="23" text="透"/> |
|---|
| 209 |
<mx:HSlider id="alphaSlider" x="18" y="20" width="99" minimum="0.05" maximum="1" snapInterval="0.05" value="1" change="onChangeAlphaSlider(event)"/> |
|---|
| 210 |
<mx:Button id="horizontalMirrorButton" label="全レイヤー左右反転" width="117" height="17" buttonDown="IApplication(Application.application).canvasModule.horizontalMirror(Painter.ALL_LAYERS)" y="273" x="3"/> |
|---|
| 211 |
<mx:Button id="verticalMirrorButton" label="全レイヤー上下反転" width="117" height="17" buttonDown="IApplication(Application.application).canvasModule.verticalMirror(Painter.ALL_LAYERS)" x="3" y="295"/> |
|---|
| 212 |
</mx:TitleWindow> |
|---|