/// <summary>
        /// Renders the key in the specified surface.
        /// </summary>
        /// <param name="g">The GDI+ surface to render on.</param>
        /// <param name="speed">The speed of the mouse.</param>
        public void Render(Graphics g, SizeF speed)
        {
            var subStyle = GlobalSettings.CurrentStyle.TryGetElementStyle <MouseSpeedIndicatorStyle>(this.Id)
                           ?? GlobalSettings.CurrentStyle.DefaultMouseSpeedIndicatorStyle;

            // Small circles have a fifth of the radius of the full control.
            var smallRadius = (float)this.Radius / 5;

            // The sensitivity is a factor over the mouse speed.
            var sensitivity = GlobalSettings.Settings.MouseSensitivity / (float)100;

            // The total length is determined by the sensitivity, speed and radius. But never more than the radius.
            var pointerLength = (int)Math.Min(this.Radius, sensitivity * speed.GetLength() * this.Radius);

            var colorMultiplier = Math.Max(0, Math.Min(1, (float)pointerLength / this.Radius));

            Color color1     = subStyle.InnerColor;
            Color outerColor = subStyle.OuterColor;
            // The second color should be averaged over the two specified colours, based upon how far out the thingymabob is.
            var color2 = Color.FromArgb(
                (int)(color1.R * (1 - colorMultiplier) + outerColor.R * colorMultiplier),
                (int)(color1.G * (1 - colorMultiplier) + outerColor.G * colorMultiplier),
                (int)(color1.B * (1 - colorMultiplier) + outerColor.B * colorMultiplier));

            // Draw the edge.
            g.DrawEllipse(
                new Pen(color1, subStyle.OutlineWidth),
                Geom.CircleToRectangle(this.Location, this.Radius));

            // Only calculate the pointer data if it has some length.
            if (pointerLength > 0)
            {
                // Determine the angle of the pointer.
                var angle = speed.GetAngle();

                // Determine the location of the pointer end.
                var pointerEnd = this.Location.CircularTranslate(pointerLength, angle);

                // If the pointer doesn't end where it starts, draw it.
                if (pointerEnd.X != this.Location.X || pointerEnd.Y != this.Location.Y)
                {
                    // Draw the pointer, as a pie.
                    g.FillPie(
                        new LinearGradientBrush(this.Location, pointerEnd, color1, color2),
                        Geom.CircleToRectangle(this.Location, pointerLength),
                        Geom.RadToDeg(angle) - 10,
                        20);

                    // Draw a circle on the outter edge in the direction of the pointer.
                    var pointerEdge = this.Location.CircularTranslate(this.Radius, angle);
                    g.FillEllipse(new SolidBrush(color2), Geom.CircleToRectangle(pointerEdge, (int)smallRadius));
                }
            }

            // Draw the circle in the center.
            g.FillEllipse(new SolidBrush(color1), Geom.CircleToRectangle(this.Location, (int)smallRadius));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders a simple representation of the element while it is being highlighted in edit mode.
        /// </summary>
        /// <param name="g">The graphics context to render to.</param>
        public override void RenderHighlight(Graphics g)
        {
            g.FillEllipse(Constants.HighlightBrush, Geom.CircleToRectangle(this.Location, this.Radius));

            if (this.RelevantManipulation?.Type == ElementManipulationType.Scale)
            {
                g.DrawEllipse(new Pen(Color.White, 3), Geom.CircleToRectangle(this.Location, this.Radius));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders a simple representation of the element while it is selected in edit mode.
        /// </summary>
        /// <param name="g">The graphics context to render to.</param>
        public override void RenderSelected(Graphics g)
        {
            g.DrawEllipse(new Pen(Constants.SelectedColor, 2), Geom.CircleToRectangle(this.Location, this.Radius));
            g.FillEllipse(
                new SolidBrush(Constants.SelectedColor),
                Geom.CircleToRectangle(this.Location, this.Radius / 5));

            if (this.RelevantManipulation?.Type == ElementManipulationType.Scale)
            {
                g.DrawEllipse(
                    new Pen(Constants.SelectedColorSpecial, 3),
                    Geom.CircleToRectangle(this.Location, this.Radius));
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Renders a simple representation of the element while it is being edited. This representation does not depend
 /// on the state of the program and is merely intended to provide a clear overview of the current position and
 /// shape of the element.
 /// </summary>
 /// <param name="g">The graphics context to render to.</param>
 public override void RenderEditing(Graphics g)
 {
     g.FillEllipse(new SolidBrush(Color.Silver), Geom.CircleToRectangle(this.Location, this.Radius));
     g.DrawEllipse(new Pen(Color.White, 1), Geom.CircleToRectangle(this.Location, this.Radius));
     g.FillEllipse(new SolidBrush(Color.White), Geom.CircleToRectangle(this.Location, this.Radius / 5));
 }