Ejemplo n.º 1
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);
		}
	}
}                                   
int	myDrawGNSCallback(XPLMDrawingPhase inPhase, int inIsBefore, void *inRefcon)
{
    if(!gnsVisible)
    {
        return -1;
    }
    if(!gnsOpened)
    {
        return -1;
    }

    /// Tell Xplane what we are doing
    XPLMSetGraphicsState(0/*Fog*/, 1/*TexUnits*/, 0/*Lighting*/, 0/*AlphaTesting*/, 0/*AlphaBlending*/, 0/*DepthTesting*/, 0/*DepthWriting*/);

    /// Handle day/night
    glColor3f(1.0, 1.0, 1.0);

    // Draw Panel
    glPushMatrix();

    glTranslated(g_pos_x, g_pos_y, 0);
    glScalef(g_zoom, g_zoom, 0);

    XPLMBindTexture2d(gTexture[TEX_BEZEL], GL_TEXTURE_2D);
    glBegin(GL_QUADS);

    glTexCoord2f(1, 0.0f);
    glVertex2f((float)gpGNSIntf->bezel_width, 0);	// Bottom Right Of The Texture and Quad

    glTexCoord2f(0, 0.0f);
    glVertex2f(0, 0);	// Bottom Left Of The Texture and Quad

    glTexCoord2f(0, 1.0f);
    glVertex2f(0, (float)gpGNSIntf->bezel_height);	// Top Left Of The Texture and Quad

    glTexCoord2f(1, 1.0f);
    glVertex2f((float)gpGNSIntf->bezel_width, (float)gpGNSIntf->bezel_height);	// Top Right Of The Texture and Quad
    glEnd();

    XPLMBindTexture2d(gTexture[TEX_LCD], GL_TEXTURE_2D);

    if(gpGNSIntf->LCDUpdated)
    {
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, gpGNSIntf->lcd_width, gpGNSIntf->lcd_height, 0, GL_BGR, GL_UNSIGNED_BYTE, gpGNSIntf->LCD_data);

        gpGNSIntf->LCDUpdated = false;
    }

    //float gltexture_x = (float)gpGNSIntf->lcd_width/(float)gpGNSIntf->lcd_width	;
    //float gltexture_y = (float)gpGNSIntf->lcd_height/(float)gpGNSIntf->lcd_height;

    //glPopMatrix();
    //glPushMatrix();
    //glTranslated(g_pos_x, g_pos_y 0);
    //glScalef(g_zoom, g_zoom, 0);
    glTranslated(gpGNSIntf->bezel_lcd_left, gpGNSIntf->bezel_height - gpGNSIntf->bezel_lcd_height - gpGNSIntf->bezel_lcd_top, 0);

    glBegin(GL_QUADS);

    glTexCoord2f(1, 0.0f);
    glVertex2f((float)gpGNSIntf->bezel_lcd_width, 0);	// Bottom Right Of The Texture and Quad

    glTexCoord2f(0, 0.0f);
    glVertex2f(0, 0);	// Bottom Left Of The Texture and Quad

    glTexCoord2f(0, 1.0f);
    glVertex2f(0, (float)gpGNSIntf->bezel_lcd_height);	// Top Left Of The Texture and Quad

    glTexCoord2f(1, 1.0f);
    glVertex2f((float)gpGNSIntf->bezel_lcd_width, (float)gpGNSIntf->bezel_lcd_height);	// Top Right Of The Texture and Quad

    glEnd();

    glPopMatrix();

    glFlush();

    return 1;
}