PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { strcpy(outName, "ATIS Printer"); strcpy(outSig, "de.bwravencl.atis_printer"); strcpy(outDesc, "A plugin that prints ATIS data from the VATSIM network."); XPLMMenuID menu = XPLMCreateMenu("ACARS Weather", NULL, 0, MyHandleMenuCallback, 0); XPLMAppendMenuItem(menu, "Departure ATIS", (void *) 0, 1); XPLMAppendMenuItem(menu, "Destination ATIS", (void *) 1, 1); XPLMAppendMenuItem(menu, "Departure METAR", (void *) 2, 1); XPLMAppendMenuItem(menu, "Destination METAR", (void *) 3, 1); mainWindow = XPLMCreateWindow( WINDOW_POS_X, WINDOW_POS_Y, WINDOW_POS_X + WINDOW_WIDTH, WINDOW_POS_Y - WINDOW_HEIGHT, 1, MyDrawWindowCallback, MyHandleKeyCallback, MyHandleMouseClickCallback, NULL); return 1; }
/* * XPluginStart * * Our start routine registers our window and does any other initialization we * must do. * */ PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { /* First we must fill in the passed in buffers to describe our * plugin to the plugin-system. */ strcpy(outName, "HelloWorld"); strcpy(outSig, "xplanesdk.examples.helloworld"); strcpy(outDesc, "A plugin that makes a window."); /* Now we create a window. We pass in a rectangle in left, top, * right, bottom screen coordinates. We pass in three callbacks. */ gWindow = XPLMCreateWindow( 50, 600, 300, 200, /* Area of the window. */ 1, /* Start visible. */ MyDrawWindowCallback, /* Callbacks */ MyHandleKeyCallback, MyHandleMouseClickCallback, NULL); /* Refcon - not used. */ /* We must return 1 to indicate successful initialization, otherwise we * will not be called back again. */ return 1; }
PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { /* First set up our plugin info. */ strcpy(outName, "KeySniffer"); strcpy(outSig, "xplanesdk.examples.keysniffer"); strcpy(outDesc, "A plugin that makes a window."); /* Now create a new window. Pass in our three callbacks. */ gWindow = XPLMCreateWindow( 50, 750, 350, 700, /* Area of the window. */ 1, /* Start visible. */ MyDrawWindowCallback, /* Callbacks */ MyHandleKeyCallback, MyHandleMouseClickCallback, NULL); /* Refcon - not used. */ /* Finally register our key sniffer. */ XPLMRegisterKeySniffer( MyKeySniffer, /* Our callback. */ 1, /* Receive input before plugin windows. */ 0); /* Refcon - not used. */ return 1; }
/* * XPluginStart * * Our start routine registers our window and does any other initialization we * must do. * */ PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { /* First we must fill in the passed in buffers to describe our * plugin to the plugin-system. */ strcpy(outName, "DisPlugin"); strcpy(outSig, "edu.nps.moves.xplane"); strcpy(outDesc, "A plugin that sends DIS to reflect aircraft position"); /* Now we create a window. We pass in a rectangle in left, top, * right, bottom screen coordinates. We pass in three callbacks. */ gWindow = XPLMCreateWindow( 50, 600, 300, 200, /* Area of the window. */ 1, /* Start visible. */ MyDrawWindowCallback, /* Callbacks */ MyHandleKeyCallback, MyHandleMouseClickCallback, NULL); /* Refcon - not used. */ // Register a callback that will be executed every N seconds //gPlaneLat = XPLMFindDataRef("sim/flightmodel/position/latitude"); //gPlaneLon = XPLMFindDataRef("sim/flightmodel/position/longitude"); //gPlaneEl = XPLMFindDataRef("sim/flightmodel/position/elevation"); XPLMRegisterFlightLoopCallback( MyFlightLoopCallback, // Function to call 0.1, // Time interval NULL); // refcon not used // Call C++ capable functions return wrap_startPlugin(); /* We must return 1 to indicate successful initialization, otherwise we * will not be called back again. */ //return 1; }
// This routine just has to build the popup and then the window takes care of itself. void XPPickPopup( int inMouseX, int inMouseY, const char * inItems, int inCurrentItem, XPPopupPick_f inCallback, void * inRefcon) { int screenWidth, screenHeight; int fontWidth, fontHeight; // XPLMGetScreenSize(&screenWidth, &screenHeight); screenWidth = 1024; screenHeight = 768; XPLMGetFontDimensions(xplmFont_Menus, &fontWidth, &fontHeight, NULL); // Allocate mem for the structure and build a new window as big as teh screen. XPPopupMenu_t * info = new XPPopupMenu_t; XPLMWindowID windID = XPLMCreateWindow(0, screenHeight, screenWidth, 0, 1, XPPopupDrawWindowCB, XPPopupHandleKeyCB, XPPopupHandleMouseClickCB, info); if (inCurrentItem < 0) inCurrentItem = 0; /************ PARSE THE MENU STRING INTO MENU ITEMS **********/ // Parse the itemes into arrays. Remember how tall they are so // we can calculate the geometry. std::vector<int> heights; std::string items(inItems); while (!items.empty()) { std::string::size_type split = items.find(';'); if (split == items.npos) { split = items.size(); } std::string item = items.substr(0, split); if (item == "-") { info->items.push_back("-"); info->enabled.push_back(false); heights.push_back(2); } else { if (!item.empty() && item[0] == '(') { info->enabled.push_back(false); info->items.push_back(item.substr(1)); heights.push_back(12); } else { info->enabled.push_back(true); info->items.push_back(item); heights.push_back(12); } } if (item.size() == items.size()) break; else items = items.substr(split+1); } /************ PLACE THE ITEMS IN COLUMNS **********/ unsigned int menuWidth = 0; int leftOff = 0, topOff = 0; // Calculate the widest menu item anywhere. for (std::vector<std::string>::iterator iter = info->items.begin(); iter != info->items.end(); ++iter) if (iter->size() > menuWidth) menuWidth = iter->size(); menuWidth *= fontWidth; menuWidth += 35; int cols = 1; int itemsInCol = 0; int maxLen = 0; int ourItemLeft = 0, ourItemTop = 0; // Stack up each item, building new columns as necessary. for( unsigned int i = 0; i < heights.size(); ++i ) { itemsInCol++; info->lefts.push_back(leftOff); info->rights.push_back(leftOff + menuWidth); info->tops.push_back(topOff); info->bottoms.push_back(topOff - heights[i]); if (i == inCurrentItem) { ourItemLeft = leftOff; ourItemTop = topOff; } topOff -= heights[i]; if (maxLen > topOff) maxLen = topOff; if (topOff < -(screenHeight - 50)) { itemsInCol = 0; cols++; topOff = 0; leftOff += menuWidth; info->vstripes.push_back(leftOff); } } // If we built a new column but had no items for it, throw it out. if (itemsInCol == 0) { cols--; info->vstripes.pop_back(); } // Now place the window. Make sure to not let it go off screen. info->window = windID; info->left = inMouseX - ourItemLeft; info->top = inMouseY - ourItemTop; info->right = inMouseX + (menuWidth * cols) - ourItemLeft; info->bottom = inMouseY + maxLen - ourItemTop; if (info->right > (screenWidth-10)) { int deltaLeft = (info->right - (screenWidth-10)); info->right -= deltaLeft; info->left -= deltaLeft; } if (info->left < 10) { int deltaRight = 10 - info->left; info->right += deltaRight; info->left += deltaRight; } if (info->bottom < 10) { int deltaUp = 10 - info->bottom; info->bottom += deltaUp; info->top += deltaUp; } if (info->top > (screenHeight-30)) { int deltaDown = (info->top - (screenHeight-30)); info->top -= deltaDown; info->bottom -= deltaDown; } info->function = inCallback; info->ref = inRefcon; }
/* * XPluginStart */ PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { int rc; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* Inform X-Plane about the plugin */ strcpy(outName, "AP Interface " VERSION); strcpy(outSig, COMPANY "." PACKAGE "." PLUGIN); strcpy(outDesc, "Interface for autopilot"); /* Create buffer for console */ lines = (char **) malloc (sizeof(char *) * LINECOUNT); for(int i = 0; i < LINECOUNT; i++) { lines[i] = (char *) calloc (256, sizeof(char)); } pthread_mutex_init(&lines_m, NULL); /* Create Main Window */ gWindow = XPLMCreateWindow( 50, /* left */ 900, /* top */ 300, /* right */ 800, /* bottom */ 1, /* visible */ MyDrawWindowCallback, /* draw callback */ MyHandleKeyCallback, /* key handling callback */ MyHandleMouseClickCallback, /* mouseclick handling callback */ NULL); indicated_airspeed2 = XPLMFindDataRef("sim/flightmodel/position/indicated_airspeed2"); if(indicated_airspeed2 != NULL) printMsg("Indicated Airspeed 2 initialized"); alpha = XPLMFindDataRef("sim/flightmodel/position/alpha"); if(alpha != NULL) printMsg("AOA initialized"); phi = XPLMFindDataRef("sim/flightmodel/position/phi"); if(phi != NULL) printMsg("Roll initialized"); magpsi = XPLMFindDataRef("sim/flightmodel/position/magpsi"); if(magpsi != NULL) printMsg("Magnetometer initialized"); theta = XPLMFindDataRef("sim/flightmodel/position/theta"); if(theta != NULL) printMsg("Pitch initialized"); elevation = XPLMFindDataRef("sim/flightmodel/position/elevation"); if(elevation != NULL) printMsg("Elevation initialized"); throttle_ref = XPLMFindDataRef("sim/flightmodel/engine/ENGN_thro"); if(throttle_ref != NULL) printMsg("Throttle initialized"); override = XPLMFindDataRef("sim/operation/override/override_control_surfaces");
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc) { /* First set up our plugin info. */ strcpy(outName, "SmoothSailing 0.1"); strcpy(outSig, "Smooth Sailing by Colin Lieberman"); strcpy(outDesc, "Simple weather and visibility controls for convenience"); initConfig(); /* datarefs used for the transponder setting & checks to determine if i want to set it */ ref_xpndr_mode = XPLMFindDataRef("sim/cockpit/radios/transponder_mode"); ref_xpndr_setting = XPLMFindDataRef("sim/cockpit/radios/transponder_code"); ref_alt_agl = XPLMFindDataRef("sim/flightmodel/position/y_agl"); ref_grnd_spd = XPLMFindDataRef("sim/flightmodel/position/groundspeed"); /* dataref for visibility */ ref_visibility = XPLMFindDataRef("sim/weather/visibility_reported_m"); /* datarefs for cloud base */ ref_cloud_base0 = XPLMFindDataRef("sim/weather/cloud_base_msl_m[0]"); ref_cloud_base1 = XPLMFindDataRef("sim/weather/cloud_base_msl_m[1]"); ref_cloud_base2 = XPLMFindDataRef("sim/weather/cloud_base_msl_m[2]"); ref_cloud_tops0 = XPLMFindDataRef("sim/weather/cloud_tops_msl_m[0]"); ref_cloud_tops1 = XPLMFindDataRef("sim/weather/cloud_tops_msl_m[1]"); ref_cloud_tops2 = XPLMFindDataRef("sim/weather/cloud_tops_msl_m[2]"); ref_alt_msl = XPLMFindDataRef("sim/flightmodel/position/elevation"); /* datarefs for setting time */ ref_use_sys_time = XPLMFindDataRef("sim/time/use_system_time"); ref_local_time = XPLMFindDataRef("sim/time/local_time_sec"); ref_zulu_time = XPLMFindDataRef("sim/time/zulu_time_sec"); /* datarefs for wind */ ref_heading = XPLMFindDataRef("sim/flightmodel/position/psi"); ref_wind_speed0 = XPLMFindDataRef("sim/weather/wind_speed_kt[0]"); ref_wind_speed1 = XPLMFindDataRef("sim/weather/wind_speed_kt[1]"); ref_wind_speed2 = XPLMFindDataRef("sim/weather/wind_speed_kt[2]"); ref_wind_direction0 = XPLMFindDataRef("sim/weather/wind_direction_degt[0]"); ref_wind_direction1 = XPLMFindDataRef("sim/weather/wind_direction_degt[1]"); ref_wind_direction2 = XPLMFindDataRef("sim/weather/wind_direction_degt[2]"); ref_wind_altitude = XPLMFindDataRef("sim/weather/wind_altitude_msl_m[0]"); ref_wind_turb0 = XPLMFindDataRef("sim/weather/turbulence[0]"); if( DEBUG ) { debug_window = XPLMCreateWindow( 50, 600, 400, 200, /* Area of the window. */ 1, /* Start visible. */ MyDrawWindowCallback, /* Callbacks */ MyHandleKeyCallback, MyHandleMouseClickCallback, NULL); /* Refcon - not used. */ } // * Register our callback for every loop. Positive intervals // * are in seconds, negative are the negative of sim frames. Zero // * registers but does not schedule a callback for time. XPLMRegisterFlightLoopCallback( SmoothSailingCallback, // * Callback * CALLBACK_INTERVAL, // * Interval -1 every loop* NULL); // * refcon not used. * return 1; }