mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-12-16 04:44:56 +01:00
ready for testing
This commit is contained in:
113
ObservatoryCore/UI/PluginListView.cs
Normal file
113
ObservatoryCore/UI/PluginListView.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Observatory.UI
|
||||
{
|
||||
internal class PluginListView : ListView
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);
|
||||
|
||||
private const int WM_SETREDRAW = 11;
|
||||
|
||||
public PluginListView()
|
||||
{
|
||||
OwnerDraw = true;
|
||||
GridLines = false;
|
||||
DrawItem += PluginListView_DrawItem;
|
||||
DrawSubItem += PluginListView_DrawSubItem;
|
||||
DrawColumnHeader += PluginListView_DrawColumnHeader;
|
||||
|
||||
|
||||
DoubleBuffered = true;
|
||||
base.GridLines = false;//We should prevent the default drawing of gridlines.
|
||||
}
|
||||
|
||||
private static void DrawBorder(Graphics graphics, Pen pen, Rectangle bounds, bool header = false)
|
||||
{
|
||||
|
||||
Point topRight = new(bounds.Right, bounds.Top);
|
||||
Point bottomRight = new(bounds.Right, bounds.Bottom);
|
||||
|
||||
graphics.DrawLine(pen, topRight, bottomRight);
|
||||
|
||||
if (header)
|
||||
{
|
||||
Point bottomLeft = new(bounds.Left, bounds.Bottom);
|
||||
// Point topLeft = new(bounds.Left, bounds.Top);
|
||||
// graphics.DrawLine(pen, topLeft, topRight);
|
||||
// graphics.DrawLine(pen, topLeft, bottomLeft);
|
||||
graphics.DrawLine(pen, bottomLeft, bottomRight);
|
||||
}
|
||||
}
|
||||
|
||||
private void PluginListView_DrawColumnHeader(object? sender, DrawListViewColumnHeaderEventArgs e)
|
||||
{
|
||||
using (var g = e.Graphics)
|
||||
if (g != null)
|
||||
{
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
Pen pen = new(new SolidBrush(Color.LightGray));
|
||||
DrawBorder(g, pen, e.Bounds);
|
||||
using (var font = new Font(this.Font, FontStyle.Bold))
|
||||
{
|
||||
Brush textBrush = new SolidBrush(ForeColor);
|
||||
g.DrawString(e.Header?.Text, font, textBrush, e.Bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PluginListView_DrawSubItem(object? sender, DrawListViewSubItemEventArgs e)
|
||||
{
|
||||
using (var g = e.Graphics)
|
||||
if (g != null)
|
||||
{
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
Pen pen = new(new SolidBrush(Color.LightGray));
|
||||
DrawBorder(g, pen, e.Bounds, false);
|
||||
|
||||
e.DrawText();
|
||||
}
|
||||
}
|
||||
|
||||
private void PluginListView_DrawItem(object? sender, DrawListViewItemEventArgs e)
|
||||
{
|
||||
var offsetColor = (int value) =>
|
||||
{
|
||||
if (value > 127)
|
||||
{
|
||||
return value - 20;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value + 20;
|
||||
}
|
||||
};
|
||||
|
||||
using (var g = e.Graphics)
|
||||
{
|
||||
if (e.ItemIndex % 2 == 0)
|
||||
{
|
||||
e.Item.BackColor = BackColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Item.BackColor = Color.FromArgb(offsetColor(BackColor.R), offsetColor(BackColor.G), offsetColor(BackColor.B));
|
||||
}
|
||||
|
||||
if (g != null)
|
||||
{
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
Pen pen = new(new SolidBrush(Color.LightGray));
|
||||
e.DrawBackground();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user