-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Piglet.Plugin.Barn.Helpers; | ||
using Piglet.SDK.Core; | ||
using Piglet.SDK.Interfaces; | ||
using Piglet.SDK.Models; | ||
using Piglet.SDK.Util; | ||
using System; | ||
using System.Drawing; | ||
|
||
namespace Piglet.Plugin.Barn.Commands | ||
{ | ||
[CompatibleWith(DeviceModel.XL)] | ||
[ExpectedInteractionFormat(CommandType.ACTIVATION)] | ||
class ShowCPUUsage : IPigletCommand | ||
{ | ||
public string Name => "Launch Application"; | ||
public string Description => "Launches an application on the machine."; | ||
|
||
public void ExecuteOnAction(int keyIndex, string arguments) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void ExecuteOnActivation(int keyIndex, string arguments) | ||
{ | ||
var randomIconFromText = IconGenerator.GenerateTestImageFromText("92%", new Font("Consolas", 12), Color.Red, Color.Blue); | ||
var resizeImage = ImageHelpers.ResizeImage(ImageHelpers.GetImageBuffer(randomIconFromText), DeviceConstants.XLButtonSize, DeviceConstants.XLButtonSize); | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Drawing; | ||
using System.Drawing.Text; | ||
|
||
namespace Piglet.Plugin.Barn.Helpers | ||
{ | ||
internal class IconGenerator | ||
{ | ||
// Adapted from this snippet: https://stackoverflow.com/a/2070493/303696 | ||
internal static Image GenerateTestImageFromText(string text, Font font, Color textColor, Color backgroundColor) | ||
{ | ||
Image img = new Bitmap(1, 1); | ||
Graphics drawing = Graphics.FromImage(img); | ||
|
||
SizeF textSize = drawing.MeasureString(text, font); | ||
|
||
img.Dispose(); | ||
drawing.Dispose(); | ||
|
||
img = new Bitmap((int)textSize.Width, (int)textSize.Height); | ||
|
||
drawing = Graphics.FromImage(img); | ||
|
||
drawing.Clear(backgroundColor); | ||
|
||
Brush textBrush = new SolidBrush(textColor); | ||
|
||
drawing.TextRenderingHint = TextRenderingHint.AntiAlias; | ||
drawing.DrawString(text, font, textBrush, 0, 0); | ||
|
||
drawing.Save(); | ||
|
||
textBrush.Dispose(); | ||
drawing.Dispose(); | ||
|
||
return img; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters