mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-01 17:24:59 +00:00
optimize<*>: remove dragdrop adorner; redesign bookmark style on welcome page
This commit is contained in:
parent
bdd147f737
commit
787cf5bb02
9 changed files with 36 additions and 151 deletions
|
@ -1,49 +0,0 @@
|
|||
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 {
|
||||
private FrameworkElement renderElem;
|
||||
|
||||
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) {
|
||||
renderElem = elem;
|
||||
IsHitTestVisible = false;
|
||||
Window.AddAdorner(elem, this);
|
||||
}
|
||||
|
||||
public void Remove() {
|
||||
Window.RemoveAdorner(renderElem, this);
|
||||
}
|
||||
|
||||
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));
|
||||
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(new VisualBrush(renderElem), null, rect);
|
||||
dc.DrawRectangle(null, new Pen(Brushes.DeepSkyBlue, 2), rect);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,37 +20,9 @@ namespace SourceGit.Views.Controls {
|
|||
set { SetValue(IsMaximizedProperty, value); }
|
||||
}
|
||||
|
||||
private AdornerLayer adornerLayer = null;
|
||||
private List<Adorner> adorners = new List<Adorner>();
|
||||
|
||||
public Window() {
|
||||
Style = FindResource("Style.Window") as Style;
|
||||
|
||||
Loaded += (_, __) => {
|
||||
adornerLayer = AdornerLayer.GetAdornerLayer(Content as FrameworkElement);
|
||||
OnStateChanged(null);
|
||||
};
|
||||
}
|
||||
|
||||
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(FrameworkElement windowContext, Adorner adorner) {
|
||||
var wnd = GetWindow(windowContext) as Window;
|
||||
if (wnd != null && wnd.adornerLayer != null) {
|
||||
wnd.adorners.Remove(adorner);
|
||||
wnd.adornerLayer.Remove(adorner);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPreviewGiveFeedback(GiveFeedbackEventArgs e) {
|
||||
base.OnPreviewGiveFeedback(e);
|
||||
if (adornerLayer != null && adorners.Count > 0) adornerLayer.Update();
|
||||
Loaded += (_, __) => OnStateChanged(null);
|
||||
}
|
||||
|
||||
protected override void OnStateChanged(EventArgs e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue