mirror of
https://gitee.com/houstudio/Cdroid.git
synced 2024-12-05 13:48:02 +08:00
roundscrollbar test ok
This commit is contained in:
parent
30dfc630fa
commit
cca7d90d0c
@ -834,10 +834,10 @@ void GradientDrawable::draw(Canvas&canvas) {
|
||||
case OVAL:
|
||||
canvas.save();
|
||||
rad = mRect.height/2.f;
|
||||
canvas.translate(mRect.left + mRect.width/2.f ,mRect.top+mRect.height/2.f);
|
||||
canvas.translate(mRect.centerX(),mRect.centerY());
|
||||
canvas.scale(float(mRect.width)/mRect.height,1.f);
|
||||
LOGV("%p size=%.fx%.f radius=%f strokewidth=%d",this,mRect.width,mRect.height,(float)st->mRadius,st->mStrokeWidth);
|
||||
canvas.move_to(mRect.left+mRect.width/2.f +rad,mRect.top+mRect.height/2.f);
|
||||
canvas.begin_new_sub_path();
|
||||
canvas.arc(0,0,rad,0,M_PI*2.f*(getUseLevel()?(float)getLevel()/10000.f:1));
|
||||
|
||||
if(mFillPaint)canvas.set_source(mFillPaint);
|
||||
@ -863,7 +863,6 @@ void GradientDrawable::draw(Canvas&canvas) {
|
||||
RectF innerBounds = bounds;
|
||||
float x= bounds.width/2.f;
|
||||
float y= bounds.height/2.f;
|
||||
//thickness=20;
|
||||
if( sweep<360.f && sweep>-360.f ) {
|
||||
innerBounds.inflate(x-radius,y-radius);
|
||||
bounds = innerBounds;
|
||||
|
@ -165,10 +165,8 @@ View::View(int w,int h){
|
||||
mBottom = h;
|
||||
mLeft = mTop =0;
|
||||
setBackgroundColor(0xFF000000);
|
||||
#ifdef ENABLE_ROUNDSCROLLBAR
|
||||
if(ViewConfiguration::isScreenRound())
|
||||
mRoundScrollbarRenderer=new RoundScrollbarRenderer(this);
|
||||
#endif
|
||||
mRoundScrollbarRenderer = new RoundScrollbarRenderer(this);
|
||||
}
|
||||
|
||||
View::View(Context*ctx,const AttributeSet&attrs){
|
||||
@ -507,9 +505,7 @@ View::~View(){
|
||||
delete mBackgroundTint;
|
||||
if(mLayoutParams)
|
||||
delete mLayoutParams;
|
||||
#ifdef ENABLE_ROUNDSCROLLBAR
|
||||
delete mRoundScrollbarRenderer;
|
||||
#endif
|
||||
delete mCurrentAnimation;
|
||||
delete mTransformationInfo;
|
||||
delete mOverlay;
|
||||
@ -2356,7 +2352,6 @@ void View::onDrawScrollBars(Canvas& canvas){
|
||||
|
||||
// Fork out the scroll bar drawing for round wearable devices.
|
||||
if (mRoundScrollbarRenderer != nullptr) {
|
||||
#ifdef ENABLE_ROUNDSCROLLBAR
|
||||
if (drawVerticalScrollBar) {
|
||||
Rect& bounds = mScrollCache->mScrollBarBounds;
|
||||
getVerticalScrollBarBounds(&bounds, nullptr);
|
||||
@ -2364,7 +2359,6 @@ void View::onDrawScrollBars(Canvas& canvas){
|
||||
canvas, (float)mScrollCache->scrollBar->getAlpha() / 255.f, bounds);
|
||||
if (bInvalidate) invalidate(true);
|
||||
}
|
||||
#endif
|
||||
// Do not draw horizontal scroll bars for round wearable devices.
|
||||
} else if ( drawVerticalScrollBar || drawHorizontalScrollBar) {
|
||||
ScrollBarDrawable* scrollBar = mScrollCache->scrollBar;
|
||||
@ -5424,10 +5418,8 @@ void View::layout(int l, int t, int w, int h){
|
||||
if(changed|| ((mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED)){
|
||||
onLayout(changed, l, t, w, h);
|
||||
if (shouldDrawRoundScrollbar()) {
|
||||
#ifdef ENABLE_ROUNDSCROLLBAR
|
||||
if(mRoundScrollbarRenderer == nullptr)
|
||||
mRoundScrollbarRenderer = new RoundScrollbarRenderer(this);
|
||||
#endif
|
||||
} else {
|
||||
mRoundScrollbarRenderer = nullptr;
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ namespace cdroid{
|
||||
const int MAX_SCROLLBAR_ANGLE_SWIPE = 16;
|
||||
const int MIN_SCROLLBAR_ANGLE_SWIPE = 6;
|
||||
const float WIDTH_PERCENTAGE = 0.02f;
|
||||
const int DEFAULT_THUMB_COLOR = 0x4CFFFFFF;
|
||||
const int DEFAULT_TRACK_COLOR = 0x26FFFFFF;
|
||||
const int DEFAULT_THUMB_COLOR = 0xFFE8EAED;
|
||||
const int DEFAULT_TRACK_COLOR = 0x4CFFFFFF;
|
||||
|
||||
RoundScrollbarRenderer::RoundScrollbarRenderer(View*parent) {
|
||||
// Paints for the round scrollbar.
|
||||
@ -23,14 +23,14 @@ namespace cdroid{
|
||||
void RoundScrollbarRenderer::drawRoundScrollbars(Canvas&canvas, float alpha,const Rect&bounds) {
|
||||
if (alpha == 0)return;
|
||||
// Get information about the current scroll state of the parent view.
|
||||
float maxScroll = mParent->computeVerticalScrollRange();
|
||||
float scrollExtent = mParent->computeVerticalScrollExtent();
|
||||
const float maxScroll = mParent->computeVerticalScrollRange();
|
||||
const float scrollExtent = mParent->computeVerticalScrollExtent();
|
||||
if (scrollExtent <= 0 || maxScroll <= scrollExtent) {
|
||||
return;
|
||||
}
|
||||
float currentScroll = std::max(0, mParent->computeVerticalScrollOffset());
|
||||
float linearThumbLength = mParent->computeVerticalScrollExtent();
|
||||
float thumbWidth = mParent->getWidth() * WIDTH_PERCENTAGE;
|
||||
const float currentScroll = std::max(0, mParent->computeVerticalScrollOffset());
|
||||
const float linearThumbLength = mParent->computeVerticalScrollExtent();
|
||||
const float thumbWidth = mParent->getWidth() * WIDTH_PERCENTAGE;
|
||||
|
||||
setThumbColor(applyAlpha(DEFAULT_THUMB_COLOR, alpha));
|
||||
setTrackColor(applyAlpha(DEFAULT_TRACK_COLOR, alpha));
|
||||
@ -47,20 +47,24 @@ namespace cdroid{
|
||||
mRect = bounds;
|
||||
mRect.inflate(-thumbWidth /2,0);
|
||||
|
||||
LOGV("alpha=%.2f thumbWidth=%f angle=%f/%f bounds=(%d,%d,%d,%d)",alpha,thumbWidth,
|
||||
startAngle,sweepAngle,mRect.left,mRect.top,mRect.width,mRect.height);
|
||||
const double radius = double(mRect.width)/2.0;
|
||||
canvas.save();
|
||||
canvas.set_line_width(thumbWidth);
|
||||
canvas.set_color(mThumbColor);
|
||||
canvas.set_antialias(Cairo::ANTIALIAS_SUBPIXEL);
|
||||
canvas.set_color(mTrackColor);
|
||||
canvas.set_antialias(Cairo::ANTIALIAS_DEFAULT);
|
||||
canvas.set_line_cap(Cairo::Context::LineCap::ROUND);
|
||||
canvas.arc(mRect.left+mRect.width/2,mRect.top+mRect.height/2,mRect.width/2.,
|
||||
0,M_PI*SCROLLBAR_ANGLE_RANGE/180.);
|
||||
canvas.translate(mRect.centerX(),mRect.centerY());
|
||||
|
||||
canvas.scale(1.f,double(mRect.height)/mRect.width);
|
||||
canvas.begin_new_sub_path();
|
||||
canvas.arc(0,0,radius, -M_PI*SCROLLBAR_ANGLE_RANGE/360.f,M_PI*SCROLLBAR_ANGLE_RANGE/360.f);
|
||||
canvas.stroke();
|
||||
|
||||
canvas.set_color(mTrackColor);
|
||||
canvas.arc(mRect.left+mRect.width/2,mRect.top+mRect.height/2,mRect.width/2.,
|
||||
startAngle*M_PI/180.,(startAngle+sweepAngle)*M_PI/180.);
|
||||
canvas.set_color(mThumbColor);
|
||||
canvas.begin_new_sub_path();
|
||||
canvas.arc(0,0,radius, startAngle*M_PI/180.f,(startAngle+sweepAngle)*M_PI/180.f);
|
||||
canvas.stroke();
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
float RoundScrollbarRenderer::clamp(float val, float min, float max) {
|
||||
@ -74,15 +78,15 @@ namespace cdroid{
|
||||
}
|
||||
|
||||
int RoundScrollbarRenderer::applyAlpha(int color, float alpha) {
|
||||
int alphaByte = (int) (Color::alpha(color) * alpha);
|
||||
return Color::toArgb(alphaByte, Color::red(color), Color::green(color), Color::blue(color));
|
||||
const int alphaByte = (int) (Color::alpha(color) * alpha);
|
||||
return Color::toArgb(Color::red(color), Color::green(color), Color::blue(color),alphaByte);
|
||||
}
|
||||
|
||||
void RoundScrollbarRenderer::setThumbColor(int thumbColor) {
|
||||
mThumbColor=thumbColor;
|
||||
mThumbColor = thumbColor;
|
||||
}
|
||||
|
||||
void RoundScrollbarRenderer::setTrackColor(int trackColor) {
|
||||
mTrackColor=trackColor;
|
||||
mTrackColor = trackColor;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user