Skip to content

Commit

Permalink
v2.5.0 - StreamDeckMobile support + GenerateGenericKeyImage method
Browse files Browse the repository at this point in the history
- Added support for StreamDeckMobile device type
- Added new `Tools.GenerateGenericKeyImage()` function that generates an image that fits all Stream Decks
  • Loading branch information
BarRaider committed Aug 12, 2019
1 parent c49194b commit f5c6d0e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 38 deletions.
4 changes: 4 additions & 0 deletions NUGET.md
Expand Up @@ -7,6 +7,10 @@
**Author's website and contact information:** [https://barraider.github.io](https://barraider.github.io)
** Samples of plugins using this framework: [Samples][1]

### Version 2.5 is out!
- Added support for StreamDeckMobile device type
- Added new `Tools.GenerateGenericKeyImage()` function that generates an image that fits all Stream Decks

### Version 2.4.2 is out!
- Added support for Plugin version inside the StreamDeckInfo class.
- Current plugin version is now shown in the `pluginlog.log` log file
Expand Down
33 changes: 18 additions & 15 deletions README.md
Expand Up @@ -13,15 +13,17 @@
* [Install.bat](https://github.com/BarRaider/streamdeck-tools/blob/master/utils/install.bat) - Script that quickly uninstalls and reinstalls your plugin on the streamdeck (view batch file for more details)
* [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio - Automatically creates a project with all the files needed to compile a plugin


### Version 2.5 is out!
- Added support for StreamDeckMobile device type
- Added new `Tools.GenerateGenericKeyImage()` function that generates an image that fits all Stream Decks
-

### Version 2.4.2 is out!
- Added support for Plugin version inside the StreamDeckInfo class.
- Current plugin version is now shown in the `pluginlog.log` log file
- Publishing through `GlobalSettingsManager` now raises the GlobalSettingsReceived event by default

### Version 2.3 is out!
v2.3:
- Added support for StreamDeck XL
1. `Connection.DeviceInfo()` now gives you information on the device the plugin is on (including the `StreamDeckDeviceType`)
2. `StreamDeckDeviceType` enum now recognizes the StreamDeck XL
Expand Down Expand Up @@ -94,19 +96,6 @@ class Program

3. There is no step 3 - that's it! The abstract functions from PluginBase that are implemented in MyPlugin hold all the basics needed for a plugin to work. You can always listen to additional events using the `Connection` property.

## Upgrading from version 1.x
1. Change your Plugin's constructor second parameter to receive a `InitialPayload` instead of a `JObject`. Explanation:
The PluginBase constructor no longer receives a `JObject` called "settings". It now receives an actual `InitialPayload` class named "payload". (see example above)
The InitialPayload class hold additional information, not just the Settings such as information about the Stream Deck device and the actual row and column in the Stream Deck where the plugin is located.

2. Modify your `KeyPressed` and `KeyReleased` function to receive a parameter of type `KeyPayload`. Explanation:
The `KeyPayload` class includes information relevant to when the key is pressed or released. One example is whether this is part of a MultiAction or not.

3. The `UpdateSettings` method has been deprecated. Instead, implement (or just leave empty) the `ReceivedSettings` and the `ReceivedGlobalSettings` methods.
Explanation:
`UpdateSettings` is no longer needed in StreamDeck SDK 4.1 - the `ReceivedSettings` function will be called every time the settings change in the Property Inspector.
If you used the same concepts as in the samples linked above: You created a private class in your plugin, where each setting is a Property that has a JsonProperty attribute. As such, you can use the `Tools.AutoPopulateSettings()` method (as shown above) instead of manually updating your settings.

## Auto-populating plugin settings
By following a very basic convention, the StreamDeck-Tools can handle populating all the settings between the PropertyInspector and your plugin. All the Stream-Deck Tools samples use this convention so you can see it in the samples too:
1. In your Plugin create a private class that will hold your plugin's settings. In the samples and in this example, we will call the private class `PluginSettings`
Expand Down Expand Up @@ -153,4 +142,18 @@ public async override void ReceivedSettings(ReceivedSettingsPayload payload)
}
```

#### Upgrading from version 1.x
1. Change your Plugin's constructor second parameter to receive a `InitialPayload` instead of a `JObject`. Explanation:
The PluginBase constructor no longer receives a `JObject` called "settings". It now receives an actual `InitialPayload` class named "payload". (see example above)
The InitialPayload class hold additional information, not just the Settings such as information about the Stream Deck device and the actual row and column in the Stream Deck where the plugin is located.

2. Modify your `KeyPressed` and `KeyReleased` function to receive a parameter of type `KeyPayload`. Explanation:
The `KeyPayload` class includes information relevant to when the key is pressed or released. One example is whether this is part of a MultiAction or not.

3. The `UpdateSettings` method has been deprecated. Instead, implement (or just leave empty) the `ReceivedSettings` and the `ReceivedGlobalSettings` methods.
Explanation:
`UpdateSettings` is no longer needed in StreamDeck SDK 4.1 - the `ReceivedSettings` function will be called every time the settings change in the Property Inspector.
If you used the same concepts as in the samples linked above: You created a private class in your plugin, where each setting is a Property that has a JsonProperty attribute. As such, you can use the `Tools.AutoPopulateSettings()` method (as shown above) instead of manually updating your settings.


[1]: https://github.com/BarRaider/streamdeck-tools/blob/master/samples.md
7 changes: 6 additions & 1 deletion barraider-sdtools/StreamDeckInfo/StreamDeckDeviceInfo.cs
Expand Up @@ -25,7 +25,12 @@ public enum StreamDeckDeviceType
/// <summary>
/// StreamDeck XL with 32 keys
/// </summary>
StreamDeckXL = 2
StreamDeckXL = 2,

/// <summary>
/// StreamDeck Mobile version
/// </summary>
StreamDeckMobile = 3
}

/// <summary>
Expand Down
60 changes: 44 additions & 16 deletions barraider-sdtools/Tools.cs
Expand Up @@ -23,6 +23,7 @@ public static class Tools
private const int CLASSIC_KEY_DEFAULT_WIDTH = 72;
private const int XL_KEY_DEFAULT_HEIGHT = 96;
private const int XL_KEY_DEFAULT_WIDTH = 96;
private const int GENERIC_KEY_IMAGE_SIZE = 144;

#region Image Related

Expand Down Expand Up @@ -104,11 +105,15 @@ public static int GetKeyDefaultHeight(StreamDeckDeviceType streamDeckType)
{
case StreamDeckDeviceType.StreamDeckClassic:
case StreamDeckDeviceType.StreamDeckMini:
case StreamDeckDeviceType.StreamDeckMobile:
return CLASSIC_KEY_DEFAULT_HEIGHT;
case StreamDeckDeviceType.StreamDeckXL:
return XL_KEY_DEFAULT_HEIGHT;
default:
Logger.Instance.LogMessage(TracingLevel.ERROR, $"SDTools GetKeyDefaultHeight Error: Invalid StreamDeckDeviceType: {streamDeckType}");
break;
}
return -1;
return 1;
}

/// <summary>
Expand All @@ -123,11 +128,15 @@ public static int GetKeyDefaultWidth(StreamDeckDeviceType streamDeckType)
{
case StreamDeckDeviceType.StreamDeckClassic:
case StreamDeckDeviceType.StreamDeckMini:
case StreamDeckDeviceType.StreamDeckMobile:
return CLASSIC_KEY_DEFAULT_WIDTH;
case StreamDeckDeviceType.StreamDeckXL:
return XL_KEY_DEFAULT_WIDTH;
default:
Logger.Instance.LogMessage(TracingLevel.ERROR, $"SDTools GetKeyDefaultHeight Error: Invalid StreamDeckDeviceType: {streamDeckType}");
break;
}
return -1;
return 1;
}

/// <summary>
Expand All @@ -140,19 +149,40 @@ public static Bitmap GenerateKeyImage(StreamDeckDeviceType streamDeckType, out G
{
int height = GetKeyDefaultHeight(streamDeckType);
int width = GetKeyDefaultWidth(streamDeckType);
Bitmap bitmap = new Bitmap(width, height);
var brush = new SolidBrush(Color.Black);

graphics = Graphics.FromImage(bitmap);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
return GenerateKeyImage(height, width, out graphics);
}

public static Bitmap GenerateGenericKeyImage(out Graphics graphics)
{
return GenerateKeyImage(GENERIC_KEY_IMAGE_SIZE, GENERIC_KEY_IMAGE_SIZE, out graphics);
}

private static Bitmap GenerateKeyImage(int height, int width, out Graphics graphics)
{
try
{
Bitmap bitmap = new Bitmap(width, height);
var brush = new SolidBrush(Color.Black);

graphics = Graphics.FromImage(bitmap);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

//Fill background black
graphics.FillRectangle(brush, 0, 0, width, height);
return bitmap;
//Fill background black
graphics.FillRectangle(brush, 0, 0, width, height);
return bitmap;
}
catch (Exception ex)
{
Logger.Instance.LogMessage(TracingLevel.ERROR, $"SDTools GenerateKeyImage exception: {ex} Height: {height} Width: {width}");
}
graphics = null;
return null;
}


/// <summary>
/// Extracts the actual filename from a file payload received from the Property Inspector
Expand Down Expand Up @@ -221,8 +251,7 @@ public static int AutoPopulateSettings<T>(T toSettings, JObject fromJObject)
object[] attributes = prop.GetCustomAttributes(true);
foreach (object attr in attributes)
{
JsonPropertyAttribute jprop = attr as JsonPropertyAttribute;
if (jprop != null)
if (attr is JsonPropertyAttribute jprop)
{
dicProperties.Add(jprop.PropertyName, prop);
break;
Expand All @@ -249,8 +278,7 @@ public static PluginActionId[] AutoLoadPluginActions()
var pluginTypes = Assembly.GetEntryAssembly().GetTypes().Where(typ => typ.IsClass && typ.GetCustomAttributes(typeof(PluginActionIdAttribute), true).Length > 0).ToList();
pluginTypes.ForEach(typ =>
{
var attr = typ.GetCustomAttributes(typeof(PluginActionIdAttribute), true).First() as PluginActionIdAttribute;
if (attr != null)
if (typ.GetCustomAttributes(typeof(PluginActionIdAttribute), true).First() is PluginActionIdAttribute attr)
{
actions.Add(new PluginActionId(attr.ActionId, typ));
}
Expand Down
12 changes: 6 additions & 6 deletions barraider-sdtools/barraider-sdtools.csproj
Expand Up @@ -16,19 +16,19 @@ Feel free to contact me for more information: https://barraider.github.io</Descr
<PackageTags>StreamDeck Elgato Library Plugin Stream Deck</PackageTags>
<PackageId>StreamDeck-Tools</PackageId>
<PackageIconUrl>https://raw.githubusercontent.com/BarRaider/barraider.github.io/master/images/BRLogo.png</PackageIconUrl>
<AssemblyVersion>2.4.2.0</AssemblyVersion>
<FileVersion>2.4.2.0</FileVersion>
<Version>2.4.2</Version>
<PackageReleaseNotes>2.4.2 - 1. Added support for Plugin version inside the StreamDeckInfo class. Current plugin version is now shown in logs
2. Publishing through GlobalSettingsManager now raises the GlobalSettingsReceived event by default</PackageReleaseNotes>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<FileVersion>2.5.0.0</FileVersion>
<Version>2.5.0</Version>
<PackageReleaseNotes>2.5.0 - 1. Support for StreamDeckMobile device type
2. Added new `Tools.GenerateGenericKeyImage()` function that generates an image that fits all Stream Decks</PackageReleaseNotes>
<RootNamespace>BarRaider.SdTools</RootNamespace>
<AssemblyName>StreamDeckTools</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<DocumentationFile>D:\Projects\github\barraider-sdtools\barraider-sdtools\barraider-sdtools.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.5.0" />
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NLog" Version="4.6.6" />
<PackageReference Include="streamdeck-client-csharp" Version="4.1.1" />
Expand Down

0 comments on commit f5c6d0e

Please sign in to comment.