XPCWidget::XPCWidget( int inLeft, int inTop, int inRight, int inBottom, bool inVisible, const char * inDescriptor, bool inIsRoot, XPWidgetID inParent, XPWidgetClass inClass) : mWidget(NULL), mOwnsChildren(false), mOwnsWidget(true) { mWidget = XPCreateWidget( inLeft, inTop, inRight, inBottom, inVisible ? 1 : 0, inDescriptor, inIsRoot ? 1 : 0, inIsRoot ? NULL : inParent, inClass); XPSetWidgetProperty(mWidget, xpProperty_Object, reinterpret_cast<long>(this)); XPAddWidgetCallback(mWidget, WidgetCallback); }
/* Create the Widget dialog */ void CreateAboutWidget(int x, int y, int w, int h) { int Index; int x2 = x + w; int y2 = y - h; /* Create the Main Widget window */ AboutWidget = XPCreateWidget(x, y, x2, y2, 1, /* Visible */ "XPUDPng " VERSION, /* Description */ 1, /* root */ NULL, /* No container */ xpWidgetClass_MainWindow); /* Add Close Box to the Main Widget. Other options are available */ XPSetWidgetProperty(AboutWidget, xpProperty_MainWindowHasCloseBoxes, 1); /* Print each line of the About Text */ for (Index=0;Index < 50; Index++) { if(strcmp(AboutText[Index],"end") == 0) break; /* Create a text widget */ AboutTextWidget[Index] = XPCreateWidget(x+10, y-(30+(Index*20)), x2-10, y-(42+(Index*20)), 1, /* Visible */ AboutText[Index], /* Description */ 0, /* root */ AboutWidget, xpWidgetClass_Caption); } /* Register our widget handler */ XPAddWidgetCallback(AboutWidget, AboutHandler); }
// This routine is called by our popup menu when it is picked; we // have stored our widget in our refcon, so we save the new choice // and send a widget message. static void XPPopupWidgetProc(int inChoice, void * inRefcon) { if (inChoice != -1) { XPSetWidgetProperty(inRefcon, xpProperty_PopupCurrentItem, inChoice); XPSendMessageToWidget(inRefcon, xpMessage_PopupNewItemPicked, xpMode_UpChain, (long) inRefcon, inChoice); } }
XPCWidget::XPCWidget( XPWidgetID inWidget, bool inOwnsWidget) : mWidget(inWidget), mOwnsChildren(false), mOwnsWidget(inOwnsWidget) { XPSetWidgetProperty(mWidget, xpProperty_Object, reinterpret_cast<long>(this)); XPAddWidgetCallback(mWidget, WidgetCallback); }
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; } }
void create_dialog() { int x1, y1, x2, y2; if (ui_dialog_x == UI_POSITION_DEFAULT || ui_dialog_y == UI_POSITION_DEFAULT) { x1 = 0; y1 = ui_dialog_h - 1; x2 = ui_dialog_w - 1; y2 = 0; } else { // (x0, y0) top left dialog x1 = ui_dialog_x; y1 = ui_dialog_y + ui_dialog_h - 1; // (x2, y2) bottom right dialog x2 = x1 + ui_dialog_w - 1; y2 = ui_dialog_y; } ui_dialog_wid = XPCreateWidget(x1, y1, x2, y2, // dialog coordinates 0, // initially hide "EZPushback", // window title 1, // root NULL, // no container xpWidgetClass_MainWindow); if (ui_dialog_wid == NULL) { debug("could not create UI dialog"); return; } XPSetWidgetProperty(ui_dialog_wid, xpProperty_MainWindowType, xpMainWindowStyle_Translucent); XPSetWidgetProperty(ui_dialog_wid, xpProperty_MainWindowHasCloseBoxes, 0); // dialog text subwindow ui_dlg_text_wid = XPCreateWidget(x1, y1, x2, y2, 1, // show "", // text (set by set_dialog_text) 0, // not root ui_dialog_wid, // parent is dialog window xpWidgetClass_Caption); if (ui_dlg_text_wid == NULL) { debug("could not create UI text widget"); return; } XPSetWidgetProperty(ui_dlg_text_wid, xpProperty_CaptionLit, 1); int button_width = 100; int bx1 = x1 + ((ui_dialog_w - button_width) / 2); int bx2 = bx1 + button_width; ui_button_wid = XPCreateWidget(bx1, y2+20, bx2, y2+10, 0, // initially hide "", // button text (set by set_button_text) 0, // not root ui_dialog_wid, // parent is dialog window xpWidgetClass_Button); if (ui_button_wid == NULL) { debug("could not create UI button widget"); return; } XPSetWidgetProperty(ui_button_wid, xpProperty_ButtonType, xpPushButton); XPAddWidgetCallback(ui_dialog_wid, ui_dialog_handler); }