Added plugin support for drawing messages to screen.

- Either a single string will be drawn to screen, or nothing will be drawn.
 - Intelligently registers and unregisters drawing callback to minimize overhead when no message is being displayed.
 - Currently does not support newline characters (\r or \n). Newlines will cause text to be drawn overlapped.
This commit is contained in:
Jason Watkins
2015-04-07 14:47:57 -07:00
parent 38ae9e699d
commit 453ea65619
7 changed files with 124 additions and 2 deletions

View File

@@ -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;