1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Tango.Scripting.Editors.Rendering;
using Tango.Scripting.Editors.Utils;
namespace Tango.Scripting.Editors.Folding
{
sealed class FoldingMarginMarker : UIElement
{
internal VisualLine VisualLine;
internal FoldingSection FoldingSection;
bool isExpanded;
public bool IsExpanded {
get { return isExpanded; }
set {
if (isExpanded != value) {
isExpanded = value;
InvalidateVisual();
}
if (FoldingSection != null)
FoldingSection.IsFolded = !value;
}
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
base.OnMouseDown(e);
if (!e.Handled) {
if (e.ChangedButton == MouseButton.Left) {
IsExpanded = !IsExpanded;
e.Handled = true;
}
}
}
const double MarginSizeFactor = 0.7;
protected override Size MeasureCore(Size availableSize)
{
double size = MarginSizeFactor * FoldingMargin.SizeFactor * (double)GetValue(TextBlock.FontSizeProperty);
size = PixelSnapHelpers.RoundToOdd(size, PixelSnapHelpers.GetPixelSize(this).Width);
return new Size(size, size);
}
protected override void OnRender(DrawingContext drawingContext)
{
FoldingMargin margin = VisualParent as FoldingMargin;
Pen activePen = new Pen(margin.SelectedFoldingMarkerBrush, 1);
Pen inactivePen = new Pen(margin.FoldingMarkerBrush, 1);
activePen.StartLineCap = inactivePen.StartLineCap = PenLineCap.Square;
activePen.EndLineCap = inactivePen.EndLineCap = PenLineCap.Square;
Size pixelSize = PixelSnapHelpers.GetPixelSize(this);
Rect rect = new Rect(pixelSize.Width / 2,
pixelSize.Height / 2,
this.RenderSize.Width - pixelSize.Width - 2,
this.RenderSize.Height - pixelSize.Height - 2);
drawingContext.DrawRectangle(
IsMouseDirectlyOver ? margin.FoldingMarkerBackgroundBrush : margin.FoldingMarkerBackgroundBrush,
IsMouseDirectlyOver ? activePen : inactivePen, rect);
double middleX = rect.Left + rect.Width / 2;
double middleY = rect.Top + rect.Height / 2;
double space = PixelSnapHelpers.Round(rect.Width / 8, pixelSize.Width) + pixelSize.Width;
drawingContext.DrawLine(activePen,
new Point(rect.Left + space, middleY),
new Point(rect.Right - space, middleY));
if (!isExpanded) {
drawingContext.DrawLine(activePen,
new Point(middleX, rect.Top + space),
new Point(middleX, rect.Bottom - space));
}
}
protected override void OnIsMouseDirectlyOverChanged(DependencyPropertyChangedEventArgs e)
{
base.OnIsMouseDirectlyOverChanged(e);
InvalidateVisual();
}
}
}
|