/* * MyDrawWindowCallback * * This routine draws the window, showing the last keyboard stroke to be * recorded by our sniffer. * */ void MyDrawWindowCallback( XPLMWindowID inWindowID, void * inRefcon) { char str[50]; int left, top, right, bottom; float color[] = { 1.0, 1.0, 1.0 }; /* First get our window's location. */ XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); /* Draw a translucent dark box as our window outline. */ XPLMDrawTranslucentDarkBox(left, top, right, bottom); /* Take the last key stroke and form a descriptive string. * Note that ASCII values may be printed directly. Virtual key * codes are not ASCII and cannot be, but the utility function * XPLMGetVirtualKeyDescription provides a human-readable string * for each key. These strings may be multicharacter, e.g. 'ENTER' * or 'NUMPAD-0'. */ sprintf(str,"%d '%c' | %d '%s' (%c %c %c %c %c)", gChar, (gChar) ? gChar : '0', (long) (unsigned char) gVirtualKey, XPLMGetVirtualKeyDescription(gVirtualKey), (gFlags & xplm_ShiftFlag) ? 'S' : ' ', (gFlags & xplm_OptionAltFlag) ? 'A' : ' ', (gFlags & xplm_ControlFlag) ? 'C' : ' ', (gFlags & xplm_DownFlag) ? 'D' : ' ', (gFlags & xplm_UpFlag) ? 'U' : ' '); /* Draw the string into the window. */ XPLMDrawString(color, left + 5, top - 20, str, NULL, xplmFont_Basic); }
void MyDrawWindowCallback( XPLMWindowID inWindowID, void * inRefcon) { int left, top, right, bottom; float color[] = { 0.0, 0.0, 0.0 }; XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); if (getData != NULL) { //if (newData) parseJSON(); if (message != NULL) { XPLMDrawTranslucentDarkBox(left, top, right, bottom); /*char out[512]; sprintf(out, "SIZE: %d\n", (int) sizeof(message)); XPLMDebugString(out); char m[sizeof(message)]; strcpy(m, message[1], sizeof(message) - 1); m[sizeof(message) - 1] = '\0';*/ char *m = strndup(message+29, 29+50); XPLMDrawString(color, left + 50, top - 20, m, NULL, xplmFont_Basic); // TODO: start thread to reset getData after x seconds and hide the window } } }
/* * MyDrawingWindowCallback * * This callback does the work of drawing our window once per sim cycle each time * it is needed. It dynamically changes the text depending on the saved mouse * status. Note that we don't have to tell X-Plane to redraw us when our text * changes; we are redrawn by the sim continuously. * */ void MyDrawWindowCallback( XPLMWindowID inWindowID, void * inRefcon) { int left, top, right, bottom; float color[] = { 1.0, 1.0, 1.0 }; /* RGB White */ int xpndr_mode; float alt_agl, grnd_spd; char buffer[50]; xpndr_mode = XPLMGetDatai( ref_xpndr_mode ); alt_agl = XPLMGetDataf( ref_alt_agl ); grnd_spd = XPLMGetDataf( ref_grnd_spd ); /* First we get the location of the window passed in to us. */ XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); /* We now use an XPLMGraphics routine to draw a translucent dark * rectangle that is our window's shape. */ XPLMDrawTranslucentDarkBox(left, top, right, bottom); /* Finally we draw the text into the window, also using XPLMGraphics * routines. The NULL indicates no word wrapping. */ sprintf(buffer, "xpndr_mode: %d", xpndr_mode); XPLMDrawString(color, left + 5, top - 20, buffer, NULL, xplmFont_Basic); sprintf(buffer, "alt_agl: %d", (int)floor(alt_agl)); XPLMDrawString(color, left + 5, top - 40, buffer, NULL, xplmFont_Basic); sprintf(buffer, "grnd_spd: %d", (int)floor(grnd_spd)); XPLMDrawString(color, left + 5, top - 60, buffer, NULL, xplmFont_Basic); XPLMDrawString(color, left + 5, top - 80, debug_string, NULL, xplmFont_Basic); }
int MyHandleMouseClickCallback( XPLMWindowID inWindowID, int x, int y, XPLMMouseStatus inMouse, void * inRefcon) { static int dX = 0, dY = 0; static int width = 0, height = 0; int left, top, right, bottom; static int dragging = 0; XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); switch(inMouse) { case xplm_MouseDown: if (CoordInRect(x, y, left, top, right, bottom)) { dX = x - left; dY = y - top; width = right - left; height = bottom - top; dragging = 1; } break; case xplm_MouseDrag: if (dragging) { left = (x - dX); right = left + width; top = (y - dY); bottom = top + height; XPLMSetWindowGeometry(inWindowID, left, top, right, bottom); } break; case xplm_MouseUp: dragging = 0; break; } return 1; }
/* * MyDrawingWindowCallback * * This callback does the work of drawing our window once per sim cycle each time * it is needed. It dynamically changes the text depending on the saved mouse * status. Note that we don't have to tell X-Plane to redraw us when our text * changes; we are redrawn by the sim continuously. * */ void MyDrawWindowCallback( XPLMWindowID inWindowID, void * inRefcon) { int left, top, right, bottom; float color[] = { 1.0, 1.0, 1.0 }; /* RGB White */ /* First we get the location of the window passed in to us. */ XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); /* We now use an XPLMGraphics routine to draw a translucent dark * rectangle that is our window's shape. */ XPLMDrawTranslucentDarkBox(left, top, right, bottom); /* Finally we draw the text into the window, also using XPLMGraphics * routines. The NULL indicates no word wrapping. */ XPLMDrawString(color, left + 5, top - 20, (char*)(gClicked ? "I'm a plugin" : "Hello world"), NULL, xplmFont_Basic); }
void redraw(XPLMWindowID inWindowID) { pthread_mutex_lock(&lines_m); int space = 13; int left, top, right, bottom; float color[] = { 1.0, 1.0, 1.0 }; /* RGB White */ XPLMGetWindowGeometry(inWindowID, &left, &top, &right, &bottom); for(int i = 0; i < LINECOUNT; i++) { XPLMDrawString(color, left + 5, top - space, lines[i], NULL, /* no word-wrap */ xplmFont_Basic); space += OFFSET; } pthread_mutex_unlock(&lines_m); }
// MyHandleMouseClickCallback // Our key handling callback does nothing in this plugin. This is ok; // we simply don't use keyboard input. // Returning 1 tells X-Plane that we 'accepted' the click; otherwise // it would be passed to the next window behind us. If we accept // the click we get mouse moved and mouse up callbacks, if we don't // we do not get any more callbacks. It is worth noting that we // will receive mouse moved and mouse up even if the mouse is dragged // out of our window's box as long as the click started in our window's // box. int myHandleMouseClickCallback(XPLMWindowID inWindowID, int x, int y, XPLMMouseStatus inMouse, void*inRefcon) { //char temp[200]; static int dX = 0, dY = 0; static int Width = 0, Height = 0; int Left, Top, Right, Bottom; int mouse_pos_x; int mouse_pos_y; static int gDragging = 0; float mx, my; if(!gnsVisible) { return 0; } if (!gnsOpened) { return 0; } /// Get the windows current position XPLMGetWindowGeometry(inWindowID, &Left, &Top, &Right, &Bottom); switch(inMouse) { case xplm_MouseDown: /// Test for the mouse in the top part of the window dX = x - Left; dY = y - Bottom; mx = (float)dX/(float)(Right - Left); my = 1.0f - (float)dY/(float)(Top - Bottom); logMessageEx("### xplm_MouseDown %d,%d -> %f,%f", dX, dY, mx, my); // The window is left, top (0,0) right bottom (BEZEL_WIDTH, BEZEL_HEIGHT) mouse_pos_x = (int)(mx*gpGNSIntf->bezel_width); mouse_pos_y = (int)(my*gpGNSIntf->bezel_height); if (coordInRect(mouse_pos_x, mouse_pos_y, ®ionLCD)) { Width = Right - Left; Height = Top - Bottom; gDragging = 1; logMessageEx("### xplm_MouseDown gDragging=1"); } else { gGNSx30Proxy.sendMsg(0,mouse_pos_x ,mouse_pos_y ); logMessageEx("### xplm_MouseDown sendMsg(%d,%d)", mouse_pos_x ,mouse_pos_y); } break; case xplm_MouseDrag: /// We are dragging so update the window position if (gDragging) { Left+= (x - Left) - dX; Right = Left + Width; Bottom += (y - Bottom) - dY; Top = Bottom + Height; g_pos_x = Left; g_pos_y = Bottom; XPLMSetWindowGeometry(inWindowID, Left, Top, Right, Bottom); logMessageEx("### xplm_MouseDrag"); } break; case xplm_MouseUp: logMessageEx("### xplm_MouseUp gDragging=%d", gDragging); if(!gDragging) { dX = x - Left; dY = y - Bottom; mx = (float)dX/(float)(Right - Left); my = 1.0f - (float)dY/(float)(Top - Bottom); mouse_pos_x = (int)(mx*gpGNSIntf->bezel_width); mouse_pos_y = (int)(my*gpGNSIntf->bezel_height); gGNSx30Proxy.sendMsg(1, mouse_pos_x, mouse_pos_y); //logMessageEx("### xplm_MouseUp sendMsg(%d,%d)", mouse_pos_x, mouse_pos_y); } gDragging = 0; break; } return 1; }
void myMenuHandlerCallback(void* inMenuRef, void* inItemRef) { // This is our handler for the menu item. Our inItemRef is the refcon // we registered in our XPLMAppendMenuItem calls. It is either 0 or // 1 depending on which menu item is picked. long val = (long) inItemRef; int outLeft; int outTop; int outRight; int outBottom; if (MENU_OPEN == val) { if(!gnsOpened) { createGNSWindow(); gnsVisible = true; } } else if (MENU_SHOW == val) { if(gnsOpened) { gnsVisible = true; } else { gnsVisible = false; } } else if(MENU_HIDE == val) { if(gnsOpened) { gnsVisible = false; } } else if(MENU_CLOSE == val) { if(gnsOpened) { gnsVisible = false; XPLMCheckMenuItem(mySubMenu, myMenuItemWAASAutoipilot,xplm_Menu_Unchecked); autopilotConnected = false; destroyGNSWindow(); } } else if(MENU_SIZE_INC == val) { if(gnsVisible) { g_zoom+=ZOOM_STEP; XPLMGetWindowGeometry(gWindow, &outLeft, &outTop, &outRight, &outBottom); outTop = outBottom + (int)(gpGNSIntf->bezel_height*g_zoom); outRight = outLeft + (int)(gpGNSIntf->bezel_width*g_zoom); XPLMSetWindowGeometry(gWindow, outLeft, outTop, outRight, outBottom); initClickRegions(); } } else if(MENU_SIZE_DEC == val) { if(gnsVisible) { g_zoom-=ZOOM_STEP; XPLMGetWindowGeometry(gWindow, &outLeft, &outTop, &outRight, &outBottom); outTop = outBottom + (int)(gpGNSIntf->bezel_height*g_zoom); outRight = outLeft + (int)(gpGNSIntf->bezel_width*g_zoom); XPLMSetWindowGeometry(gWindow, outLeft, outTop, outRight, outBottom); initClickRegions(); } } else if(MENU_SIZE_RESTORE == val) { if(gnsVisible) { g_zoom=1.0; XPLMGetWindowGeometry(gWindow, &outLeft, &outTop, &outRight, &outBottom); outTop = outBottom + (int)(gpGNSIntf->bezel_height*g_zoom); outRight = outLeft + (int)(gpGNSIntf->bezel_width*g_zoom); XPLMSetWindowGeometry(gWindow, outLeft, outTop, outRight, outBottom); initClickRegions(); } } else if(MENU_AUTOPILOT_CONNECTED == val) { if(gnsOpened) { int state; XPLMCheckMenuItemState(mySubMenu, myMenuItemWAASAutoipilot, &state); if(xplm_Menu_Unchecked== state) { XPLMCheckMenuItem(mySubMenu, myMenuItemWAASAutoipilot,xplm_Menu_Checked); autopilotConnected = true; } else { XPLMCheckMenuItem(mySubMenu, myMenuItemWAASAutoipilot,xplm_Menu_Unchecked); autopilotConnected = false; } } } }