Comunidad de diseño web y desarrollo en internet online

como mensurar o medir textField con filtros?

Citar            
MensajeEscrito el 29 Jun 2010 08:33 pm
Hola gente, alguien sabe como obtener el ancho y alto de un textField en AS3, teniendo en cuenta que tiene aplicado un filtro dropShadow, el cual no se tiene en cuenta al leer las propiedades width y height.
Osea, lo que digo es que con o sin sombra width y height devuelven las medidas del texto, sin contan la sombra.
Necesito sabes el las dimensiones totales, incluyendo la sombra.

muchas gracias por su ayuda!
saludos

Por yo_k_ballo

13 de clabLevel



 

firefox
Citar            
MensajeEscrito el 01 Jul 2010 07:33 am
Lo que quieres se puede lograr calculando la coordenada polar.

Código ActionScript :

//Digamos que tienes esta sombra:
var distance:Number = 4;
var angle:Number = 45;
var blurX:Number = 4;
var blurY:Number = 4;

myText.filters = [new DropShadowFilter(distance, angle, 0x000000, 1, blurX, blurY)];

//Entonces calculamos la polar:
import flash.geom.Point;
var shadowDistance:Number= Point.distance(new Point(), new Point(distance + blurX, distance + blurY));
var angleRadians:Number = angle / (180/Math.PI);
var pShadow:Point = Point.polar( shadowDistance, angleRadians);

Listo! ya tienes la distancia que proyecta tu sombra, ahora sólo debes sumarla al ancho de tu texto.

Código ActionScript :

var shadowWidth:Number = pShadow.x;
var shadowHeight:Number = pShadow.y;

var _width:Number = myText.width + shadowWidth;
var _height:Number = myText.height + shadowHeight;

Sin embargo, en el caso de la sombra, cuando la distancia es menor que el difuminado (distance < blur), la sombra puede ocupar unos pixeles en el sentido contrario.

Para solucionar esto haremos una validación:

Código ActionScript :

var offset:Point = new Point();
if( distance < blurX ) offset.x = distance - blurX;
if( distance < blurY ) offset.y = distance - blurY;

var shadowWidth:Number = pShadow.x + offset.x;
var shadowHeight:Number = pShadow.y + offset.y;

// Valores finales
var _width:Number = myText.width + shadowWidth;
var _height:Number = myText.height + shadowHeight;
var _x:Number = offset.x;
var _y:Number = offset.y;


Podrías mantener los valores en un Rectangle ( new Rectangle(_x, _y, _width, _height) ), según lo que quieras hacer.

y listo!, Espero te sirva ;) .

Por Otaku RzO

BOFH

1890 de clabLevel

12 tutoriales
1 articulo

Genero:Masculino   Desarrollador de GAIA Bastard Operators From Hell

Lima - Perú

firefox
Citar            
MensajeEscrito el 01 Jul 2010 07:37 pm
muchas gracias!! me ha sido util.

tambien he logrado un resultado bastante acertado de esta manera

var shadowWidth:Number = Math.cos(toRadians(shadow.angle))*(shadow.distance+shadow.blurX)
var shadowHeight:Number = Math.sin(toRadians(shadow.angle))*(shadow.distance+shadow.blurY)

lo dejo por si a alguien le resulta util

saludos

Por yo_k_ballo

13 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.