-
-
Notifications
You must be signed in to change notification settings - Fork 70
Advanced examples
BarRaider edited this page Mar 24, 2021
·
1 revision
The following is an example of how you can use the title settings built-in the property inspector to show it as an image on the key:
// Note this exists in SdTools.Wrappers namespace
private SdTools.Wrappers.TitleParameters titleParameters = null;
private string userTitle;
// Constructor
public MyPlugin(SDConnection connection, InitialPayload payload) : base(connection, payload)
{
if (payload.Settings == null || payload.Settings.Count == 0)
{
// Create default settings and save them
this.settings = PluginSettings.CreateDefaultSettings();
_ = Connection.SetSettingsAsync(JObject.FromObject(this.settings));
}
else
{
this.settings = payload.Settings.ToObject<PluginSettings>();
}
// Get title information
Connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;
}
private void Connection_OnTitleParametersDidChange(object sender, SdTools.Wrappers.SDEventReceivedEventArgs<SdTools.Events.TitleParametersDidChange> e)
{
titleParameters = e.Event?.Payload?.TitleParameters;
userTitle = e.Event?.Payload?.Title;
}
// Display on key with OnTick
public async override void OnTick()
{
using (Bitmap img = Tools.GenerateGenericKeyImage(out Graphics graphics))
{
int height = img.Height;
int width = img.Width;
Tools.AddTextPathToGraphics(graphics, titleParameters, img.Height, img.Width, userTitle);
await Connection.SetImageAsync(img);
graphics.Dispose();
}
}
© Copyright 2021 By BarRaider