mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-07-07 14:01:00 +02:00
feat(plugin): create a window in simulator
This commit is contained in:
parent
fe52804365
commit
33b9941f9a
@ -1,5 +1,6 @@
|
||||
#include "XPLMDisplay.h"
|
||||
#include "XPLMGraphics.h"
|
||||
#include <cstring>
|
||||
|
||||
#if IBM
|
||||
#include <windows.h>
|
||||
@ -31,16 +32,89 @@
|
||||
#error This is made to be compiled against the XPLM401 SDK
|
||||
#endif
|
||||
|
||||
PLUGIN_API int XPluginStart(char * outName, char * outSignature, char * outDescription) {
|
||||
return 0;
|
||||
// Opaque handle for the window
|
||||
static XPLMWindowID g_window;
|
||||
|
||||
// Callbacks for creating window
|
||||
void draw_window(XPLMWindowID in_window_id, void * in_refcon);
|
||||
int dummy_mouse_handler(XPLMWindowID in_window_id, int x, int y, int is_down, void * in_refcon) { return 0; }
|
||||
XPLMCursorStatus dummy_cursor_status_handler(XPLMWindowID in_window_id, int x, int y, void * in_refcon) { return xplm_CursorDefault; }
|
||||
int dummy_wheel_handler(XPLMWindowID in_window_id, int x, int y, int wheel, int clicks, void * in_refcon) { return 0; }
|
||||
void dummy_key_handler(XPLMWindowID in_window_id, char key, XPLMKeyFlags flags, char virtual_key, void * in_refcon, int losing_focus) { }
|
||||
|
||||
|
||||
PLUGIN_API int XPluginStart(char * outName, char * outSig, char * outDesc) {
|
||||
// Defining plugin details
|
||||
strcpy(outName, "Checklist Tester");
|
||||
strcpy(outSig, "io.anthonyberg.checklistplugin");
|
||||
strcpy(outDesc, "Plugin to connect and complete actions in X-Plane for the Checklist Tester");
|
||||
|
||||
XPLMCreateWindow_t params;
|
||||
params.structSize = sizeof(params);
|
||||
params.visible = 1;
|
||||
params.drawWindowFunc = draw_window;
|
||||
// Register mandatory "dummy" handlers
|
||||
params.handleMouseClickFunc = dummy_mouse_handler;
|
||||
params.handleRightClickFunc = dummy_mouse_handler;
|
||||
params.handleMouseWheelFunc = dummy_wheel_handler;
|
||||
params.handleKeyFunc = dummy_key_handler;
|
||||
params.handleCursorFunc = dummy_cursor_status_handler;
|
||||
params.refcon = nullptr;
|
||||
params.layer = xplm_WindowLayerFloatingWindows;
|
||||
// Newest X-Plane GUI styling
|
||||
params.decorateAsFloatingWindow = xplm_WindowDecorationRoundRectangle;
|
||||
|
||||
// Set the window's initial bounds
|
||||
int left, bottom, right, top;
|
||||
XPLMGetScreenBoundsGlobal(&left, &top, &right, &bottom);
|
||||
params.left = left + 50;
|
||||
params.bottom = bottom + 150;
|
||||
params.right = params.left + 200;
|
||||
params.top = params.bottom + 200;
|
||||
|
||||
g_window = XPLMCreateWindowEx(¶ms);
|
||||
|
||||
// Make window free floating window
|
||||
XPLMSetWindowPositioningMode(g_window, xplm_WindowPositionFree, -1);
|
||||
// Window resizing limits
|
||||
XPLMSetWindowResizingLimits(g_window, 200, 200, 300, 300);
|
||||
|
||||
XPLMSetWindowTitle(g_window, "Checklist Tester");
|
||||
|
||||
|
||||
return g_window != nullptr;
|
||||
}
|
||||
|
||||
PLUGIN_API int XPluginEnable(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, int inMsg, void * inParam) { }
|
||||
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFromWho, int inMessage, void * inParam) { }
|
||||
|
||||
PLUGIN_API void XPluginDisable(void) { }
|
||||
|
||||
PLUGIN_API void XPluginStop(void) { }
|
||||
PLUGIN_API void XPluginStop(void) {
|
||||
// Cleaning up the window
|
||||
XPLMDestroyWindow(g_window);
|
||||
g_window = nullptr;
|
||||
}
|
||||
|
||||
void draw_window(XPLMWindowID in_window_id, void * in_refcon) {
|
||||
// Set OpenGL state before drawing
|
||||
XPLMSetGraphicsState(
|
||||
0, // No fog
|
||||
0, // 0 texture units
|
||||
0, // No lighting
|
||||
0, // No alpha testing
|
||||
1, // Do alpha blend
|
||||
1, // Do depth testing
|
||||
0 // No depth writing
|
||||
);
|
||||
|
||||
int l, t, r, b;
|
||||
XPLMGetWindowGeometry(in_window_id, &l, &t, &r, &b);
|
||||
|
||||
float col_white[] = {1.0, 1.0, 1.0}; // RGB
|
||||
|
||||
XPLMDrawString(col_white, l + 10, t - 20, "Hello World!", nullptr, xplmFont_Proportional);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user