예제 #1
0
파일: Canvas.cs 프로젝트: kuggaa/longomatch
 /// <summary>
 /// Must be called before any drawing operation is performed
 /// to apply transformation, scalling and clipping.
 /// </summary>
 /// <param name="context">Context to draw</param>
 protected void Begin(IContext context)
 {
     tk.Context = context;
     tk.Begin();
     if (ClipRegion != null)
     {
         tk.Clip(ClipRegion);
     }
     tk.TranslateAndScale(Translation, new Point(ScaleX, ScaleY));
 }
예제 #2
0
        public override void Draw(IDrawingToolkit tk, Area area)
        {
            Point    arrowLocation;
            ISurface arrow;

            if (Player == null)
            {
                return;
            }

            var zero = new Point(0, 0);

            GetArrowAndLocation(out arrow, out arrowLocation);

            tk.Begin();
            tk.TranslateAndScale(Position, new Point(1, 1));

            if (!UpdateDrawArea(tk, area, new Area(zero, Size, Size)))
            {
                tk.End();
                return;
            }

            // Draw shadow and clip
            if (Circular)
            {
                tk.FillColor = App.Current.Style.ColorShadow;
                tk.LineWidth = 0;
                tk.DrawCircle(new Point(Size / 2, Size / 2 + 1), Size / 2);
                tk.ClipCircle(new Point(Size / 2, Size / 2), Size / 2);
            }
            else
            {
                tk.Clip(new Area(new Point(0, 0), Size, Size));
            }

            /* Background */
            tk.FillColor = PlayerBackground;
            tk.LineWidth = 0;
            tk.DrawRectangle(zero, Size, Size);

            /* Image */
            if (Player.Photo != null)
            {
                tk.DrawImage(zero, Size, Size, Player.Photo, ScaleMode.AspectFit);
            }
            else
            {
                tk.DrawSurface(zero, Size, Size, DefaultPhoto, ScaleMode.AspectFit);
            }

            var numberY = Size * PlayerNumberRelativePosition;

            /* Draw number rectangle */
            var numberStart = new Point(0, numberY);
            var color       = Color.Copy();

            color.SetAlpha(PlayerNumberAlpha);
            tk.FillColor = color;
            tk.DrawRectangle(numberStart, Size, Size / 2);

            /* Draw number */
            tk.FillColor     = Color.White;
            tk.StrokeColor   = Color.White;
            tk.FontAlignment = FontAlignment.Center;
            tk.FontWeight    = FontWeight.Bold;
            if (ViewModel.Number >= 100)
            {
                tk.FontSize = PlayerSmallFontSize;
            }
            else
            {
                tk.FontSize = PlayerFontSize;
            }
            tk.DrawText(numberStart, Size, Size - numberY, ViewModel.Number.ToString());

            if (Player.Tagged)
            {
                Color selColor = Color.Copy();
                selColor.SetAlpha(PlayerSelectionAlpha);
                tk.FillColor = selColor;
                tk.DrawRectangle(zero, Size, Size);
            }

            /* Draw Arrow */
            if (SubstitutionMode && (Highlighted || ViewModel.Tagged))
            {
                var arrowSize = Size * PlayerArrowRelativeSize;
                /* Arrow shadow */
                tk.FillColor = Color.White;
                tk.DrawSurface(new Point(arrowLocation.X + 1, arrowLocation.Y + 1), arrowSize, arrowSize, arrow, ScaleMode.AspectFit, true);
                tk.FillColor = Color;
                tk.DrawSurface(arrowLocation, arrowSize, arrowSize, arrow, ScaleMode.AspectFit, true);
            }

            tk.End();
        }