1

選択インジケーターで凝ったことをしたいと思います。現在選択されている文字の境界ボックスを取得するにはどうすればよいですか?

4

2 に答える 2

1

これは自明ではありませんでした。まず、選択には複数の長方形が必要になる場合があります。次に、便利な方法はありません。

これが私がしなければならなかったことです:

        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();

        // For each selected character, make a box
        for( var i:int=start; i < end; i++) {

            var flowLine:TextFlowLine = textFlow.flowComposer.findLineAtPosition( i, true );

            if( rectangles[ flowLine.absoluteStart ] == null ) {
                rectangles[ flowLine.absoluteStart ] = new Rectangle();
                (rectangles[ flowLine.absoluteStart ] as Rectangle).x = 0xffffff;
                (rectangles[ flowLine.absoluteStart ] as Rectangle).right = 0;
            }
            var currentRect:Rectangle = rectangles[ flowLine.absoluteStart ];

            var textLine:TextLine = flowLine.getTextLine(true);
            var atomIndex:int = textLine.getAtomIndexAtCharIndex( i );
            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;
于 2011-01-26T20:48:41.800 に答える
0

これを完全に制御する簡単な方法があるとは思いません。ドキュメントを少し調べてみると、次のようになりました。 http://opensource.adobe.com/wiki/display/flexsdk/Spark+Text+Primitives# SparkTextPrimitives-FTE

[Style(name="focusedTextSelectionColor", type="uint", format="Color", inherit="yes")]

[Style(name="inactiveTextSelectionColor", type="uint", format="Color", inherit="yes")]

[Style(name="unfocusedTextSelectionColor", type="uint", format="Color", inherit="yes")]

また、次のことに注意してください。

アンカー位置 - 矢印キーで選択範囲を拡張したときに固定されたままの選択範囲の終わりを指定する文字インデックス。

アクティブな位置 - 矢印キーで選択範囲を拡張したときに移動する選択範囲の末尾を指定する文字インデックス。

これらはすべて色 (またはインデックス) にすぎないため、あなたがやりたいと思う空想が得られるかどうかはわかりません。カスタムのテキスト選択コントロールを処理するために Flex 3 で何かに取り組み、最終的には、画面上のものと同じプロパティを持つ TextField を画面外に配置し、文字を 1 つずつダンプする、ある種の「オフスクリーン バッファ」を使用することになりました。目的の幅に達するまで、文字のどこにコントロールがドロップされたかを把握できました(Androidの選択のようなものです)。

お持ちのSDKで上記のスタイルを検索することをお勧めします(特にRichEditableTextとそのスーパークラスでは、これを行いますが、現在かなりの数のバージョンがあり、使用しているTLFとFTEの両方がわかりません少し流動的なようです)。これらのスタイルが使用されている場所を見つけたら、おそらく選択インジケーターの描画コードの近くにいることになり、適切なメソッドをオーバーライドするために、クラスから拡張する必要があるでしょう。

申し訳ありませんが、率直な答えを出すことはできませんが、うまくいけば、これが役立つか、他の誰かがより簡単な方法があればチャイムを鳴らすことができます.

ショーン

于 2011-01-26T01:27:43.463 に答える