mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
155 lines
4.5 KiB
C#
155 lines
4.5 KiB
C#
/*
|
|
Copyright (C) 2011 Birunthan Mohanathas
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*/
|
|
|
|
// Define/undefine to control exports. Undefine to infrom that this plugin does not support
|
|
// a particular function.
|
|
#define ExportUpdate
|
|
#undef ExportGetString
|
|
#undef ExportExecuteBang
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using Rainmeter;
|
|
|
|
namespace ExampleCS
|
|
{
|
|
/// <summary>
|
|
/// Represents a measure. Members are specific to a measure. Methods are called by Rainmeter
|
|
/// when needed.
|
|
/// </summary>
|
|
internal class Measure
|
|
{
|
|
/// <summary>
|
|
/// Called when a measure is created.
|
|
/// </summary>
|
|
internal Measure()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when a measure is destroyed. Use this rather than a destructor to perform
|
|
/// cleanup.
|
|
/// </summary>
|
|
internal void Cleanup()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the measure settings must be (re)read.
|
|
/// </summary>
|
|
internal void Reload(Rainmeter.API rm)
|
|
{
|
|
// Examples:
|
|
// string value = rm.ReadString("TestOption", "DefaultValue");
|
|
// double value = rm.ReadFormula("TestOption", 20);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called when the measure settings must be (re)read.
|
|
/// </summary>
|
|
#if ExportUpdate
|
|
internal double Update()
|
|
{
|
|
return 42.0;
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Called when the string representation of the measure value is required.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Can be called multiple times per update cycle. Do not call heavy functions here.
|
|
/// Instead create a string member, set it in Update, and simply return it here.
|
|
/// </remarks>
|
|
#if ExportGetString
|
|
internal string GetString()
|
|
{
|
|
return "Hello, world!";
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Called when as a result of a !CommandMeasure bang aimed at the measure.
|
|
/// </summary>
|
|
#if ExportExecuteBang
|
|
internal void ExecuteBang(string args)
|
|
{
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Handles communication between Rainmeter and the plugin.
|
|
/// </summary>
|
|
public static class Plugin
|
|
{
|
|
[DllExport]
|
|
public unsafe static void Initialize(void** data)
|
|
{
|
|
IntPtr dataPtr = (IntPtr)((void*)*data);
|
|
Measures.Add(dataPtr, new Measure());
|
|
}
|
|
|
|
[DllExport]
|
|
public unsafe static void Finalize(void* data)
|
|
{
|
|
IntPtr dataPtr = (IntPtr)data;
|
|
Measures[dataPtr].Cleanup();
|
|
Measures.Remove(dataPtr);
|
|
}
|
|
|
|
[DllExport]
|
|
public unsafe static void Reload(void* data, void* rm, double* maxValue)
|
|
{
|
|
IntPtr dataPtr = (IntPtr)data;
|
|
Measures[dataPtr].Reload(new Rainmeter.API((IntPtr)rm));
|
|
}
|
|
|
|
#if ExportUpdate
|
|
[DllExport]
|
|
public unsafe static double Update(void* data)
|
|
{
|
|
IntPtr dataPtr = (IntPtr)data;
|
|
return Measures[dataPtr].Update();
|
|
}
|
|
#endif
|
|
|
|
#if ExportGetString
|
|
[DllExport]
|
|
public unsafe static char* GetString(void* data)
|
|
{
|
|
IntPtr dataPtr = (IntPtr)data;
|
|
return Rainmeter.API.ToUnsafe(Measures[dataPtr].GetString());
|
|
}
|
|
#endif
|
|
|
|
#if ExportExecuteBang
|
|
[DllExport]
|
|
public unsafe static void ExecuteBang(void* data, char* args)
|
|
{
|
|
IntPtr dataPtr = (IntPtr)data;
|
|
Measures[dataPtr].ExecuteBang(new string(args));
|
|
Measures.Remove(dataPtr);
|
|
}
|
|
#endif
|
|
|
|
internal static Dictionary<IntPtr, Measure> Measures = new Dictionary<IntPtr, Measure>();
|
|
}
|
|
}
|