This commit is contained in:
Wiesław Šoltés 2015-03-14 20:52:43 +01:00
Родитель ed012175a2
Коммит 5d6857741c
1 изменённых файлов: 68 добавлений и 23 удалений

Просмотреть файл

@ -21,9 +21,27 @@ namespace Test
{ {
InitializeComponent(); InitializeComponent();
var container = new WpfContainer(); // initialize container
var container = new WpfContainer()
{
Layers = new ObservableCollection<ILayer>()
};
var layer = new Layer()
{
Shapes = new ObservableCollection<XShape>()
};
container.Layers.Add(layer);
container.Current = layer;
// initialize editor
var editor = new PortableEditor(container); var editor = new PortableEditor(container);
// initialize canvas
canvas.Children.Add(container); canvas.Children.Add(container);
canvas.PreviewMouseLeftButtonDown += (s, e) => canvas.PreviewMouseLeftButtonDown += (s, e) =>
@ -44,12 +62,14 @@ namespace Test
editor.Move(p.X, p.Y); editor.Move(p.X, p.Y);
}; };
// initialize demo
//Demo(container); //Demo(container);
} }
private static void Demo(IContainer container) private static void Demo(IContainer container)
{ {
var layer = container.Layers.First(); var layer = container.Current;
var style1 = new XStyle() var style1 = new XStyle()
{ {
@ -114,8 +134,6 @@ namespace Test
public class WpfContainer : FrameworkElement, IContainer public class WpfContainer : FrameworkElement, IContainer
{ {
public IList<ILayer> Layers { get; set; }
protected override void OnRender(DrawingContext drawingContext) protected override void OnRender(DrawingContext drawingContext)
{ {
base.OnRender(drawingContext); base.OnRender(drawingContext);
@ -129,6 +147,15 @@ namespace Test
} }
} }
public IList<ILayer> Layers { get; set; }
private ILayer _layer;
public ILayer Current
{
get { return _layer; }
set { _layer = value; }
}
public void Invalidate() public void Invalidate()
{ {
this.InvalidateVisual(); this.InvalidateVisual();
@ -305,6 +332,7 @@ namespace Test
public interface IContainer public interface IContainer
{ {
IList<ILayer> Layers { get; set; } IList<ILayer> Layers { get; set; }
ILayer Current { get; set; }
void Invalidate(); void Invalidate();
void Draw(object dc, XLine line); void Draw(object dc, XLine line);
void Draw(object dc, XRectangle rectangle); void Draw(object dc, XRectangle rectangle);
@ -418,24 +446,41 @@ namespace Test
Two, Two,
Three Three
} }
private readonly IContainer _container;
private ILayer _layer;
private XShape _temp;
private XStyle _style;
private bool _defaultIsFilled;
private Tool _tool; private Tool _tool;
public Tool CurrentTool
{
get { return _tool; }
set { _tool = value; }
}
private State _state; private State _state;
public State CurrentState
{
get { return _state; }
set { _state = value; }
}
private bool _defaultIsFilled;
public bool DefaultIsFilled
{
get { return _defaultIsFilled; }
set { _defaultIsFilled = value; }
}
private XStyle _style;
public XStyle CurrentStyle
{
get { return _style; }
set { _style = value; }
}
private readonly IContainer _container;
private XShape _temp;
public PortableEditor(IContainer container) public PortableEditor(IContainer container)
{ {
_container = container; _container = container;
_container.Layers = new ObservableCollection<ILayer>();
_layer = new Layer();
_layer.Shapes = new ObservableCollection<XShape>();
_container.Layers.Add(_layer);
_temp = null; _temp = null;
@ -469,7 +514,7 @@ namespace Test
case State.None: case State.None:
{ {
_temp = XLine.Create(x, y, _style); _temp = XLine.Create(x, y, _style);
_layer.Shapes.Add(_temp); _container.Current.Shapes.Add(_temp);
_container.Invalidate(); _container.Invalidate();
_state = State.One; _state = State.One;
} }
@ -494,7 +539,7 @@ namespace Test
case State.None: case State.None:
{ {
_temp = XRectangle.Create(x, y, _style, _defaultIsFilled); _temp = XRectangle.Create(x, y, _style, _defaultIsFilled);
_layer.Shapes.Add(_temp); _container.Current.Shapes.Add(_temp);
_container.Invalidate(); _container.Invalidate();
_state = State.One; _state = State.One;
} }
@ -519,7 +564,7 @@ namespace Test
case State.None: case State.None:
{ {
_temp = XEllipse.Create(x, y, _style, _defaultIsFilled); _temp = XEllipse.Create(x, y, _style, _defaultIsFilled);
_layer.Shapes.Add(_temp); _container.Current.Shapes.Add(_temp);
_container.Invalidate(); _container.Invalidate();
_state = State.One; _state = State.One;
} }
@ -559,7 +604,7 @@ namespace Test
break; break;
case State.One: case State.One:
{ {
_layer.Shapes.Remove(_temp); _container.Current.Shapes.Remove(_temp);
_container.Invalidate(); _container.Invalidate();
_state = State.None; _state = State.None;
} }
@ -578,7 +623,7 @@ namespace Test
break; break;
case State.One: case State.One:
{ {
_layer.Shapes.Remove(_temp); _container.Current.Shapes.Remove(_temp);
_container.Invalidate(); _container.Invalidate();
_state = State.None; _state = State.None;
} }
@ -597,7 +642,7 @@ namespace Test
break; break;
case State.One: case State.One:
{ {
_layer.Shapes.Remove(_temp); _container.Current.Shapes.Remove(_temp);
_container.Invalidate(); _container.Invalidate();
_state = State.None; _state = State.None;
} }