Example #1
0
/*
 * 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);

}
Example #2
0
	/// Draws the string set by the TEXT command.
	static int MessageDrawCallback(XPLMDrawingPhase inPhase, int inIsBefore, void * inRefcon)
	{
		const int LINE_HEIGHT = 16;
		XPLMDrawString(rgb, msgX, msgY, msgVal, NULL, xplmFont_Basic);
		int y = msgY - LINE_HEIGHT;
		for (size_t i = 0; i < newLineCount; ++i)
		{
			XPLMDrawString(rgb, msgX, y, msgVal + newLines[i], NULL, xplmFont_Basic);
			y -= LINE_HEIGHT;
		}
		return 1;
	}
Example #3
0
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
        }
    }
}
/*
 * 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);
}
Example #5
0
int DrawStrings(XPLMDrawingPhase inPhase, int inIsBefore, void* inRefcon)
{
	// unused
	(void)inPhase;
	(void)inIsBefore;
	(void)inRefcon;

	XPLMDrawString(fTextColour, 300, 740, szString, NULL, xplmFont_Basic);
	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);
}
Example #8
0
int		XPPopupButtonProc(
					XPWidgetMessage			inMessage,
					XPWidgetID				inWidget,
					long					inParam1,
					long					inParam2)
{
	// Select if we're in the background.
	if (XPUSelectIfNeeded(inMessage, inWidget, inParam1, inParam2, 1/*eat*/))	return 1;
	
	int fh, fv;
	int l, t, r, b;
	char	buf[4096];
	
	XPGetWidgetGeometry(inWidget, &l, &t, &r, &b);
	XPLMGetFontDimensions(xplmFont_Basic, &fh, &fv, NULL);
	
	int	curItem = XPGetWidgetProperty(inWidget, xpProperty_PopupCurrentItem, NULL);

	switch(inMessage) {
	case xpMsg_Create:
	case xpMsg_DescriptorChanged:
	case xpMsg_PropertyChanged:
		// If our data changes, reparse our descriptor to change our current item.
		if (inMessage != xpMsg_PropertyChanged || inParam1 == xpProperty_PopupCurrentItem)
		{
			XPGetWidgetDescriptor(inWidget, buf, sizeof(buf));
			char * p = buf;
			int picksToSkip = curItem;
			while (picksToSkip > 0)
			{
				while (*p && *p != ';') ++p;
				if (*p == 0) break;
				++p;
				--picksToSkip;
			}
			char * term = p;
			while (*term && *term != ';') ++term;
			// Store an offset and length of our descriptor that will show as our current text.
			XPSetWidgetProperty(inWidget, xpProperty_OffsetToCurrentItem, p - buf);
			XPSetWidgetProperty(inWidget, xpProperty_CurrentItemLen, term - p);			
			XPSetWidgetProperty(inWidget, xpProperty_Enabled, 1);
		}
		return 1;
	case xpMsg_Draw:
		{
			float		white [4];
			float		gray [4];
			
			int itemOffset = XPGetWidgetProperty(inWidget, xpProperty_OffsetToCurrentItem, NULL);
			int itemLen = XPGetWidgetProperty(inWidget, xpProperty_CurrentItemLen, NULL);

			// Drawing time.  Find the sim version once.
			static	int sim;
			static float firstTime = true;
			static	int	charWidth;
			if (firstTime)
			{
				firstTime = false;
				int	plugin;
				XPLMHostApplicationID id;
				XPLMGetVersions(&sim, &plugin, &id);
				
				XPLMGetFontDimensions(xplmFont_Basic, &charWidth, NULL, NULL);
			}
			
			// If we are version 7 of the sim, use Sergio's great new popup item.
			// Since there is no UI element code for this, we must draw it by hand!
			if (sim >= 700)
			{
/*				XPLMSetGraphicsState(0, 1, 0,  0, 1,  0, 0);
				XPLMBindTexture2d(XPLMGetTexture(xplm_Tex_GeneralInterface), 0);
				glColor4f(1.0, 1.0, 1.0, 1.0);*/
				
				int center = (t + b) / 2;

/// This is in the new widgets lib				
/*				XPDrawElement(	l - 4, center - 13, r + 4, center + 13, 
								xpElement_PushButtonWithSelector, 0);
*/
				XPDrawElement(	l - 4, center - 13, r + 4, center + 13, 
								xpElement_PushButton, 0);
				
/*
				// These are offsets for the popup button in the texture
				DrawStretchedQuad(l - 4, center - 13, r + 4, center + 13, 
									357, 357+12,357+12+30, 357+12+30+26, 
									486, 486+8, 486+8+6, 486+8+6+12);*/
		
			} else 
				// If we are version 6, use a window drag bar as a fake popup button.
				XPDrawElement(l+2, b, r-2, t, xpElement_WindowDragBarSmooth, 0);

			// Now draw the button label.
			long	titleLen = XPGetWidgetDescriptor(inWidget, buf, sizeof(buf));

			SetupAmbientColor(xpColor_MenuText, white);
			SetupAmbientColor(xpColor_MenuTextDisabled, gray);
			
			if (charWidth)
			{
				long	maxCharCapacity = (r - l - 24) / charWidth;
				if (itemLen > maxCharCapacity)
					itemLen = maxCharCapacity;
			}
			
			buf[itemOffset + itemLen] = 0;
			if (buf[itemOffset] == '(')	++itemOffset;
			titleLen = strlen(buf + itemOffset);
			
			XPLMDrawString(XPGetWidgetProperty(inWidget, xpProperty_Enabled, 0) ? white : gray, l + 4, //(l + r) / 2 - (fh * titleLen / 2), 
						(t + b) / 2 - (fv / 2) + 2,
						buf + itemOffset, NULL, xplmFont_Basic);
					
		}
		return 1;
	case xpMsg_MouseDown:
		// If the mouse is clicked, do a popup pick.
		if (XPGetWidgetProperty(inWidget, xpProperty_Enabled, 0))
		{
			XPGetWidgetDescriptor(inWidget, buf, sizeof(buf));
			
			XPPickPopup(l, t, buf, XPGetWidgetProperty(inWidget, xpProperty_PopupCurrentItem, NULL),
								XPPopupWidgetProc, inWidget);
			return 1;
		}
	default:
		return 0;
	}	
}				
Example #9
0
// This is the drawing hook for a popup menu.
static void XPPopupDrawWindowCB(
                                   XPLMWindowID         inWindowID,    
                                   void *               inRefcon)
{
	XPPopupMenu_t * pmenu = (XPPopupMenu_t *) inRefcon;
	int	x, y;
	XPLMGetMouseLocation(&x, &y);

	// This is the index number of the currently selected item, based
	// on where the mouse is.
	int menu_offset = XPItemForHeight(pmenu, x, y);	

	//unused: int	item_top = pmenu->top;
	unsigned int n;
	XPLMSetGraphicsState(0, 0, 0,  0, 0,  0, 0);
	
	// Draw any vertical stripes that must be drawn for multi-column menus.
	for (n = 0; n < pmenu->vstripes.size(); ++n)
	{
		SetupAmbientColor(xpColor_MenuDarkTinge, NULL);
		glBegin(GL_LINES);
		glVertex2i(pmenu->left + pmenu->vstripes[n] - 1, pmenu->top);
		glVertex2i(pmenu->left + pmenu->vstripes[n] - 1, pmenu->bottom);
		glEnd();
		SetupAmbientColor(xpColor_MenuLiteTinge, NULL);
		glBegin(GL_LINES);
		glVertex2i(pmenu->left + pmenu->vstripes[n], pmenu->top);
		glVertex2i(pmenu->left + pmenu->vstripes[n], pmenu->bottom);
		glEnd();	
	}
	
	// Now draw each item.
	for (n = 0; n < pmenu->items.size(); ++n)
	{
		// Calcualte the item rect in global coordinates.
		int item_bottom = pmenu->bottoms[n] + pmenu->top;
		int item_top    = pmenu->tops[n] + pmenu->top;
		int item_left   = pmenu->lefts[n] + pmenu->left;
		int item_right  = pmenu->rights[n] + pmenu->left;
		
		XPDrawElement(	item_left,
						item_bottom,
						item_right,
						item_top, 
						(menu_offset == n && pmenu->enabled[n])? xpElement_PushButtonLit : xpElement_PushButton, 0);

		if (!pmenu->enabled[n] && pmenu->items[n] == "-")
		{
			// Draw two lines for dividers.
			XPLMSetGraphicsState(0, 0, 0,  0, 0,  0, 0);
			SetupAmbientColor(xpColor_MenuLiteTinge, NULL);
			glBegin(GL_LINE_STRIP);
			glVertex2i(item_left, item_top - 1);
			glVertex2i(item_right, item_top - 1);
			glEnd();
			SetupAmbientColor(xpColor_MenuDarkTinge, NULL);
			glBegin(GL_LINE_STRIP);
			glVertex2i(item_left, item_top);
			glVertex2i(item_right, item_top);
			glEnd();
		} else {
			// If we are hilited, draw the hilite bkgnd.
			if (menu_offset == n && pmenu->enabled[n])
			{
				SetAlphaLevels(0.25);
				XPLMSetGraphicsState(0, 0, 0,  0, 1, 0, 0);
				SetupAmbientColor(xpColor_MenuHilite, NULL);
				SetAlphaLevels(1.0);
				glBegin(GL_QUADS);
				glVertex2i(item_left, item_top);
				glVertex2i(item_right, item_top);
				glVertex2i(item_right, item_bottom);
				glVertex2i(item_left, item_bottom);
				glEnd();						
			}
			
			// Draw the text for the menu item, taking into account
			// disabling as a color.
			float	text[3];
			SetupAmbientColor(pmenu->enabled[n] ? xpColor_MenuText : xpColor_MenuTextDisabled, text);
			
			XPLMDrawString(text,
						item_left + 18, item_bottom + 2,
						const_cast<char *>(pmenu->items[n].c_str()), NULL, xplmFont_Menus);
		}
	}
}