fix pivotx/y

This commit is contained in:
houzh 2024-02-29 11:58:42 +08:00
parent 98a7354ee5
commit 58a24f6a37
2 changed files with 5 additions and 6 deletions

View File

@ -12,7 +12,7 @@ RenderNode::RenderNode(){
mTranslationX = .0f;
mTranslationY = .0f;
mTranslationZ = .0f;
mPivotX = mPivotY = FLT_MIN;//std::numeric_limits<float>::min();
mPivotX = mPivotY = 0.5f;
mRotation = .0f;
mRotationX = .0f;
mRotationY = .0f;
@ -32,13 +32,12 @@ static inline float sdot(float a,float b,float c,float d){
void RenderNode::getMatrix(Matrix&outMatrix)const{
outMatrix = identity_matrix();
const float px = (mPivotX==FLT_MIN) ? (mRight - mLeft)/2.f : mPivotX;
const float py = (mPivotY==FLT_MIN) ? (mBottom- mTop)/2.f : mPivotY;
const float px = (mRight - mLeft)*mPivotX;
const float py = (mBottom- mTop)*mPivotY;
outMatrix.translate(px,py);
outMatrix.scale(mScaleX,mScaleY);
outMatrix.rotate(mRotation*M_PI/180.f);
outMatrix.translate(mTranslationX - px,mTranslationY - py);
//outMatrix.translate((mTranslationX-px)/mScaleX,(mTranslationY-py)/mScaleY);
}
void RenderNode::getInverseMatrix(Matrix&outMatrix)const{

View File

@ -118,8 +118,8 @@ View::View(Context*ctx,const AttributeSet&attrs){
setRotationY( attrs.getFloat("rotationY",0) );
setScaleX( attrs.getFloat("scaleX",1.f) );
setScaleY( attrs.getFloat("scaleY",1.f) );
setPivotX( attrs.getDimensionPixelSize("transformPivotX",0));
setPivotY( attrs.getDimensionPixelSize("transformPivotY",0));
setPivotX( attrs.getFloat("transformPivotX",0.5));
setPivotY( attrs.getFloat("transformPivotY",0.5));
setKeyboardNavigationCluster( attrs.getBoolean("keyboardNavigationCluster",false) );