Repository navigation
Expand file tree
/
Copy pathPictureViewerWidgetObject.cs
More file actions
96 lines (82 loc) · 3.45 KB
/
Copy pathPictureViewerWidgetObject.cs
File metadata and controls
96 lines (82 loc) · 3.45 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using WigiDashWidgetFramework;
using WigiDashWidgetFramework.WidgetUtility;
namespace PictureViewerWidget
{
public class PictureViewerWidgetObject : IWidgetObject
{
public Guid Guid => new Guid("{A1B2C3D4-1234-5678-90AB-CDEF12345678}");
public string Name => "Picture Viewer";
public string Author => "headpiece747";
public string Website => "https://eclipticsight.com";
public string Description => "Click to cycle through pictures in a folder.";
// Assembly.GetName().Version is always 4-part (e.g. 1.0.0.0).
// Trim trailing .0 segments so the display matches the 3-part
// version set in AssemblyInfo.cs (e.g. 1.0.0).
public Version Version
{
get
{
var v = Assembly.GetExecutingAssembly().GetName().Version;
if (v == null) return new Version(1, 0, 0);
if (v.Revision != 0)
return new Version(v.Major, v.Minor, v.Build, v.Revision);
if (v.Build != 0)
return new Version(v.Major, v.Minor, v.Build);
return new Version(v.Major, v.Minor);
}
}
public SdkVersion TargetSdk => WidgetUtility.CurrentSdkVersion;
public List<WidgetSize> SupportedSizes => new List<WidgetSize>
{
new WidgetSize(2, 2),
new WidgetSize(3, 3),
new WidgetSize(4, 4),
new WidgetSize(5, 4)
};
public IWidgetManager WidgetManager { get; set; }
public string LastErrorMessage { get; set; }
// Cached once; disposed in Unload()
private Bitmap _previewImage;
// All three properties share the same cached instance
public Bitmap PreviewImage => EnsurePreview();
public Bitmap WidgetThumbnail => EnsurePreview();
public Bitmap GetWidgetPreview(WidgetSize _) => EnsurePreview();
private Bitmap EnsurePreview()
{
if (_previewImage == null)
_previewImage = CreatePlaceholderBitmap("Pic Viewer");
return _previewImage;
}
public IWidgetInstance CreateWidgetInstance(WidgetSize widgetSize, Guid instanceGuid)
=> new PictureViewerWidgetInstance(this, widgetSize, instanceGuid);
public bool RemoveWidgetInstance(Guid instanceGuid) => true;
public WidgetError Load(string resourcePath) => WidgetError.NO_ERROR;
public WidgetError Unload()
{
_previewImage?.Dispose();
_previewImage = null;
return WidgetError.NO_ERROR;
}
private Bitmap CreatePlaceholderBitmap(string text)
{
var bmp = new Bitmap(200, 145);
using (var g = Graphics.FromImage(bmp))
using (var f = new Font("Arial", 20, System.Drawing.FontStyle.Bold))
using (var sf = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center
})
{
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
g.Clear(Color.Red);
g.DrawString(text, f, Brushes.White, new RectangleF(0, 0, 200, 145), sf);
}
return bmp;
}
}
}