-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathapi.html
More file actions
278 lines (267 loc) · 9.77 KB
/
api.html
File metadata and controls
278 lines (267 loc) · 9.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
---
layout: docs
permalink: developers/plugin/csharp/api/
title: 'C# API Overview'
---
<p>This is an overview of the functions available in the C# Rainmeter API. All the functions are behind a Rainmeter.API wrapper which is created using the <code>rm</code> IntPtr.</p>
<dl>
<dt id="ReadString"><code>ReadString</code> <small><code>string ReadString(string option, string defValue, bool replaceMeasures = true)</code></small></dt>
<dd>
<p>Returns a string representation of an option.</p>
<p>
<ul>
<li><code>option</code> : Option name to be read from the measure.</li>
<li><code>defValue</code> : Default value for the option if it is not found or invalid.</li>
<li><code>replaceMeasures</code> : If true, replaces section variables in the returned string.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
// The following will replace regular variables and
// section variables in the 'Value' option.
string value = rm.ReadString("Value", "DefaultValue");
// The following will only replace regular variables,
// but NOT section variables like [MeasureNames].
string action = rm.ReadString("Action", "", false);
}
```
</dd>
<dt id="ReadStringFromSection"><code>ReadStringFromSection</code> <small><span style="font-size: 0.85em;"><code>string ReadStringFromSection(string section, string option, string defValue, bool replace = true)</code></span></small></dt>
<dd>
<p>Returns a string representation of an option from a section.</p>
<p>
</p><ul>
<li><code>section</code> : Section name to read the option from.</li>
<li><code>option</code> : Option name to be read from the measure/meter.</li>
<li><code>defValue</code> : Default value for the option if it is not found or invalid.</li>
<li><code>replace</code> : If true, replaces section variables in the returned string.</li>
</ul>
<p></p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
// The following will replace regular variables and
// section variables in the 'Value' option.
string value = rm.ReadStringFromSection("Section","Option", "DefaultValue");
// The following will only replace regular variables,
// but NOT section variables like [MeasureNames].
string action = rm.ReadStringFromSection("Section", "Action", "", false);
}
```
</dd>
<dt id="ReadInt"><code>ReadInt</code> <small><code>int ReadInt(string option, int defValue)</code></small></dt>
<dd>
<p>Retrieves the option defined in the skin file and converts it to an integer.</p>
<p>
<ul>
<li><code>option</code> : Option name to be read from the measure.</li>
<li><code>defValue</code> : Default value for the option if it is not found, invalid, or a formula could not be parsed.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
int value = rm.ReadInt("Value", 20);
}
```
</dd>
<dt id="ReadIntFromSection"><code>ReadIntFromSection</code> <small><code>int ReadIntFromSection(string section, string option, int defValue)</code></small></dt></code></small></dt>
<dd>
<p>Retrieves the option defined in a section and converts it to an integer.</p>
<p>
</p><ul>
<li><code>section</code> : Section name to read the option from.</li>
<li><code>option</code> : Option name to be read from the measure/meter.</li>
<li><code>defValue</code> : Default value for the option if it is not found, invalid, or a formula could not be parsed.</li>
</ul>
<p></p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
int value = rm.ReadIntFromSection("Section", "Option", 20);
}
```
</dd>
<dt id="ReadDouble"><code>ReadDouble</code> <small><code>double ReadDouble(string option, double defValue)</code></small></dt>
<dd>
<p>Retrieves the option defined in the plugin measure in the skin file and converts it to a double type.</p>
<p>
<ul>
<li><code>option</code> : Option name to be read from the plugin measure.</li>
<li><code>defValue</code> : Default value for the option if it is not found, invalid, or a formula could not be parsed.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
double value = rm.ReadDouble("Value", 20.0);
}
```
</dd>
<dt id="ReadDoubleFromSection"><code>ReadDoubleFromSection</code> <small><code>double ReadDoubleFromSection(string section, string option, double defValue)</code></small></dt>
<dd>
<p>Retrieves the option defined in any section and converts it to a double type.</p>
<p>
</p><ul>
<li><code>section</code> : Section name to read the option from.</li>
<li><code>option</code> : Option name to be read from the measure/meter.</li>
<li><code>defValue</code> : Default value for the option if it is not found, invalid, or a formula could not be parsed.</li>
</ul>
<p></p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
double value = rm.ReadDoubleFromSection("Section", "Option", 20.0);
}
```
</dd>
</dd>
<dt id="ReadPath"><code>ReadPath</code> <small><code>string ReadPath(string option, string defValue)</code></small></dt>
<dd>
<p>Retrieves the option defined in the skin file and converts a relative path to a absolute path.</p>
<p>
<ul>
<li><code>option</code> : Option name to be read from the measure.</li>
<li><code>defValue</code> : Default value for the option if it is not found or invalid.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
internal void Reload(Rainmeter.API rm, ref double maxValue)
{
string path = rm.ReadPath("MyPath", "C:\\");
}
```
</dd>
<dt id="Execute"><code>Execute</code> <small><code>void Execute(IntPtr skin, string command)</code></small></dt>
<dd>
<p>Executes an <a href="/manual/skins/option-types/#Action">action</a>.</p>
<p>
<ul>
<li><code>skin</code> : Pointer to current skin (see <a href="!plugin/csharp/api/#GetSkin">GetSkin</a>).</li>
<li><code>command</code> : Action to execute.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
internal double Update(IntPtr data)
{
Measure measure = (Measure)data;
// 'mySkin' stored previously in the Initialize function
API.Execute(mySkin, L"[!SetVariable SomeVar 10]");
return 0.0;
}
```
</dd>
<dt id="ReplaceVariables"><code>ReplaceVariables</code> <small><code>string ReplaceVariables(string str)</code></small></dt>
<dd>
<p>Returns a string, replacing any variables (or section variables) within the inputted string.</p>
<p>
<ul>
<li><code>str</code> : String with unresolved variables.</li>
</ul>
</p><h3>Example:</h3>
``` cs
internal double Update()
{
string myVar = ReplaceVariables("#MyVar#").ToUpperInvariant();
if (myVar == "SOMETHING") { return 1.0; }
return 0.0;
}
```
</dd>
<dt id="GetMeasureName"><code>GetMeasureName</code> <small><code>string GetMeasureName()</code></small></dt>
<dd>
<p>Retrieves the name of the measure.</p>
<h3>Example:</h3>
``` cs
internal void Initialize(Rainmeter.API rm)
{
myName = GetMeasureName(); // declare 'myName' as a string in class scope
}
```
</dd>
<dt id="GetSkin"><code>GetSkin</code> <small><code>IntPtr GetSkin()</code></small></dt>
<dd>
<p>Retrieves an internal pointer to the current skin.</p>
<h3>Example:</h3>
``` cs
internal void Initialize(Rainmeter.API rm)
{
mySkin = GetSkin(); // declare 'mySkin' as a IntPtr in class scope
}
```
</dd>
<dt id="GetSkinName"><code>GetSkinName</code> <small><code>string GetSkinName()</code></small></dt>
<dd>
<p>Retrieves full path and name of the skin.</p>
<h3>Example:</h3>
``` cs
internal void Initialize(Rainmeter.API rm)
{
// declare 'skinName' as a string in class scope
skinName = GetSkinName();
}
```
</dd>
<dt id="GetSkinWindow"><code>GetSkinWindow</code> <small><code>IntPtr GetSkinWindow()</code></small></dt>
<dd>
<p>Returns a pointer to the handle (HWND) of the skin window.</p>
<h3>Example:</h3>
``` cs
internal void Initialize(Rainmeter.API rm)
{
// declare 'skinWindow' as a IntPtr in class scope
skinWindow = GetSkinWindow();
}
```
</dd>
<dt id="GetSettingsFile"><code>GetSettingsFile</code> <small><code>string GetSettingsFile()</code></small></dt>
<dd>
<p>Retrieves a path to the Rainmeter data file (Rainmeter.data).</p>
``` cs
internal void Initialize(Rainmeter.API rm)
{
// declare 'rmDataFile' as a string in global scope
if (rmDataFile == null) { rmDataFile = GetSettingsFile(); }
}
```
</dd>
<dt id="Log"><code>Log</code> <small><code>void Log(LogType type, string message)</code></small></dt>
<dd>
<p>Sends a message to the Rainmeter log.</p>
<p>
<ul>
<li><code>type</code> : Log level (<a href="https://github.com/rainmeter/rainmeter-plugin-sdk/blob/master/API/RainmeterAPI.cs#L80-L86">API.LogType.Error, API.LogType.Warning, API.LogType.Notice, or API.LogType.Debug</a>)</li>
<li><code>message</code> : Message to be logged.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
API.Log(API.LogType.Notice, "I am a 'notice' log message with a source");
```
</dd>
<dt id="LogF"><code>LogF</code> <small><code>void LogF(LogType type, string format, params string[] args)</code></small></dt>
<dd>
<p>Sends a formatted message to the Rainmeter log.</p>
<p>
<ul>
<li><code>type</code> : Log level (<a href="https://github.com/rainmeter/rainmeter-plugin-sdk/blob/master/API/RainmeterAPI.cs#L80-L86">API.LogType.Error, API.LogType.Warning, API.LogType.Notice, or API.LogType.Debug</a>)</li>
<li><code>format</code> : Formatted message to be logged, follows <a href="https://learn.microsoft.com/dotnet/standard/base-types/composite-formatting">composite formatting</a>.</li>
<li><code>args</code> : Comma separated list of arguments referenced in the formatted message.</li>
</ul>
</p>
<h3>Example:</h3>
``` cs
string notice = "notice";
API.LogF(API.LogType.Notice, "I am a '{0}' log message with a source", notice);
```
</dd>
</dl>