mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-05 05:37:53 +08:00
fix numberpicker's fadingedge
This commit is contained in:
parent
89ad75addb
commit
0f643ae309
@ -136,8 +136,8 @@ public:
|
||||
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);
|
||||
shader->add_color_stop_rgba(0.f,0,0,0,1.f);
|
||||
shader->add_color_stop_rgba(1.f,0,0,0,0.f);
|
||||
this->host=host;
|
||||
mRunner =[this](){
|
||||
run();
|
||||
@ -2850,8 +2850,9 @@ void View::draw(Canvas&canvas){
|
||||
|
||||
if (drawBottom) {
|
||||
canvas.save();
|
||||
canvas.translate(left,bottom);
|
||||
canvas.scale(1,-fadeHeight * bottomFadeStrength);
|
||||
canvas.translate(right,bottom);
|
||||
canvas.rotate_degrees(-180);
|
||||
canvas.scale(1,fadeHeight * bottomFadeStrength);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(0,0,right-left,length);
|
||||
canvas.fill();
|
||||
@ -2860,21 +2861,23 @@ void View::draw(Canvas&canvas){
|
||||
|
||||
if (drawLeft) {
|
||||
canvas.save();
|
||||
canvas.translate(left, top);
|
||||
canvas.scale(fadeHeight * leftFadeStrength,1);
|
||||
canvas.translate(left, bottom);
|
||||
canvas.rotate_degrees(90);
|
||||
canvas.scale(1,fadeHeight * leftFadeStrength);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(0,0, length, bottom);
|
||||
canvas.rectangle(0,0,bottom - top, length + 200);
|
||||
canvas.fill();
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
if (drawRight) {
|
||||
canvas.save();
|
||||
canvas.scale(1, fadeHeight * rightFadeStrength);
|
||||
canvas.rotate_degrees(90);
|
||||
canvas.translate(right, top);
|
||||
canvas.rotate_degrees(-90);
|
||||
canvas.scale(1, fadeHeight * rightFadeStrength);
|
||||
canvas.set_source(fade);
|
||||
canvas.rectangle(right - length, top, right, bottom);
|
||||
canvas.rectangle(0,0,bottom - top,length);
|
||||
canvas.fill();
|
||||
canvas.restore();
|
||||
}
|
||||
// Step 6, draw decorations (foreground, scrollbars)
|
||||
|
@ -85,7 +85,6 @@ NumberPicker::NumberPicker(Context* context,const AttributeSet& atts)
|
||||
mTextSize2 = atts.getDimensionPixelSize("textSize2",mTextSize);
|
||||
setSelectedTextSize(atts.getDimensionPixelSize("selectedTextSize",mSelectedTextSize));
|
||||
setTextColor(atts.getColor("textColor"));
|
||||
setTextColor(mTextColor,atts.getColor("textColor2",mTextColor));
|
||||
setSelectedTextColor(atts.getColor("selectedTextColor"));
|
||||
ColorStateList*colors=mSelectedText->getTextColors();
|
||||
if(colors->isStateful())
|
||||
@ -916,12 +915,12 @@ void NumberPicker::onResolveDrawables(int layoutDirection){
|
||||
|
||||
void NumberPicker::setTextColor(int color){
|
||||
mTextColor = color;
|
||||
mTextColor2= color;
|
||||
// mTextColor2= color;
|
||||
invalidate();
|
||||
}
|
||||
void NumberPicker::setTextColor(int color,int color2){
|
||||
mTextColor = color;
|
||||
mTextColor2 = color2;
|
||||
//mTextColor2 = color2;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@ -1025,29 +1024,8 @@ void NumberPicker::onDraw(Canvas&canvas){
|
||||
canvas.clip();
|
||||
}
|
||||
}
|
||||
if( mTextColor != mTextColor2 ){
|
||||
if( mPat == nullptr ) {
|
||||
Color c1(mTextColor), c2(mTextColor2);
|
||||
CycleInterpolator ci(0.5f);
|
||||
if(isHorizontalMode())
|
||||
mPat = Cairo::LinearGradient::create(x + mSelectorElementSize/2,0,x + mSelectorElementSize/2 + getWidth(),0);
|
||||
else
|
||||
mPat = Cairo::LinearGradient::create(0,y + mSelectorElementSize/2,0,y + mSelectorElementSize/2 + getHeight());
|
||||
const int cStops = mSelectorIndices.size()*3;
|
||||
for(int i = 0; i < cStops ;i++){
|
||||
const float offset = (i<cStops/2)?sin(M_PI*i/(cStops-1))/2.f:(1.f+sin(M_PI*i/(cStops-1))/2.f);//float(i)/cStops;
|
||||
const float fraction = ci.getInterpolation(offset);
|
||||
mPat->add_color_stop_rgba(offset,lerp(c2.red(),c1.red(),fraction),
|
||||
lerp(c2.green(),c1.green(),fraction),
|
||||
lerp(c2.blue(),c1.blue(),fraction),
|
||||
std::abs(lerp(c2.alpha(),c1.alpha(),fraction)));
|
||||
LOGV("[%d] offset=%.2f/%f fraction=%f alpha=%f",i,float(i)/cStops,offset,fraction,lerp(c2.alpha(),c1.alpha(),fraction));
|
||||
}
|
||||
}
|
||||
canvas.set_source(mPat);
|
||||
}else{
|
||||
canvas.set_color(mTextColor);
|
||||
}
|
||||
|
||||
canvas.set_color(mTextColor);
|
||||
canvas.set_font_size(mTextSize);
|
||||
// draw the selector wheel
|
||||
std::vector<int>& selectorIndices = mSelectorIndices;
|
||||
|
@ -53,7 +53,7 @@ private:
|
||||
bool mComputeMaxWidth;
|
||||
int mTextSize,mTextSize2;
|
||||
int mSelectedTextSize;
|
||||
int mTextColor,mTextColor2;
|
||||
int mTextColor;
|
||||
int mSelectedTextColor;
|
||||
int mSelectorTextGapWidth;
|
||||
int mSelectorTextGapHeight;
|
||||
@ -116,7 +116,6 @@ private:
|
||||
int mLastHandledDownDpadKeyCode = -1;
|
||||
bool mHideWheelUntilFocused;
|
||||
bool mWrapSelectorWheelPreferred=true;
|
||||
Cairo::RefPtr<Cairo::LinearGradient>mPat;
|
||||
|
||||
//PressedStateHelper's members
|
||||
Runnable mPressedStateHelpers;
|
||||
|
Loading…
Reference in New Issue
Block a user