コード例 #1
0
        public void RotateSwastika(float x, float y, float size, float stroke, Direct2DColor color)
        {
            if (!swastikaDeltaTimer.IsRunning)
            {
                swastikaDeltaTimer.Start();
            }

            int thisTime = (int)swastikaDeltaTimer.ElapsedMilliseconds;

            if (Math.Abs(thisTime - lastTime) >= 3)
            {
                rotationState += 0.1f;
                lastTime       = (int)swastikaDeltaTimer.ElapsedMilliseconds;
            }

            if (thisTime >= 1000)
            {
                swastikaDeltaTimer.Restart();
            }

            if (rotationState > size)
            {
                rotationState = size * -1.0f;
            }

            _sharedBrush.Color = color;

            RawVector2 first  = new RawVector2(x - size, y - rotationState);
            RawVector2 second = new RawVector2(x + size, y + rotationState);

            RawVector2 third  = new RawVector2(x + rotationState, y - size);
            RawVector2 fourth = new RawVector2(x - rotationState, y + size);

            RawVector2 haken_1 = new RawVector2(third.X + size, third.Y + rotationState);
            RawVector2 haken_2 = new RawVector2(second.X - rotationState, second.Y + size);
            RawVector2 haken_3 = new RawVector2(fourth.X - size, fourth.Y - rotationState);
            RawVector2 haken_4 = new RawVector2(first.X + rotationState, first.Y - size);

            _device.DrawLine(first, second, _sharedBrush, stroke);
            _device.DrawLine(third, fourth, _sharedBrush, stroke);

            _device.DrawLine(third, haken_1, _sharedBrush, stroke);
            _device.DrawLine(second, haken_2, _sharedBrush, stroke);
            _device.DrawLine(fourth, haken_3, _sharedBrush, stroke);
            _device.DrawLine(first, haken_4, _sharedBrush, stroke);
        }
コード例 #2
0
        public void BorderedCircle(float x, float y, float radius, float stroke, Direct2DColor color, Direct2DColor borderColor)
        {
            _sharedBrush.Color = color;

            var ellipse = new Ellipse(new RawVector2(x, y), radius, radius);

            _device.DrawEllipse(ellipse, _sharedBrush, stroke);

            float half = stroke / 2.0f;

            _sharedBrush.Color = borderColor;

            ellipse.RadiusX += half;
            ellipse.RadiusY += half;

            _device.DrawEllipse(ellipse, _sharedBrush, half);

            ellipse.RadiusX -= stroke;
            ellipse.RadiusY -= stroke;

            _device.DrawEllipse(ellipse, _sharedBrush, half);
        }
コード例 #3
0
        public void BorderedLine(float start_x, float start_y, float end_x, float end_y, float stroke, Direct2DColor color, Direct2DColor borderColor)
        {
            var geometry = new PathGeometry(_factory);

            var sink = geometry.Open();

            float half    = stroke / 2.0f;
            float quarter = half / 2.0f;

            sink.BeginFigure(new RawVector2(start_x, start_y - half), FigureBegin.Filled);

            sink.AddLine(new RawVector2(end_x, end_y - half));
            sink.AddLine(new RawVector2(end_x, end_y + half));
            sink.AddLine(new RawVector2(start_x, start_y + half));

            sink.EndFigure(FigureEnd.Closed);

            sink.Close();

            _sharedBrush.Color = borderColor;

            _device.DrawGeometry(geometry, _sharedBrush, half);

            _sharedBrush.Color = color;

            _device.FillGeometry(geometry, _sharedBrush);

            sink.Dispose();
            geometry.Dispose();
        }
コード例 #4
0
 public void FillRectangle(float x, float y, float width, float height, Direct2DColor color)
 {
     _sharedBrush.Color = color;
     _device.FillRectangle(new RawRectangleF(x, y, x + width, y + height), _sharedBrush);
 }
コード例 #5
0
 public void FillEllipse(float x, float y, float radius_x, float radius_y, Direct2DColor color)
 {
     _sharedBrush.Color = color;
     _device.FillEllipse(new Ellipse(new RawVector2(x, y), radius_x, radius_y), _sharedBrush);
 }
