bool save_prefs() { char *prefs; prefs = pluginPath("Xchecklist.prf"); if(!prefs){ xcDebug("Can't save prefs (NULL plugin path received).\n"); return false; } std::fstream fout; fout.open(prefs, std::ios::out); if(fout.is_open()){ //Store prefs version first fout<<"1"<<std::endl; XPGetWidgetGeometry(xCheckListWidget, &win_pos_x1, &win_pos_x2, &win_pos_y1, &win_pos_y2); fout<<win_pos_x1<<" "<<win_pos_x2<<" "<<win_pos_y1<<" "<<win_pos_y2<<std::endl; fout<<state[TRANSLUCENT]<<" "<<state[SHOW_CHECKLIST]<<" "<<state[COPILOT_ON]<<" " <<state[VOICE]<<" "<<state[AUTO_HIDE]<<std::endl; fout.close(); }else{ xcDebug("Can't open prefs for writing.\n"); free(prefs); return false; } free(prefs); return true; }
int get_dialog_y() { int y = 0; if (ui_dialog_wid) { XPGetWidgetGeometry(ui_dialog_wid, NULL, &y, NULL, NULL); } return y; }
int get_dialog_x() { int x = 0; if (ui_dialog_wid) { XPGetWidgetGeometry(ui_dialog_wid, &x, NULL, NULL, NULL); } return x; }
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; } }