コード例 #1
0
        public override void Render(GuiContext c)
        {
            var box = new Rectangle(c.X, c.Y, Width, Height);

            var g = c.GetGraphics();

            // important locations (TODO: fix for horizontal)
            var fullRect      = new RectangleF(c.X, c.Y, Width, Height);
            var faderAreaRect = new RectangleF(c.X, c.Y, Width / 2, Height);
            var slotRect      = new RectangleF(faderAreaRect.X + faderAreaRect.Width / 2 - 3, faderAreaRect.Y, 6, faderAreaRect.Height);
            var valueAreaRect = new RectangleF(c.X + Width / 2, c.Y, Width / 2, Height);

            // draw slot
            g.FillRectangle(new SolidBrush(Parent.Gray1), slotRect);
            g.DrawLine(new Pen(Parent.Gray5, 2), slotRect.X, slotRect.Y, slotRect.X + slotRect.Width, slotRect.Y);
            g.DrawLine(new Pen(Parent.Gray5, 2), slotRect.X, slotRect.Y, slotRect.X, slotRect.Y + slotRect.Height);

            // draw fader knob
            float knobHeight = faderAreaRect.Height / 10;

            RectangleF faderKnob = new RectangleF();

            if (Type == FaderType.Vertical)
            {
                faderKnob = new RectangleF(faderAreaRect.X, faderAreaRect.Y + faderAreaRect.Height - (int)(Percent * (faderAreaRect.Height * 0.9)) - faderAreaRect.Height / 10, faderAreaRect.Width, faderAreaRect.Height / 10);
            }
            else if (Type == FaderType.Horizontal)
            {
                faderKnob = new RectangleF(faderAreaRect.X + (int)(Percent * (faderAreaRect.Width * 0.9)), faderAreaRect.Y, faderAreaRect.Width / 10, faderAreaRect.Height);
            }
            g.FillRectangle(new SolidBrush(Parent.BaseColor), faderKnob);


            // draw value
            var valuePen = new Pen(Parent.BaseColor, 5);

            if (Type == FaderType.Vertical)
            {
                float x0 = valueAreaRect.X + valueAreaRect.Width / 2;
                float y1 = valueAreaRect.Y + valueAreaRect.Height;
                float y0 = (float)(y1 - valueAreaRect.Height * Percent);
                g.DrawLine(valuePen, x0, y0, x0, y1);
            }


            // draw borders
            //var pen = new Pen(Color.White, 3);
            //  g.DrawRectangle(pen, box);
        }
コード例 #2
0
        /// <summary>
        /// Copies the renderered image to the GuiContext.
        /// </summary>
        public override void Render(GuiContext c)
        {
            // should we assume its already rendered?
            //Rendererer.Render();

            var r = new Rectangle();

            r.X      = c.X;
            r.Y      = c.Y;
            r.Width  = Width;
            r.Height = Height;

            var g = c.GetGraphics();

            g.DrawImageUnscaledAndClipped(Rendererer.Image, r);
        }
コード例 #3
0
        /// <summary>
        /// Draws a white circle 3px thick with a line representing
        /// the current value, with 1/4 of the circle at the bottom
        /// not used, with a curve around it from the start point
        /// to the current point in yellow.
        /// </summary>
        public override void Render(GuiContext c)
        {
            var testbmp = new Bitmap(Width, Height);

            //var g = Graphics.FromImage(testbmp);
            var g = c.GetGraphics();

            g.SmoothingMode      = SmoothingMode.AntiAlias;
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

            // get different radiuses
            var fullRadius      = Width / 2.0;
            var lineStartRadius = fullRadius * 0.25;
            var lineEndRadius   = fullRadius * 0.55;

            // get theta of value
            var theta0 = Math.PI * (-0.25);
            var theta1 = Math.PI * 1.25;
            var theta  = theta0 + ((theta1 - theta0) * (1 - Percent));

            // get line sizes
            float valuePenWidth = (float)Width * 0.12F;
            float linePenWidth  = (float)Width * 0.04F;

            // shadow positions
            float shadowOffset1 = Width * 0.035F;
            float shadowOffset2 = Width * 0.025F;


            // calculate important points
            var midpoint       = new PointF(c.X + Width / 2, c.Y + Height / 2);
            var fullRect       = new RectangleF(c.X, c.Y, Width, Height);
            var borderRect     = new RectangleF(c.X + valuePenWidth / 2, c.Y + valuePenWidth / 2, Width - valuePenWidth, Height - valuePenWidth);
            var bandCenterRect = new RectangleF(c.X + valuePenWidth, c.Y + valuePenWidth, Width - valuePenWidth * 2, Height - valuePenWidth * 2);
            var knobRect       = new RectangleF(c.X + valuePenWidth * 1.5F, c.Y + valuePenWidth * 1.5F, Width - valuePenWidth * 3F, Height - valuePenWidth * 3F);
            var knobBorderRect = new RectangleF(knobRect.X + 1, knobRect.Y + 1, knobRect.Width - 2, knobRect.Height - 2);

            var shawdowRect = new RectangleF(fullRect.X + 2, fullRect.Y + 5, fullRect.Width, fullRect.Height);


            // draw the outer band
            g.FillEllipse(new LinearGradientBrush(borderRect, BandColor1, BandColor2, LinearGradientMode.Vertical), borderRect);

            // draw the outline for the outer band
            g.DrawEllipse(new Pen(OuterBorderColor, 2), borderRect);
            //g.DrawEllipse(new Pen(InnerBorderColor1, 3), knobBorderRect);
            //g.DrawEllipse(new Pen(InnerBorderColor2, 5), knobBorderRect2);

            // draw the knob
            g.FillEllipse(new LinearGradientBrush(knobRect, KnobColor1, KnobColor2, LinearGradientMode.Vertical), knobRect);
            g.DrawArc(new Pen(InnerBorderColor1, 1), knobBorderRect, 210, 120);
            g.DrawArc(new Pen(InnerBorderColor2, 2), knobBorderRect, 30, 120);



            // draw the value arc
            float arcLength = (float)Percent * 270;

            g.DrawArc(new Pen(ValueColor, valuePenWidth), fullRect, 135, arcLength);
            g.DrawArc(new Pen(ValueBandColor, valuePenWidth), bandCenterRect, 135, arcLength);

            // draw the line pointing at the value
            var lineStartRel = new PointF((float)(Math.Cos(theta) * lineStartRadius), (float)(Math.Sin(theta) * lineStartRadius));
            var lineEndRel   = new PointF((float)(Math.Cos(theta) * lineEndRadius), (float)(Math.Sin(theta) * lineEndRadius));

            g.DrawLine(new Pen(LineColor, linePenWidth), midpoint.X + lineStartRel.X, midpoint.Y - lineStartRel.Y, midpoint.X + lineEndRel.X, midpoint.Y - lineEndRel.Y);



            // label test
            var font = new Font("arial", 8);

            g.DrawString("Knob", font, new SolidBrush(Color.White), c.X + Width / 2, c.Y + Height, new StringFormat()
            {
                Alignment = StringAlignment.Center
            });
        }