コード例 #6
0
        public void DrawCrosshair(CrosshairStyle style, float x, float y, float size, float stroke, Direct2DColor color)
        {
            _sharedBrush.Color = color;

            if (style == CrosshairStyle.Dot)
            {
                FillCircle(x, y, size, color);
            }
            else if (style == CrosshairStyle.Plus)
            {
                DrawLine(x - size, y, x + size, y, stroke, color);
                DrawLine(x, y - size, x, y + size, stroke, color);
            }
            else if (style == CrosshairStyle.Cross)
            {
                DrawLine(x - size, y - size, x + size, y + size, stroke, color);
                DrawLine(x + size, y - size, x - size, y + size, stroke, color);
            }
            else if (style == CrosshairStyle.Gap)
            {
                DrawLine(x - size - stroke, y, x - stroke, y, stroke, color);
                DrawLine(x + size + stroke, y, x + stroke, y, stroke, color);

                DrawLine(x, y - size - stroke, x, y - stroke, stroke, color);
                DrawLine(x, y + size + stroke, x, y + stroke, stroke, color);
            }
            else if (style == CrosshairStyle.Diagonal)
            {
                DrawLine(x - size, y - size, x + size, y + size, stroke, color);
                DrawLine(x + size, y - size, x - size, y + size, stroke, color);
            }
            else if (style == CrosshairStyle.Swastika)
            {
                RawVector2 first  = new RawVector2(x - size, y);
                RawVector2 second = new RawVector2(x + size, y);

                RawVector2 third  = new RawVector2(x, y - size);
                RawVector2 fourth = new RawVector2(x, y + size);

                RawVector2 haken_1 = new RawVector2(third.X + size, third.Y);
                RawVector2 haken_2 = new RawVector2(second.X, second.Y + size);
                RawVector2 haken_3 = new RawVector2(fourth.X - size, fourth.Y);
                RawVector2 haken_4 = new RawVector2(first.X, first.Y - size);

                _device.DrawLine(first, second, _sharedBrush, stroke);
                _device.DrawLine(third, fourth, _sharedBrush, stroke);

                _device.DrawLine(third, haken_1, _sharedBrush, stroke);
                _device.DrawLine(second, haken_2, _sharedBrush, stroke);
                _device.DrawLine(fourth, haken_3, _sharedBrush, stroke);
                _device.DrawLine(first, haken_4, _sharedBrush, stroke);
            }
        }
コード例 #7
0
 public void DrawEllipse(float x, float y, float radius_x, float radius_y, float stroke, Direct2DColor color)
 {
     _sharedBrush.Color = color;
     _device.DrawEllipse(new Ellipse(new RawVector2(x, y), radius_x, radius_y), _sharedBrush, stroke);
 }
コード例 #8
0
        public void DrawArrowLine(float start_x, float start_y, float end_x, float end_y, float size, Direct2DColor color)
        {
            float delta_x = end_x >= start_x ? end_x - start_x : start_x - end_x;
            float delta_y = end_y >= start_y ? end_y - start_y : start_y - end_y;

            float length = (float)Math.Sqrt(delta_x * delta_x + delta_y * delta_y);

            float xm = length - size;
            float xn = xm;

            float ym = size;
            float yn = -ym;

            float sin = delta_y / length;
            float cos = delta_x / length;

            float x = xm * cos - ym * sin + end_x;

            ym = xm * sin + ym * cos + end_y;
            xm = x;

            x  = xn * cos - yn * sin + end_x;
            yn = xn * sin + yn * cos + end_y;
            xn = x;

            FillTriangle(start_x, start_y, xm, ym, xn, yn, color);
        }
コード例 #9
0
 public void ClearScene(Direct2DColor color)
 {
     _device.Clear(color);
 }
コード例 #10
0
 public Direct2DBrush CreateBrush(Direct2DColor color)
 {
     return(new Direct2DBrush(_device, color));
 }
コード例 #11
0
        public void DrawTextWithBackground(string text, float x, float y, float fontSize, Direct2DFont font, Direct2DColor color, Direct2DColor backgroundColor)
        {
            var layout = new TextLayout(_fontFactory, text, font, float.MaxValue, float.MaxValue);

            layout.SetFontSize(fontSize, new TextRange(0, text.Length));

            float modifier = fontSize / 4.0f;

            _sharedBrush.Color = backgroundColor;

            _device.FillRectangle(new RawRectangleF(x - modifier, y - modifier, x + layout.Metrics.Width + modifier, y + layout.Metrics.Height + modifier), _sharedBrush);

            _sharedBrush.Color = color;

            _device.DrawTextLayout(new RawVector2(x, y), layout, _sharedBrush, DrawTextOptions.NoSnap);

            layout.Dispose();
        }
コード例 #12
0
        public void DrawText(string text, float x, float y, float fontSize, Direct2DFont font, Direct2DColor color)
        {
            _sharedBrush.Color = color;

            var layout = new TextLayout(_fontFactory, text, font, float.MaxValue, float.MaxValue);

            layout.SetFontSize(fontSize, new TextRange(0, text.Length));

            _device.DrawTextLayout(new RawVector2(x, y), layout, _sharedBrush, DrawTextOptions.NoSnap);

            layout.Dispose();
        }
コード例 #13
0
 public void DrawText(string text, float x, float y, Direct2DFont font, Direct2DColor color)
 {
     _sharedBrush.Color = color;
     _device.DrawText(text, text.Length, font, new RawRectangleF(x, y, float.MaxValue, float.MaxValue), _sharedBrush, DrawTextOptions.NoSnap, MeasuringMode.Natural);
 }
