-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverlayForm.cs
More file actions
68 lines (57 loc) · 2.43 KB
/
Copy pathOverlayForm.cs
File metadata and controls
68 lines (57 loc) · 2.43 KB
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
using System.Drawing.Drawing2D;
namespace DesktopIconDropper;
// Bu, tüm ekranı kaplayan ama TAMAMEN ŞEFFAF ve tıklamalara KAPALI (tıklamalar
// altındaki masaüstüne geçer) özel bir pencere. Gerçek Windows simgeleri
// döndürülemediği için, bir simge "takla atarken" gerçek simgeyi geçici olarak
// ekran dışına gizleyip, onun yerine burada döndürerek çizdiğimiz bir kopya
// resim gösteriyoruz. Simge yere inince gerçek simge geri görünür oluyor.
internal class OverlayForm : Form
{
private readonly Dictionary<int, (Bitmap Bitmap, float X, float Y, float RotationDeg)> _items = new();
public OverlayForm()
{
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
TopMost = true;
StartPosition = FormStartPosition.Manual;
BackColor = Color.Magenta;
TransparencyKey = Color.Magenta; // bu renk görünmez olacak
DoubleBuffered = true;
Bounds = SystemInformation.VirtualScreen; // tüm monitörleri kapsayacak şekilde
}
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
cp.ExStyle |= NativeMethods.WS_EX_TRANSPARENT | NativeMethods.WS_EX_NOACTIVATE;
return cp;
}
}
protected override bool ShowWithoutActivation => true;
// Bir simgeyi (index) belirtilen ekran konumunda, verilen açıyla döndürerek çizmeye ekler/günceller
public void SetIcon(int index, Bitmap bitmap, float screenX, float screenY, float rotationDeg)
{
_items[index] = (bitmap, screenX, screenY, rotationDeg);
}
// Bir simgeyi artık burada çizmeyi bırak (gerçek simge tekrar görünür olacak)
public void RemoveIcon(int index)
{
_items.Remove(index);
}
public void RedrawAll() => Invalidate();
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
foreach (var (bitmap, x, y, rotationDeg) in _items.Values)
{
int w = bitmap.Width, h = bitmap.Height;
var state = e.Graphics.Save();
e.Graphics.TranslateTransform(x - Left + w / 2f, y - Top + h / 2f);
e.Graphics.RotateTransform(rotationDeg);
e.Graphics.DrawImage(bitmap, -w / 2f, -h / 2f, w, h);
e.Graphics.Restore(state);
}
}
}