我在面板中有一个主画布“黑板”,这个画布本身有几个孩子,如工具栏(图块)、标签和一些皮肤。
问题是,当我移动到矩形工具并开始绘制矩形时,如果我想在单击其他工具(例如“圆形”或“选择”)时更改工具,则按钮不会捕获单击事件,而是画布将抓住鼠标并开始绘图。
就像图片上一样。因此,一旦开始绘图,我就无法更换工具。
替代文字 http://www.freeimagehosting.net/uploads/397a7cd49e.png
我怎么能让画布在工具上时不做出反应,或者我怎么能让按钮先捕捉到点击并告诉画布不画任何东西。
当然,我可以将工具栏放在画布上以外的其他地方,但由于空间很重要,我希望按钮位于画布上。
我愿意接受任何建议。
=== 这里有一些代码来展示它是如何在内部工作的。===
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:degrafa="http://www.degrafa.com/2007"
xmlns:comp="org.foo.bar.view.components.*"
layout="absolute"
title="Tableau">
<mx:Script>
<![CDATA[
import org.edorado.edoboard.ApplicationFacade;
]]>
</mx:Script>
<mx:Canvas id="blackBoard">
<degrafa:Surface id="boardSurfaceContainer">
skinning
</degrafa:Surface>
<!-- Tool bar -->
<comp:ToolbarView
id = "toolbar"
name = "toolbar"
verticalScrollPolicy="off"
horizontalScrollPolicy="off"
bottom="5"
right="5"
top="5"
direction="vertical"
width="30" />
<mx:Label x="10" y="10" text="Label" color="#FFFFFF" id="lbl"/>
</mx:Canvas>
</mx:Panel>
工具栏是包含在磁贴中的按钮列表。画布“黑板”链接到几个事件处理,特别是鼠标上下移动以绘制形状。
...
boardCanvas.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
boardCanvas.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
...
private function handleMouseDown(event:MouseEvent):void {
// Get the current mouse location which may be adjusted to the grid
var selectPoint:Point = boardCanvas.globalToLocal(new Point(event.stageX, event.stageY));
startPoint = snapPoint(selectPoint.x, selectPoint.y);
boardView.lbl.text = '(' + startPoint.x +',' + startPoint.y + ')';
....
工具栏也听点击
<?xml version="1.0" encoding="utf-8"?>
<mx:Tile xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.charts.BubbleChart;
import org.edorado.edoboard.view.components.shapes.*;
public static const TOOL_CHANGE:String = "toolChange";
public static const TEXT_TOOL:String = "textTool";
public static const SELECT_TOOL:String = "selectTool";
public static const RECTANGLE_TOOL:String = "rectangleTool";
private var b:Button = null;
private function handleButtonClick(event:MouseEvent):void {
trace("CLICKED TOOL");
// selectButton.dispatchEvent(new Event(TOOL_CHANGE, true, true))
b = event.target as Button;
b.dispatchEvent(new Event(TOOL_CHANGE, true, true));
}
]]>
</mx:Script>
<!-- Use class facotry ? -->
<mx:Button id="selectButton"
name="{SELECT_TOOL}"
selectedUpSkin="assets.skins.ToolButtonSkin"
width="30"
height="30"
styleName="selectButton"
toolTip="selection"
click="handleButtonClick(event); " />
<mx:Button id="textButton"
name = "{TEXT_TOOL}"
selectedUpSkin="assets.skins.ToolButtonSkin"
width="30"
height="30"
styleName="textButton"
toolTip="text"
click="handleButtonClick(event);" />
<mx:Button id="rectButton"
name = "{RECTANGLE_TOOL}"
selectedUpSkin="assets.skins.ToolButtonSkin"
width="30"
height="30"
styleName="rectButton"
toolTip="rectButton"
click="handleButtonClick(event);" />
</mx:Tile>