GX Typhoon WidgetPlugin SDK Creation Guide

GX and Typhoon hardware, this includes, displays, cables and accessory cards.

Moderator: Mods

Post Reply
Daniel Divino
Matrix Orbital
Matrix Orbital
Posts: 98
Joined: Thu Sep 24, 2015 9:38 am

GX Typhoon WidgetPlugin SDK Creation Guide

Post by Daniel Divino » Wed Mar 29, 2017 12:10 pm

1) Open up vs.net and click New Project
2) Choose the language of your choice and create a new Class library project and call it MyWidget
3) Add a reference to CoreInterfaces.dll located in your lcdstudio folder.
4) Add a reference to System.Drawing.dll located in the .net tab of the add reference dialog.
5) Paste the following code into class1.cs (C# is used but this code is that basic it shoudn't be hard to convert to VB.Net)
Code:

Code: Select all

using System; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Drawing.Text; 
using LcdStudio.Base; 
using LcdStudio.CoreInterfaces; 

namespace MyWidget 
{ 
  
   public class MyWidgetRenderer : AbstractWidget 
   { 
      public override void Render() 
      { 
         Graphics g = Graphics.FromImage(_Canvas); 
          
         //Clear the drawing space 
         g.Clear(CoreSettings.ColorOff); 

         //Define some Drawing tools 
         Pen p = new Pen(CoreSettings.ColorOn); 
         Brush B = new SolidBrush(CoreSettings.ColorOn); 

         //Draw our neat little square 
         Rectangle R = new Rectangle(0,0,this.rect.Width-1,this.rect.Height-1); 
         g.DrawRectangle(p,R); 
         g.DrawLine(p, R.X, R.Y, R.Right,R.Bottom); 
         g.DrawLine(p, R.X, R.Bottom, R.Right,R.Top); 
          

         //If there is an data item set draw it 
         if (LcdDataItem != null) 
         { 
            //turn off aa and other text smoothing effects 
            g.SmoothingMode = SmoothingMode.None; 
            g.TextRenderingHint  = TextRenderingHint.SingleBitPerPixelGridFit; 
            //Draw the text 
            g.DrawString(LcdDataItem.Value.ToString(),new Font("Arial",12),B,0,0 ); 
         } 
          
         // Neatly dispose our gfx object 
         g.Dispose(); 
      } 

      public override bool AcceptsData(LcdDataItem i) 
      { 
         //our widget accepts any data you drop on it. 
         return true; 
      } 

   } 
  
   public class Plugin : AbstractPlugin 
   {  
      public override void Initialize(System.Xml.XmlNode configNode) 
      { 
         IToolboxView tbv = (IToolboxView)ServiceManager.GetService(typeof(IToolboxView)); 
         if (tbv!=null) 
         { 
            // The perferd way to do this is ofcourse embed an icon into the dll but for 
            // Simplicity reasons we'll just draw one our selves. 
            Bitmap MyIcon = new Bitmap(32,32); 
            Graphics G = Graphics.FromImage(MyIcon); 
            G.Clear(Color.Purple); 
            G.DrawString("HI",new Font("Arial",15),Brushes.GreenYellow,0,0); 
            G.Dispose(); 
             
            // Add The icon to the Toolboxpanel 
            int iMyIcon = tbv.AddIcon(MyIcon) ; 
             
            //Add The Widget To the toolbox 
            tbv.AddItem("MyWidgets","Square",iMyIcon,typeof(MyWidgetRenderer)); 
         } 
      } 
   } 
}
6) Create a file in your LcdStudio folder called MyWidget.Plugin with the following lines

Code: Select all

<?xml version="1.0" encoding="utf-8" ?> 
<Plugins> 
   <Plugin ID="My Widget" Type="MyWidget.Plugin, MyWidget" Visible="Yes" > 
      <Depends ID="ToolboxView" /> 
   </Plugin> 
</Plugins> 
7) Run LcdStudio and add your Plugin in the config panel & Restart the application

You'll find a how-to guide to creating DataPlugin SDK's here.

Cheers,
Daniel
Daniel Divino
Technical Support
Matrix Orbital

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests