mirror of
https://github.com/smyalygames/checklist-tester.git
synced 2025-05-17 22:14:13 +02:00
feat(plugin): add menu and allow window to toggle
This commit is contained in:
parent
50515cc1ec
commit
0b8c2410c7
@ -1,6 +1,9 @@
|
||||
file(GLOB PLUGIN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
|
||||
file(GLOB PLUGIN_HDR "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
|
||||
file(GLOB UI_SRC "${CMAKE_CURRENT_SOURCE_DIR}/ui/*.cpp")
|
||||
file(GLOB UI_HDR "${CMAKE_CURRENT_SOURCE_DIR}/ui/*.h")
|
||||
|
||||
add_library(XPL-Checklist-Connector MODULE ${PLUGIN_SRC})
|
||||
add_library(XPL-Checklist-Connector MODULE ${PLUGIN_SRC} ${PLUGIN_HDR} ${UI_SRC} ${UI_HDR})
|
||||
|
||||
# Set compile options for XPLM
|
||||
add_definitions(-DXPLM200=1 -DXPLM210=1 -DXPLM300=1 -DXPLM301=1 -DXPLM302=1 -DXPLM303=1 -DXPLM401=1)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "XPLMDisplay.h"
|
||||
#include "XPLMGraphics.h"
|
||||
#include "XPLMPlugin.h"
|
||||
#include "ui/ui.h"
|
||||
#include <cstring>
|
||||
|
||||
#if IBM
|
||||
@ -32,16 +32,6 @@
|
||||
#error This is made to be compiled against the XPLM401 SDK
|
||||
#endif
|
||||
|
||||
// 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
|
||||
@ -49,40 +39,9 @@ PLUGIN_API int XPluginStart(char * outName, char * outSig, char * outDesc) {
|
||||
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;
|
||||
UI::Init();
|
||||
|
||||
// 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;
|
||||
return 1;
|
||||
}
|
||||
|
||||
PLUGIN_API int XPluginEnable(void) {
|
||||
@ -94,27 +53,6 @@ PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFromWho, int inMessage, voi
|
||||
PLUGIN_API void XPluginDisable(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);
|
||||
// Cleaning up UI components
|
||||
UI::Destroy();
|
||||
}
|
||||
|
29
plugin/src/plugin/ui/menu.cpp
Normal file
29
plugin/src/plugin/ui/menu.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <cstring>
|
||||
#include "XPLMMenus.h"
|
||||
#include "window.h"
|
||||
#include "menu.h"
|
||||
|
||||
|
||||
XPLMMenuID g_menu_id;
|
||||
int g_menu_container_idx;
|
||||
|
||||
void menu_handler(void *, void *);
|
||||
|
||||
int create_menu() {
|
||||
g_menu_container_idx = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "Checklist Tester", nullptr, 0);
|
||||
g_menu_id = XPLMCreateMenu("Checklist Tester", XPLMFindPluginsMenu(), g_menu_container_idx, menu_handler, nullptr);
|
||||
|
||||
XPLMAppendMenuItem(g_menu_id, "Open Checklist Tester", (void *)"Open Menu", 1);
|
||||
|
||||
return g_menu_id != nullptr;
|
||||
}
|
||||
|
||||
void destroy_menu() {
|
||||
XPLMDestroyMenu(g_menu_id);
|
||||
}
|
||||
|
||||
void menu_handler(void * in_menu_ref, void * in_item_ref) {
|
||||
if(!strcmp((const char *)in_item_ref, "Open Menu")) {
|
||||
toggle_window();
|
||||
}
|
||||
}
|
8
plugin/src/plugin/ui/menu.h
Normal file
8
plugin/src/plugin/ui/menu.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef XPL_CHECKLIST_CONNECTOR_MENU_H
|
||||
#define XPL_CHECKLIST_CONNECTOR_MENU_H
|
||||
|
||||
int create_menu();
|
||||
|
||||
void destroy_menu();
|
||||
|
||||
#endif //XPL_CHECKLIST_CONNECTOR_MENU_H
|
14
plugin/src/plugin/ui/ui.cpp
Normal file
14
plugin/src/plugin/ui/ui.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "menu.h"
|
||||
#include "window.h"
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
void UI::Init() {
|
||||
create_menu();
|
||||
create_window();
|
||||
};
|
||||
|
||||
void UI::Destroy() {
|
||||
destroy_window();
|
||||
destroy_menu();
|
||||
}
|
10
plugin/src/plugin/ui/ui.h
Normal file
10
plugin/src/plugin/ui/ui.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef XPL_CHECKLIST_CONNECTOR_UI_H
|
||||
#define XPL_CHECKLIST_CONNECTOR_UI_H
|
||||
|
||||
class UI {
|
||||
public:
|
||||
static void Init();
|
||||
static void Destroy();
|
||||
};
|
||||
|
||||
#endif //XPL_CHECKLIST_CONNECTOR_UI_H
|
79
plugin/src/plugin/ui/window.cpp
Normal file
79
plugin/src/plugin/ui/window.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
#include "XPLMDisplay.h"
|
||||
#include "XPLMGraphics.h"
|
||||
#include "window.h"
|
||||
|
||||
|
||||
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) { }
|
||||
|
||||
int create_window() {
|
||||
XPLMCreateWindow_t params;
|
||||
params.structSize = sizeof(params);
|
||||
params.visible = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void toggle_window() {
|
||||
int state = XPLMGetWindowIsVisible(g_window);
|
||||
XPLMSetWindowIsVisible(g_window, !state);
|
||||
}
|
||||
|
||||
void destroy_window() {
|
||||
XPLMDestroyWindow(g_window);
|
||||
g_window = nullptr;
|
||||
}
|
10
plugin/src/plugin/ui/window.h
Normal file
10
plugin/src/plugin/ui/window.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef XPL_CHECKLIST_CONNECTOR_WINDOW_H
|
||||
#define XPL_CHECKLIST_CONNECTOR_WINDOW_H
|
||||
|
||||
int create_window();
|
||||
|
||||
void toggle_window();
|
||||
|
||||
void destroy_window();
|
||||
|
||||
#endif //XPL_CHECKLIST_CONNECTOR_WINDOW_H
|
Loading…
x
Reference in New Issue
Block a user