OSDN Git Service

275e4583b7cea7e8e7eb408d1611964e2b311d0f
[fooeditengine/FooEditEngine.git] / Common / Direct2D / MarkerFactory.cs
1 /*
2  * Copyright (C) 2013 FooProject
3  * * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
5
6  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
7  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
9 You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10  */
11 using System;
12 using System.Collections.Generic;
13 using System.Linq;
14 using System.Text;
15 using System.Windows;
16 using SharpDX;
17 using D2D = SharpDX.Direct2D1;
18 using DW = SharpDX.DirectWrite;
19
20 namespace FooEditEngine
21 {
22     interface IMarkerEffecter
23     {
24         void Draw(double x, double y, double width, double height);
25     }
26
27     abstract class SquilleLineMarker : IMarkerEffecter
28     {
29         public abstract void DrawLine(double x, double y, double tox, double toy);
30         public void Draw(double x, double y, double width, double height)
31         {
32             double lineWidthSize = Util.RoundUp(height / 24) + 1;
33             double lineLength = lineWidthSize + (lineWidthSize * 4);
34             double waveHeight = Util.RoundUp(height / 12) + 1;
35             double lineSpacing = lineWidthSize * 8;
36
37             double valleyY = Util.RoundUp(y + waveHeight);
38             double ridgeY = Util.RoundUp(y);
39             double endX = x + width - 1;
40             for (; x < endX; x += (waveHeight * 2))
41             {
42                 double ridgeX = x + waveHeight;
43                 double valleyX = ridgeX + waveHeight;
44                 if (ridgeX <= endX)
45                     this.DrawLine(x, valleyY, ridgeX, ridgeY);
46                 if (valleyX <= endX)
47                     this.DrawLine(ridgeX, ridgeY, valleyX, valleyY);
48             }
49         }
50     }
51
52     sealed class D2DSquilleLineMarker : SquilleLineMarker
53     {
54         D2D.SolidColorBrush brush;
55         D2D.StrokeStyle stroke;
56         D2D.RenderTarget render;
57         float thickness;
58         public D2DSquilleLineMarker(D2D.RenderTarget render, D2D.SolidColorBrush brush, D2D.StrokeStyle stroke, float thickness)
59         {
60             this.brush = brush;
61             this.stroke = stroke;
62             this.thickness = thickness;
63             this.render = render;
64         }
65
66         public override void DrawLine(double x, double y, double tox, double toy)
67         {
68             this.render.DrawLine(new Vector2((float)x, (float)y), new Vector2((float)tox, (float)toy), this.brush, this.thickness, this.stroke);
69         }
70     }
71
72     sealed class LineMarker : IMarkerEffecter
73     {
74         D2D.SolidColorBrush brush;
75         D2D.StrokeStyle stroke;
76         D2D.RenderTarget render;
77         float thickness;
78         public LineMarker(D2D.RenderTarget render, D2D.SolidColorBrush brush,D2D.StrokeStyle stroke, float thickness)
79         {
80             this.brush = brush;
81             this.stroke = stroke;
82             this.thickness = thickness;
83             this.render = render;
84         }
85
86         public void Draw(double x, double y, double width, double height)
87         {
88             render.DrawLine(new Vector2((float)x, (float)(y)),
89                 new Vector2((float)(x + width - 1), (float)(y)),
90                 this.brush,
91                 this.thickness,
92                 this.stroke);
93         }
94     }
95
96     sealed class HilightMarker : IMarkerEffecter
97     {
98         D2D.SolidColorBrush brush;
99         D2D.RenderTarget render;
100         public HilightMarker(D2D.RenderTarget render,D2D.SolidColorBrush brush)
101         {
102             this.brush = brush;
103             this.render = render;
104         }
105
106         public void Draw(double x, double y, double width, double height)
107         {
108             render.FillRectangle(new RectangleF((float)x, (float)y, (float)width, (float)height), brush);
109         }
110     }
111 }