Пример #1
0
 /// <summary>
 /// 添加菜单
 /// </summary>
 /// <param name="roundMenu"> </param>
 public virtual void AddRoundMenu(RoundMenu roundMenu)
 {
     if (roundMenu == null)
     {
         return;
     }
     if (roundMenus == null)
     {
         roundMenus = new List <RoundMenu>();
     }
     roundMenus.Add(roundMenu);
     Invalidate();
 }
Пример #2
0
        protected override void OnDraw(Canvas canvas)
        {
            coreX       = Width / 2;
            coreY       = Height / 2;
            roundRadius = (int)(Width / 2 * radiusDistance); //计算中心圆圈半径

            RectF rect = new RectF(0, 0, Width, Height);

            if (roundMenus != null && roundMenus.Count > 0)
            {
                float sweepAngle = 360 / roundMenus.Count; //每个弧形的角度
                deviationDegree = sweepAngle / 2;          //其实的偏移角度,如果4个扇形的时候是X形状,而非+,设为0试试就知道什么意思了
                for (int i = 0; i < roundMenus.Count; i++)
                {
                    RoundMenu roundMenu = roundMenus[i];
                    //填充
                    Paint paint = new Paint();
                    paint.AntiAlias = true;
                    if (onClickState == i)
                    {
                        //选中
                        paint.Color = new Color(roundMenu.selectSolidColor);
                    }
                    else
                    {
                        //未选中
                        paint.Color = new Color(roundMenu.solidColor);
                    }
                    canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, true, paint);

                    //画描边
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = roundMenu.strokeSize;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = new Color(roundMenu.strokeColor);
                    canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, roundMenu.useCenter, paint);

                    //画图案
                    Matrix matrix = new Matrix();
                    matrix.PostTranslate((float)((coreX + Width / 2 * roundMenu.iconDistance) - (roundMenu.icon.Width / 2)), coreY - (roundMenu.icon.Height / 2));
                    matrix.PostRotate(((i + 1) * sweepAngle), coreX, coreY);
                    canvas.DrawBitmap(roundMenu.icon, matrix, null);
                }
            }

            //画中心圆圈
            if (isCoreMenu)
            {
                //填充
                RectF rect1 = new RectF(coreX - roundRadius, coreY - roundRadius, coreX + roundRadius, coreY + roundRadius);
                Paint paint = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = coreMenuStrokeSize;
                if (onClickState == -1)
                {
                    paint.Color = new Color(coreMenuSelectColor);
                }
                else
                {
                    paint.Color = new Color(coreMenuColor);
                }
                canvas.DrawArc(rect1, 0, 360, true, paint);

                //画描边
                paint             = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = coreMenuStrokeSize;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = new Color(coreMenuStrokeColor);
                canvas.DrawArc(rect1, 0, 360, true, paint);
                if (coreBitmap != null)
                {
                    //画中心圆圈的"OK"图标
                    canvas.DrawBitmap(coreBitmap, coreX - coreBitmap.Width / 2, coreY - coreBitmap.Height / 2, null); //在 0,0坐标开始画入src
                }
            }
        }