37 lines
3.0 KiB
C#
37 lines
3.0 KiB
C#
#if WINDOWS
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Windows.Forms;
|
|
namespace PlotDirector.Companion.Agent;
|
|
internal sealed class RoundedCard:TableLayoutPanel
|
|
{
|
|
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
|
|
public Color Outside {get;set;}
|
|
public RoundedCard(){DoubleBuffered=true;ColumnStyles.Add(new(SizeType.Percent,100));}
|
|
protected override void OnPaintBackground(PaintEventArgs e)
|
|
{
|
|
e.Graphics.Clear(Outside);e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;
|
|
var radius=Math.Min(24*DeviceDpi/96,Math.Min(Width,Height));if(radius<2)return;
|
|
using var path=new GraphicsPath();path.AddArc(0,0,radius,radius,180,90);path.AddArc(Width-radius-1,0,radius,radius,270,90);path.AddArc(Width-radius-1,Height-radius-1,radius,radius,0,90);path.AddArc(0,Height-radius-1,radius,radius,90,90);path.CloseFigure();using var brush=new SolidBrush(BackColor);e.Graphics.FillPath(brush,path);
|
|
}
|
|
}
|
|
internal sealed class CoverView:Control
|
|
{
|
|
private Image? image;[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
|
|
public string Caption {get;set;}="Your book";
|
|
public CoverView(){DoubleBuffered=true;AccessibleName="Associated book cover";AccessibleRole=AccessibleRole.Graphic;}
|
|
public void SetImage(Image? value){var previous=image;image=value;previous?.Dispose();Invalidate();}
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);var bounds=new Rectangle(2,2,Math.Max(1,Width-8),Math.Max(1,Height-8));var ratio=2d/3;
|
|
if(bounds.Width>bounds.Height*ratio)bounds.Width=(int)(bounds.Height*ratio);else bounds.Height=(int)(bounds.Width/ratio);
|
|
e.Graphics.SmoothingMode=SmoothingMode.AntiAlias;using var shadow=new SolidBrush(Color.FromArgb(30,0,0,0));e.Graphics.FillRectangle(shadow,bounds.X+4,bounds.Y+5,bounds.Width,bounds.Height);
|
|
if(image!=null){var scale=Math.Min((double)bounds.Width/image.Width,(double)bounds.Height/image.Height);var w=(int)(image.Width*scale);var h=(int)(image.Height*scale);e.Graphics.DrawImage(image,new Rectangle(bounds.X+(bounds.Width-w)/2,bounds.Y+(bounds.Height-h)/2,w,h));return;}
|
|
using var brush=new LinearGradientBrush(bounds,Color.FromArgb(99,63,93),Color.FromArgb(50,41,61),90);e.Graphics.FillRectangle(brush,bounds);
|
|
using var line=new Pen(Color.FromArgb(130,218,191,166));e.Graphics.DrawRectangle(line,bounds.X+9,bounds.Y+9,Math.Max(1,bounds.Width-18),Math.Max(1,bounds.Height-18));
|
|
using var titleFont=new Font("Segoe UI",11,FontStyle.Bold);TextRenderer.DrawText(e.Graphics,Caption,titleFont,new Rectangle(bounds.X+16,bounds.Y+30,Math.Max(1,bounds.Width-32),Math.Max(1,bounds.Height-54)),Color.FromArgb(250,240,224),TextFormatFlags.WordBreak|TextFormatFlags.HorizontalCenter|TextFormatFlags.EndEllipsis);
|
|
}
|
|
protected override void Dispose(bool disposing){if(disposing)image?.Dispose();base.Dispose(disposing);}
|
|
}
|
|
#endif
|