-
Notifications
You must be signed in to change notification settings - Fork 0
/
xplane.cpp
164 lines (141 loc) · 3.86 KB
/
xplane.cpp
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
#include <stdio.h>
#include "XPLMProcessing.h"
#include "XPLMMenus.h"
#include "XPWidgets.h"
#include "XPWidgetDefs.h"
#include "XPWidgetUtils.h"
#include "XPStandardWidgets.h"
#include "Illuminate.h"
int g_MenuItem;
XPWidgetID IlluminateWidget = NULL;
XPWidgetID IlluminateWindow = NULL;
float IlluminateFLCB(float elapsedMe, float elapsedSim, int counter, void * refcon);
void IlluminateMenuHandler(void *, void*);
void CreateIlluminateWidget(int x1, int y1, int w, int h);
int IlluminateWidgetHandler(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2);
Illuminate illuminate;
PLUGIN_API int XPluginStart(
char * outName,
char * outSig,
char * outDesc)
{
XPLMMenuID PluginMenu;
int PluginSubMenuItem;
/* Provide our plugin's profile to the plugin system. */
strcpy(outName, "Illuminate");
strcpy(outSig, "edwardandrew.xplane.illuminate");
strcpy(outDesc, "Interactive keyboard illumination.");
// Create menu
PluginSubMenuItem = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "Illuminate", NULL, 1);
PluginMenu = XPLMCreateMenu("Illuminate", XPLMFindPluginsMenu(), PluginSubMenuItem, IlluminateMenuHandler, NULL);
XPLMAppendMenuItem(PluginMenu, "Reload Config", (void *)+1, 1);
XPLMAppendMenuItem(PluginMenu, "Settings", (void *)+2, 2);
g_MenuItem = 0;
illuminate = Illuminate();
if (!illuminate.Start()) {
return 0;
}
XPLMRegisterFlightLoopCallback(IlluminateFLCB, 0.0, NULL);
XPLMSetFlightLoopCallbackInterval(IlluminateFLCB, 0.01, 1, NULL);
return 1;}
PLUGIN_API void XPluginStop(void)
{
XPLMUnregisterFlightLoopCallback(IlluminateFLCB, NULL);
illuminate.Stop();
if (g_MenuItem == 1)
{
XPDestroyWidget(IlluminateWidget, 1);
g_MenuItem = 0;
}
}
PLUGIN_API void XPluginDisable(void)
{
XPLMUnregisterFlightLoopCallback(IlluminateFLCB, NULL);
illuminate.Disable();
if (g_MenuItem == 1)
{
XPDestroyWidget(IlluminateWidget, 1);
g_MenuItem = 0;
}
}
PLUGIN_API int XPluginEnable(void)
{
illuminate.Enable();
XPLMRegisterFlightLoopCallback(IlluminateFLCB, 0.0, NULL);
XPLMSetFlightLoopCallbackInterval(IlluminateFLCB, 0.01, 1, NULL);
return 1;
}
PLUGIN_API void XPluginReceiveMessage(
XPLMPluginID inFromWho,
int inMessage,
void * inParam)
{
}
float IlluminateFLCB(
float inElapsedSinceLastCall,
float inElapsedTimeSinceLastFlightLoop,
int inCounter,
void * inRefcon)
{
return illuminate.FLCB(
inElapsedSinceLastCall,
inElapsedTimeSinceLastFlightLoop,
inCounter,
inRefcon
);
}
void IlluminateMenuHandler(void * inMenuRef, void * inItemRef)
{
switch ((int)inItemRef)
{
case 1:
illuminate.ReloadConfig();
break;
default:
if (g_MenuItem == 0)
{
CreateIlluminateWidget(500, 500, 500, 500);
XPShowWidget(IlluminateWidget);
g_MenuItem = 1;
}
else
{
if (!XPIsWidgetVisible(IlluminateWidget)) {
XPShowWidget(IlluminateWidget);
}
}
break;
}
}
void CreateIlluminateWidget(int x, int y, int w, int h)
{
int Index;
int x2 = x + w;
int y2 = y - h;
IlluminateWidget = XPCreateWidget(x, y, x2, y2,
1,
"Illuminate",
1,
NULL,
xpWidgetClass_MainWindow);
XPSetWidgetProperty(IlluminateWidget, xpProperty_MainWindowHasCloseBoxes, 1);
//for (int i = 0; i < config.conditions.size(); i++)
//{
// Condition c = config.conditions[i];
// XPWidgetID btn = XPCreateWidget(x+10, y-(40*(i+1)), x + 400, y - (60 *(i +1)), 1, std::to_string(c.dataType).c_str(), 0, IlluminateWidget, xpWidgetClass_TextField);
// XPSetWidgetProperty(btn, xpTextEntryField, 0);
//}
XPAddWidgetCallback(IlluminateWidget, IlluminateWidgetHandler);
}
int IlluminateWidgetHandler(XPWidgetMessage inMessage, XPWidgetID inWidget, intptr_t inParam1, intptr_t inParam2)
{
if (inMessage == xpMessage_CloseButtonPushed)
{
if (g_MenuItem == 1)
{
XPHideWidget(IlluminateWidget);
}
return 1;
}
return 0;
}