I write a program to learn english with sdl2 and I want to return a vlue from a function in another function every function have separate window and I want to close window after return this value how ?
I can't do it it's very dificult please help.
this is the code of my function:
int Lrecord::select_mic(SDL_Event* le)
{
int index = 100;
mWindow = SDL_CreateWindow("select mic", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 400, SDL_WINDOW_SHOWN);
if (mWindow == NULL)
printf("window error... %s", SDL_GetError());
SDL_Renderer *srender = SDL_CreateRenderer(mWindow, -1, SDL_RENDERER_ACCELERATED);
if (srender == NULL)
printf("renderer error %s", SDL_GetError());
mWindowID = SDL_GetWindowID(mWindow);
tex1.loadmedia(srender);
tex1.loadtext("Select your mic from the list by press its number: ", mTextColor, srender);
tex1.render(srender, 0);
//Get capture device count
tex1.gRecordingDeviceCount = SDL_GetNumAudioDevices(SDL_TRUE);
//No recording devices
if (tex1.gRecordingDeviceCount < 1)
{
printf("Unable to get audio capture device! SDL Error: %s\n", SDL_GetError());
}
//At least one device connected
else
{
//Cap recording device count
if (tex1.gRecordingDeviceCount > MAX_RECORDING_DEVICES)
{
tex1.gRecordingDeviceCount = MAX_RECORDING_DEVICES;
}
//Render device names
std::stringstream promptText;
for (int i = 0; i < tex1.gRecordingDeviceCount; ++i)
{
//Get capture device name
promptText.str("");
promptText << i << ": " << SDL_GetAudioDeviceName(i, SDL_TRUE);
//Set texture from name
tex1.loadtext(promptText.str().c_str(), mTextColor, srender);
tex1.render(srender, i + 1);
}
}
if (le->type == SDL_KEYDOWN)
{
//Handle key press from 0 to 9
if (le->key.keysym.sym >= SDLK_0 && le->key.keysym.sym <= SDLK_9)
{
//Get selection index
index = le->key.keysym.sym - SDLK_0;
}
}
return index;
}