Create Instructions Widget

From X-Plane SDK
Revision as of 19:56, 15 September 2009 by BFeaver (Talk | contribs)

Jump to: navigation, search


/* PullDown Menu Creates Widget Window to Disply Plugin Instructions or Notes.

This example shows how to use a pulldown menu to create a widget window to display a list of instructions or notes. The widget window is distroyed by clicking a close box. There are several other widget window features that can be explored; please see the SDK documentation.

This content added by Blue Side Up Bob.

  • /

// #define XPLM200 = 1; This example does not require SDK2.0.

  1. include "XPLMUtilities.h"
  2. include "XPLMProcessing.h"
  3. include "XPLMDataAccess.h"
  4. include "XPLMMenus.h"
  5. include "XPWidgets.h"
  6. include "XPStandardWidgets.h"
  7. include <string.h>
  8. include <stdio.h>
  9. include <stdlib.h>

int gMenuItem;

char InstructionsText[50][200] = { " 1. Text line one.", " 2. Text.", " 3. Text.", " 4. Text.", " 5. Text.", " 6. Text.", "end"

};


XPWidgetID InstructionsWidget = NULL; XPWidgetID InstructionsWindow = NULL; XPWidgetID InstructionsTextWidget[50] = {NULL};

void InstructionsMenuHandler(void *, void *); void CreateInstructionsWidget(int x1, int y1, int w, int h); int InstructionsHandler(XPWidgetMessage inMessage, XPWidgetID inWidget, long inParam1, long inParam2);


PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { XPLMMenuID PluginMenu; int PluginSubMenuItem;

strcpy(outName, "Instructions"); strcpy(outSig, "BlueSideUpBob.Example.Instructions"); strcpy(outDesc, "A plugin to display an Instruction Text window from the pull down menu.");

// Create our menu PluginSubMenuItem = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "Instructions Plugin", NULL, 1); PluginMenu = XPLMCreateMenu("Instructions Plugin", XPLMFindPluginsMenu(), PluginSubMenuItem, InstructionsMenuHandler, NULL); XPLMAppendMenuItem(PluginMenu, "Instructions", (void *) +1, 1);

// Flag to tell us if the widget is being displayed. gMenuItem = 0;

return 1; }

PLUGIN_API void XPluginStop(void) {

if (gMenuItem == 1) { XPDestroyWidget(InstructionsWidget, 1); gMenuItem = 0; } }

PLUGIN_API int XPluginEnable(void) { return 1; }

PLUGIN_API void XPluginDisable(void) { }

PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, long inMsg, void * inParam) { }


void InstructionsMenuHandler(void * inMenuRef, void * inItemRef) { switch ( (int) inItemRef) {

case 1: if (gMenuItem == 0) { CreateInstructionsWidget(50, 712, 974, 662); //left, top, right, bottom. gMenuItem = 1; } else { if(!XPIsWidgetVisible(InstructionsWidget)) XPShowWidget(InstructionsWidget); } break; } }

// This will create our widget dialog. void CreateInstructionsWidget(int x, int y, int w, int h) { int Index;

int x2 = x + w; int y2 = y - h;

// Create the Main Widget window. InstructionsWidget = XPCreateWidget(x, y, x2, y2, 1, // Visible "INSTRUCTIONS Blue Side Up Bob", // desc 1, // root NULL, // no container xpWidgetClass_MainWindow);


// Add Close Box to the Main Widget. Other options are available. See the SDK Documentation. XPSetWidgetProperty(InstructionsWidget, xpProperty_MainWindowHasCloseBoxes, 1);


// Print each line of instructions. for (Index=0; Index < 50; Index++) { if(strcmp(InstructionsText[Index],"end") == 0) {break;}

// Create a text widget InstructionsTextWidget[Index] = XPCreateWidget(x+10, y-(30+(Index*20)) , x2-10, y-(42+(Index*20)), 1, // Visible InstructionsText[Index],// desc 0, // root InstructionsWidget, xpWidgetClass_Caption); }


// Register our widget handler XPAddWidgetCallback(InstructionsWidget, InstructionsHandler); }


// This is our widget handler. In this example we are only interested when the close box is pressed. int InstructionsHandler(XPWidgetMessage inMessage, XPWidgetID inWidget, long inParam1, long inParam2) { if (inMessage == xpMessage_CloseButtonPushed) { if (gMenuItem == 1) { XPHideWidget(InstructionsWidget); } return 1; }

return 0; }