flex - How do I get a bounding box for the current selection? -


i'd fancy things selection indicator. how bounding box selected characters?

this non-trivial. first, selection may require more 1 rectangle. next, there's no convenient way it.

here's had do:

        var start:int = op.activeposition < op.anchorposition ? op.activeposition : op.anchorposition;         var end:int = op.activeposition > op.anchorposition ? op.activeposition : op.anchorposition;          var textflow:textflow = this.textflow;         var rectangles:dictionary = new dictionary();          // each selected character, make box         for( var i:int=start; < end; i++) {              var flowline:textflowline = textflow.flowcomposer.findlineatposition( i, true );              if( rectangles[ flowline.absolutestart ] == null ) {                 rectangles[ flowline.absolutestart ] = new rectangle();                 (rectangles[ flowline.absolutestart ] rectangle).x = 0xffffff;                 (rectangles[ flowline.absolutestart ] rectangle).right = 0;             }             var currentrect:rectangle = rectangles[ flowline.absolutestart ];              var textline:textline = flowline.gettextline(true);             var atomindex:int = textline.getatomindexatcharindex( );             if( atomindex >= 0) {                 var atombounds:rectangle = textline.getatombounds( atomindex );                  var pt:point = this.globaltolocal( textline.localtoglobal( new point( atombounds.left, atombounds.top ) ) );                                     if( pt.x <= currentrect.left ) {                     currentrect.left = pt.x;                     currentrect.top = pt.y;                 }                  pt = this.globaltolocal( textline.localtoglobal( new point( atombounds.right, atombounds.bottom) ) );                 if( pt.x >= currentrect.right ) {                     currentrect.right = pt.x;                     currentrect.bottom = pt.y;                 }                                }         }          return rectangles; 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -