- Joined
- Mar 30, 2008
- Messages
- 450
- Reaction score
- 1
- Points
- 18
Hi all,
In an MFD I'm working on, I'm trying to allow the user to input a target base via oapiOpenInputBox, though I'm getting some strange behavior.
The goal in this simple case is to simply open a dialog box, have the user input a string, and then print the string to the MFD. I have the following code (I'm only showing relevant code here, not the full file contents):
MFDTemplate.cpp:
I would like the old string to be displayed on the MFD until the user types the new string and hits enter. I'm getting some bizarre behavior though:
1. Everything works normally the first time (presumably because testStr is initialized to NULL and there's nothing to display).
2. The second time and onward, whenever the button is pressed, testStr is set to "" when the line oapiOpenInputBox(... is executed. I tried to get around this using string placeholder, but placeholder is also set to "" when the oapiOpenInputBox line is called! This makes no sense, since placeholder is only assigned a value in one line of code.
Any help would be greatly appreciated.
In an MFD I'm working on, I'm trying to allow the user to input a target base via oapiOpenInputBox, though I'm getting some strange behavior.
The goal in this simple case is to simply open a dialog box, have the user input a string, and then print the string to the MFD. I have the following code (I'm only showing relevant code here, not the full file contents):
MFDTemplate.cpp:
Code:
#define STRICT
#define ORBITER_MODULE
#include "windows.h"
#include "orbitersdk.h"
#include "MFDTemplate.h"
// Global variables
int g_MFDmode; // identifier for new MFD mode
char* testStr;
char* placeholder;
bool MFDTemplate::ConsumeButton(int bt, int event) {
bool UpdateGlobalVariableTestFxn(void *id, char *str, void *user_data);
// Do nothing for click/hold
if (!(event &PANEL_MOUSE_LBDOWN))
{
return false;
}
if (bt == 0) {
placeholder = testStr;
oapiOpenInputBox("Test", UpdateGlobalVariableTestFxn, 0, 20, (void*)this);
return true;
}
return false;
}
bool UpdateGlobalVariableTestFxn(void *id, char *str, void *user_data) {
testStr= str;
return true;
}
bool MFDTemplate::Update (oapi::Sketchpad *skp)
{
Title (skp, "MFD Template");
skp->SetFont (font);
skp->SetTextAlign (oapi::Sketchpad::CENTER, oapi::Sketchpad::BASELINE);
skp->SetTextColor (0x00FFFF);
skp->Text (W/2, H/2, testStr, 12);
return true;
}
I would like the old string to be displayed on the MFD until the user types the new string and hits enter. I'm getting some bizarre behavior though:
1. Everything works normally the first time (presumably because testStr is initialized to NULL and there's nothing to display).
2. The second time and onward, whenever the button is pressed, testStr is set to "" when the line oapiOpenInputBox(... is executed. I tried to get around this using string placeholder, but placeholder is also set to "" when the oapiOpenInputBox line is called! This makes no sense, since placeholder is only assigned a value in one line of code.
Any help would be greatly appreciated.