mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-05 13:48:02 +08:00
add fadingadge support(only vertical edges)
This commit is contained in:
parent
4394242830
commit
89ad75addb
@ -1,5 +1,5 @@
|
||||
#include <animation/animator.h>
|
||||
|
||||
#include <algorithm>
|
||||
namespace cdroid{
|
||||
Animator::~Animator(){
|
||||
}
|
||||
@ -60,22 +60,26 @@ std::shared_ptr<ConstantState<Animator*>> Animator::createConstantState(){
|
||||
return nullptr;//new AnimatorConstantState(this);
|
||||
}
|
||||
|
||||
void Animator::addListener(AnimatorListener listener) {
|
||||
void Animator::addListener(const AnimatorListener& listener) {
|
||||
mListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void Animator::removeListener(AnimatorListener listener){
|
||||
void Animator::removeListener(const AnimatorListener& listener){
|
||||
auto it = std::find(mListeners.begin(), mListeners.end(),listener);
|
||||
if( it!=mListeners.end() ) mListeners.erase(it);
|
||||
}
|
||||
|
||||
std::vector<Animator::AnimatorListener> Animator::getListeners() {
|
||||
return mListeners;
|
||||
}
|
||||
|
||||
void Animator::addPauseListener(AnimatorPauseListener listener) {
|
||||
void Animator::addPauseListener(const AnimatorPauseListener& listener) {
|
||||
mPauseListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void Animator::removePauseListener(AnimatorPauseListener listener){
|
||||
void Animator::removePauseListener(const AnimatorPauseListener& listener){
|
||||
auto it = std::find(mPauseListeners.begin(),mPauseListeners.end(),listener);
|
||||
if( it != mPauseListeners.end() ) mPauseListeners.erase(it);
|
||||
}
|
||||
|
||||
void Animator::removeAllListeners() {
|
||||
|
@ -40,14 +40,14 @@ private:
|
||||
public:
|
||||
static constexpr long DURATION_INFINITE = -1;
|
||||
|
||||
class AnimatorListener{
|
||||
class AnimatorListener:public EventSet{
|
||||
public:
|
||||
CallbackBase<void,Animator& /*animation*/, bool/*isReverse*/>onAnimationStart;
|
||||
CallbackBase<void,Animator& /*animation*/, bool/*isReverse*/>onAnimationEnd;
|
||||
CallbackBase<void,Animator& /*animation*/>onAnimationCancel;
|
||||
CallbackBase<void,Animator& /*animation*/>onAnimationRepeat;
|
||||
};
|
||||
class AnimatorPauseListener{
|
||||
class AnimatorPauseListener:public EventSet{
|
||||
public:
|
||||
CallbackBase<void,Animator&> onAnimationPause;
|
||||
CallbackBase<void,Animator&> onAnimationResume;
|
||||
@ -83,11 +83,11 @@ public:
|
||||
virtual TimeInterpolator* getInterpolator();
|
||||
virtual bool isRunning()=0;
|
||||
virtual bool isStarted();
|
||||
void addListener(AnimatorListener listener);
|
||||
void removeListener(AnimatorListener listener);
|
||||
void addListener(const AnimatorListener& listener);
|
||||
void removeListener(const AnimatorListener& listener);
|
||||
std::vector<AnimatorListener> getListeners();
|
||||
void addPauseListener(AnimatorPauseListener listener);
|
||||
void removePauseListener(AnimatorPauseListener listener);
|
||||
void addPauseListener(const AnimatorPauseListener& listener);
|
||||
void removePauseListener(const AnimatorPauseListener& listener);
|
||||
void removeAllListeners();
|
||||
int getChangingConfigurations();
|
||||
void setChangingConfigurations(int configs);
|
||||
|
@ -520,10 +520,10 @@ static Drawable*parseShapeDrawable(const AttributeSet&atts,const std::vector<Att
|
||||
|
||||
if(stroke) {
|
||||
d->setStroke(stroke->getDimensionPixelSize("width",1),stroke->getColor("color",0),
|
||||
stroke->getDimensionPixelSize("dashWidth"),stroke->getDimensionPixelSize("dashGap"));
|
||||
stroke->getDimensionPixelSize("dashWidth"),stroke->getDimensionPixelSize("dashGap"));
|
||||
}
|
||||
if(padding)d->setPadding(padding->getInt("left"),padding->getInt("top"),
|
||||
padding->getInt("right"),padding->getInt("bottom"));
|
||||
padding->getInt("right"),padding->getInt("bottom"));
|
||||
return d;
|
||||
} else {
|
||||
ShapeDrawable*sd=new ShapeDrawable();
|
||||
|
@ -122,6 +122,7 @@ public:
|
||||
|
||||
int mScrollBarDraggingState = NOT_DRAGGING;
|
||||
int mScrollBarDraggingPos;
|
||||
Cairo::RefPtr<LinearGradient> shader;
|
||||
public:
|
||||
ScrollabilityCache(ViewConfiguration&configuration,View*host){//int sz){
|
||||
fadingEdgeLength = configuration.getScaledFadingEdgeLength();
|
||||
@ -134,6 +135,9 @@ public:
|
||||
mScrollBarDraggingPos = 0;
|
||||
mScrollBarBounds.set(0,0,0,0);
|
||||
mScrollBarTouchBounds.set(0,0,0,0);
|
||||
shader = LinearGradient::create(0,0,0,1);
|
||||
shader->add_color_stop_rgba(0.f,1.0,0,0,.8f);
|
||||
shader->add_color_stop_rgba(1.f,0,0,0,.0f);
|
||||
this->host=host;
|
||||
mRunner =[this](){
|
||||
run();
|
||||
@ -2790,7 +2794,7 @@ void View::draw(Canvas&canvas){
|
||||
}
|
||||
|
||||
int left = mScrollX + paddingLeft;
|
||||
int right = left + (mRight-mLeft) - mPaddingRight - paddingLeft;
|
||||
int right = left + (mRight - mLeft) - mPaddingRight - paddingLeft;
|
||||
int top = mScrollY + getFadeTop(offsetRequired);
|
||||
int bottom = top + getFadeHeight(offsetRequired);
|
||||
|
||||
@ -2834,40 +2838,45 @@ void View::draw(Canvas&canvas){
|
||||
dispatchDraw(canvas);
|
||||
|
||||
// Step 5, draw the fade effect and restore layers
|
||||
/*if (drawTop) {
|
||||
matrix.setScale(1, fadeHeight * topFadeStrength);
|
||||
matrix.postTranslate(left, top);
|
||||
fade.setLocalMatrix(matrix);
|
||||
p.setShader(fade);
|
||||
canvas.drawRect(left, top, right, top + length, p);
|
||||
Cairo::RefPtr<LinearGradient>fade = getScrollCache()->shader;
|
||||
if (drawTop) {
|
||||
canvas.save();
|
||||
canvas.scale(1,fadeHeight * topFadeStrength);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(left, top,right-left,length);
|
||||
canvas.fill();
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (drawBottom) {
|
||||
matrix.setScale(1, fadeHeight * bottomFadeStrength);
|
||||
matrix.postRotate(180);
|
||||
matrix.postTranslate(left, bottom);
|
||||
fade.setLocalMatrix(matrix);
|
||||
p.setShader(fade);
|
||||
canvas.drawRect(left, bottom - length, right, bottom, p);
|
||||
canvas.save();
|
||||
canvas.translate(left,bottom);
|
||||
canvas.scale(1,-fadeHeight * bottomFadeStrength);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(0,0,right-left,length);
|
||||
canvas.fill();
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (drawLeft) {
|
||||
matrix.setScale(1, fadeHeight * leftFadeStrength);
|
||||
matrix.postRotate(-90);
|
||||
matrix.postTranslate(left, top);
|
||||
fade.setLocalMatrix(matrix);
|
||||
p.setShader(fade);
|
||||
canvas.drawRect(left, top, left + length, bottom, p);
|
||||
canvas.save();
|
||||
canvas.translate(left, top);
|
||||
canvas.scale(fadeHeight * leftFadeStrength,1);
|
||||
canvas.rotate_degrees(90);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(0,0, length, bottom);
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (drawRight) {
|
||||
matrix.setScale(1, fadeHeight * rightFadeStrength);
|
||||
matrix.postRotate(90);
|
||||
matrix.postTranslate(right, top);
|
||||
fade.setLocalMatrix(matrix);
|
||||
p.setShader(fade);
|
||||
canvas.drawRect(right - length, top, right, bottom, p);
|
||||
}*/
|
||||
canvas.save();
|
||||
canvas.scale(1, fadeHeight * rightFadeStrength);
|
||||
canvas.rotate_degrees(90);
|
||||
canvas.translate(right, top);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(right - length, top, right, bottom);
|
||||
canvas.restore();
|
||||
}
|
||||
// Step 6, draw decorations (foreground, scrollbars)
|
||||
drawAutofilledHighlight(canvas);
|
||||
if(mOverlay && !mOverlay->isEmpty())
|
||||
|
@ -1057,11 +1057,11 @@ void NumberPicker::onDraw(Canvas&canvas){
|
||||
if(mTextSize != mTextSize2){
|
||||
if(isHorizontalMode()){
|
||||
const float harfWidth = getWidth()/2.f;
|
||||
const float fraction = std::abs(x-harfWidth)/harfWidth;
|
||||
const float fraction = std::abs(x - harfWidth)/harfWidth;
|
||||
font_size = lerp(mTextSize,mTextSize2,fraction);
|
||||
}else{
|
||||
const float harfHeight = getHeight()/2.f;
|
||||
const float fraction = std::abs(y-harfHeight+mSelectorElementSize/2)/harfHeight;
|
||||
const float fraction = std::abs(y - harfHeight + mSelectorElementSize/2)/harfHeight;
|
||||
font_size = lerp(mTextSize,mTextSize2,fraction);
|
||||
}
|
||||
canvas.set_font_size(font_size);
|
||||
@ -1266,8 +1266,8 @@ void NumberPicker::initializeSelectorWheelIndices(){
|
||||
if (mWrapSelectorWheel) {
|
||||
selectorIndex = getWrappedSelectorIndex(selectorIndex);
|
||||
}
|
||||
if(mSelectorIndices.size() > count && count > 0 )
|
||||
selectorIndex = (selectorIndex + count)%count;/*make wrapable*/
|
||||
if(mSelectorIndices.size() > count && count)
|
||||
selectorIndex = (selectorIndex + count)%count;/*make wrapable*/
|
||||
mSelectorIndices[i] = selectorIndex;
|
||||
ensureCachedScrollSelectorValue(mSelectorIndices[i]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user