Publish Zonghengjia Windows 0.3.13 client source
This commit is contained in:
+130
-32
@@ -7,7 +7,7 @@ namespace UCVL.VPNPlus;
|
||||
// baked into this asset, and none of the theme methods access network state.
|
||||
internal static class ScenicTheme
|
||||
{
|
||||
internal const int HeaderHeight = 108;
|
||||
internal const int HeaderHeight = 84;
|
||||
private static readonly Lazy<Image?> Landscape = new(() =>
|
||||
{
|
||||
// Embedded in the existing EXE payload: an older updater cannot omit
|
||||
@@ -51,7 +51,8 @@ internal static class ScenicTheme
|
||||
g.InterpolationMode = interpolation;
|
||||
}
|
||||
|
||||
internal static void Backdrop(Graphics g, Size size, int dpi, bool header = false, bool footer = false, bool login = false)
|
||||
internal static void Backdrop(Graphics g, Size size, int dpi, bool header = false, bool footer = false,
|
||||
bool login = false, bool dashboard = false, int headerArtworkOffset = 0)
|
||||
{
|
||||
if (size.Width <= 0 || size.Height <= 0) return;
|
||||
float scale = dpi / 96f;
|
||||
@@ -62,6 +63,11 @@ internal static class ScenicTheme
|
||||
Art(g, new Rectangle(0, -S(32), size.Width, size.Height + S(72)), .25f);
|
||||
return;
|
||||
}
|
||||
if (dashboard)
|
||||
{
|
||||
DashboardBackdrop(g, size, dpi, headerArtworkOffset);
|
||||
return;
|
||||
}
|
||||
if (login && Landscape.Value is { } landscape)
|
||||
{
|
||||
// Only the login canvas gets this centered landscape. Crop out
|
||||
@@ -72,14 +78,15 @@ internal static class ScenicTheme
|
||||
var height = Math.Min(size.Height, Math.Max(S(440), size.Width / 3));
|
||||
var area = new Rectangle(0, (size.Height - height) / 2, size.Width, height);
|
||||
using var attributes = new ImageAttributes();
|
||||
attributes.SetColorMatrix(new ColorMatrix { Matrix33 = .74f });
|
||||
attributes.SetColorMatrix(new ColorMatrix { Matrix33 = .57f });
|
||||
g.DrawImage(landscape, area, 0, landscape.Height / 3, landscape.Width,
|
||||
landscape.Height * 2 / 3, GraphicsUnit.Pixel, attributes);
|
||||
var veil = new Rectangle(area.X, area.Y, area.Width, Math.Min(S(48), height));
|
||||
var veil = new Rectangle(area.X, area.Y, area.Width, Math.Min(S(64), height));
|
||||
using var blend = new LinearGradientBrush(veil, Brand.Surface, Color.FromArgb(0, Brand.Surface), 90f)
|
||||
{ WrapMode = WrapMode.TileFlipXY };
|
||||
g.FillRectangle(blend, veil);
|
||||
var tail = new Rectangle(area.X, area.Bottom - Math.Min(S(64), height), area.Width, Math.Min(S(64), height));
|
||||
var tailHeight = Math.Min(S(88), height);
|
||||
var tail = new Rectangle(area.X, area.Bottom - tailHeight, area.Width, tailHeight);
|
||||
using var lowerMist = new LinearGradientBrush(tail, Color.FromArgb(0, Brand.Surface), Brand.Surface, 90f)
|
||||
{ WrapMode = WrapMode.TileFlipXY };
|
||||
g.FillRectangle(lowerMist, tail);
|
||||
@@ -101,33 +108,109 @@ internal static class ScenicTheme
|
||||
}
|
||||
// Fade the illustration itself, preserving the mountains beneath
|
||||
// it. An opaque blue veil would leave a hard horizontal seam.
|
||||
var upper = Math.Min(S(96), area.Height / 2);
|
||||
var lower = Math.Min(S(32), area.Height / 2);
|
||||
const float sceneOpacity = .32f;
|
||||
var upper = Math.Min(S(112), area.Height / 2);
|
||||
var lower = Math.Min(S(48), area.Height / 2);
|
||||
var step = Math.Max(1, S(2));
|
||||
for (var y = 0; y < upper; y += step)
|
||||
{
|
||||
var height = Math.Min(step, upper - y);
|
||||
Segment(y, height, .72f * (y + height / 2f) / upper);
|
||||
Segment(y, height, sceneOpacity * (y + height / 2f) / upper);
|
||||
}
|
||||
if (area.Height > upper + lower) Segment(upper, area.Height - upper - lower, .72f);
|
||||
if (area.Height > upper + lower) Segment(upper, area.Height - upper - lower, sceneOpacity);
|
||||
for (var y = area.Height - lower; y < area.Height; y += step)
|
||||
{
|
||||
var height = Math.Min(step, area.Height - y);
|
||||
Segment(y, height, .72f * (area.Height - y - height / 2f) / lower);
|
||||
Segment(y, height, sceneOpacity * (area.Height - y - height / 2f) / lower);
|
||||
}
|
||||
g.InterpolationMode = interpolation;
|
||||
}
|
||||
// Same image coordinate space above and below the client title area.
|
||||
var offset = header ? 0 : S(HeaderHeight);
|
||||
var offset = header ? 0 : headerArtworkOffset > 0 ? headerArtworkOffset : S(HeaderHeight);
|
||||
var artHeight = S(HeaderHeight + 72);
|
||||
Art(g, new Rectangle(0, -offset, size.Width, artHeight));
|
||||
var fade = new Rectangle(0, artHeight - offset - S(40), size.Width, S(40) + 1);
|
||||
using var mist = new LinearGradientBrush(fade, Color.FromArgb(0, Brand.Surface), Brand.Surface, 90)
|
||||
{ WrapMode = WrapMode.TileFlipXY };
|
||||
g.FillRectangle(mist, fade);
|
||||
var artwork = new Rectangle(0, -offset, size.Width, artHeight);
|
||||
if (login)
|
||||
BlendLoginHeader(g, artwork, Math.Max(1, S(58)), Math.Max(1, S(1)));
|
||||
else
|
||||
{
|
||||
Art(g, artwork);
|
||||
var fade = new Rectangle(0, artwork.Bottom - S(40), size.Width, S(40) + 1);
|
||||
using var mist = new LinearGradientBrush(fade, Color.FromArgb(0, Brand.Surface), Brand.Surface, 90)
|
||||
{ WrapMode = WrapMode.TileFlipXY };
|
||||
g.FillRectangle(mist, fade);
|
||||
}
|
||||
if (!header) Clouds(g, new Rectangle(size.Width - S(240), S(8), S(105), S(46)), .3f);
|
||||
}
|
||||
|
||||
private static void BlendLoginHeader(Graphics g, Rectangle artwork, int blendHeight, int step)
|
||||
{
|
||||
var blendTop = Math.Max(0, artwork.Bottom - blendHeight);
|
||||
if (blendTop > 0) DrawBand(0, blendTop, 1f);
|
||||
for (var y = blendTop; y < artwork.Bottom; y += step)
|
||||
{
|
||||
var height = Math.Min(step, artwork.Bottom - y);
|
||||
DrawBand(y, height, (artwork.Bottom - y - height / 2f) / blendHeight);
|
||||
}
|
||||
|
||||
void DrawBand(int y, int height, float opacity)
|
||||
{
|
||||
var state = g.Save();
|
||||
g.IntersectClip(new Rectangle(0, y, artwork.Width, height));
|
||||
Art(g, artwork, opacity);
|
||||
g.Restore(state);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DashboardBackdrop(Graphics g, Size size, int dpi, int headerOffset)
|
||||
{
|
||||
int S(int value) => (int)Math.Round(value * dpi / 96f);
|
||||
var bounds = new Rectangle(Point.Empty, size);
|
||||
using var sky = new LinearGradientBrush(bounds, Color.FromArgb(211, 235, 251),
|
||||
Color.FromArgb(218, 238, 251), 90f)
|
||||
{
|
||||
WrapMode = WrapMode.TileFlipXY,
|
||||
InterpolationColors = new ColorBlend
|
||||
{
|
||||
Colors = [Color.FromArgb(211, 235, 251), Color.FromArgb(232, 245, 254), Color.FromArgb(218, 238, 251)],
|
||||
Positions = [0f, .49f, 1f],
|
||||
},
|
||||
};
|
||||
g.FillRectangle(sky, bounds);
|
||||
if (Landscape.Value is not { } landscape) return;
|
||||
|
||||
// Keep the sun in the header and use the lower mountains as a faint
|
||||
// backdrop. Drawing the entire image again duplicates the sun and
|
||||
// competes with the chart at compact sizes.
|
||||
var scale = Math.Max(size.Width / (double)landscape.Width, size.Height / (landscape.Height * .74));
|
||||
var width = (int)Math.Ceiling(landscape.Width * scale);
|
||||
var height = (int)Math.Ceiling(landscape.Height * scale);
|
||||
Art(g, new Rectangle((size.Width - width) / 2, size.Height - height, width, height), .27f);
|
||||
|
||||
// Continue the header panorama into the upper edge, fading the image
|
||||
// itself into the dashboard scenery so there is no hard divider.
|
||||
var panoramaHeight = Math.Max(1, S(HeaderHeight + 72));
|
||||
var offset = Math.Clamp(headerOffset > 0 ? headerOffset : S(HeaderHeight), 0, panoramaHeight - 1);
|
||||
var transition = Math.Min(Math.Min(size.Height, S(60)), panoramaHeight - offset);
|
||||
var step = Math.Max(1, S(2));
|
||||
using var attributes = new ImageAttributes();
|
||||
var interpolation = g.InterpolationMode;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
try
|
||||
{
|
||||
for (var y = 0; y < transition; y += step)
|
||||
{
|
||||
var bandHeight = Math.Min(step, transition - y);
|
||||
var fade = 1f - (y + bandHeight / 2f) / transition;
|
||||
var opacity = fade * fade;
|
||||
attributes.SetColorMatrix(new ColorMatrix { Matrix33 = opacity });
|
||||
g.DrawImage(landscape, new Rectangle(0, y, size.Width, bandHeight), 0,
|
||||
(offset + y) * landscape.Height / (float)panoramaHeight, landscape.Width,
|
||||
bandHeight * landscape.Height / (float)panoramaHeight, GraphicsUnit.Pixel, attributes);
|
||||
}
|
||||
}
|
||||
finally { g.InterpolationMode = interpolation; }
|
||||
}
|
||||
|
||||
internal static void Clouds(Graphics g, Rectangle area, float opacity)
|
||||
{
|
||||
if (area.Width <= 0 || area.Height <= 0) return;
|
||||
@@ -147,14 +230,25 @@ internal static class ScenicTheme
|
||||
|
||||
internal sealed class ScenicPanel : Panel
|
||||
{
|
||||
private Bitmap? _loginBackdrop;
|
||||
private int _loginBackdropDpi;
|
||||
private bool _loginBackdropFooter;
|
||||
private Bitmap? _artBackdrop;
|
||||
private int _artBackdropDpi, _artBackdropHeaderOffset, _headerArtworkOffset;
|
||||
private bool _artBackdropFooter, _artBackdropLogin, _artBackdropDashboard;
|
||||
// Only the account-content subtree is composed. Do not compose the entire
|
||||
// top-level window or delay native caption/resize/input handling.
|
||||
internal bool ComposeChildren { get; set; }
|
||||
internal bool FooterArtwork { get; set; }
|
||||
internal bool LoginArtwork { get; set; }
|
||||
internal bool DashboardArtwork { get; set; }
|
||||
internal int HeaderArtworkOffset
|
||||
{
|
||||
get => _headerArtworkOffset;
|
||||
set
|
||||
{
|
||||
if (_headerArtworkOffset == value) return;
|
||||
_headerArtworkOffset = value;
|
||||
if (LoginArtwork || DashboardArtwork) Invalidate(true);
|
||||
}
|
||||
}
|
||||
internal bool ParentArtwork { get; set; }
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
@@ -176,42 +270,46 @@ internal sealed class ScenicPanel : Panel
|
||||
e.Graphics.Restore(state);
|
||||
return;
|
||||
}
|
||||
if (!LoginArtwork)
|
||||
if (!LoginArtwork && !DashboardArtwork)
|
||||
{
|
||||
ScenicTheme.Backdrop(e.Graphics, ClientSize, DeviceDpi, footer: FooterArtwork);
|
||||
return;
|
||||
}
|
||||
if (Width <= 0 || Height <= 0) return;
|
||||
// Transparent labels ask their ancestors to repaint. Cache decoration
|
||||
// only (never child text/account data), so each label does not resample
|
||||
// a full-window landscape during the first login frame.
|
||||
if (_loginBackdrop is null || _loginBackdrop.Size != ClientSize
|
||||
|| _loginBackdropDpi != DeviceDpi || _loginBackdropFooter != FooterArtwork)
|
||||
// Transparent children can ask for the same backdrop many times.
|
||||
// Cache only decoration, never the account data or child controls.
|
||||
if (_artBackdrop is null || _artBackdrop.Size != ClientSize || _artBackdropDpi != DeviceDpi
|
||||
|| _artBackdropFooter != FooterArtwork || _artBackdropLogin != LoginArtwork
|
||||
|| _artBackdropDashboard != DashboardArtwork || _artBackdropHeaderOffset != HeaderArtworkOffset)
|
||||
{
|
||||
Bitmap? next = null;
|
||||
try
|
||||
{
|
||||
next = new Bitmap(Width, Height);
|
||||
using (var graphics = Graphics.FromImage(next))
|
||||
ScenicTheme.Backdrop(graphics, ClientSize, DeviceDpi, footer: FooterArtwork, login: true);
|
||||
ScenicTheme.Backdrop(graphics, ClientSize, DeviceDpi, footer: FooterArtwork,
|
||||
login: LoginArtwork, dashboard: DashboardArtwork, headerArtworkOffset: HeaderArtworkOffset);
|
||||
// Transfer the completed bitmap rather than copying the whole
|
||||
// canvas on the UI thread. A failed render leaves the previous
|
||||
// cache owned and intact; only the incomplete replacement dies.
|
||||
var previous = _loginBackdrop;
|
||||
_loginBackdrop = next;
|
||||
var previous = _artBackdrop;
|
||||
_artBackdrop = next;
|
||||
next = null;
|
||||
_loginBackdropDpi = DeviceDpi;
|
||||
_loginBackdropFooter = FooterArtwork;
|
||||
_artBackdropDpi = DeviceDpi;
|
||||
_artBackdropFooter = FooterArtwork;
|
||||
_artBackdropLogin = LoginArtwork;
|
||||
_artBackdropDashboard = DashboardArtwork;
|
||||
_artBackdropHeaderOffset = HeaderArtworkOffset;
|
||||
previous?.Dispose();
|
||||
}
|
||||
finally { next?.Dispose(); }
|
||||
}
|
||||
e.Graphics.DrawImageUnscaled(_loginBackdrop, Point.Empty);
|
||||
e.Graphics.DrawImageUnscaled(_artBackdrop, Point.Empty);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing) { _loginBackdrop?.Dispose(); _loginBackdrop = null; }
|
||||
if (disposing) { _artBackdrop?.Dispose(); _artBackdrop = null; }
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user