コード例 #14
0
        public void BorderedRectangle(float x, float y, float width, float height, float stroke, Direct2DColor color, Direct2DColor borderColor)
        {
            float half = stroke / 2.0f;

            width  += x;
            height += y;

            _sharedBrush.Color = color;

            _device.DrawRectangle(new RawRectangleF(x, y, width, height), _sharedBrush, half);

            _sharedBrush.Color = borderColor;

            _device.DrawRectangle(new RawRectangleF(x - half, y - half, width + half, height + half), _sharedBrush, half);

            _device.DrawRectangle(new RawRectangleF(x + half, y + half, width - half, height - half), _sharedBrush, half);
        }
コード例 #15
0
 public void DrawLine(float start_x, float start_y, float end_x, float end_y, float stroke, Direct2DColor color)
 {
     _sharedBrush.Color = color;
     _device.DrawLine(new RawVector2(start_x, start_y), new RawVector2(end_x, end_y), _sharedBrush, stroke);
 }
コード例 #16
0
        public void FillTriangle(float a_x, float a_y, float b_x, float b_y, float c_x, float c_y, Direct2DColor color)
        {
            _sharedBrush.Color = color;

            var geometry = new PathGeometry(_factory);

            var sink = geometry.Open();

            sink.BeginFigure(new RawVector2(a_x, a_y), FigureBegin.Filled);
            sink.AddLine(new RawVector2(b_x, b_y));
            sink.AddLine(new RawVector2(c_x, c_y));
            sink.EndFigure(FigureEnd.Closed);

            sink.Close();

            _device.FillGeometry(geometry, _sharedBrush);

            sink.Dispose();
            geometry.Dispose();
        }
コード例 #17
0
 public void DrawRectangle(float x, float y, float width, float height, float stroke, Direct2DColor color)
 {
     _sharedBrush.Color = color;
     _device.DrawRectangle(new RawRectangleF(x, y, x + width, y + height), _sharedBrush, stroke);
 }
コード例 #18
0
        public void DrawBox2D(float x, float y, float width, float height, float stroke, Direct2DColor interiorColor, Direct2DColor color)
        {
            var geometry = new PathGeometry(_factory);

            var sink = geometry.Open();

            sink.BeginFigure(new RawVector2(x, y), FigureBegin.Filled);
            sink.AddLine(new RawVector2(x + width, y));
            sink.AddLine(new RawVector2(x + width, y + height));
            sink.AddLine(new RawVector2(x, y + height));
            sink.EndFigure(FigureEnd.Closed);

            sink.Close();

            _sharedBrush.Color = color;

            _device.DrawGeometry(geometry, _sharedBrush, stroke);

            _sharedBrush.Color = interiorColor;

            _device.FillGeometry(geometry, _sharedBrush);

            sink.Dispose();
            geometry.Dispose();
        }
コード例 #19
0
        public void DrawRectangleEdges(float x, float y, float width, float height, float stroke, Direct2DColor color)
        {
            _sharedBrush.Color = color;

            int length = (int)(((width + height) / 2.0f) * 0.2f);

            RawVector2 first  = new RawVector2(x, y);
            RawVector2 second = new RawVector2(x, y + length);
            RawVector2 third  = new RawVector2(x + length, y);

            _device.DrawLine(first, second, _sharedBrush, stroke);
            _device.DrawLine(first, third, _sharedBrush, stroke);

            first.Y += height;
            second.Y = first.Y - length;
            third.Y  = first.Y;
            third.X  = first.X + length;

            _device.DrawLine(first, second, _sharedBrush, stroke);
            _device.DrawLine(first, third, _sharedBrush, stroke);

            first.X  = x + width;
            first.Y  = y;
            second.X = first.X - length;
            second.Y = first.Y;
            third.X  = first.X;
            third.Y  = first.Y + length;

            _device.DrawLine(first, second, _sharedBrush, stroke);
            _device.DrawLine(first, third, _sharedBrush, stroke);

            first.Y  += height;
            second.X += length;
            second.Y  = first.Y - length;
            third.Y   = first.Y;
            third.X   = first.X - length;

            _device.DrawLine(first, second, _sharedBrush, stroke);
            _device.DrawLine(first, third, _sharedBrush, stroke);
        }
コード例 #20
0
        public void DrawHorizontalBar(float percentage, float x, float y, float width, float height, float stroke, Direct2DColor interiorColor, Direct2DColor color)
        {
            float half = stroke / 2.0f;

            _sharedBrush.Color = color;

            var rect = new RawRectangleF(x - half, y - half, x + width + half, y + height + half);

            _device.DrawRectangle(rect, _sharedBrush, stroke);

            if (percentage == 0.0f)
            {
                return;
            }

            rect.Left   += half;
            rect.Right  -= half;
            rect.Top    += height - (height / 100.0f * percentage) + half;
            rect.Bottom -= half;

            _sharedBrush.Color = interiorColor;

            _device.FillRectangle(rect, _sharedBrush);
        }
コード例 #21
0
 public Direct2DBrush(RenderTarget renderTarget, Direct2DColor color)
 {
     Brush = new SolidColorBrush(renderTarget, color);
 }