diff --git a/xpcPlugin/XPCPlugin.cpp b/xpcPlugin/XPCPlugin.cpp index c6e1143..5dca72b 100755 --- a/xpcPlugin/XPCPlugin.cpp +++ b/xpcPlugin/XPCPlugin.cpp @@ -68,6 +68,7 @@ //#include "XPLMPlanes.h" #include "XPLMProcessing.h" #include "XPLMGraphics.h" +#include "xpcDrawing.h" #include "xpcPluginTools.h" #ifdef _WIN32 /* WIN32 SYSTEM */ @@ -124,6 +125,7 @@ int handleGETD(char *buf); int handleDREF(char *buf); int handleVIEW(); int handleDATA(char *buf, int buflen); +int handleTEXT(char *buf, int len); short handleInput(struct XPCMessage * theMessage); char setPOSI(short aircraft, float pos[3]); @@ -189,6 +191,8 @@ PLUGIN_API void XPluginDisable(void) closeUDP(recSocket); closeUDP(sendSocket); updateLog(logmsg,strlen(logmsg)); + + XPCClearMessage(); } PLUGIN_API int XPluginEnable(void) @@ -369,6 +373,10 @@ short handleInput(struct XPCMessage * theMessage) { handleDATA(theMessage->msg, theMessage->msglen); } + else if (strncmp(theMessage->head, "TEXT", 4) == 0) // Header = TEXT (Screen message) + { + handleTEXT(theMessage->msg, theMessage->msglen); + } else if ((strncmp(theMessage->head,"DSEL",4)==0) || (strncmp(theMessage->head,"USEL",4)==0)) // Header = DSEL/USEL (Select UDP Send) { sendBUF(theMessage->msg,theMessage->msglen); // Send to UDP @@ -409,9 +417,9 @@ short handleInput(struct XPCMessage * theMessage) { sendBUF(theMessage->msg,theMessage->msglen); // Send to UDP } - else if (strncmp(theMessage->head,"BOAT",4)==0) + else if (strncmp(theMessage->head, "BOAT", 4) == 0) { - sendBUF(theMessage->msg,theMessage->msglen); // Send to UDP + sendBUF(theMessage->msg, theMessage->msglen); // Send to UDP } else { //unrecognized header @@ -491,6 +499,31 @@ int handleSIMU(char buf[]) return 0; } +int handleTEXT(char *buf, int len) +{ + char msg[256] = { 0 }; + if (len < 14) + { + updateLog("[TEXT] ERROR: Length less than 14 bytes", 39); + return -1; + } + int msgLen = buf[13]; + if (msgLen == 0) + { + updateLog("[TEXT] Text cleared", 19); + XPCClearMessage(); + } + else + { + updateLog("[TEXT] Text set", 15); + int x = *((int*)(buf + 5)); + int y = *((int*)(buf + 9)); + strncpy(msg, buf + 14, msgLen); + XPCSetMessage(x, y, msg); + } + return 0; +} + char setDREF(XPLMDataRef theDREF, float floatarray[], short arrayStart, short arraySize) { XPLMDataTypeID dataType; diff --git a/xpcPlugin/XPlaneConnect/64/win.xpl b/xpcPlugin/XPlaneConnect/64/win.xpl index 4db8497..0c78063 100644 Binary files a/xpcPlugin/XPlaneConnect/64/win.xpl and b/xpcPlugin/XPlaneConnect/64/win.xpl differ diff --git a/xpcPlugin/XPlaneConnect/win.xpl b/xpcPlugin/XPlaneConnect/win.xpl index b0cd298..ae7d5cc 100644 Binary files a/xpcPlugin/XPlaneConnect/win.xpl and b/xpcPlugin/XPlaneConnect/win.xpl differ diff --git a/xpcPlugin/xpcDrawing.cpp b/xpcPlugin/xpcDrawing.cpp new file mode 100644 index 0000000..3cbbabf --- /dev/null +++ b/xpcPlugin/xpcDrawing.cpp @@ -0,0 +1,73 @@ +#include "xpcDrawing.h" +#include "XPLMDisplay.h" +#include "XPLMGraphics.h" + +//Internal Memory +static int msgEnabled = 0; +static int msgX = -1; +static int msgY = -1; +static char* msgVal = NULL; +static float rgb[4] = { 0.5F, 1.0F, 0.5F }; + +//Internal Functions +static int MessageDrawCallback(XPLMDrawingPhase inPhase, int inIsBefore, void * inRefcon) +{ + if (msgVal) + { + XPLMDrawString(rgb, msgX, msgY, msgVal, NULL, xplmFont_Basic); + } + return 1; +} + +//Public Functions +void XPCClearMessage() +{ + if (msgVal != NULL) + { + free(msgVal); + } + msgVal = NULL; + if (msgEnabled) + { + XPLMUnregisterDrawCallback(MessageDrawCallback, xplm_Phase_LastCockpit, 0, NULL); + msgEnabled = 0; + } +} + +void XPCSetMessage(int x, int y, char* msg) +{ + //Determine size of message and clear instead if the message string + //is empty. + size_t len = strlen(msg); + if (len == 0) + { + XPCClearMessage(); + return; + } + + //Try to size msgVal to fit the new message. If we fail for any + //reason, clear the message and bail. + if (msgVal != NULL) + { + msgVal = (char*)realloc(msgVal, len); + } + else + { + msgVal = (char*)malloc(len); + } + if (!msgVal) + { + XPCClearMessage(); + return; + } + + //Set the message, location, and enable drawing if necessary. + strcpy(msgVal, msg); + msgX = x < 0 ? 10 : x; + msgY = y < 0 ? 600 : y; + if (!msgEnabled) + { + XPLMRegisterDrawCallback(MessageDrawCallback, xplm_Phase_LastCockpit, 0, NULL); + msgEnabled = 1; + } +} \ No newline at end of file diff --git a/xpcPlugin/xpcDrawing.h b/xpcPlugin/xpcDrawing.h new file mode 100644 index 0000000..fe0d9d1 --- /dev/null +++ b/xpcPlugin/xpcDrawing.h @@ -0,0 +1,8 @@ +#ifndef xpcDrawing_h +#define xpcDrawing_h + +void XPCClearMessage(); + +void XPCSetMessage(int x, int y, char* msg); + +#endif \ No newline at end of file diff --git a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj index e16b698..0cdd781 100644 --- a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj +++ b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj @@ -97,10 +97,12 @@ + + diff --git a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj.filters b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj.filters index a0809e4..0082526 100644 --- a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj.filters +++ b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj.filters @@ -21,6 +21,9 @@ Header Files + + Header Files + @@ -32,6 +35,9 @@ Source Files + + Source Files +