Skip to content

Instantly share code, notes, and snippets.

@trxcllnt
Created April 30, 2010 17:13
Show Gist options
  • Save trxcllnt/385495 to your computer and use it in GitHub Desktop.
Save trxcllnt/385495 to your computer and use it in GitHub Desktop.
package com.voyager.clubhouse.modules.admin.view.components.passage.display.interaction
{
import com.voyager.common.view.components.text.interaction.AbstractTextDispatcher;
import com.voyager.common.view.components.text.interaction.LineInfo;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.text.engine.TextLine;
import flash.ui.Mouse;
import flash.ui.MouseCursor;
public class WordTextBehavior extends AbstractTextDispatcher
{
public function WordTextBehavior()
{
super();
}
override protected function mouseMoveHandler(event:MouseEvent):void
{
super.mouseMoveHandler(event);
Mouse.cursor = MouseCursor.BUTTON;
var info:LineInfo = LineInfo.getInfo(event, this);
if(!info)
return;
info.container.blockFactory.decorator.flushDecorations();
var index:int = info.line.getAtomIndexAtPoint(event.stageX, event.stageY);
var center:Number = info.line.getAtomCenter(index);
var p:Point = info.line.globalToLocal(new Point(event.stageX, event.stageY));
if(p.x <= center && index > 0)
{
index--;
}
if(index < 0)
return;
var rect:Rectangle = info.line.getAtomBounds(index);
rect.x += rect.width - 1.5;
rect.width = 3;
rect.y = info.line.y - rect.height;
info.container.blockFactory.decorator.addDecoration(rect, "backgroundColor", ".passageWordOver");
}
override protected function mouseOutHandler(event:MouseEvent):void
{
super.mouseOutHandler(event);
Mouse.cursor = MouseCursor.ARROW;
var info:LineInfo = LineInfo.getInfo(event, this);
if(!info)
return;
info.container.blockFactory.decorator.removeStyle(info.element);
info.container.blockFactory.decorator.addStyle(info.element, ".passageWord");
}
override protected function mouseUpHandler(event:MouseEvent):void
{
super.mouseUpHandler(event);
var info:LineInfo = LineInfo.getInfo(event);
if(!info)
return;
trace(info.element.text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment