fix gradientdrawable's roundrectangle while size is less than radii

This commit is contained in:
houzh 2024-03-01 19:18:28 +08:00
parent efbd404115
commit 0cb4cb8913
2 changed files with 15 additions and 5 deletions

View File

@ -40,14 +40,14 @@ private:
public: public:
static constexpr long DURATION_INFINITE = -1; static constexpr long DURATION_INFINITE = -1;
class AnimatorListener:virtual public EventSet{ class AnimatorListener:public EventSet{
public: public:
CallbackBase<void,Animator& /*animation*/, bool/*isReverse*/>onAnimationStart; CallbackBase<void,Animator& /*animation*/, bool/*isReverse*/>onAnimationStart;
CallbackBase<void,Animator& /*animation*/, bool/*isReverse*/>onAnimationEnd; CallbackBase<void,Animator& /*animation*/, bool/*isReverse*/>onAnimationEnd;
CallbackBase<void,Animator& /*animation*/>onAnimationCancel; CallbackBase<void,Animator& /*animation*/>onAnimationCancel;
CallbackBase<void,Animator& /*animation*/>onAnimationRepeat; CallbackBase<void,Animator& /*animation*/>onAnimationRepeat;
}; };
class AnimatorPauseListener:virtual public EventSet{ class AnimatorPauseListener:public EventSet{
public: public:
CallbackBase<void,Animator&> onAnimationPause; CallbackBase<void,Animator&> onAnimationPause;
CallbackBase<void,Animator&> onAnimationResume; CallbackBase<void,Animator&> onAnimationResume;
@ -100,7 +100,7 @@ public:
virtual void reverse(); virtual void reverse();
}; };
class AnimatorListenerAdapter:public Animator::AnimatorListener,Animator::AnimatorPauseListener{ class AnimatorListenerAdapter:public Animator::AnimatorListener,public Animator::AnimatorPauseListener{
public: public:
AnimatorListenerAdapter(); AnimatorListenerAdapter();
}; };

View File

@ -854,6 +854,16 @@ static void drawRound(Canvas&canvas,const RectF&r,const std::vector<float>&radii
float db=180.f; float db=180.f;
float pts[8]; float pts[8];
double radian = M_PI; double radian = M_PI;
if((r.width<radii[0]+radii[1])||(r.height<radii[0]+radii[1])){
const float d = (radii[0]+radii[1]-r.width)/2;
const float dd= sqrt(radii[0]*radii[0]-d*d)*2;
const bool insetHoriz =r.width>r.height;
RectF rclip = r;
if(insetHoriz==false)rclip.inset(0,(r.height-dd)/2.f);
else rclip.inset((r.width-dd)/2.f,0);
canvas.rectangle(rclip.left,rclip.top,rclip.width,rclip.height);
canvas.clip();
}
pts[0]=r.left + radii[0]; pts[0]=r.left + radii[0];
pts[1]=r.top + radii[0]; pts[1]=r.top + radii[0];
pts[2]=r.right() - radii[1]; pts[2]=r.right() - radii[1];
@ -862,12 +872,12 @@ static void drawRound(Canvas&canvas,const RectF&r,const std::vector<float>&radii
pts[5]=r.bottom()- radii[2]; pts[5]=r.bottom()- radii[2];
pts[6]=r.left + radii[3]; pts[6]=r.left + radii[3];
pts[7]=r.bottom()- radii[3]; pts[7]=r.bottom()- radii[3];
canvas.begin_new_sub_path(); //canvas.begin_new_sub_path();
for(int i=0,j=0; i<8; i+=2,j++) { for(int i=0,j=0; i<8; i+=2,j++) {
canvas.arc(pts[i],pts[i+1],radii[j],radian,radian+M_PI/2.0); canvas.arc(pts[i],pts[i+1],radii[j],radian,radian+M_PI/2.0);
radian += M_PI/2.0; radian += M_PI/2.0;
} }
canvas.close_path(); //canvas.close_path();
} }
} }