mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
optimize<DragDropAdorner>: use realtime visual to create VisualBrush for drag-drop element
This commit is contained in:
parent
2309f9c126
commit
d6d4482a4e
2 changed files with 9 additions and 11 deletions
|
@ -8,8 +8,7 @@ namespace SourceGit.Views.Controls {
|
|||
/// 展示正在拖拽的视图
|
||||
/// </summary>
|
||||
public class DragDropAdorner : Adorner {
|
||||
private Size renderSize;
|
||||
private Brush renderBrush;
|
||||
private FrameworkElement renderElem;
|
||||
|
||||
public struct PInPoint {
|
||||
public int X;
|
||||
|
@ -23,14 +22,13 @@ namespace SourceGit.Views.Controls {
|
|||
static extern void GetCursorPos(ref PInPoint p);
|
||||
|
||||
public DragDropAdorner(FrameworkElement elem) : base(elem) {
|
||||
renderSize = elem.RenderSize;
|
||||
renderBrush = new VisualBrush(elem);
|
||||
renderElem = elem;
|
||||
IsHitTestVisible = false;
|
||||
Window.AddAdorner(elem, this);
|
||||
}
|
||||
|
||||
public void Remove() {
|
||||
Window.RemoveAdorner(this);
|
||||
Window.RemoveAdorner(renderElem, this);
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext dc) {
|
||||
|
@ -40,11 +38,11 @@ namespace SourceGit.Views.Controls {
|
|||
GetCursorPos(ref p);
|
||||
|
||||
Point pos = PointFromScreen(new Point(p.X, p.Y));
|
||||
Rect rect = new Rect(pos.X, pos.Y, renderSize.Width, renderSize.Height);
|
||||
Rect rect = new Rect(pos.X, pos.Y, renderElem.RenderSize.Width, renderElem.RenderSize.Height);
|
||||
|
||||
dc.PushOpacity(1);
|
||||
dc.DrawRectangle(FindResource("Brush.Window") as Brush, null, rect);
|
||||
dc.DrawRectangle(renderBrush, null, rect);
|
||||
dc.DrawRectangle(new VisualBrush(renderElem), null, rect);
|
||||
dc.DrawRectangle(null, new Pen(Brushes.DeepSkyBlue, 2), rect);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,16 +28,16 @@ namespace SourceGit.Views.Controls {
|
|||
Loaded += (_, __) => adornerLayer = AdornerLayer.GetAdornerLayer(Content as FrameworkElement);
|
||||
}
|
||||
|
||||
public static void AddAdorner(FrameworkElement elem, Adorner adorner) {
|
||||
var wnd = GetWindow(elem) as Window;
|
||||
public static void AddAdorner(FrameworkElement windowContext, Adorner adorner) {
|
||||
var wnd = GetWindow(windowContext) as Window;
|
||||
if (wnd != null && wnd.adornerLayer != null) {
|
||||
wnd.adorners.Add(adorner);
|
||||
wnd.adornerLayer.Add(adorner);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveAdorner(Adorner adorner) {
|
||||
var wnd = GetWindow(adorner) as Window;
|
||||
public static void RemoveAdorner(FrameworkElement windowContext, Adorner adorner) {
|
||||
var wnd = GetWindow(windowContext) as Window;
|
||||
if (wnd != null && wnd.adornerLayer != null) {
|
||||
wnd.adorners.Remove(adorner);
|
||||
wnd.adornerLayer.Remove(adorner);
|
||||
|
|
Loading…
Reference in a new issue