2021-04-29 05:05:55 -07:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Windows;
|
|
|
|
using System.Windows.Documents;
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
namespace SourceGit.Views.Controls {
|
|
|
|
/// <summary>
|
|
|
|
/// 展示正在拖拽的视图
|
|
|
|
/// </summary>
|
|
|
|
public class DragDropAdorner : Adorner {
|
2021-08-06 05:04:10 -07:00
|
|
|
private FrameworkElement renderElem;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
public struct PInPoint {
|
|
|
|
public int X;
|
|
|
|
public int Y;
|
|
|
|
|
|
|
|
public PInPoint(int x, int y) { X = x; Y = y; }
|
|
|
|
public PInPoint(double x, double y) { X = (int)x; Y = (int)y; }
|
|
|
|
}
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
static extern void GetCursorPos(ref PInPoint p);
|
|
|
|
|
|
|
|
public DragDropAdorner(FrameworkElement elem) : base(elem) {
|
2021-08-06 05:04:10 -07:00
|
|
|
renderElem = elem;
|
2021-04-29 05:05:55 -07:00
|
|
|
IsHitTestVisible = false;
|
2021-08-06 02:19:04 -07:00
|
|
|
Window.AddAdorner(elem, this);
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove() {
|
2021-08-06 05:04:10 -07:00
|
|
|
Window.RemoveAdorner(renderElem, this);
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnRender(DrawingContext dc) {
|
|
|
|
base.OnRender(dc);
|
|
|
|
|
|
|
|
PInPoint p = new PInPoint();
|
|
|
|
GetCursorPos(ref p);
|
|
|
|
|
|
|
|
Point pos = PointFromScreen(new Point(p.X, p.Y));
|
2021-08-06 05:04:10 -07:00
|
|
|
Rect rect = new Rect(pos.X, pos.Y, renderElem.RenderSize.Width, renderElem.RenderSize.Height);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
dc.PushOpacity(1);
|
2021-08-06 02:19:04 -07:00
|
|
|
dc.DrawRectangle(FindResource("Brush.Window") as Brush, null, rect);
|
2021-08-06 05:04:10 -07:00
|
|
|
dc.DrawRectangle(new VisualBrush(renderElem), null, rect);
|
2021-04-29 05:05:55 -07:00
|
|
|
dc.DrawRectangle(null, new Pen(Brushes.DeepSkyBlue, 2), rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|